diff options
Diffstat (limited to 'src/demuxers/demux_matroska.c')
-rw-r--r-- | src/demuxers/demux_matroska.c | 161 |
1 files changed, 54 insertions, 107 deletions
diff --git a/src/demuxers/demux_matroska.c b/src/demuxers/demux_matroska.c index 2bd8f3540..4a99492ef 100644 --- a/src/demuxers/demux_matroska.c +++ b/src/demuxers/demux_matroska.c @@ -15,9 +15,7 @@ * * 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 - * - * $Id: demux_matroska.c,v 1.53 2007/03/12 16:27:21 dgp85 Exp $ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA * * demultiplexer for matroska streams * @@ -25,7 +23,6 @@ * more decoders init * metadata * non seekable input plugins support - * */ #ifdef HAVE_CONFIG_H @@ -45,10 +42,10 @@ /* #define LOG */ -#include "xine_internal.h" -#include "xineutils.h" -#include "demux.h" -#include "buffer.h" +#include <xine/xine_internal.h> +#include <xine/xineutils.h> +#include <xine/demux.h> +#include <xine/buffer.h> #include "bswap.h" #include "ebml.h" @@ -68,13 +65,6 @@ #define MAX(a, b) ((a)>(b)?(a):(b)) #endif -/* FOURCC will be manipulated using machine endian */ -#ifdef WORDS_BIGENDIAN -#define meFOURCC BE_FOURCC -#else -#define meFOURCC LE_FOURCC -#endif - typedef struct { int track_num; off_t *pos; @@ -617,8 +607,7 @@ static void init_codec_real(demux_matroska_t *this, matroska_track_t * track) { track->fifo->put (track->fifo, buf); } - -static void init_codec_vorbis(demux_matroska_t *this, matroska_track_t *track) { +static void init_codec_xiph(demux_matroska_t *this, matroska_track_t *track) { buf_element_t *buf; uint8_t nb_lace; int frame[3]; @@ -790,7 +779,7 @@ static int vobsub_parse_custom_colors(matroska_track_t *t, const char *start) { use_custom_colors = 1; else if (!strncasecmp(start, "OFF", 3) || (*start == '0')) use_custom_colors = 0; - lprintf("VobSub custom colors: %s\n", use_custom_colors ? "ON" : "OFF"); + lprintf("VobSub custom colours: %s\n", use_custom_colors ? "ON" : "OFF"); if ((start = strstr(start, "colors:")) != NULL) { start += 7; while (isspace(*start)) @@ -804,7 +793,7 @@ static int vobsub_parse_custom_colors(matroska_track_t *t, const char *start) { } if (i == 4) { t->sub_track->custom_colors = 4; - lprintf("VobSub colors: %06x,%06x,%06x,%06x\n", t->sub_track->colors[0], + lprintf("VobSub colours: %06x,%06x,%06x,%06x\n", t->sub_track->colors[0], t->sub_track->colors[1], t->sub_track->colors[2], t->sub_track->colors[3]); } @@ -864,7 +853,7 @@ static void init_codec_vobsub(demux_matroska_t *this, things_found |= vobsub_parse_size(track, start); else if (!strncasecmp(start, "palette:", 8)) things_found |= vobsub_parse_palette(track, start); - else if (!strncasecmp(start, "custom colors:", 14)) + else if (!strncasecmp(start, "custom colours:", 14)) things_found |= vobsub_parse_custom_colors(track, start); else if (!strncasecmp(start, "forced subs:", 12)) things_found |= vobsub_parse_forced_subs(track, start); @@ -1192,18 +1181,22 @@ static int parse_track_entry(demux_matroska_t *this, matroska_track_t *track) { case MATROSKA_ID_TR_CODECID: { char *codec_id = malloc (elem.len + 1); lprintf("CodecID\n"); - if (!ebml_read_ascii(ebml, &elem, codec_id)) + if (!ebml_read_ascii(ebml, &elem, codec_id)) { + free(codec_id); return 0; + } codec_id[elem.len] = '\0'; track->codec_id = codec_id; } break; case MATROSKA_ID_TR_CODECPRIVATE: { - char *codec_private = malloc (elem.len); + uint8_t *codec_private = malloc (elem.len); lprintf("CodecPrivate\n"); - if (!ebml_read_binary(ebml, &elem, codec_private)) + if (!ebml_read_binary(ebml, &elem, codec_private)) { + free(codec_private); return 0; + } track->codec_private = codec_private; track->codec_private_len = elem.len; } @@ -1212,8 +1205,10 @@ static int parse_track_entry(demux_matroska_t *this, matroska_track_t *track) { case MATROSKA_ID_TR_LANGUAGE: { char *language = malloc (elem.len + 1); lprintf("Language\n"); - if (!ebml_read_ascii(ebml, &elem, language)) + if (!ebml_read_ascii(ebml, &elem, language)) { + free(language); return 0; + } language[elem.len] = '\0'; track->language = language; } @@ -1320,7 +1315,7 @@ static int parse_track_entry(demux_matroska_t *this, matroska_track_t *track) { /* create a bitmap info header struct for MPEG 4 */ bih = malloc(sizeof(xine_bmiheader) + track->codec_private_len); bih->biSize = sizeof(xine_bmiheader) + track->codec_private_len; - bih->biCompression = meFOURCC('M', 'P', '4', 'S'); + bih->biCompression = ME_FOURCC('M', 'P', '4', 'S'); bih->biWidth = track->video_track->pixel_width; bih->biHeight = track->video_track->pixel_height; _x_bmiheader_le2me(bih); @@ -1341,7 +1336,7 @@ static int parse_track_entry(demux_matroska_t *this, matroska_track_t *track) { /* create a bitmap info header struct for h264 */ bih = malloc(sizeof(xine_bmiheader) + track->codec_private_len); bih->biSize = sizeof(xine_bmiheader) + track->codec_private_len; - bih->biCompression = meFOURCC('a', 'v', 'c', '1'); + bih->biCompression = ME_FOURCC('a', 'v', 'c', '1'); bih->biWidth = track->video_track->pixel_width; bih->biHeight = track->video_track->pixel_height; _x_bmiheader_le2me(bih); @@ -1380,6 +1375,10 @@ static int parse_track_entry(demux_matroska_t *this, matroska_track_t *track) { init_codec = init_codec_real; } else if (!strcmp(track->codec_id, MATROSKA_CODEC_ID_V_MJPEG)) { + } else if (!strcmp(track->codec_id, MATROSKA_CODEC_ID_V_THEORA)) { + lprintf("MATROSKA_CODEC_ID_V_THEORA\n"); + track->buf_type = BUF_VIDEO_THEORA_RAW; + init_codec = init_codec_xiph; } else if ((!strcmp(track->codec_id, MATROSKA_CODEC_ID_A_MPEG1_L1)) || (!strcmp(track->codec_id, MATROSKA_CODEC_ID_A_MPEG1_L2)) || (!strcmp(track->codec_id, MATROSKA_CODEC_ID_A_MPEG1_L3))) { @@ -1404,7 +1403,7 @@ static int parse_track_entry(demux_matroska_t *this, matroska_track_t *track) { lprintf("MATROSKA_CODEC_ID_A_VORBIS\n"); track->buf_type = BUF_AUDIO_VORBIS; - init_codec = init_codec_vorbis; + init_codec = init_codec_xiph; } else if (!strcmp(track->codec_id, MATROSKA_CODEC_ID_A_ACM)) { xine_waveformatex *wfh; @@ -1661,10 +1660,10 @@ static int parse_cue_point(demux_matroska_t *this) { this->num_indexes++; } if ((index->num_entries % 1024) == 0) { - index->pos = (off_t *)realloc(index->pos, sizeof(off_t) * - (index->num_entries + 1024)); - index->timecode = (off_t *)realloc(index->timecode, sizeof(uint64_t) * - (index->num_entries + 1024)); + index->pos = realloc(index->pos, sizeof(off_t) * + (index->num_entries + 1024)); + index->timecode = realloc(index->timecode, sizeof(uint64_t) * + (index->num_entries + 1024)); } index->pos[index->num_entries] = pos; index->timecode[index->num_entries] = timecode; @@ -1750,10 +1749,7 @@ static int parse_tags(demux_matroska_t *this) { static void alloc_block_data (demux_matroska_t *this, int len) { /* memory management */ if (this->block_data_size < len) { - if (this->block_data) - this->block_data = realloc(this->block_data, len); - else - this->block_data = malloc(len); + this->block_data = realloc(this->block_data, len); this->block_data_size = len; } } @@ -1846,11 +1842,11 @@ 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_uint(this, data, &track_num))) + if (!(num_len = parse_ebml_sint(this, data, &track_num))) return 0; data += num_len; - timecode_diff = (int)BE_16(data); + timecode_diff = (int)_X_BE_16(data); data += 2; flags = *data; @@ -1860,6 +1856,7 @@ static int parse_block (demux_matroska_t *this, uint64_t block_size, gap = flags & 1; lacing = (flags >> 1) & 0x3; +/*fprintf(stderr, "lacing: %x\n", lacing);*/ if (!find_track_by_id(this, (int)track_num, &track)) { xprintf(this->stream->xine, XINE_VERBOSITY_LOG, @@ -1977,7 +1974,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_uint(this, data, &tmp))) + if (!(num_len = parse_ebml_sint(this, data, &tmp))) return 0; data += num_len; block_size_left -= num_len; frame[0] = (int) tmp; @@ -2678,37 +2675,26 @@ static void demux_matroska_dispose (demux_plugin_t *this_gen) { /* free tracks */ for (i = 0; i < this->num_tracks; i++) { - matroska_track_t *track; - - track = this->tracks[i]; - if (track->language) - free (track->language); - if (track->codec_id) - free (track->codec_id); - if (track->codec_private) - free (track->codec_private); - if (track->video_track) - free (track->video_track); - if (track->audio_track) - free (track->audio_track); - if (track->sub_track) - free (track->sub_track); + matroska_track_t *const track = this->tracks[i]; + + free (track->language); + free (track->codec_id); + free (track->codec_private); + free (track->video_track); + free (track->audio_track); + free (track->sub_track); free (track); } /* Free the cues. */ for (i = 0; i < this->num_indexes; i++) { - if (this->indexes[i].pos) - free(this->indexes[i].pos); - if (this->indexes[i].timecode) - free(this->indexes[i].timecode); + free(this->indexes[i].pos); + free(this->indexes[i].timecode); } - if (this->indexes) - free(this->indexes); + free(this->indexes); /* Free the top_level elem list */ - if (this->top_level_list) - free(this->top_level_list); + free(this->top_level_list); dispose_ebml_parser(this->ebml); free (this); @@ -2805,18 +2791,7 @@ static demux_plugin_t *open_plugin (demux_class_t *class_gen, xine_stream_t *str } break; - case METHOD_BY_EXTENSION: { - const char *const mrl = input->get_mrl(input); - const char *const extensions = class_gen->get_extensions (class_gen);; - - lprintf ("stage by extension %s\n", mrl); - - if (!_x_demux_check_extension (mrl, extensions)) - return NULL; - - } - break; - + case METHOD_BY_MRL: case METHOD_EXPLICIT: break; @@ -2867,34 +2842,6 @@ error: /* * demux matroska class */ - -static const char *get_description (demux_class_t *this_gen) { - return "matroska demux plugin"; -} - - -static const char *get_identifier (demux_class_t *this_gen) { - return "matroska"; -} - - -static const char *get_extensions (demux_class_t *this_gen) { - return "mkv"; -} - - -static const char *get_mimetypes (demux_class_t *this_gen) { - return "video/mkv: mkv: matroska;"; -} - - -static void class_dispose (demux_class_t *this_gen) { - - demux_matroska_class_t *this = (demux_matroska_class_t *) this_gen; - - free (this); -} - static void *init_class (xine_t *xine, void *data) { demux_matroska_class_t *this; @@ -2903,11 +2850,11 @@ static void *init_class (xine_t *xine, void *data) { this->xine = xine; this->demux_class.open_plugin = open_plugin; - this->demux_class.get_description = get_description; - this->demux_class.get_identifier = get_identifier; - this->demux_class.get_mimetypes = get_mimetypes; - this->demux_class.get_extensions = get_extensions; - this->demux_class.dispose = class_dispose; + this->demux_class.description = N_("matroska demux plugin"); + this->demux_class.identifier = "matroska"; + this->demux_class.mimetypes = "video/mkv: mkv: matroska;"; + this->demux_class.extensions = "mkv"; + this->demux_class.dispose = default_demux_class_dispose; return this; } @@ -2921,6 +2868,6 @@ static const demuxer_info_t demux_info_matroska = { const plugin_info_t xine_plugin_info[] EXPORTED = { /* type, API, "name", version, special_info, init_function */ - { PLUGIN_DEMUX, 26, "matroska", XINE_VERSION_CODE, &demux_info_matroska, init_class }, + { PLUGIN_DEMUX, 27, "matroska", XINE_VERSION_CODE, &demux_info_matroska, init_class }, { PLUGIN_NONE, 0, "", 0, NULL, NULL } }; |