From 8e6c006e9b55e0f270a4f571c0199f02c00c0ed2 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Sat, 12 Jun 2004 17:42:42 +0000 Subject: [PATCH] Removed the aviclasses. --- Makefile.in | 33 +- Makefile.mingw | 33 +- Makefile.mingw.options | 4 - aviclasses/AVIIndex.cpp | 229 --- aviclasses/AVIIndex.h | 120 -- aviclasses/AVIReadHandler.cpp | 2471 --------------------------------- aviclasses/AVIReadHandler.h | 69 - aviclasses/Fixes.h | 58 - aviclasses/Makefile.in | 2 - aviclasses/Makefile.mingw | 5 - aviclasses/ac_common.h | 173 --- aviclasses/common_endian.h | 189 --- aviclasses/common_gdivfw.h | 384 ----- aviclasses/common_mmreg.h | 118 -- aviclasses/list.cpp | 93 -- aviclasses/list.h | 272 ---- configure.in | 61 +- src/input/r_avi.cpp | 257 +--- src/input/r_avi.h | 16 - 19 files changed, 12 insertions(+), 4575 deletions(-) delete mode 100644 aviclasses/AVIIndex.cpp delete mode 100644 aviclasses/AVIIndex.h delete mode 100644 aviclasses/AVIReadHandler.cpp delete mode 100644 aviclasses/AVIReadHandler.h delete mode 100644 aviclasses/Fixes.h delete mode 100644 aviclasses/Makefile.in delete mode 100644 aviclasses/Makefile.mingw delete mode 100644 aviclasses/ac_common.h delete mode 100644 aviclasses/common_endian.h delete mode 100644 aviclasses/common_gdivfw.h delete mode 100644 aviclasses/common_mmreg.h delete mode 100644 aviclasses/list.cpp delete mode 100644 aviclasses/list.h diff --git a/Makefile.in b/Makefile.in index 45a3211fb..e264a1707 100644 --- a/Makefile.in +++ b/Makefile.in @@ -54,8 +54,6 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_HEADER = $(INSTALL_DATA) # Variable stuff as set by configure -AVICLASSES_LIBS = @AVICLASSES_LIBS@ -AVILIB_LIBS = @AVILIB_LIBS@ BZ2_LIBS = @BZ2_LIBS@ DEBUG_CFLAGS = @DEBUG_CFLAGS@ EBML_CFLAGS = @EBML_CFLAGS@ @@ -87,29 +85,18 @@ CFLAGS += -DPACKAGE=\"$(PACKAGE)\" -DVERSION=\"$(VERSION)\" CXXFLAGS += -DPACKAGE=\"$(PACKAGE)\" -DVERSION=\"$(VERSION)\" # Which additional stuff to compile -USE_AVICLASSES = @USE_AVICLASSES@ -USE_AVILIB0610 = @USE_AVILIB0610@ USE_WXWINDOWS = @USE_WXWINDOWS@ -ifeq (yes,$(USE_AVICLASSES)) -AVICLASSES_INCLUDES = -Iaviclasses -AVICLASSES_LIBDIRS = -Laviclasses -AVICLASSES_LIBRARIES = -laviclasses -DEP_AVICLASSES = aviclasses/libaviclasses.a -endif - -ifeq (yes,$(USE_AVILIB0610)) AVILIB_INCLUDES = -Iavilib-0.6.10 AVILIB_LIBDIRS = -Lavilib-0.6.10 DEP_AVILIB = avilib-0.6.10/libavi.a -endif DEP_COMMON = src/common/libmtxcommon.a DEP_EBMLCOMMON = src/common/libmtxebmlcommon.a DEP_KAXCOMMON = src/common/libmtxkaxcommon.a DEP_INPUT = src/input/libmtxinput.a DEP_OUTPUT = src/output/libmtxoutput.a -DEP_AVI = $(DEP_AVILIB) $(DEP_AVICLASSES) +DEP_AVI = $(DEP_AVILIB) DEP_RMFF = librmff/librmff.a COMPRESSION_LIBRARIES = $(LZO_LIBS) $(BZ2_LIBS) @@ -144,9 +131,9 @@ install-mans: $(INSTALL_DATA) $$i $(DESTDIR)$(man1dir)/$$inst; \ done -SYSTEM_INCLUDES = $(AVILIB_INCLUDES) $(AVICLASSES_INCLUDES) \ +SYSTEM_INCLUDES = $(AVILIB_INCLUDES) \ -I. -Ilibrmff -Isrc -Isrc/common -Isrc/input -Isrc/output -SYSTEM_LIBDIRS = $(AVILIB_LIBDIRS) $(AVICLASSES_LIBDIRS) \ +SYSTEM_LIBDIRS = $(AVILIB_LIBDIRS) \ -Llibrmff -Lsrc/common -Lsrc/input -Lsrc/output RUNAR = $(AR) rcu @@ -191,18 +178,6 @@ avilib-0.6.10/libavi.a: $(libavi_OBJECTS) $(RUNAR) $@ $(libavi_OBJECTS) $(RANLIB) $@ -# -# aviclasses -# - -libaviclasses_SOURCES = $(wildcard aviclasses/*.cpp) -libaviclasses_OBJECTS := $(patsubst %.cpp,%.o,$(libaviclasses_SOURCES)) - -aviclasses/libaviclasses.a: $(libaviclasses_OBJECTS) - rm -f $@ - $(RUNAR) $@ $(libaviclasses_OBJECTS) - $(RANLIB) $@ - # # librmff # @@ -266,7 +241,7 @@ mkvmerge_DEPENDENCIES += $(DEP_COMMON) \ $(DEP_COMP) $(DEP_INPUT) $(DEP_OUTPUT) $(DEP_AVI) $(DEP_RMFF) mkvmerge_LDADD = -lmtxinput -lmtxoutput \ -lmtxcommon -lmatroska -lebml \ - -lavi $(AVICLASSES_LIBDIRS) $(AVICLASSES_LIBRARIES) -lrmff \ + -lavi -lrmff \ $(FLAC_LIBS) -lvorbis -logg -lz $(COMPRESSION_LIBRARIES) \ -lexpat $(ICONV_LIBS) diff --git a/Makefile.mingw b/Makefile.mingw index 83f34ba56..b3822c358 100644 --- a/Makefile.mingw +++ b/Makefile.mingw @@ -9,14 +9,6 @@ CFLAGS += -g -DDEBUG CXXFLAGS += -g -DDEBUG endif -ifneq (,$(findstring aviclasses,$(AVILIB))) -CXXFLAGS += -DHAVE_AVICLASSES=1 -AVICLASSES_INCLUDES = -Iaviclasses -AVICLASSES_LIBDIRS = -Laviclasses -AVICLASSES_LIBRARIES = -laviclasses -DEP_AVICLASSES = aviclasses/libaviclasses.a -endif - ifneq (,$(findstring bzlib,$(COMPRESSION_LIBS))) CXXFLAGS += -DHAVE_BZLIB_H=1 COMPRESSION_LIBRARIES = -lbz2 @@ -47,25 +39,21 @@ endif DEP_INPUT = src/input/libmtxinput.a DEP_OUTPUT = src/output/libmtxoutput.a DEP_AVILIB = avilib-0.6.10/libavi.a -DEP_AVI = $(DEP_AVILIB) $(DEP_AVICLASSES) +DEP_AVI = $(DEP_AVILIB) DEP_RMFF = librmff/librmff.a # # System settings. Don't change anything below here. # -ifneq (,$(findstring aviclasses,$(AVILIB))) -SUBDIRS = avilib-0.6.10 aviclasses src -else SUBDIRS = avilib-0.6.10 src -endif APPLICATIONS=src/mkvmerge src/mkvinfo src/mkvextract src/base64tool src/mmg all: config.h $(APPLICATIONS) -SYSTEM_INCLUDES = -Iavilib-0.6.10 $(AVICLASSES_INCLUDES) \ +SYSTEM_INCLUDES = -Iavilib-0.6.10 \ -I. -Ilibrmff -Isrc -Isrc/common -Isrc/input -Isrc/output -SYSTEM_LIBDIRS = -Lavilib-0.6.10 $(AVICLASSES_LIBDIRS) \ +SYSTEM_LIBDIRS = -Lavilib-0.6.10 \ -Llibrmff -Lsrc/common -Lsrc/input -Lsrc/output RUNAR = $(AR) rcu @@ -118,18 +106,6 @@ avilib-0.6.10/libavi.a: $(libavi_OBJECTS) $(RUNAR) $@ $(libavi_OBJECTS) $(RANLIB) $@ -# -# aviclasses -# - -libaviclasses_SOURCES = $(wildcard aviclasses/*.cpp) -libaviclasses_OBJECTS := $(patsubst %.cpp,%.o,$(libaviclasses_SOURCES)) - -aviclasses/libaviclasses.a: $(libaviclasses_OBJECTS) - rm -f $@ - $(RUNAR) $@ $(libaviclasses_OBJECTS) - $(RANLIB) $@ - # # librmff # @@ -193,8 +169,7 @@ mkvmerge_DEPENDENCIES += $(DEP_COMMON) \ $(DEP_COMP) $(DEP_INPUT) $(DEP_OUTPUT) $(DEP_AVI) $(DEP_RMFF) mkvmerge_LDADD = -lmtxinput -lmtxoutput \ -lmtxcommon -lmatroska -lebml \ - -lavi $(AVICLASSES_LIBDIRS) $(AVICLASSES_LIBRARIES) \ - -lvorbis -lflac -logg -lz $(COMPRESSION_LIBRARIES) \ + -lavi -lvorbis -lflac -logg -lz $(COMPRESSION_LIBRARIES) \ -lexpat -liconv -lrmff mkvinfo_SOURCES = $(wildcard src/mkvinfo*.cpp) diff --git a/Makefile.mingw.options b/Makefile.mingw.options index be69df4da..1bcf69fd6 100644 --- a/Makefile.mingw.options +++ b/Makefile.mingw.options @@ -6,10 +6,6 @@ LIBDIRS = -Lc:/cygwin/usr/local/src/libebml/make/mingw32 \ -Lc:/cygwin/usr/local/src/libmatroska/make/mingw32 \ -Lc:/cygwin/usr/local/lib -# Which AVI libraries should be used for reading AVIs? -# Default is to use aviclasses. -AVILIB = aviclasses - # Which compression libraries should be supported? # zlib is always used, possible other values are bzlib and lzo. #COMPRESSION_LIBS = bzlib lzo diff --git a/aviclasses/AVIIndex.cpp b/aviclasses/AVIIndex.cpp deleted file mode 100644 index b901d2886..000000000 --- a/aviclasses/AVIIndex.cpp +++ /dev/null @@ -1,229 +0,0 @@ -// VirtualDub - Video processing and capture application -// Copyright (C) 1998-2001 Avery Lee -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. - -// -// Modified by Julien 'Cyrius' Coloos -// 20-09-2003 -// - -#include "AVIIndex.h" - -/////////////////////////////////////////////////////////////////////////// - -class AVIIndexChainNode { -public: - enum { ENTS=2048 }; - - AVIIndexChainNode *next; - - AVIIndexEntry2 ient[ENTS]; - int num_ents; - - AVIIndexChainNode() { - num_ents = 0; - next = NULL; - } - - bool add(uint32_le ckid, sint64 pos, long size, bool is_keyframe) { - if (num_ents < ENTS) { - ient[num_ents].ckid = ckid; - ient[num_ents].pos = pos; - ient[num_ents].size = is_keyframe ? size : 0x80000000+size; - ++num_ents; - return true; - } - return false; - } - - void put(w32AVIINDEXENTRY *&avieptr) { - int i; - - for(i=0; ickid = ient[i].ckid; - avieptr->dwFlags = ient[i].size & 0x80000000 ? 0 : AVIIF_KEYFRAME; - avieptr->dwChunkOffset = ient[i].pos; - avieptr->dwChunkLength = ient[i].size & 0x7FFFFFFF; - - ++avieptr; - } - } - - void put(AVIIndexEntry2 *&avie2ptr) { - int i; - - for(i=0; idwSizeKeyframe = ient[i].size; - avie3ptr->dwOffset = (uint32)(ient[i].pos - offset); - - ++avie3ptr; - } - } -}; - -/////////////////////////////////////////////////////////////////////////// - -AVIIndexChain::AVIIndexChain() { - head = tail = NULL; - total_ents = 0; -} - -void AVIIndexChain::delete_chain() { - AVIIndexChainNode *aicn = head,*aicn2; - - while(aicn) { - aicn2 = aicn->next; - delete aicn; - aicn = aicn2; - } - - head = tail = NULL; -} - -AVIIndexChain::~AVIIndexChain() { - delete_chain(); -} - -bool AVIIndexChain::add(w32AVIINDEXENTRY *avie) { - if (!tail || !tail->add(avie->ckid, avie->dwChunkOffset, avie->dwChunkLength, !!(avie->dwFlags & AVIIF_KEYFRAME))) { - AVIIndexChainNode *aicn = new AVIIndexChainNode(); - - if (tail) tail->next = aicn; else head=aicn; - tail = aicn; - - if (tail->add(avie->ckid, avie->dwChunkOffset, avie->dwChunkLength, !!(avie->dwFlags & AVIIF_KEYFRAME))) { - ++total_ents; - return true; - } - - return false; - } - - ++total_ents; - - return true; -} - -bool AVIIndexChain::add(AVIIndexEntry2 *avie2) { - return add(avie2->ckid, avie2->pos, avie2->size & 0x7FFFFFFF, !!(avie2->size & 0x80000000)); -} - -bool AVIIndexChain::add(uint32_le ckid, sint64 pos, long size, bool is_keyframe) { - if (!tail || !tail->add(ckid, pos, size, is_keyframe)) { - AVIIndexChainNode *aicn = new AVIIndexChainNode(); - - if (tail) tail->next = aicn; else head=aicn; - tail = aicn; - - if (tail->add(ckid, pos, size, is_keyframe)) { - ++total_ents; - return true; - } - - return false; - } - - ++total_ents; - - return true; -} - -void AVIIndexChain::put(w32AVIINDEXENTRY *avietbl) { - AVIIndexChainNode *aicn = head; - - while(aicn) { - aicn->put(avietbl); - aicn=aicn->next; - } - - delete_chain(); -} - -void AVIIndexChain::put(AVIIndexEntry2 *avie2tbl) { - AVIIndexChainNode *aicn = head; - - while(aicn) { - aicn->put(avie2tbl); - aicn=aicn->next; - } - - delete_chain(); -} - -void AVIIndexChain::put(AVIIndexEntry3 *avie3tbl, sint64 offset) { - AVIIndexChainNode *aicn = head; - - while(aicn) { - aicn->put(avie3tbl, offset); - aicn=aicn->next; - } - - delete_chain(); -} - -AVIIndex::AVIIndex() { - index = NULL; - index2 = NULL; - index3 = NULL; -} - -AVIIndex::~AVIIndex() { - delete[] index; - delete[] index2; - delete[] index3; -} - -bool AVIIndex::makeIndex() { - if (!allocateIndex(total_ents)) return false; - - put(indexPtr()); - - return true; -} - -bool AVIIndex::makeIndex2() { - if (!allocateIndex2(total_ents)) return false; - - put(index2Ptr()); - - return true; -} - -bool AVIIndex::makeIndex3(sint64 offset) { - if (!allocateIndex3(total_ents)) return false; - - put(index3Ptr(), offset); - - return true; -} - -void AVIIndex::clear() { - delete_chain(); - delete[] index; - delete[] index2; - delete[] index3; - index = NULL; - index2 = NULL; - index3 = NULL; - total_ents = 0; -} diff --git a/aviclasses/AVIIndex.h b/aviclasses/AVIIndex.h deleted file mode 100644 index e4a4a55f5..000000000 --- a/aviclasses/AVIIndex.h +++ /dev/null @@ -1,120 +0,0 @@ -// VirtualDub - Video processing and capture application -// Copyright (C) 1998-2001 Avery Lee -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. - -// -// Modified by Julien 'Cyrius' Coloos -// 20-09-2003 -// - -#ifndef f_AVIINDEX_H -#define f_AVIINDEX_H - -#include "common_endian.h" -#include "common_gdivfw.h" - -class AVIIndexChainNode; - -class AVIIndexEntry2 { -public: - sint64 pos; - union { - uint32_le ckid; - int fileno; - }; - sint32 size; -}; - -class AVIIndexEntry3 { -public: - uint32 dwOffset; - uint32 dwSizeKeyframe; -}; - -class AVIIndexChain { -protected: - AVIIndexChainNode *head, *tail; - - void delete_chain(); -public: - int total_ents; - - AVIIndexChain(); - ~AVIIndexChain(); - - bool add(w32AVIINDEXENTRY *avie); - bool add(AVIIndexEntry2 *avie2); - bool add(uint32_le ckid, sint64 pos, long len, bool is_keyframe); - void put(w32AVIINDEXENTRY *avietbl); - void put(AVIIndexEntry2 *avie2tbl); - void put(AVIIndexEntry3 *avie3tbl, sint64 offset); -}; - -class AVIIndex : public AVIIndexChain { -protected: - w32AVIINDEXENTRY *index; - AVIIndexEntry2 *index2; - AVIIndexEntry3 *index3; - int index_len; - - w32AVIINDEXENTRY *allocateIndex(int total_entries) { - return index = new w32AVIINDEXENTRY[index_len = total_entries]; - } - - AVIIndexEntry2 *allocateIndex2(int total_entries) { - return index2 = new AVIIndexEntry2[index_len = total_entries]; - } - - AVIIndexEntry3 *allocateIndex3(int total_entries) { - return index3 = new AVIIndexEntry3[index_len = total_entries]; - } - -public: - AVIIndex(); - ~AVIIndex(); - - bool makeIndex(); - bool makeIndex2(); - bool makeIndex3(sint64 offset); - void clear(); - - w32AVIINDEXENTRY *indexPtr() { - return index; - } - - AVIIndexEntry2 *index2Ptr() { - return index2; - } - - AVIIndexEntry3 *index3Ptr() { - return index3; - } - - AVIIndexEntry2 *takeIndex2() { - AVIIndexEntry2 *idx = index2; - - index2 = NULL; - return idx; - } - - int size() { return total_ents; } - - int indexLen() { - return index_len; - } -}; - -#endif diff --git a/aviclasses/AVIReadHandler.cpp b/aviclasses/AVIReadHandler.cpp deleted file mode 100644 index c60e0060b..000000000 --- a/aviclasses/AVIReadHandler.cpp +++ /dev/null @@ -1,2471 +0,0 @@ -// VirtualDub - Video processing and capture application -// Copyright (C) 1998-2001 Avery Lee -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. - -// -// Modified by Julien 'Cyrius' Coloos -// 20-09-2003 -// - -#include "AVIReadHandler.h" -#include "AVIIndex.h" -#include "list.h" -#include "Fixes.h" - -#include "common_mmreg.h" -#include - -#include "common.h" -#include "error.h" - -//#define STREAMING_DEBUG - -/////////////////////////////////////////////////////////////////////////// - -/*namespace { - enum { kVDST_AVIReadHandler = 2 }; - - enum { - kVDM_AvisynthDetected, // AVI: Avisynth detected. Extended error handling enabled. - kVDM_OpenDMLIndexDetected, // AVI: OpenDML hierarchical index detected on stream %d. - kVDM_IndexMissing, // AVI: Index not found or damaged -- reconstructing via file scan. - kVDM_InvalidChunkDetected, // AVI: Invalid chunk detected at %lld. Enabling aggressive recovery mode. - kVDM_StreamFailure, // AVI: Invalid block found at %lld -- disabling streaming. - kVDM_FixingBadSampleRate, // AVI: Stream %d has an invalid sample rate. Substituting %lu samples/sec as placeholder. - }; -}*/ - -/////////////////////////////////////////////////////////////////////////// - -// The following comes from the OpenDML 1.0 spec for extended AVI files - -// bIndexType codes -// -#define AVI_INDEX_OF_INDEXES 0x00 // when each entry in aIndex - // array points to an index chunk - -#define AVI_INDEX_OF_CHUNKS 0x01 // when each entry in aIndex - // array points to a chunk in the file - -#define AVI_INDEX_IS_DATA 0x80 // when each entry is aIndex is - // really the data - -// bIndexSubtype codes for INDEX_OF_CHUNKS - -#define AVI_INDEX_2FIELD 0x01 // when fields within frames - // are also indexed - struct _avisuperindex_entry { - sint64_le qwOffset; // absolute file offset, offset 0 is - // unused entry?? - uint32_le dwSize; // size of index chunk at this offset - uint32_le dwDuration; // time span in stream ticks - }; - struct _avistdindex_entry { - uint32_le dwOffset; // qwBaseOffset + this is absolute file offset - uint32_le dwSize; // bit 31 is set if this is NOT a keyframe - }; - struct _avifieldindex_entry { - uint32_le dwOffset; - uint32_le dwSize; - uint32_le dwOffsetField2; - }; - -typedef struct __attribute__((__packed__)) _avisuperindex_chunk { - uint32_le fcc; // ’ix##’ - uint32_le cb; // size of this structure - uint16_le wLongsPerEntry; // must be 4 (size of each entry in aIndex array) - uint8 bIndexSubType; // must be 0 or AVI_INDEX_2FIELD - uint8 bIndexType; // must be AVI_INDEX_OF_INDEXES - uint32_le nEntriesInUse; // number of entries in aIndex array that - // are used - uint32_le dwChunkId; // ’##dc’ or ’##db’ or ’##wb’, etc - uint32_le dwReserved[3]; // must be 0 - struct _avisuperindex_entry aIndex[]; -} AVISUPERINDEX, * PAVISUPERINDEX; - -typedef struct __attribute__((__packed__)) _avistdindex_chunk { - uint32_le fcc; // ’ix##’ - uint32_le cb; - uint16_le wLongsPerEntry; // must be sizeof(aIndex[0])/sizeof(DWORD) - uint8 bIndexSubType; // must be 0 - uint8 bIndexType; // must be AVI_INDEX_OF_CHUNKS - uint32_le nEntriesInUse; // - uint32_le dwChunkId; // ’##dc’ or ’##db’ or ’##wb’ etc.. - sint64_le qwBaseOffset; // all dwOffsets in aIndex array are - // relative to this - uint32_le dwReserved3; // must be 0 - struct _avistdindex_entry aIndex[]; -} AVISTDINDEX, * PAVISTDINDEX; - -/*typedef struct _avifieldindex_chunk { - uint32_le fcc; - uint32_le cb; - uint16_le wLongsPerEntry; - uint8 bIndexSubType; - uint8 bIndexType; - uint32_le nEntriesInUse; - uint32_le dwChunkId; - sint64_le qwBaseOffset; - uint32_le dwReserved3; - struct _avifieldindex_entry aIndex[]; -} AVIFIELDINDEX, * PAVIFIELDINDEX;*/ - -/////////////////////////////////////////////////////////////////////////// - -IAVIReadStream::~IAVIReadStream() { -} - -/////////////////////////////////////////////////////////////////////////// - -class AVIStreamNode; -class AVIReadHandler; - -class AVIReadCache { -public: - long cache_hit_bytes, cache_miss_bytes; - int reads; - - AVIReadCache(int nlines, int nstream, AVIReadHandler *root, AVIStreamNode *psnData); - ~AVIReadCache(); - - void ResetStatistics(); - bool WriteBegin(sint64 pos, long len); - void Write(void *buffer, long len); - void WriteEnd(); - long Read(void *dest, sint64 chunk_pos, sint64 pos, long len); - - long getMaxRead() { - return (lines_max - 1) << 4; - } - -private: - AVIStreamNode *psnData; - sint64 (*buffer)[2]; - int lines_max, lines; - long read_tail, write_tail, write_hdr; - int write_offset; - int stream; - AVIReadHandler *source; -}; - -class AVIStreamNode : public ListNode2 { -public: - AVIStreamHeader_fixed hdr; - char *pFormat; - long lFormatLen; - AVIIndex index; - sint64 bytes; - bool keyframe_only; - bool was_VBR; - double bitrate_mean; - double bitrate_stddev; - double max_deviation; // seconds - int handler_count; - class AVIReadCache *cache; - int streaming_count; - sint64 stream_push_pos; - sint64 stream_bytes; - int stream_pushes; - long length; - long frames; - List2 listHandlers; - - AVIStreamNode(); - ~AVIStreamNode(); - - void FixVBRAudio(); -}; - -AVIStreamNode::AVIStreamNode() { - pFormat = NULL; - bytes = 0; - handler_count = 0; - streaming_count = 0; - - stream_bytes = 0; - stream_pushes = 0; - cache = NULL; - - was_VBR = false; -} - -AVIStreamNode::~AVIStreamNode() { - delete pFormat; - delete cache; -} - -void AVIStreamNode::FixVBRAudio() { - w32WAVEFORMATEX *pWaveFormat = (w32WAVEFORMATEX *)pFormat; - - // If this is an MP3 stream, undo the Nandub 1152 value. - - if (pWaveFormat->wFormatTag == 0x0055) { - pWaveFormat->nBlockAlign = 1; - } - - // Determine VBR statistics. - - was_VBR = true; - - const AVIIndexEntry2 *pent = index.index2Ptr(); - sint64 size_accum = 0; - sint64 max_dev = 0; - double size_sq_sum = 0.0; - - for(int i=0; i>1)); - - if (dev<0) - dev = -dev; - - if (dev > max_dev) - max_dev = dev; - - size_accum += size; - size_sq_sum += (double)size*size; - } - - // I hate probability & sadistics. - // - // Var(X) = E(X2) - E(X)^2 - // = S(X2)/n - (S(x)/n)^2 - // = (n*S(X2) - S(X)^2)/n^2 - // - // SD(x) = sqrt(n*S(X2) - S(X)^2) / n - - double frames_per_second = (double)hdr.dwRate / (double)hdr.dwScale; - double sum1_bits = bytes * 8.0; - double sum2_bits = size_sq_sum * 64.0; - - bitrate_mean = (sum1_bits / frames) * frames_per_second; - bitrate_stddev = sqrt(frames * sum2_bits - sum1_bits * sum1_bits) / frames * frames_per_second; - max_deviation = (double)max_dev * 8.0 / bitrate_mean; - - // Assume that each audio block is of the same duration. - - hdr.dwRate = (uint32)(bitrate_mean/8.0 + 0.5); - hdr.dwScale = pWaveFormat->nBlockAlign; - hdr.dwSampleSize = pWaveFormat->nBlockAlign; -} - -/////////////////////////////////////////////////////////////////////////// - -/*class AVIFileDesc : public ListNode2 { -public: - HANDLE hFile; - HANDLE hFileUnbuffered; - sint64 i64Size; -};*/ - -class AVIStreamNode; - -class AVIReadHandler : public IAVIReadHandler /*, private File64*/ { -public: - bool fDisableFastIO; - - AVIReadHandler(mm_io_c *input); - virtual ~AVIReadHandler(); - - void AddRef(); - void Release(); - IAVIReadStream *GetStream(uint32 fccType, sint32 lParam); - void EnableFastIO(bool); - bool isOptimizedForRealtime(); - bool isStreaming(); - bool isIndexFabricated(); - //bool AppendFile(const char *pszFile); - //bool getSegmentHint(const char **ppszPath); - - void EnableStreaming(int stream); - void DisableStreaming(int stream); - void AdjustRealTime(bool fRealTime); - bool Stream(AVIStreamNode *, sint64 pos); - sint64 getStreamPtr(); - void FixCacheProblems(class AVIReadStream *); - long ReadData(int stream, void *buffer, sint64 position, long len); - -private: -// enum { STREAM_SIZE = 65536 }; - enum { STREAM_SIZE = 1048576 }; - enum { STREAM_RT_SIZE = 65536 }; - enum { STREAM_BLOCK_SIZE = 4096 }; - - mm_io_c *m_pInput, *m_pUnbufferedInput; - - int ref_count; - sint64 i64StreamPosition; - int streams; - char *streamBuffer; - int sbPosition; - int sbSize; - long fStreamsActive; - int nRealTime; - int nActiveStreamers; - bool fFakeIndex; - sint64 i64Size; - int nFiles, nCurrentFile; - char * pSegmentHint; - - // Whenever a file is aggressively recovered, do not allow streaming. - - bool mbFileIsDamaged; - - List2 listStreams; - //List2 listFiles; - - void _construct(/*const char *pszFile*/); - void _parseFile(List2& streams); - bool _parseStreamHeader(List2& streams, uint32 dwLengthLeft, bool& bIndexDamaged); - bool _parseIndexBlock(List2& streams, int count, sint64); - void _parseExtendedIndexBlock(List2& streams, AVIStreamNode *pasn, sint64 fpos, uint32 dwLength); - void _destruct(); - - char * _StreamRead(long& bytes); - void _SelectFile(int file); - - bool _readChunkHeader(uint32_le& pfcc, uint32& pdwLen); -}; - -IAVIReadHandler *CreateAVIReadHandler(mm_io_c *input) { - return new AVIReadHandler(input); -} - -/////////////////////////////////////////////////////////////////////////// - -AVIReadCache::AVIReadCache(int nlines, int nstream, AVIReadHandler *root, AVIStreamNode *psnData) { - buffer = new sint64[nlines][2]; - if (!buffer) throw error_c("out of memory"); - - this->psnData = psnData; - lines = 0; - lines_max = nlines; - read_tail = 0; - write_tail = 0; - stream = nstream; - source = root; - ResetStatistics(); -} - -AVIReadCache::~AVIReadCache() { - delete[] buffer; -} - -void AVIReadCache::ResetStatistics() { - reads = 0; - cache_hit_bytes = cache_miss_bytes = 0; -} - -bool AVIReadCache::WriteBegin(sint64 pos, long len) { - int needed; - - // delete lines as necessary to make room - - needed = 1 + (len+15)/16; - - if (needed > lines_max) - return false; - - while(lines+needed > lines_max) { - int siz = (int)((buffer[read_tail][1]+15)/16 + 1); - read_tail += siz; - lines -= siz; - if (read_tail >= lines_max) - read_tail -= lines_max; - } - - // write in header - -// _RPT1(0,"\tbeginning write at line %ld\n", write_tail); - - write_hdr = write_tail; - write_offset = 0; - - buffer[write_tail][0] = pos; - buffer[write_tail][1] = 0; - - if (++write_tail >= lines_max) - write_tail = 0; - - return true; -} - -void AVIReadCache::Write(void *src, long len) { - long dest; - - // copy in data - - buffer[write_hdr][1] += len; - - dest = write_tail + (len + write_offset + 15)/16; - - if (dest > lines_max) { - int tc = (lines_max - write_tail)*16 - write_offset; - - memcpy((char *)&buffer[write_tail][0] + write_offset, src, tc); - memcpy(&buffer[0][0], (char *)src + tc, len - tc); - - write_tail = (len-tc)/16; - write_offset = (len-tc)&15; - - } else { - memcpy((char *)&buffer[write_tail][0] + write_offset, src, len); - write_tail += (len+write_offset)/16; - if (write_tail >= lines_max) - write_tail = 0; - - write_offset = (len+write_offset) & 15; - } -} - -void AVIReadCache::WriteEnd() { - long cnt = (long)(1 + (buffer[write_hdr][1]+15)/16); - lines += cnt; - write_tail = write_hdr + cnt; - - if (write_tail >= lines_max) - write_tail -= lines_max; - -// _RPT3(0,"\twrite complete -- header at line %d, size %ld, next line %ld\n", write_hdr, (long)buffer[write_hdr][1], write_tail); -} - -long AVIReadCache::Read(void *dest, sint64 chunk_pos, sint64 pos, long len) { - long ptr; - sint64 offset; - -// _RPT3(0,"Read request: chunk %16I64, pos %16I64d, %ld bytes\n", chunk_pos, pos, len); - - ++reads; - - do { - // scan buffer looking for a range that contains data - - ptr = read_tail; - while(ptr != write_tail) { - offset = pos - buffer[ptr][0]; - -// _RPT4(0,"line %8d: pos %16I64d, len %ld bytes (%ld lines)\n", ptr, buffer[ptr][0], (long)buffer[ptr][1], (long)(buffer[ptr][1]+15)/16); - - if (offset>=0 && offset < buffer[ptr][1]) { - long end; - - // cache hit - -// _RPT1(0, "cache hit (offset %I64d)\n", chunk_pos); - - cache_hit_bytes += len; - - while (cache_hit_bytes > 16777216) { - cache_miss_bytes >>= 1; - cache_hit_bytes >>= 1; - } - - if (len > (long)(buffer[ptr][1]*16 - offset)) - len = (long)(buffer[ptr][1]*16 - offset); - - ptr += 1+((long)offset>>4); - if (ptr >= lines_max) - ptr -= lines_max; - - end = ptr + ((len+((long)offset&15)+15)>>4); - - if (end > lines_max) { - long tc = (lines_max - ptr)*16 - ((long)offset&15); - memcpy(dest, (char *)&buffer[ptr][0] + ((long)offset&15), tc); - memcpy((char *)dest + tc, (char *)&buffer[0][0], len-tc); - } else { - memcpy(dest, (char *)&buffer[ptr][0] + ((long)offset&15), len); - } - - return len; - } - -// _RPT4(0,"[x] line %8d: pos %16I64d, len %ld bytes (%ld lines)\n", ptr, buffer[ptr][0], (long)buffer[ptr][1], (long)(buffer[ptr][1]+15)/16); - ptr += (long)(1+(buffer[ptr][1] + 15)/16); - - if (ptr >= lines_max) - ptr -= lines_max; - } - - if (source->getStreamPtr() > chunk_pos) - break; - - } while(source->Stream(psnData, chunk_pos)); - -// OutputDebugString("cache miss\n"); -// _RPT1(0, "cache miss (offset %I64d)\n", chunk_pos); - - cache_miss_bytes += len; - - while (cache_miss_bytes > 16777216) { - cache_miss_bytes >>= 1; - cache_hit_bytes >>= 1; - } - - return source->ReadData(stream, dest, pos, len); -} - -/////////////////////////////////////////////////////////////////////////// - -class AVIReadStream : public IAVIReadStream, public ListNode2 { - friend class AVIReadHandler; - -public: - AVIReadStream(AVIReadHandler *, AVIStreamNode *, int); - ~AVIReadStream(); - - long BeginStreaming(long lStart, long lEnd, long lRate); - long EndStreaming(); - long Info(w32AVISTREAMINFO *pasi, long lSize); - bool IsKeyFrame(long lFrame); - long Read(long lStart, long lSamples, void *lpBuffer, long cbBuffer, long *plBytes, long *plSamples); - long Start(); - long End(); - long PrevKeyFrame(long lFrame); - long NextKeyFrame(long lFrame); - long NearestKeyFrame(long lFrame); - long FormatSize(long lFrame, long *plSize); - long ReadFormat(long lFrame, void *pFormat, long *plSize); - bool isStreaming(); - bool isKeyframeOnly(); - void Reinit(); - bool getVBRInfo(double& bitrate_mean, double& bitrate_stddev, double& maxdev); - -private: - AVIReadHandler *parent; - AVIStreamNode *psnData; - AVIIndexEntry2 *pIndex; - AVIReadCache *rCache; - long& length; - long& frames; - long sampsize; - int streamno; - bool fStreamingEnabled; - bool fStreamingActive; - int iStreamTrackCount; - long lStreamTrackValue; - long lStreamTrackInterval; - bool fRealTime; - - sint64 i64CachedPosition; - AVIIndexEntry2 *pCachedEntry; - -}; - -/////////////////////////////////////////////////////////////////////////// - -AVIReadStream::AVIReadStream(AVIReadHandler *parent, AVIStreamNode *psnData, int streamno) -:length(psnData->length) -,frames(psnData->frames) -{ - this->parent = parent; - this->psnData = psnData; - this->streamno = streamno; - - fStreamingEnabled = false; - fStreamingActive = false; - fRealTime = false; - - parent->AddRef(); - - pIndex = psnData->index.index2Ptr(); - sampsize = psnData->hdr.dwSampleSize; - - // Hack to imitate Microsoft's parser. It seems to ignore this value - // for audio streams. - - if (psnData->hdr.fccType == streamtypeAUDIO) - sampsize = ((w32WAVEFORMATEX *)psnData->pFormat)->nBlockAlign; - - if (sampsize) { - i64CachedPosition = 0; - pCachedEntry = pIndex; - } - - psnData->listHandlers.AddTail(this); -} - -AVIReadStream::~AVIReadStream() { - EndStreaming(); - // AVIReadStream is a Node in a list owned by AVIReadHandler (its parent) - // So call Remove() _before_ releasing the parent - Remove(); - parent->Release(); -} - -void AVIReadStream::Reinit() { - pIndex = psnData->index.index2Ptr(); - i64CachedPosition = 0; - pCachedEntry = pIndex; -} - -long AVIReadStream::BeginStreaming(long lStart, long lEnd, long lRate) { - if (fStreamingEnabled) - return 0; - -// OutputDebugString(lRate>1500 ? "starting: fast" : "starting: slow"); - - if (lRate <= 1500) { - parent->AdjustRealTime(true); - fRealTime = true; - } else - fRealTime = false; - - if (parent->fDisableFastIO) - return 0; - - if (!psnData->streaming_count) { -// if (!(psnData->cache = new AVIReadCache(psnData->hdr.fccType == streamtypeVIDEO ? 65536 : 16384, streamno, parent, psnData))) -// return AVIERR_MEMORY; - - psnData->stream_bytes = 0; - psnData->stream_pushes = 0; - psnData->stream_push_pos = 0; - } - ++psnData->streaming_count; - - fStreamingEnabled = true; - fStreamingActive = false; - iStreamTrackCount = 0; - lStreamTrackValue = -1; - lStreamTrackInterval = -1; - return 0; -} - -long AVIReadStream::EndStreaming() { - if (!fStreamingEnabled) - return 0; - - if (fRealTime) - parent->AdjustRealTime(false); - - if (fStreamingActive) - parent->DisableStreaming(streamno); - - fStreamingEnabled = false; - fStreamingActive = false; - - if (!--psnData->streaming_count) { - delete psnData->cache; - psnData->cache = NULL; - } - return 0; -} - -long AVIReadStream::Info(w32AVISTREAMINFO *pasi, long lSize) { - w32AVISTREAMINFO asi; - - memset(&asi, 0, sizeof asi); - - asi.fccType = psnData->hdr.fccType; - asi.fccHandler = psnData->hdr.fccHandler; - asi.dwFlags = psnData->hdr.dwFlags; - asi.wPriority = psnData->hdr.wPriority; - asi.wLanguage = psnData->hdr.wLanguage; - asi.dwScale = psnData->hdr.dwScale; - asi.dwRate = psnData->hdr.dwRate; - asi.dwStart = psnData->hdr.dwStart; - asi.dwLength = psnData->hdr.dwLength; - asi.dwInitialFrames = psnData->hdr.dwInitialFrames; - asi.dwSuggestedBufferSize = psnData->hdr.dwSuggestedBufferSize; - asi.dwQuality = psnData->hdr.dwQuality; - asi.dwSampleSize = psnData->hdr.dwSampleSize; - asi.rcFrame.top = psnData->hdr.rcFrame.top; - asi.rcFrame.left = psnData->hdr.rcFrame.left; - asi.rcFrame.right = psnData->hdr.rcFrame.right; - asi.rcFrame.bottom = psnData->hdr.rcFrame.bottom; - - if (lSize < sizeof asi) - memcpy(pasi, &asi, lSize); - else { - memcpy(pasi, &asi, sizeof asi); - memset((char *)pasi + sizeof asi, 0, lSize - sizeof asi); - } - - return 0; -} - -bool AVIReadStream::IsKeyFrame(long lFrame) { - if (sampsize) - return true; - else { - if (lFrame < 0 || lFrame >= length) - return false; - - return !(pIndex[lFrame].size & 0x80000000); - } -} - -long AVIReadStream::Read(long lStart, long lSamples, void *lpBuffer, long cbBuffer, long *plBytes, long *plSamples) { - long lActual; - - if (lStart < 0 || lStart >= length || (lSamples <= 0 && lSamples != AVISTREAMREAD_CONVENIENT)) { - // umm... dummy! can't read outside of stream! - - if (plBytes) *plBytes = 0; - if (plSamples) *plSamples = 0; - - return 0; - } - - // blocked or discrete? - - if (sampsize) { - AVIIndexEntry2 *avie2, *avie2_limit = pIndex+frames; - sint64 byte_off = (sint64)lStart * sampsize; - sint64 bytecnt; - sint64 actual_bytes=0; - sint64 block_pos; - - // too small to hold a sample? - - if (lpBuffer && cbBuffer < sampsize) { - if (plBytes) *plBytes = sampsize * lSamples; - if (plSamples) *plSamples = lSamples; - - return AVIERR_BUFFERTOOSMALL; - } - - // find the frame that has the starting sample -- try and work - // from our last position to save time - - if (byte_off >= i64CachedPosition) { - block_pos = i64CachedPosition; - avie2 = pCachedEntry; - byte_off -= block_pos; - } else { - block_pos = 0; - avie2 = pIndex; - } - - while(byte_off >= (avie2->size & 0x7FFFFFFF)) { - byte_off -= (avie2->size & 0x7FFFFFFF); - block_pos += (avie2->size & 0x7FFFFFFF); - ++avie2; - } - - pCachedEntry = avie2; - i64CachedPosition = block_pos; - - // Client too lazy to specify a size? - - if (lSamples == AVISTREAMREAD_CONVENIENT) { - lSamples = ((avie2->size & 0x7FFFFFFF) - (long)byte_off) / sampsize; - - if (!lSamples && avie2+1 < avie2_limit) - lSamples = ((avie2[0].size & 0x7FFFFFFF) + (avie2[1].size & 0x7FFFFFFF) - (long)byte_off) / sampsize; - - if (lSamples < 0) - lSamples = 1; - } - - // trim down sample count - - if (lpBuffer && lSamples > cbBuffer / sampsize) - lSamples = cbBuffer / sampsize; - - if (lStart+lSamples > length) - lSamples = length - lStart; - - bytecnt = lSamples * sampsize; - - // begin reading frames from this point on - - if (lpBuffer) { - // detect streaming - - if (fStreamingEnabled) { - - // We consider the client to be streaming if we detect at least - // 3 consecutive accesses - - if (lStart == lStreamTrackValue) { - ++iStreamTrackCount; - - if (iStreamTrackCount >= 15) { - - sint64 streamptr = parent->getStreamPtr(); - sint64 fptrdiff = streamptr - avie2->pos; - - if (!parent->isStreaming() || streamptr<0 || (fptrdiff<4194304 && fptrdiff>-4194304)) { - if (!psnData->cache) - psnData->cache = new AVIReadCache(psnData->hdr.fccType == streamtypeVIDEO ? 131072 : 16384, streamno, parent, psnData); - else - psnData->cache->ResetStatistics(); - - if (!fStreamingActive) { - fStreamingActive = true; - parent->EnableStreaming(streamno); - } - -#ifdef STREAMING_DEBUG - OutputDebugString("[a] streaming enabled\n"); -#endif - } - } else { -#ifdef STREAMING_DEBUG - OutputDebugString("[a] streaming detected\n"); -#endif - } - } else { -#ifdef STREAMING_DEBUG - OutputDebugString("[a] streaming disabled\n"); -#endif - iStreamTrackCount = 0; - - if (fStreamingActive) { - fStreamingActive = false; - parent->DisableStreaming(streamno); - } - } - } - - while(bytecnt > 0) { - long tc; - - tc = (avie2->size & 0x7FFFFFFF) - (long)byte_off; - if (tc > bytecnt) - tc = (long)bytecnt; - - if (psnData->cache && fStreamingActive && tc < psnData->cache->getMaxRead()) { -//OutputDebugString("[a] attempting cached read\n"); - lActual = psnData->cache->Read(lpBuffer, avie2->pos, avie2->pos + byte_off + 8, tc); - psnData->stream_bytes += lActual; - } else - lActual = parent->ReadData(streamno, lpBuffer, avie2->pos + byte_off + 8, tc); - - if (lActual < 0) - break; - - actual_bytes += lActual; - ++avie2; - byte_off = 0; - - if (lActual < tc) - break; - - bytecnt -= tc; - lpBuffer = (char *)lpBuffer + tc; - } - - if (actual_bytes < sampsize) { - if (plBytes) *plBytes = 0; - if (plSamples) *plSamples = 0; - return AVIERR_FILEREAD; - } - - actual_bytes -= actual_bytes % sampsize; - - if (plBytes) *plBytes = (long)actual_bytes; - if (plSamples) *plSamples = (long)actual_bytes / sampsize; - - lStreamTrackValue = lStart + (long)actual_bytes / sampsize; - - } else { - if (plBytes) *plBytes = (long)bytecnt; - if (plSamples) *plSamples = lSamples; - } - - } else { - AVIIndexEntry2 *avie2 = &pIndex[lStart]; - - if (lpBuffer && (avie2->size & 0x7FFFFFFF) > cbBuffer) { - if (plBytes) *plBytes = avie2->size & 0x7FFFFFFF; - if (plSamples) *plSamples = 1; - - return AVIERR_BUFFERTOOSMALL; - } - - if (lpBuffer) { - - // detect streaming - - if (fStreamingEnabled && lStart != lStreamTrackValue) { - if (lStreamTrackValue>=0 && lStart-lStreamTrackValue == lStreamTrackInterval) { - if (++iStreamTrackCount >= 15) { - - sint64 streamptr = parent->getStreamPtr(); - sint64 fptrdiff = streamptr - avie2->pos; - - if (!parent->isStreaming() || streamptr<0 || (fptrdiff<4194304 && fptrdiff>-4194304)) { - if (!psnData->cache) - psnData->cache = new AVIReadCache(psnData->hdr.fccType == streamtypeVIDEO ? 131072 : 16384, streamno, parent, psnData); - else - psnData->cache->ResetStatistics(); - - if (!fStreamingActive) { - fStreamingActive = true; - parent->EnableStreaming(streamno); - } - -#ifdef STREAMING_DEBUG - OutputDebugString("[v] streaming activated\n"); -#endif - } - } else { -#ifdef STREAMING_DEBUG - OutputDebugString("[v] streaming detected\n"); -#endif - } - } else { - iStreamTrackCount = 0; -#ifdef STREAMING_DEBUG - OutputDebugString("[v] streaming disabled\n"); -#endif - if (lStreamTrackValue>=0 && lStart > lStreamTrackValue) { - lStreamTrackInterval = lStart - lStreamTrackValue; - } else - lStreamTrackInterval = -1; - - if (fStreamingActive) { - fStreamingActive = false; - parent->DisableStreaming(streamno); - } - } - - lStreamTrackValue = lStart; - } - - // read data - - unsigned size = avie2->size & 0x7FFFFFFF; - - if (psnData->cache && fStreamingActive && size < psnData->cache->getMaxRead()) { -//OutputDebugString("[v] attempting cached read\n"); - lActual = psnData->cache->Read(lpBuffer, avie2->pos, avie2->pos + 8, size); - psnData->stream_bytes += lActual; - } else - lActual = parent->ReadData(streamno, lpBuffer, avie2->pos+8, size); - - if (lActual != size) { - if (plBytes) *plBytes = 0; - if (plSamples) *plSamples = 0; - return AVIERR_FILEREAD; - } - } - - if (plBytes) *plBytes = avie2->size & 0x7FFFFFFF; - if (plSamples) *plSamples = 1; - } - - if (psnData->cache && fStreamingActive) { - - // Are we experiencing a high rate of cache misses? - - if (psnData->cache->cache_miss_bytes*2 > psnData->cache->cache_hit_bytes && psnData->cache->reads > 50) { - - // sh*t, notify the parent that we have cache misses so it can check which stream is - // screwing up, and disable streaming on feeds that are too far off - - parent->FixCacheProblems(this); - iStreamTrackCount = 0; - } - }/* else if (fStreamingEnabled) { - - // hmm... our cache got killed! - - iStreamTrackCount = 0; - - }*/ - - return 0; -} - -long AVIReadStream::Start() { - return 0; -} - -long AVIReadStream::End() { - return length; -} - -long AVIReadStream::PrevKeyFrame(long lFrame) { - if (sampsize) - return lFrame>0 ? lFrame-1 : -1; - - if (lFrame < 0) - return -1; - - if (lFrame >= length) - lFrame = length; - - while(--lFrame > 0) - if (!(pIndex[lFrame].size & 0x80000000)) - return lFrame; - - return -1; -} - -long AVIReadStream::NextKeyFrame(long lFrame) { - if (sampsize) - return lFrame= length) - return -1; - - while(++lFrame < length) - if (!(pIndex[lFrame].size & 0x80000000)) - return lFrame; - - return -1; -} - -long AVIReadStream::NearestKeyFrame(long lFrame) { - long lprev; - - if (sampsize) - return lFrame; - - if (IsKeyFrame(lFrame)) - return lFrame; - - lprev = PrevKeyFrame(lFrame); - - if (lprev < 0) - return 0; - else - return lprev; -} - -long AVIReadStream::FormatSize(long lFrame, long *plSize) { - *plSize = psnData->lFormatLen; - return 0; -} - -long AVIReadStream::ReadFormat(long lFrame, void *pFormat, long *plSize) { - if (!pFormat) { - *plSize = psnData->lFormatLen; - return 0; - } - - if (*plSize < psnData->lFormatLen) { - memcpy(pFormat, psnData->pFormat, *plSize); - } else { - memcpy(pFormat, psnData->pFormat, psnData->lFormatLen); - *plSize = psnData->lFormatLen; - } - - return 0; -} - -bool AVIReadStream::isStreaming() { - return psnData->cache && fStreamingActive && parent->isStreaming(); -} - -bool AVIReadStream::isKeyframeOnly() { - return psnData->keyframe_only; -} - -bool AVIReadStream::getVBRInfo(double& bitrate_mean, double& bitrate_stddev, double& maxdev) { - if (psnData->was_VBR) { - bitrate_mean = psnData->bitrate_mean; - bitrate_stddev = psnData->bitrate_stddev; - maxdev = psnData->max_deviation; - return true; - } - - return false; -} - -/////////////////////////////////////////////////////////////////////////// - -AVIReadHandler::AVIReadHandler(mm_io_c *input) -:/* pAvisynthClipInfo(0) -, */ - m_pInput(input), - mbFileIsDamaged(false) -{ - //this->hFile = INVALID_HANDLE_VALUE; - //this->hFileUnbuffered = INVALID_HANDLE_VALUE; - //this->paf = NULL; - ref_count = 1; - streams=0; - fStreamsActive = 0; - fDisableFastIO = false; - streamBuffer = NULL; - nRealTime = 0; - nActiveStreamers = 0; - fFakeIndex = false; - nFiles = 1; - nCurrentFile = 0; - pSegmentHint = NULL; - - _construct(/*s*/); -} - -AVIReadHandler::~AVIReadHandler() { - _destruct(); -} - -void AVIReadHandler::_construct(/*const char *pszFile*/) { - - try { - //AVIFileDesc *pDesc; - - // open file - - /*hFile = CreateFile(pszFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); - - if (INVALID_HANDLE_VALUE == hFile) - throw MyWin32Error("Couldn't open %s: %%s", GetLastError(), pszFile); - - hFileUnbuffered = CreateFile( - pszFile, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING, - NULL - );*/ - - //i64FilePosition = 0; - -// m_pUnbufferedInput = m_pInput->Clone(); -// if(m_pUnbufferedInput) { -// m_pUnbufferedInput->setAccess(false, true); -// if(!m_pUnbufferedInput->IsOpened()) { -// delete m_pUnbufferedInput; -// m_pUnbufferedInput = &m_pInput; -// } -// } else - m_pUnbufferedInput = m_pInput; - - m_pInput->setFilePointer2(0, seek_beginning); - - // recursively parse file - - _parseFile(listStreams); - - // Create first link - - i64Size = m_pInput->get_size(); - - /*if (!(pDesc = new AVIFileDesc)) - throw error_c("out of memory"); - - pDesc->hFile = hFile; - pDesc->hFileUnbuffered = hFileUnbuffered; - pDesc->i64Size = i64Size = _sizeFile(); - - listFiles.AddHead(pDesc);*/ - - } catch(...) { - _destruct(); - throw; - } -} - -#if 0 -bool AVIReadHandler::AppendFile(const char *pszFile) { - List2 newstreams; - AVIStreamNode *pasn_old, *pasn_new, *pasn_old_next=NULL, *pasn_new_next=NULL; - //AVIFileDesc *pDesc; - - nCurrentFile = -1; - - // open file - - /*hFile = CreateFile(pszFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); - - if (INVALID_HANDLE_VALUE == hFile) - throw MyWin32Error("Couldn't open %s: %%s", GetLastError(), pszFile); - - hFileUnbuffered = CreateFile( - pszFile, - GENERIC_READ, - FILE_SHARE_READ, - NULL, - OPEN_EXISTING, - FILE_ATTRIBUTE_NORMAL | FILE_FLAG_NO_BUFFERING, - NULL - );*/ - - try { - _parseFile(newstreams); - - pasn_old = listStreams.AtHead(); - pasn_new = newstreams.AtHead(); - - while(!!(pasn_old_next = pasn_old->NextFromHead()) & !!(pasn_new_next = pasn_new->NextFromHead())) { - const char *szPrefix; - - switch(pasn_old->hdr.fccType) { - case streamtypeAUDIO: szPrefix = "Cannot append segment: The audio streams "; break; - case streamtypeVIDEO: szPrefix = "Cannot append segment: The video streams "; break; - case streamtypeINTERLEAVED: szPrefix = "Cannot append segment: The DV streams "; break; - default: szPrefix = ""; break; - } - - // If it's not an audio or video stream, why do we care? - - if (szPrefix) { - // allow ivas as a synonym for vids - - uint32_le fccOld = pasn_old->hdr.fccType; - uint32_le fccNew = pasn_new->hdr.fccType; - - if (fccOld != fccNew) - throw error_c("Cannot append segment: The stream types do not match."); - -// if (pasn_old->hdr.fccHandler != pasn_new->hdr.fccHandler) -// throw error_c("%suse incompatible compression types.", szPrefix); - - // A/B ?= C/D ==> AD ?= BC - - if ((sint64)pasn_old->hdr.dwScale * pasn_new->hdr.dwRate != (sint64)pasn_new->hdr.dwScale * pasn_old->hdr.dwRate) - throw error_c("%shave different sampling rates (%.5f vs. %.5f)" - ,szPrefix - ,(double)pasn_old->hdr.dwRate / pasn_old->hdr.dwScale - ,(double)pasn_new->hdr.dwRate / pasn_new->hdr.dwScale - ); - - if (pasn_old->hdr.dwSampleSize != pasn_new->hdr.dwSampleSize) - throw error_c("%shave different block sizes (%d vs %d).", szPrefix, pasn_old->hdr.dwSampleSize, pasn_new->hdr.dwSampleSize); - - // I hate PCMWAVEFORMAT. - - bool fOk = pasn_old->lFormatLen == pasn_new->lFormatLen && !memcmp(pasn_old->pFormat, pasn_new->pFormat, pasn_old->lFormatLen); - - if (pasn_old->hdr.fccType == streamtypeAUDIO) - if (((w32WAVEFORMATEX *)pasn_old->pFormat)->wFormatTag == WAVE_FORMAT_PCM - && ((w32WAVEFORMATEX *)pasn_new->pFormat)->wFormatTag == WAVE_FORMAT_PCM) - fOk = !memcmp(pasn_old->pFormat, pasn_new->pFormat, sizeof(w32PCMWAVEFORMAT)); - - if (!fOk) - throw error_c("%shave different data formats.", szPrefix); - } - - pasn_old = pasn_old_next; - pasn_new = pasn_new_next; - } - - if (pasn_old_next || pasn_new_next) - throw error_c("Cannot append segment: The segment has a different number of streams."); - - /*if (!(pDesc = new AVIFileDesc)) - throw error_c("out of memory"); - - pDesc->hFile = hFile; - pDesc->hFileUnbuffered = hFileUnbuffered; - pDesc->i64Size = _sizeFile();*/ - } catch(const error_c&) { - while(pasn_new = newstreams.RemoveHead()) - delete pasn_new; - - /*CloseHandle(hFile); - if (hFileUnbuffered != INVALID_HANDLE_VALUE) - CloseHandle(hFileUnbuffered);*/ - - throw; - } - - // Accept segment; begin merging process. - - pasn_old = listStreams.AtHead(); - - while(pasn_old_next = pasn_old->NextFromHead()) { - pasn_new = newstreams.RemoveHead(); - - // Fix up header. - - pasn_old->hdr.dwLength += pasn_new->hdr.dwLength; - - if (pasn_new->hdr.dwSuggestedBufferSize > pasn_old->hdr.dwSuggestedBufferSize) - pasn_old->hdr.dwSuggestedBufferSize = pasn_new->hdr.dwSuggestedBufferSize; - - pasn_old->bytes += pasn_new->bytes; - pasn_old->frames += pasn_new->frames; - pasn_old->length += pasn_new->length; - - // Merge indices. - - int oldlen = pasn_old->index.indexLen(); - AVIIndexEntry2 *idx_old = pasn_old->index.takeIndex2(); - AVIIndexEntry2 *idx_new = pasn_new->index.index2Ptr(); - int i; - - pasn_old->index.clear(); - - for(i=0; iindex.add(&idx_old[i]); - } - - delete[] idx_old; - - for(i=pasn_new->index.indexLen(); i; i--) { - idx_new->size ^= 0x80000000; - idx_new->pos += (sint64)nFiles << 48; - pasn_old->index.add(idx_new++); - } - - pasn_old->index.makeIndex2(); - - // Notify all handlers. - - AVIReadStream *pStream, *pStreamNext; - - pStream = pasn_old->listHandlers.AtHead(); - while(pStreamNext = pStream->NextFromHead()) { - pStream->Reinit(); - - pStream = pStreamNext; - } - - // Next! - - pasn_old = pasn_old_next; - delete pasn_new; - } - - ++nFiles; - //listFiles.AddTail(pDesc); - - return true; -} -#endif - -void AVIReadHandler::_parseFile(List2& streamlist) { - uint32_le fccType; - uint32 dwLength; - bool index_found = false; - bool fAcceptIndexOnly = true; - bool hyperindexed = false; - bool bScanRequired = false; - AVIStreamNode *pasn, *pasn_next; - w32MainAVIHeader avihdr; - bool bMainAVIHeaderFound = false; - - sint64 i64ChunkMoviPos = 0; - uint32 dwChunkMoviLength = 0; - - if (!_readChunkHeader(fccType, dwLength)) - throw error_c("Invalid AVI file: File is less than 8 bytes"); - - if (fccType != FOURCC_RIFF) - throw error_c("Invalid AVI file: Not a RIFF file"); - - // If the RIFF header is <4 bytes, assume it was an improperly closed - // file. - - if(m_pInput->read(&fccType, 4) != 4) - return; - - if (fccType != formtypeAVI) - throw error_c("Invalid AVI file: RIFF type is not 'AVI'"); - - // Aggressive mode recovery does extensive validation and searching to attempt to - // recover an AVI. It is significantly slower, however. We place the flag here - // so we can set it if something dreadfully wrong is with the AVI. - - bool bAggressive = false; - - // begin parsing chunks - - while(_readChunkHeader(fccType, dwLength)) { - -// _RPT4(0,"%08I64x %08I64x Chunk '%-4s', length %08lx\n", _posFile()+dwLengthLeft, _posFile(), &fccType, dwLength); - - // Invalid FCCs are bad. If we find one, set the aggressive flag so if a scan - // starts, we aggressively search for and validate data. - - if (!isValidFOURCC(fccType)) { - bAggressive = true; - break; - } - -// bool bInvalidLength = false; - - switch(fccType) { - case FOURCC_LIST: - if(m_pInput->read(&fccType, 4) != 4) - return; - - // If we find a LIST/movi chunk with zero size, jump straight to reindexing - // (unclosed AVIFile output). - - if (!dwLength && fccType == listtypeAVIMOVIE) { - i64ChunkMoviPos = m_pInput->getFilePointer(); - dwChunkMoviLength = 0xFFFFFFF0; - goto terminate_scan; - } - - // Some idiot Premiere plugin is writing AVI files with an invalid - // size field in the LIST/hdrl chunk. - - if (dwLength<4 && fccType != listtypeAVIHEADER) - throw error_c("Invalid AVI file: LIST chunk <4 bytes"); - - if (dwLength < 4) - dwLength = 0; - else - dwLength -= 4; - -// _RPT1(0,"\tList type '%-4s'\n", &fccType); - - switch(fccType) { - case listtypeAVIMOVIE: - - if (dwLength < 8) { - i64ChunkMoviPos = m_pInput->getFilePointer(); - dwChunkMoviLength = 0xFFFFFFF0; - dwLength = 0; - } else { - i64ChunkMoviPos = m_pInput->getFilePointer(); - dwChunkMoviLength = dwLength; - } - - if (fAcceptIndexOnly) - goto terminate_scan; - - break; - case listtypeAVIRECORD: // silently enter grouping blocks - case listtypeAVIHEADER: // silently enter header blocks - dwLength = 0; - break; - case listtypeSTREAMHEADER: - if (!_parseStreamHeader(streamlist, dwLength, bScanRequired)) - fAcceptIndexOnly = false; - else { - mxverb(3, "AVI: OpenDML hierarchical index detected on stream %d.\n", streams); - hyperindexed = true; - } - - ++streams; - dwLength = 0; - break; - } - - break; - - case ckidAVINEWINDEX: // idx1 - if (!hyperindexed) { - index_found = _parseIndexBlock(streamlist, dwLength/16, i64ChunkMoviPos); - dwLength &= 15; - } - break; - - case ckidAVIPADDING: // JUNK - break; - - case mmioFOURCC('s','e','g','m'): // VirtualDub segment hint block - delete pSegmentHint; - if (!(pSegmentHint = new char[dwLength])) - throw error_c("out of memory"); - - if(m_pInput->read(pSegmentHint, dwLength) != dwLength) - return; - - if (dwLength&1) - m_pInput->setFilePointer2(1, seek_current); - - dwLength = 0; - break; - - case listtypeAVIHEADER: - if (!bMainAVIHeaderFound) { - uint32 tc = std::min(dwLength, sizeof avihdr); - memset(&avihdr, 0, sizeof avihdr); - if(m_pInput->read(&avihdr, tc) != tc) - return; - dwLength -= tc; - bMainAVIHeaderFound = true; - } - break; - } - - if (dwLength) { - if (!m_pInput->setFilePointer2(dwLength + (dwLength&1), seek_current)) - break; - } - - // Quit as soon as we see the index block. - - if (fccType == ckidAVINEWINDEX) - break; - } - - if (i64ChunkMoviPos == 0) - throw error_c("This AVI file doesn't have a movie data block (movi)!"); - -terminate_scan: - - if (!hyperindexed && !index_found) - bScanRequired = true; - - if (bScanRequired) { - mxverb(3, "AVI: Index not found or damaged -- reconstructing via file scan.\n"); - - // It's possible that we were in the middle of reading an index when an error - // occurred, so we need to clear all of the indices for all streams. - - pasn = streamlist.AtHead(); - - while((pasn_next = pasn->NextFromHead()) != 0) { - pasn->index.clear(); - pasn = pasn_next; - } - - // obtain length of file and limit scanning if so - - sint64 i64FileSize = m_pInput->get_size(); - - uint32 dwLengthLeft = dwChunkMoviLength; - -// long short_length = (long)((dwChunkMoviLength + _LL(1023)) >> 10); -// long long_length = (long)((i64FileSize - i64ChunkMoviPos + _LL(1023)) >> 10); - -// sint64 length = (hyperindexed || bAggressive) ? long_length : short_length; -// ProgressDialog pd("AVI Import Filter", bAggressive ? "Reconstructing missing index block (aggressive mode)" : "Reconstructing missing index block", length, true); - -// pd.setValueFormat("%ldK of %ldK"); - - fFakeIndex = true; - - m_pInput->setFilePointer2(i64ChunkMoviPos, seek_beginning); - - // For standard AVI files, stop as soon as the movi chunk is exhausted or - // the end of the AVI file is hit. For OpenDML files, continue as long as - // valid chunks are found. - - bool bStopWhenLengthExhausted = !hyperindexed && !bAggressive; - - for(;;) { -// pd.advance((long)((m_pInput->getFilePointer() - i64ChunkMoviPos)/1024)); -// pd.check(); - - // Exit if we are out of movi chunk -- except for OpenDML files. - - if (!bStopWhenLengthExhausted && dwLengthLeft < 8) - break; - - // Validate the FOURCC itself but avoid validating the size, since it - // may be too large for the last LIST/movi. - - if (!_readChunkHeader(fccType, dwLength)) - break; - - bool bValid = isValidFOURCC(fccType) && ((m_pInput->getFilePointer() + dwLength) <= i64FileSize); - - // In aggressive mode, verify that a valid FOURCC follows this chunk. - - if (bAggressive) { - sint64 current_pos = m_pInput->getFilePointer(); - sint64 rounded_length = (dwLength+_LL(1)) & ~_LL(1); - - if (current_pos + dwLength > i64FileSize) - bValid = false; - else if (current_pos + rounded_length <= i64FileSize-8) { - uint32_le fccNext; - uint32 dwLengthNext; - - m_pInput->setFilePointer2(current_pos + rounded_length, seek_beginning); - if (!_readChunkHeader(fccNext, dwLengthNext)) - break; - - bValid &= isValidFOURCC(fccNext) && ((m_pInput->getFilePointer() + dwLengthNext) <= i64FileSize); - - m_pInput->setFilePointer2(current_pos, seek_beginning); - } - } - - if (!bValid) { - // Notify the user that recovering this file requires stronger measures. - - if (!bAggressive) { - sint64 bad_pos = m_pInput->getFilePointer(); - mxverb(3, "AVI: Invalid chunk detected at %lld. Enabling aggressive recovery mode.\n", bad_pos); - - bAggressive = true; - bStopWhenLengthExhausted = false; -// pd.setCaption("Reconstructing missing index block (aggressive mode)"); -// pd.setLimit(long_length); - } - - // Backup by seven bytes and continue. - - m_pInput->setFilePointer2(m_pInput->getFilePointer()-7, seek_beginning); - continue; - } - - int stream; - -// _RPT2(0,"(stream header) Chunk '%-4s', length %08lx\n", &fccType, dwLength); - - dwLengthLeft -= 8+(dwLength + (dwLength&1)); - - // Skip over the chunk. Don't skip over RIFF chunks of type AVIX, or - // LIST chunks of type 'movi'. - - if (dwLength) { - if (fccType == FOURCC_RIFF || fccType == FOURCC_LIST) { - uint32_le fccType2; - - if (m_pInput->read(&fccType2, 4) != 4) - break; - - if (fccType2 != formtypeAVIEXTENDED && fccType2 != listtypeAVIMOVIE) { - if (!m_pInput->setFilePointer2(dwLength + (dwLength&1) - 4, seek_current)) - break; - } - } else { - if (!m_pInput->setFilePointer2(dwLength + (dwLength&1), seek_current)) - break; - } - } - - if (m_pInput->getFilePointer() > i64FileSize) - break; - - if (isxdigit(fccType&0xff) && isxdigit((fccType>>8)&0xff)) { - stream = StreamFromFOURCC(fccType); - - if (stream >=0 && stream < streams) { - - pasn = streamlist.AtHead(); - - while((pasn_next = pasn->NextFromHead()) && stream--) - pasn = pasn_next; - - if (pasn && pasn_next) { - - // Set the keyframe flag for the first sample in the stream, or - // if this is known to be a keyframe-only stream. Do not set the - // keyframe flag if the frame has zero bytes (drop frame). - - pasn->index.add(fccType, m_pInput->getFilePointer()-(dwLength + (dwLength&1))-8, dwLength, (!pasn->bytes || pasn->keyframe_only) && dwLength>0); - pasn->bytes += dwLength; - } - } - - } - } - } - - mbFileIsDamaged |= bAggressive; - - // glue together indices - - pasn = streamlist.AtHead(); - - int nStream = 0; - while((pasn_next = pasn->NextFromHead()) != 0) { - if (!pasn->index.makeIndex2()) - throw error_c("out of memory"); - - pasn->frames = pasn->index.indexLen(); - - // Clear sample size for video streams! - - if (pasn->hdr.fccType == streamtypeVIDEO) - pasn->hdr.dwSampleSize=0; - - // Attempt to fix invalid dwRate/dwScale fractions (can result from unclosed - // AVI files being written by DirectShow). - - if (pasn->hdr.dwRate==0 || pasn->hdr.dwScale == 0) { - // If we're dealing with a video stream, try the frame rate in the AVI header. - // If we're dealing with an audio stream, try the frame rate in the audio - // format. - // Otherwise, just use... uh, 15. - - if (pasn->hdr.fccType == streamtypeVIDEO) { - if (bMainAVIHeaderFound) { - pasn->hdr.dwRate = avihdr.dwMicroSecPerFrame; // This can be zero, in which case the default '15' will kick in below. - pasn->hdr.dwScale = 1000000; - } - } else if (pasn->hdr.fccType == streamtypeAUDIO) { - const w32WAVEFORMATEX *pwfex = (const w32WAVEFORMATEX *)pasn->pFormat; - - pasn->hdr.dwRate = pwfex->nAvgBytesPerSec; - pasn->hdr.dwScale = pwfex->nBlockAlign; - } - - if (pasn->hdr.dwRate==0 || pasn->hdr.dwScale == 0) { - pasn->hdr.dwRate = 15; - pasn->hdr.dwScale = 1; - } - - const int badstream = nStream; - const double newrate = pasn->hdr.dwRate / (double)pasn->hdr.dwScale; - mxverb(3, "AVI: Stream %d has an invalid sample rate. Substituting %f samples/sec as placeholder.\n", badstream, newrate); - } - - // Verify sample size == nBlockAlign for audio. If we find runt samples, - // assume someone did a VBR hack. - - if (pasn->hdr.fccType == streamtypeAUDIO) { - const AVIIndexEntry2 *pIdx = pasn->index.index2Ptr(); - long nBlockAlign = ((w32WAVEFORMATEX *)pasn->pFormat)->nBlockAlign; - - pasn->hdr.dwSampleSize = nBlockAlign; - - for(int i=0; iframes-1; ++i) { - long s = pIdx[i].size & 0x7FFFFFFF; - - if (s && s < nBlockAlign) { - pasn->FixVBRAudio(); - break; - } - } - } - - if (pasn->hdr.dwSampleSize) - pasn->length = (long)pasn->bytes / pasn->hdr.dwSampleSize; - else - pasn->length = pasn->frames; - - pasn = pasn_next; - ++nStream; - } - -// throw error_c("Parse complete. Aborting."); -} - -bool AVIReadHandler::_parseStreamHeader(List2& streamlist, uint32 dwLengthLeft, bool& bIndexDamaged) { - AVIStreamNode *pasn; - uint32_le fccType; - uint32 dwLength; - bool hyperindexed = false; - - if (!(pasn = new AVIStreamNode())) - throw error_c("out of memory"); - - try { - while(dwLengthLeft >= 8 && _readChunkHeader(fccType, dwLength)) { - -// _RPT2(0,"(stream header) Chunk '%-4s', length %08lx\n", &fccType, dwLength); - - dwLengthLeft -= 8; - - if (dwLength > dwLengthLeft) - throw error_c("Invalid AVI file: chunk size extends outside of parent"); - - dwLengthLeft -= (dwLength + (dwLength&1)); - - switch(fccType) { - - case ckidSTREAMHEADER: - memset(&pasn->hdr, 0, sizeof pasn->hdr); - - if (dwLength < sizeof pasn->hdr) { - if(m_pInput->read(&pasn->hdr, dwLength) != dwLength) - throw error_c(); - if (dwLength & 1) - m_pInput->setFilePointer2(1, seek_current); - } else { - if(m_pInput->read(&pasn->hdr, sizeof pasn->hdr) != sizeof pasn->hdr) - throw error_c(); - m_pInput->setFilePointer2(dwLength+(dwLength&1) - sizeof pasn->hdr, seek_current); - } - dwLength = 0; - - pasn->keyframe_only = false; - - break; - - case ckidSTREAMFORMAT: - if (!(pasn->pFormat = new char[pasn->lFormatLen = dwLength])) - throw error_c("out of memory"); - - if(m_pInput->read(pasn->pFormat, dwLength) != dwLength) - throw error_c(); - - if (pasn->hdr.fccType == streamtypeVIDEO) { - switch(((w32BITMAPINFOHEADER *)pasn->pFormat)->biCompression) { - case NULL: - case bitmapFOURCC('R', 'A', 'W', ' '): - case bitmapFOURCC('D', 'I', 'B', ' '): - case bitmapFOURCC('d', 'm', 'b', '1'): - case bitmapFOURCC('m', 'j', 'p', 'g'): - case bitmapFOURCC('M', 'J', 'P', 'G'): - case bitmapFOURCC('V', 'Y', 'U', 'Y'): - case bitmapFOURCC('Y', 'U', 'Y', '2'): - case bitmapFOURCC('U', 'Y', 'V', 'Y'): - case bitmapFOURCC('Y', 'V', 'Y', 'U'): - case bitmapFOURCC('Y', 'V', '1', '2'): - case bitmapFOURCC('I', '4', '2', '0'): - case bitmapFOURCC('Y', '4', '1', 'P'): - case bitmapFOURCC('c', 'y', 'u', 'v'): - case bitmapFOURCC('H', 'F', 'Y', 'U'): - case bitmapFOURCC('b', 't', '2', '0'): - pasn->keyframe_only = true; - } - } - - if (dwLength & 1) - m_pInput->setFilePointer2(1, seek_current); - dwLength = 0; - break; - - case ckidOPENDMLINDEX: // OpenDML extended index - { - sint64 posFileSave = m_pInput->getFilePointer(); - - try { - _parseExtendedIndexBlock(streamlist, pasn, -1, dwLength); - } catch(const error_c&) { - bIndexDamaged = true; - } - - m_pInput->setFilePointer2(posFileSave, seek_beginning); - } - hyperindexed = true; - break; - - case ckidAVIPADDING: // JUNK - break; - } - - if (dwLength) { - if (!m_pInput->setFilePointer2(dwLength + (dwLength&1), seek_current)) - break; - } - } - - if (dwLengthLeft) - m_pInput->setFilePointer2(dwLengthLeft, seek_current); - } catch(...) { - delete pasn; - throw; - } - -// _RPT1(0,"Found stream: type %s\n", pasn->hdr.fccType==streamtypeVIDEO ? "video" : pasn->hdr.fccType==streamtypeAUDIO ? "audio" : "unknown"); - - streamlist.AddTail(pasn); - - return hyperindexed; -} - -bool AVIReadHandler::_parseIndexBlock(List2& streamlist, int count, sint64 movi_offset) { - w32AVIINDEXENTRY avie[32]; - AVIStreamNode *pasn, *pasn_next; - bool absolute_addr = true; - - // Some AVI files have relative addresses in their AVI index chunks, and some - // relative. They're supposed to be relative to the 'movi' chunk; all versions - // of VirtualDub using fast write routines prior to build 4936 generate absolute - // addresses (oops). AVIFile and ActiveMovie are both ambivalent. I guess we'd - // better be as well. - - while(count > 0) { - int tc = count; - int i; - - if (tc>32) tc=32; - count -= tc; - - if (tc*sizeof(w32AVIINDEXENTRY) != m_pInput->read(avie, tc*sizeof(w32AVIINDEXENTRY))) { - pasn = streamlist.AtHead(); - - while((pasn_next = pasn->NextFromHead()) != 0) { - pasn->index.clear(); - pasn->bytes = 0; - - pasn = pasn_next; - } - return false; - } - - for(i=0; iNextFromHead()) && stream--) - pasn = pasn_next; - - if (pasn && pasn_next) { - if (absolute_addr) - pasn->index.add(&avie[i]); - else - pasn->index.add(avie[i].ckid, (movi_offset-4) + (sint64)avie[i].dwChunkOffset, avie[i].dwChunkLength, !!(avie[i].dwFlags & AVIIF_KEYFRAME)); - - pasn->bytes += avie[i].dwChunkLength; - } - } - } - - return true; - -} - -void AVIReadHandler::_parseExtendedIndexBlock(List2& streamlist, AVIStreamNode *pasn, sint64 fpos, uint32 dwLength) { - union { - AVISUPERINDEX idxsuper; - AVISTDINDEX idxstd; - }; - - union { - struct _avisuperindex_entry superent[64]; - uint32 dwHeap[256]; - }; - - int entries, tp; - int i; - sint64 i64FPSave = m_pInput->getFilePointer(); - - if (fpos>=0) - m_pInput->setFilePointer2(fpos, seek_beginning); - if(m_pInput->read((char *)&idxsuper + 8, sizeof(AVISUPERINDEX) - 8) != sizeof(AVISUPERINDEX) - 8) - throw error_c(); - - switch(idxsuper.bIndexType) { - case AVI_INDEX_OF_INDEXES: - // sanity check - - if (idxsuper.wLongsPerEntry != 4) - throw error_c("Invalid superindex block in stream"); - -// if (idxsuper.bIndexSubType != 0) -// throw error_c("Field indexes not supported"); - - entries = idxsuper.nEntriesInUse; - - while(entries > 0) { - tp = sizeof superent / sizeof superent[0]; - if (tp>entries) tp=entries; - - if(m_pInput->read(superent, tp*sizeof superent[0]) != tp*sizeof superent[0]) - throw error_c(); - - for(i=0; isetFilePointer2(i64FPSave, seek_beginning); -} - -void AVIReadHandler::_destruct() { - AVIStreamNode *pasn; - //AVIFileDesc *pDesc; - - /*if (pAvisynthClipInfo) - pAvisynthClipInfo->Release(); - - if (paf) - AVIFileRelease(paf);*/ - - while((pasn = listStreams.RemoveTail()) != 0) - delete pasn; - - delete streamBuffer; - - if(m_pUnbufferedInput && (m_pUnbufferedInput!=m_pInput)) - delete m_pUnbufferedInput; - - /*if (listFiles.IsEmpty()) { - if (hFile != INVALID_HANDLE_VALUE) - CloseHandle(hFile); - if (hFileUnbuffered != INVALID_HANDLE_VALUE) - CloseHandle(hFileUnbuffered); - } else - while(pDesc = listFiles.RemoveTail()) { - CloseHandle(pDesc->hFile); - CloseHandle(pDesc->hFileUnbuffered); - delete pDesc; - }*/ - - delete pSegmentHint; -} - -/////////////////////////////////////////////////////////////////////////// - -void AVIReadHandler::Release() { - if (!--ref_count) - delete this; -} - -void AVIReadHandler::AddRef() { - ++ref_count; -} - -IAVIReadStream *AVIReadHandler::GetStream(uint32 fccType, sint32 lParam) { - { - AVIStreamNode *pasn, *pasn_next; - int streamno = 0; - - pasn = listStreams.AtHead(); - - while((pasn_next = pasn->NextFromHead()) != NULL) { - if (pasn->hdr.fccType == fccType && !lParam--) - break; - - pasn = pasn_next; - ++streamno; - } - - if (pasn_next) { - return new AVIReadStream(this, pasn, streamno); - } - - return NULL; - } -} - -void AVIReadHandler::EnableFastIO(bool f) { - fDisableFastIO = !f; -} - -bool AVIReadHandler::isOptimizedForRealtime() { - return nRealTime!=0; -} - -bool AVIReadHandler::isStreaming() { - return nActiveStreamers!=0 && !mbFileIsDamaged; -} - -bool AVIReadHandler::isIndexFabricated() { - return fFakeIndex; -} - -#if 0 -bool AVIReadHandler::getSegmentHint(const char **ppszPath) { - if (!pSegmentHint) { - if (ppszPath) - *ppszPath = NULL; - - return false; - } - - if (ppszPath) - *ppszPath = pSegmentHint+1; - - return !!pSegmentHint[0]; -} -#endif - -/////////////////////////////////////////////////////////////////////////// - -void AVIReadHandler::EnableStreaming(int stream) { - if (!fStreamsActive) { - if (!(streamBuffer = new char[STREAM_SIZE])) - throw error_c("out of memory"); - - i64StreamPosition = -1; - sbPosition = sbSize = 0; - } - - fStreamsActive |= (1<>48)) - _SelectFile((int)(i64StreamPosition>>48)); - - if (sbPosition >= sbSize) { - if (nRealTime || (((i64StreamPosition&_LL(0x0000FFFFFFFFFFFF))+sbSize) & -STREAM_BLOCK_SIZE)+STREAM_SIZE > i64Size) { - i64StreamPosition += sbSize; - sbPosition = 0; - m_pInput->setFilePointer2(i64StreamPosition & _LL(0x0000FFFFFFFFFFFF), seek_beginning); - - sbSize = m_pInput->read(streamBuffer, STREAM_RT_SIZE); - - if (sbSize < 0) { - sbSize = 0; -// #pragma message(__TODO__ "Throw ?") - //throw MyWin32Error("Failure streaming AVI file: %%s.",GetLastError()); - } - } else { - i64StreamPosition += sbSize; - sbPosition = i64StreamPosition & (STREAM_BLOCK_SIZE-1); - i64StreamPosition &= -STREAM_BLOCK_SIZE; -// #pragma message(__TODO__ "What to do with the unbuffered part ?") - m_pUnbufferedInput->setFilePointer(i64StreamPosition & _LL(0x0000FFFFFFFFFFFF), seek_beginning); - - sbSize = m_pUnbufferedInput->read(streamBuffer, STREAM_SIZE); - - if (sbSize < 0) { - sbSize = 0; -// #pragma message(__TODO__ "Throw ?") - //throw MyWin32Error("Failure streaming AVI file: %%s.",GetLastError()); - } - } - } - - if (sbPosition >= sbSize) - return NULL; - - if (bytes > sbSize - sbPosition) - bytes = sbSize - sbPosition; - - sbPosition += bytes; - - return streamBuffer + sbPosition - bytes; -} - -bool AVIReadHandler::Stream(AVIStreamNode *pusher, sint64 pos) { - - // Do not stream aggressively recovered files. - - if (mbFileIsDamaged) - return false; - - bool read_something = false; - - if (!streamBuffer) - return false; - - if (i64StreamPosition == -1) { - i64StreamPosition = pos; - sbPosition = 0; - } - - if (pos < i64StreamPosition+sbPosition) - return false; - - // >4Mb past current position!? - - if (pos > i64StreamPosition+sbPosition+4194304) { -// OutputDebugString("Resetting streaming position!\n"); - i64StreamPosition = pos; - sbSize = sbPosition = 0; - } - -/* if (pusher->hdr.fccType == streamtypeVIDEO) - OutputDebugString("pushed by video\n"); - else - OutputDebugString("pushed by audio\n");*/ - - ++pusher->stream_pushes; - pusher->stream_push_pos = pos; - - while(pos >= i64StreamPosition+sbPosition) { - long actual, left; - char *src; - uint32_le hdr[2]; - int stream; - - // read next header - - left = 8; - while(left > 0) { - actual = left; - src = _StreamRead(actual); - - if (!src) - return read_something; - - memcpy((char *)hdr + (8-left), src, actual); - left -= actual; - } - - stream = StreamFromFOURCC(hdr[0]); - - if (isxdigit(hdr[0]&0xff) && isxdigit((hdr[0]>>8)&0xff) && stream<32 && - ((1L<NextFromHead()) != NULL) { - if (streamno == stream) { - unsigned chunk_size = hdr[1] + (hdr[1]&1); - - if (chunk_size >= 0x7ffffff0) { - // Uh oh... assume the file has been damaged. Disable streaming. - sint64 bad_pos = i64StreamPosition+sbPosition-8; - - mxverb(3, "AVI: Invalid block found at %lld -- disabling streaming.\n", bad_pos); - mbFileIsDamaged = true; - i64StreamPosition = -1; - sbPosition = sbSize = 0; - return false; - } - - long left = chunk_size; - bool fWrite = pasn->cache->WriteBegin(i64StreamPosition + sbPosition, left); - char *dst; - - while(left > 0) { - actual = left; - - dst = _StreamRead(actual); - - if (!dst) { - if (fWrite) - pasn->cache->WriteEnd(); - return read_something; - } - - if (fWrite) - pasn->cache->Write(dst, actual); - - left -= actual; - } - - if (fWrite) - pasn->cache->WriteEnd(); - - read_something = true; - - break; - } - - pasn = pasn_next; - ++streamno; - } - } else { - - if (hdr[0] != FOURCC_LIST && hdr[0] != FOURCC_RIFF) { - long actual; - - // skip chunk - - unsigned chunk_size = hdr[1] + (hdr[1] & 1); - - if (chunk_size >= 0x7ffffff0) { - mbFileIsDamaged = true; - i64StreamPosition = -1; - sbPosition = sbSize = 0; - return false; - } - - // Determine if the chunk is overly large. If the chunk is too large, don't - // stream through it. - - if (chunk_size > 262144) { - // Force resynchronization on next read. - i64StreamPosition += chunk_size; - sbPosition = sbSize = 0; - return read_something; - } - - left = chunk_size; - - while(left > 0) { - actual = left; - - if (!_StreamRead(actual)) - return read_something; - - left -= actual; - } - } else { - left = 4; - - while(left > 0) { - actual = left; - - if (!_StreamRead(actual)) - return read_something; - - left -= actual; - } - } - - } - } - - return true; -} - -sint64 AVIReadHandler::getStreamPtr() { - return i64StreamPosition + sbPosition; -} - -void AVIReadHandler::FixCacheProblems(AVIReadStream *arse) { - AVIStreamNode *pasn, *pasn_next; - - // The simplest fix is simply to disable caching on the stream that's - // cache-missing. However, this is a bad idea if the problem is a low-bandwidth - // audio stream that's outrunning a high-bandwidth video stream behind it. - // Check the streaming leader, and if the streaming leader is comparatively - // low bandwidth and running at least 512K ahead of the cache-missing stream, - // disable its cache. - - AVIStreamNode *stream_leader = NULL; - int stream_leader_no=0; - int streamno=0; - - pasn = listStreams.AtHead(); - - while((pasn_next = pasn->NextFromHead()) != NULL) { - if (pasn->cache) - if (!stream_leader || pasn->stream_pushes > stream_leader->stream_pushes) { - stream_leader = pasn; - stream_leader_no = streamno; - } - - pasn = pasn_next; - ++streamno; - } - - if (stream_leader && stream_leader->stream_bytes*2 < arse->psnData->stream_bytes - && stream_leader->stream_push_pos >= arse->psnData->stream_push_pos+524288) { -#ifdef STREAMING_DEBUG - OutputDebugString("caching disabled on fast puny leader\n"); -#endif - delete stream_leader->cache; - stream_leader->cache = NULL; - - DisableStreaming(stream_leader_no); - - i64StreamPosition = -1; - sbPosition = sbSize = 0; - } else { -#ifdef STREAMING_DEBUG - OutputDebugString("disabling caching at request of client\n"); -#endif - - arse->EndStreaming(); - - if (arse->psnData == stream_leader) { - i64StreamPosition = -1; - sbPosition = sbSize = 0; - } - } - - // Reset cache statistics on all caches. - - pasn = listStreams.AtHead(); - - while((pasn_next = pasn->NextFromHead()) != 0) { - if (pasn->cache) - pasn->cache->ResetStatistics(); - - pasn = pasn_next; - } -} - -long AVIReadHandler::ReadData(int stream, void *buffer, sint64 position, long len) { - if (nCurrentFile<0 || nCurrentFile != (int)(position>>48)) - _SelectFile((int)(position>>48)); - -// _RPT3(0,"Reading from file %d, position %I64x, size %d\n", nCurrentFile, position, len); - - if (!m_pInput->setFilePointer2(position & _LL(0x0000FFFFFFFFFFFF), seek_beginning)) - return -1; - return m_pInput->read(buffer, len); -} - -bool AVIReadHandler::_readChunkHeader(uint32_le& pfcc, uint32& pdwLen) { - uint32_le dw[2]; - sint32 actual; - - actual = m_pInput->read(dw, 8); - - if(actual != 8) - return false; - - pfcc = dw[0]; - pdwLen = dw[1]; - - return true; -} - -void AVIReadHandler::_SelectFile(int file) { - //AVIFileDesc *pDesc, *pDesc_next; - - nCurrentFile = file; - - /*pDesc = listFiles.AtHead(); - while((pDesc_next = pDesc->NextFromHead()) && file--) - pDesc = pDesc_next; - - hFile = pDesc->hFile; - hFileUnbuffered = pDesc->hFileUnbuffered; - i64Size = pDesc->i64Size;*/ -} diff --git a/aviclasses/AVIReadHandler.h b/aviclasses/AVIReadHandler.h deleted file mode 100644 index 3ed6e634f..000000000 --- a/aviclasses/AVIReadHandler.h +++ /dev/null @@ -1,69 +0,0 @@ -// VirtualDub - Video processing and capture application -// Copyright (C) 1998-2001 Avery Lee -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. - -// -// Modified by Julien 'Cyrius' Coloos -// 20-09-2003 -// - -#ifndef f_AVIREADHANDLER_H -#define f_AVIREADHANDLER_H - -#include "mm_io.h" -#include "common_gdivfw.h" - -// These are meant as AVIFile replacements. They're not quite to AVIFile -// specs, but they'll do for now. - -class IAVIReadStream { -public: - virtual ~IAVIReadStream(); - - virtual long BeginStreaming(long lStart, long lEnd, long lRate)=0; - virtual long EndStreaming()=0; - virtual long Info(w32AVISTREAMINFO *pasi, long lSize)=0; - virtual bool IsKeyFrame(long lFrame)=0; - virtual long Read(long lStart, long lSamples, void *lpBuffer, long cbBuffer, long *plBytes, long *plSamples)=0; - virtual long Start()=0; - virtual long End()=0; - virtual long PrevKeyFrame(long lFrame)=0; - virtual long NextKeyFrame(long lFrame)=0; - virtual long NearestKeyFrame(long lFrame)=0; - virtual long FormatSize(long lFrame, long *plSize)=0; - virtual long ReadFormat(long lFrame, void *pFormat, long *plSize)=0; - virtual bool isStreaming()=0; - virtual bool isKeyframeOnly()=0; - - virtual bool getVBRInfo(double& bitrate_mean, double& bitrate_stddev, double& maxdev)=0; -}; - -class IAVIReadHandler { -public: - virtual void AddRef()=0; - virtual void Release()=0; - virtual IAVIReadStream *GetStream(uint32 fccType, sint32 lParam)=0; - virtual void EnableFastIO(bool)=0; - virtual bool isOptimizedForRealtime()=0; - virtual bool isStreaming()=0; - virtual bool isIndexFabricated()=0; - //virtual bool AppendFile(const char *pszFile)=0; - //virtual bool getSegmentHint(const char **ppszPath)=0; -}; - -IAVIReadHandler *CreateAVIReadHandler(mm_io_c *input); - -#endif diff --git a/aviclasses/Fixes.h b/aviclasses/Fixes.h deleted file mode 100644 index 1d09d511b..000000000 --- a/aviclasses/Fixes.h +++ /dev/null @@ -1,58 +0,0 @@ -// VirtualDub - Video processing and capture application -// Copyright (C) 1998-2001 Avery Lee -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. - -// -// Modified by Julien 'Cyrius' Coloos -// 20-09-2003 -// - -#ifndef f_FIXES_H -#define f_FIXES_H - -#include "common_gdivfw.h" - -// Those stupid idiots at Microsoft forgot to change this structure -// when making the VfW headers for Win32. The result is that the -// AVIStreamHeader is correct in 16-bit Windows, but the 32-bit -// headers define RECT as LONGs instead of SHORTs. This creates -// invalid AVI files!!!! - -typedef struct { - sint16_le left; - sint16_le top; - sint16_le right; - sint16_le bottom; -} w32RECT16; - -typedef struct { - uint32_le fccType; - uint32_le fccHandler; - uint32_le dwFlags; - uint16_le wPriority; - uint16_le wLanguage; - uint32_le dwInitialFrames; - uint32_le dwScale; - uint32_le dwRate; - uint32_le dwStart; - uint32_le dwLength; - uint32_le dwSuggestedBufferSize; - uint32_le dwQuality; - uint32_le dwSampleSize; - w32RECT16 rcFrame; -} AVIStreamHeader_fixed; - -#endif diff --git a/aviclasses/Makefile.in b/aviclasses/Makefile.in deleted file mode 100644 index a879c310d..000000000 --- a/aviclasses/Makefile.in +++ /dev/null @@ -1,2 +0,0 @@ -all %: - make -C .. $@ diff --git a/aviclasses/Makefile.mingw b/aviclasses/Makefile.mingw deleted file mode 100644 index 7e241fe2c..000000000 --- a/aviclasses/Makefile.mingw +++ /dev/null @@ -1,5 +0,0 @@ -# mkvtoolnix - Makefile for MinGW -# because I was fed up fighting against libtool - -all clean: - make -C .. $@ diff --git a/aviclasses/ac_common.h b/aviclasses/ac_common.h deleted file mode 100644 index 3d6c667ea..000000000 --- a/aviclasses/ac_common.h +++ /dev/null @@ -1,173 +0,0 @@ -// Some common tools -// Copyright (C) 2003 Julien 'Cyrius' Coloos -// -// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA -// or visit http://www.gnu.org/licenses/gpl.html - -#ifndef __TOOLS_COMMON_H__ -#define __TOOLS_COMMON_H__ - -#include "os.h" - -#include -#include -#include -#include -#include -#include - -// Provide the storage class specifier (extern for an .exe file, null -// for DLL) and the __declspec specifier (dllimport for an .exe file, -// dllexport for DLL). -// You must define TOOLS_DLL_EXPORTS when compiling the DLL. -// You can now use this header file in both the .exe file and DLL - a -// much safer means of using common declarations than two different -// header files. -#ifdef TOOLS_DLL -# ifdef TOOLS_DLL_EXPORTS -# define TOOLS_DLL_API __declspec(dllexport) -# define TOOLS_EXPIMP_TEMPLATE -# else -# define TOOLS_DLL_API __declspec(dllimport) -# define TOOLS_EXPIMP_TEMPLATE extern -# endif -#else -# define TOOLS_DLL_API -# define TOOLS_EXPIMP_TEMPLATE -#endif - -#ifndef _LL - #ifdef _MSC_VER - #define _LL(i) i ## i64 - #else - #define _LL(i) i ## ll - #endif -#endif - -// Fix taken from VirtualDub (c) Avery Lee -/////////////////////////////////////////////////////////////////////////// -// -// STL fixes -// -/////////////////////////////////////////////////////////////////////////// - -#ifdef _MSC_VER -#if _MSC_VER < 1300 - namespace std { - template - inline const T& min(const T& x, const T& y) { - return _cpp_min(x, y); - } - - template - inline const T& max(const T& x, const T& y) { - return _cpp_max(x, y); - } - }; -#endif -#endif - -#ifdef _MSC_VER -typedef signed __int8 sint8; -typedef signed __int16 sint16; -typedef signed __int32 sint32; -typedef signed __int64 sint64; -typedef unsigned __int8 uint8; -typedef unsigned __int16 uint16; -typedef unsigned __int32 uint32; -typedef unsigned __int64 uint64; -#else -typedef int8_t sint8; -typedef int16_t sint16; -typedef int32_t sint32; -typedef int64_t sint64; -typedef uint8_t uint8; -typedef uint16_t uint16; -typedef uint32_t uint32; -typedef uint64_t uint64; -#endif - - -#define RoundToLong(f) (sint32)((f)+0.5) -#define RoundToULong(f) (uint32)((f)+0.5) - - -typedef enum { - kMsg, - kMsgWarning, - kMsgError -} eMsgType; - - -#ifdef _DEBUG -#define DEBUG_MESSAGE PrintMessage -#else -#define DEBUG_MESSAGE -#endif - -template -void Duplicatelist(std::list<_T *> &dst, std::list<_T *> &src) { - int i; - for(i = 0; i < src.size(); i++) { - _T *pNewNode = new _T(*(src[i])); - dst.push_back(pNewNode); - } -} - -template -void Duplicatevector(std::vector<_T *> &dst, std::vector<_T *> &src) { - int i; - for(i = 0; i < src.size(); i++) { - _T *pNewNode = new _T(*(src[i])); - dst.push_back(pNewNode); - } -} - -template -void Clearlist(std::list<_T *>& cont) { - int i; - for (i = 0; i < cont.size(); i++) - delete cont[i]; - cont.clear(); -} - -template -void Clearvector(std::vector<_T *>& cont) { - int i; - for (i = 0; i < cont.size(); i++) - delete cont[i]; - cont.clear(); -} - - -#define CONTAINER_DUPLICATE_0(container, _T, dst, src) \ - Duplicate##container<_T>(dst, src); - -#define CONTAINER_CLEAR_0(container, _T, cont) \ - Clear##container<_T>(cont); - -#define LIST_DUPLICATE(_T, src, dst) \ - CONTAINER_DUPLICATE_0(list, _T, src, dst) -#define LIST_CLEAR(_T, cont) \ - CONTAINER_CLEAR_0(list, _T, cont) -#define VECTOR_DUPLICATE(_T, src, dst) \ - CONTAINER_DUPLICATE_0(vector, _T, src, dst) -#define VECTOR_CLEAR(_T, cont) \ - CONTAINER_CLEAR_0(vector, _T, cont) - - -template class std::vector; - -#endif // __TOOLS_COMMON_H__ diff --git a/aviclasses/common_endian.h b/aviclasses/common_endian.h deleted file mode 100644 index 652dfc808..000000000 --- a/aviclasses/common_endian.h +++ /dev/null @@ -1,189 +0,0 @@ -// Some common tools -// Copyright (C) 2003 Julien 'Cyrius' Coloos -// -// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA -// or visit http://www.gnu.org/licenses/gpl.html - -#ifndef __TOOLS_COMMON_ENDIAN_H__ -#define __TOOLS_COMMON_ENDIAN_H__ - -#include "os.h" - -#include "ac_common.h" - -#undef LIL_ENDIAN -#undef BIG_ENDIAN -#define LIL_ENDIAN 0x0102 -#define BIG_ENDIAN 0x0201 - -#if WORDS_BIGENDIAN == 1 -# define AVI_BYTE_ORDER BIG_ENDIAN -#else -# define AVI_BYTE_ORDER LIL_ENDIAN -#endif - -typedef enum { - kBigEndian, - kLittleEndian -} eEndianness; - -template -class EndianValue { -protected: - _T m_Value; - -public: - // Defining ctors cause troubles in unions - //EndianValue<_T, _ENDIANNESS>(void) { }; - //EndianValue<_T, _ENDIANNESS>(const _T& value) { - // *this = value; - //}; - inline operator _T(void) const { -#if AVI_BYTE_ORDER == LIL_ENDIAN - if(_ENDIANNESS == kLittleEndian) - return m_Value; - else { - _T value = m_Value; - std::reverse(reinterpret_cast(&value), reinterpret_cast((&value)+1)); - return value; - } -#else - if(_ENDIANNESS == kBigEndian) - return m_Value; - else { - _T value = m_Value; - std::reverse(reinterpret_cast(&value), reinterpret_cast((&value)+1)); - return value; - } -#endif - }; - inline EndianValue<_T, _ENDIANNESS>& operator =(const _T& value) { - m_Value = value; -#if AVI_BYTE_ORDER == LIL_ENDIAN - if(_ENDIANNESS == kBigEndian) - std::reverse(reinterpret_cast(&m_Value), reinterpret_cast((&m_Value)+1)); -#else - if(_ENDIANNESS == kLittleEndian) - std::reverse(reinterpret_cast(&m_Value), reinterpret_cast((&m_Value)+1)); -#endif - return *this; - }; - // If this is defined, we get an error C2622 because union members can't have - // an assignment operator - //inline EndianValue<_T, _ENDIANNESS>& operator =(const EndianValue<_T, _ENDIANNESS>& value) { - // m_Value = value.m_Value; - // return *this; - //}; - // The 'conventional' binary operators mustn't be defined (at least - // with MSVC) because a proper conversion is already done by the - // compiler (overloading again the operator generates problems) -#define DEFINE_ENDIANVALUE_BINARY_OPERATOR_1(op) \ - inline EndianValue<_T, _ENDIANNESS>& operator op(const _T& value) { \ - *this = _T(*this) op value; \ - return *this; \ - }; -#define DEFINE_ENDIANVALUE_BINARY_OPERATOR_2(op) \ - inline EndianValue<_T, _ENDIANNESS>& operator op##=(const _T& value) { \ - *this = _T(*this) op value; \ - return *this; \ - }; -#define DEFINE_ENDIANVALUE_COMPARISON_OPERATOR(op) \ - inline bool operator op(const EndianValue<_T, _ENDIANNESS>& value) const { \ - return (m_Value op value.m_Value); \ - }; -#define DEFINE_ENDIANVALUE_BINARY_OPERATOR(op) \ -DEFINE_ENDIANVALUE_BINARY_OPERATOR_2(op) - DEFINE_ENDIANVALUE_BINARY_OPERATOR(+) - DEFINE_ENDIANVALUE_BINARY_OPERATOR(-) - DEFINE_ENDIANVALUE_BINARY_OPERATOR(*) - DEFINE_ENDIANVALUE_BINARY_OPERATOR(/) - DEFINE_ENDIANVALUE_BINARY_OPERATOR(%) - DEFINE_ENDIANVALUE_BINARY_OPERATOR(&) - DEFINE_ENDIANVALUE_BINARY_OPERATOR(|) - DEFINE_ENDIANVALUE_BINARY_OPERATOR(<<) - DEFINE_ENDIANVALUE_BINARY_OPERATOR(>>) - DEFINE_ENDIANVALUE_COMPARISON_OPERATOR(==) - DEFINE_ENDIANVALUE_COMPARISON_OPERATOR(!=) - DEFINE_ENDIANVALUE_COMPARISON_OPERATOR(<) - DEFINE_ENDIANVALUE_COMPARISON_OPERATOR(<=) - DEFINE_ENDIANVALUE_COMPARISON_OPERATOR(>) - DEFINE_ENDIANVALUE_COMPARISON_OPERATOR(>=) - inline EndianValue<_T, _ENDIANNESS>& operator ++(void) { - *this = _T(*this) + 1; - return *this; - }; - inline _T operator ++(int) { - _T value = _T(*this); - ++*this; - return value; - }; - inline EndianValue<_T, _ENDIANNESS>& operator --(void) { - *this = _T(*this) - 1; - return *this; - }; - inline _T operator --(int) { - _T value = _T(*this); - --*this; - return value; - }; -}; - - -// Instantiate some EndianValue<...> classes -// This does not create an object. It only forces the generation of all of the members -// of the class. It exports them from the DLL and imports them into the .exe file. -TOOLS_EXPIMP_TEMPLATE template class TOOLS_DLL_API EndianValue; -TOOLS_EXPIMP_TEMPLATE template class TOOLS_DLL_API EndianValue; -TOOLS_EXPIMP_TEMPLATE template class TOOLS_DLL_API EndianValue; -TOOLS_EXPIMP_TEMPLATE template class TOOLS_DLL_API EndianValue; -TOOLS_EXPIMP_TEMPLATE template class TOOLS_DLL_API EndianValue; -TOOLS_EXPIMP_TEMPLATE template class TOOLS_DLL_API EndianValue; -TOOLS_EXPIMP_TEMPLATE template class TOOLS_DLL_API EndianValue; -TOOLS_EXPIMP_TEMPLATE template class TOOLS_DLL_API EndianValue; -TOOLS_EXPIMP_TEMPLATE template class TOOLS_DLL_API EndianValue; -TOOLS_EXPIMP_TEMPLATE template class TOOLS_DLL_API EndianValue; -TOOLS_EXPIMP_TEMPLATE template class TOOLS_DLL_API EndianValue; -TOOLS_EXPIMP_TEMPLATE template class TOOLS_DLL_API EndianValue; - -#if AVI_BYTE_ORDER == BIG_ENDIAN -typedef EndianValue uint16_le; -typedef EndianValue uint32_le; -typedef EndianValue uint64_le; -typedef EndianValue sint16_le; -typedef EndianValue sint32_le; -typedef EndianValue sint64_le; -typedef uint16 uint16_be; -typedef uint32 uint32_be; -typedef uint64 uint64_be; -typedef sint16 sint16_be; -typedef sint32 sint32_be; -typedef sint64 sint64_be; -#elif AVI_BYTE_ORDER == LIL_ENDIAN -typedef uint16 uint16_le; -typedef uint32 uint32_le; -typedef uint64 uint64_le; -typedef sint16 sint16_le; -typedef sint32 sint32_le; -typedef sint64 sint64_le; -typedef EndianValue uint16_be; -typedef EndianValue uint32_be; -typedef EndianValue uint64_be; -typedef EndianValue sint16_be; -typedef EndianValue sint32_be; -typedef EndianValue sint64_be; -#endif - - -#endif // __TOOLS_COMMON_ENDIAN_H__ diff --git a/aviclasses/common_gdivfw.h b/aviclasses/common_gdivfw.h deleted file mode 100644 index e3f84be28..000000000 --- a/aviclasses/common_gdivfw.h +++ /dev/null @@ -1,384 +0,0 @@ -// Some common tools -// Copyright (C) 2003 Julien 'Cyrius' Coloos -// -// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA -// or visit http://www.gnu.org/licenses/gpl.html - -#ifndef __TOOLS_COMMON_GDIVFW_H__ -#define __TOOLS_COMMON_GDIVFW_H__ - -#include "os.h" - -#include -#if defined(SYS_WINDOWS) -#include -#include -#endif - -#include "ac_common.h" -#include "common_endian.h" - -////////////////////////////////////////////////////////////////////// -// Some data 'copied' from gdi.h, vfw.h and winerror.h (Microsoft files) - -/* - * Video header (BITMAPINFOHEADER) - */ - -typedef struct tagw32BITMAPINFOHEADER { - uint32_le biSize; - sint32_le biWidth; - sint32_le biHeight; - uint16_le biPlanes; - uint16_le biBitCount; - uint32_le biCompression; - uint32_le biSizeImage; - sint32_le biXPelsPerMeter; - sint32_le biYPelsPerMeter; - uint32_le biClrUsed; - uint32_le biClrImportant; -} w32BITMAPINFOHEADER; - -/* - * AVI headers - */ - -typedef struct tagw32RECT { - sint32_le left; - sint32_le top; - sint32_le right; - sint32_le bottom; -} w32RECT; - -typedef struct _w32AVISTREAMINFOW { - uint32_le fccType; - uint32_le fccHandler; - uint32_le dwFlags; /* Contains AVITF_* flags */ - uint32_le dwCaps; - uint16_le wPriority; - uint16_le wLanguage; - uint32_le dwScale; - uint32_le dwRate; /* dwRate / dwScale == samples/second */ - uint32_le dwStart; - uint32_le dwLength; /* In units above... */ - uint32_le dwInitialFrames; - uint32_le dwSuggestedBufferSize; - uint32_le dwQuality; - uint32_le dwSampleSize; - w32RECT rcFrame; - uint32_le dwEditCount; - uint32_le dwFormatChangeCount; - char szName[64]; -} w32AVISTREAMINFOW; - -typedef struct _w32AVISTREAMINFOA { - uint32_le fccType; - uint32_le fccHandler; - uint32_le dwFlags; /* Contains AVITF_* flags */ - uint32_le dwCaps; - uint16_le wPriority; - uint16_le wLanguage; - uint32_le dwScale; - uint32_le dwRate; /* dwRate / dwScale == samples/second */ - uint32_le dwStart; - uint32_le dwLength; /* In units above... */ - uint32_le dwInitialFrames; - uint32_le dwSuggestedBufferSize; - uint32_le dwQuality; - uint32_le dwSampleSize; - w32RECT rcFrame; - uint32_le dwEditCount; - uint32_le dwFormatChangeCount; - char szName[64]; -} w32AVISTREAMINFOA; - -#ifdef UNICODE -#define w32AVISTREAMINFO w32AVISTREAMINFOW -#else -#define w32AVISTREAMINFO w32AVISTREAMINFOA -#endif - -typedef struct { - uint32_le ckid; - uint32_le dwFlags; - uint32_le dwChunkOffset; // Position of chunk - uint32_le dwChunkLength; // Length of chunk -} w32AVIINDEXENTRY; - -/* Flags for AVI file index */ -//#define AVIIF_LIST 0x00000001L -//#define AVIIF_TWOCC 0x00000002L -#define AVIIF_KEYFRAME 0x00000010L - - -typedef struct { - uint32_le dwMicroSecPerFrame; // frame display rate (or 0L) - uint32_le dwMaxBytesPerSec; // max. transfer rate - uint32_le dwPaddingGranularity; // pad to multiples of this - // size; normally 2K. - uint32_le dwFlags; // the ever-present flags - uint32_le dwTotalFrames; // # frames in file - uint32_le dwInitialFrames; - uint32_le dwStreams; - uint32_le dwSuggestedBufferSize; - - uint32_le dwWidth; - uint32_le dwHeight; - - uint32_le dwReserved[4]; -} w32MainAVIHeader; - -#define AVISTREAMREAD_CONVENIENT (-1L) - - -/* - * Error codes - */ - -#ifndef ICERR_OK -#define ICERR_OK 0L - -#define ICERR_UNSUPPORTED -1L -#define ICERR_BADFORMAT -2L -#define ICERR_MEMORY -3L -#define ICERR_INTERNAL -4L -#define ICERR_BADFLAGS -5L -#define ICERR_BADPARAM -6L -#define ICERR_BADSIZE -7L -#define ICERR_BADHANDLE -8L -#define ICERR_CANTUPDATE -9L -#define ICERR_ABORT -10L -#define ICERR_ERROR -100L -#define ICERR_BADBITDEPTH -200L -#define ICERR_BADIMAGESIZE -201L - -#define ICERR_CUSTOM -400L // errors less than ICERR_CUSTOM... -#endif - -#if !defined(SYS_WINDOWS) -#ifndef MMNOMMIO -#define MMIOERR_BASE 256 -#define MMIOERR_FILENOTFOUND (MMIOERR_BASE + 1) /* file not found */ -#define MMIOERR_OUTOFMEMORY (MMIOERR_BASE + 2) /* out of memory */ -#define MMIOERR_CANNOTOPEN (MMIOERR_BASE + 3) /* cannot open */ -#define MMIOERR_CANNOTCLOSE (MMIOERR_BASE + 4) /* cannot close */ -#define MMIOERR_CANNOTREAD (MMIOERR_BASE + 5) /* cannot read */ -#define MMIOERR_CANNOTWRITE (MMIOERR_BASE + 6) /* cannot write */ -#define MMIOERR_CANNOTSEEK (MMIOERR_BASE + 7) /* cannot seek */ -#define MMIOERR_CANNOTEXPAND (MMIOERR_BASE + 8) /* cannot expand file */ -#define MMIOERR_CHUNKNOTFOUND (MMIOERR_BASE + 9) /* chunk not found */ -#define MMIOERR_UNBUFFERED (MMIOERR_BASE + 10) /* */ -#define MMIOERR_PATHNOTFOUND (MMIOERR_BASE + 11) /* path incorrect */ -#define MMIOERR_ACCESSDENIED (MMIOERR_BASE + 12) /* file was protected */ -#define MMIOERR_SHARINGVIOLATION (MMIOERR_BASE + 13) /* file in use */ -#define MMIOERR_NETWORKERROR (MMIOERR_BASE + 14) /* network not responding */ -#define MMIOERR_TOOMANYOPENFILES (MMIOERR_BASE + 15) /* no more file handles */ -#define MMIOERR_INVALIDFILE (MMIOERR_BASE + 16) /* default error file error */ -#endif -#endif - -/* - * long values - */ -// Values are 32 bit values layed out as follows: -// -// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 -// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 -// +---+-+-+-----------------------+-------------------------------+ -// |Sev|C|R| Facility | Code | -// +---+-+-+-----------------------+-------------------------------+ -// -// Sev - is the severity code -// 00 - Success -// 01 - Informational -// 10 - Warning -// 11 - Error -// -// C - is the Customer code flag -// -// R - is a reserved bit -// -// Facility - is the facility code -// -// Code - is the facility's status code -// -// -// Define the facility codes -// -#define FACILITY_ITF 4 - -// longs are 32 bit values layed out as follows: -// -// 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 -// 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 -// +-+-+-+-+-+---------------------+-------------------------------+ -// |S|R|C|N|r| Facility | Code | -// +-+-+-+-+-+---------------------+-------------------------------+ -// -// S - Severity - indicates success/fail -// 0 - Success -// 1 - Fail (COERROR) -// -// R - reserved portion of the facility code, corresponds to NT's -// second severity bit. -// -// C - reserved portion of the facility code, corresponds to NT's -// C field. -// -// N - reserved portion of the facility code. Used to indicate a -// mapped NT status value. -// -// r - reserved portion of the facility code. Reserved for internal -// use. Used to indicate long values that are not status -// values, but are instead message ids for display strings. -// -// Facility - is the facility code -// -// Code - is the facility's status code - -// -// Severity values -// -//#define SEVERITY_SUCCESS 0 -#define SEVERITY_ERROR 1 - -// -// Success codes -// -#if !defined(S_OK) -#define S_OK ((long)0x00000000L) -#define S_FALSE ((long)0x00000001L) -#endif - -#undef MAKE_SCODE -#define MAKE_SCODE(sev,fac,code) \ - ((sint32) ((uint32(sev)<<31) | (uint32(fac)<<16) | (uint32(code))) ) - -#ifndef AVIERR_OK -#define AVIERR_OK 0L - -#define MAKE_AVIERR(error) MAKE_SCODE(SEVERITY_ERROR, FACILITY_ITF, 0x4000 + error) - -#define AVIERR_UNSUPPORTED MAKE_AVIERR(101) -#define AVIERR_BADFORMAT MAKE_AVIERR(102) -#define AVIERR_MEMORY MAKE_AVIERR(103) -#define AVIERR_INTERNAL MAKE_AVIERR(104) -#define AVIERR_BADFLAGS MAKE_AVIERR(105) -#define AVIERR_BADPARAM MAKE_AVIERR(106) -#define AVIERR_BADSIZE MAKE_AVIERR(107) -#define AVIERR_BADHANDLE MAKE_AVIERR(108) -#define AVIERR_FILEREAD MAKE_AVIERR(109) -#define AVIERR_FILEWRITE MAKE_AVIERR(110) -#define AVIERR_FILEOPEN MAKE_AVIERR(111) -#define AVIERR_COMPRESSOR MAKE_AVIERR(112) -#define AVIERR_NOCOMPRESSOR MAKE_AVIERR(113) -#define AVIERR_READONLY MAKE_AVIERR(114) -#define AVIERR_NODATA MAKE_AVIERR(115) -#define AVIERR_BUFFERTOOSMALL MAKE_AVIERR(116) -#define AVIERR_CANTCOMPRESS MAKE_AVIERR(117) -#define AVIERR_USERABORT MAKE_AVIERR(198) -#define AVIERR_ERROR MAKE_AVIERR(199) -#endif - - -/* - * FourCC codes - */ - -#ifdef mmioFOURCC -# undef mmioFOURCC -#endif -#define mmioFOURCC( ch0, ch1, ch2, ch3 ) \ - ( (uint32)uint8(ch0) | ( (uint32)uint8(ch1) << 8 ) | \ - ( (uint32)uint8(ch2) << 16 ) | ( (uint32)uint8(ch3) << 24 ) ) -/* Should work for little and big endian architectures - * (you must define your FourCC as uint32_le) : - * mmioFOURCC(a,b,c,d) will give dcba as value - * On little endian architectures, this would be stored as abcd in memory - * Affecting the value to an uint32_le will keep this memory ordering - * On big endian architectures, this would be stored as dcba in memory - * Affecting the value to an uint32_le will swap the byte ordering to abcd in memory - */ -#define bitmapFOURCC mmioFOURCC - -inline bool isValidFOURCC(uint32 fcc) { - return isprint(uint8(fcc>>24)) - && isprint(uint8(fcc>>16)) - && isprint(uint8(fcc>> 8)) - && isprint(uint8(fcc )); -} - -/* form types, list types, and chunk types */ -#define formtypeAVI mmioFOURCC('A', 'V', 'I', ' ') -#define formtypeAVIEXTENDED mmioFOURCC('A', 'V', 'I', 'X') -#define listtypeAVIHEADER mmioFOURCC('h', 'd', 'r', 'l') -#define ckidAVIMAINHDR mmioFOURCC('a', 'v', 'i', 'h') -#define listtypeSTREAMHEADER mmioFOURCC('s', 't', 'r', 'l') -#define ckidSTREAMHEADER mmioFOURCC('s', 't', 'r', 'h') -#define ckidSTREAMFORMAT mmioFOURCC('s', 't', 'r', 'f') -#define ckidSTREAMHANDLERDATA mmioFOURCC('s', 't', 'r', 'd') -#define ckidSTREAMNAME mmioFOURCC('s', 't', 'r', 'n') - -#define listtypeAVIMOVIE mmioFOURCC('m', 'o', 'v', 'i') -#define listtypeAVIRECORD mmioFOURCC('r', 'e', 'c', ' ') - -#define ckidAVINEWINDEX mmioFOURCC('i', 'd', 'x', '1') -#define ckidOPENDMLINDEX mmioFOURCC('i', 'n', 'd', 'x') - -/* -** Stream types for the field of the stream header. -*/ -#define streamtypeVIDEO mmioFOURCC('v', 'i', 'd', 's') -#define streamtypeAUDIO mmioFOURCC('a', 'u', 'd', 's') -#define streamtypeMIDI mmioFOURCC('m', 'i', 'd', 's') -#define streamtypeTEXT mmioFOURCC('t', 'x', 't', 's') -/* Interleaved video/audio stream, used by DV1 format */ -#define streamtypeINTERLEAVED mmioFOURCC('i', 'v', 'a', 's') - -/* Basic chunk types */ -/*#define cktypeDIBbits aviTWOCC('d', 'b') -#define cktypeDIBcompressed aviTWOCC('d', 'c') -#define cktypePALchange aviTWOCC('p', 'c') -#define cktypeWAVEbytes aviTWOCC('w', 'b')*/ - -/* Chunk id to use for extra chunks for padding. */ -#define ckidAVIPADDING mmioFOURCC('J', 'U', 'N', 'K') - -/* standard four character codes */ -#define FOURCC_RIFF mmioFOURCC('R', 'I', 'F', 'F') -#define FOURCC_LIST mmioFOURCC('L', 'I', 'S', 'T') - -#ifdef LOWORD -# undef LOWORD -# undef HIWORD -# undef LOBYTE -# undef HIBYTE -#endif -#define LOWORD(l) ((uint16)(uint32(l) & 0xFFFF)) -#define HIWORD(l) ((uint16)(uint32(l) >> 16)) -#define LOBYTE(w) ((uint8)(uint32(w) & 0xFF)) -#define HIBYTE(w) ((uint8)(uint32(w) >> 8)) - -/* Macro to get stream number out of a FOURCC ckid */ -#ifdef FromHex -# undef FromHex -# undef StreamFromFOURCC -#endif -#define FromHex(n) (((n) >= 'A') ? ((n) + 10 - 'A') : ((n) - '0')) -#define StreamFromFOURCC(fcc) ((uint16) ((FromHex(LOBYTE(LOWORD(fcc))) << 4) + \ - (FromHex(HIBYTE(LOWORD(fcc)))))) - - -#endif // __TOOLS_COMMON_GDIVFW_H__ diff --git a/aviclasses/common_mmreg.h b/aviclasses/common_mmreg.h deleted file mode 100644 index a61fa5477..000000000 --- a/aviclasses/common_mmreg.h +++ /dev/null @@ -1,118 +0,0 @@ -// Some common tools -// Copyright (C) 2003 Julien 'Cyrius' Coloos -// -// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA -// or visit http://www.gnu.org/licenses/gpl.html - -#ifndef __TOOLS_COMMON_MMREG_H__ -#define __TOOLS_COMMON_MMREG_H__ - -#include "os.h" - -#include "ac_common.h" -#include "common_endian.h" - -////////////////////////////////////////////////////////////////////// -// Some data 'copied' from mmreg.h (Microsoft files) - -typedef struct __attribute__((__packed__)) w32waveformat_tag { - uint16_le wFormatTag; /* format type */ - uint16_le nChannels; /* number of channels (i.e. mono, stereo...) */ - uint32_le nSamplesPerSec; /* sample rate */ - uint32_le nAvgBytesPerSec; /* for buffer estimation */ - uint16_le nBlockAlign; /* block size of data */ -} w32WAVEFORMAT; - -#define WAVE_FORMAT_PCM 1 - -typedef struct __attribute__((__packed__)) w32pcmwaveformat_tag { - w32WAVEFORMAT wf; - uint16_le wBitsPerSample; -} w32PCMWAVEFORMAT; - - -#undef WAVE_FORMAT_MPEG -#undef WAVE_FORMAT_MPEGLAYER3 -#ifndef WAVE_FORMAT_MPEG -# define WAVE_FORMAT_MPEG 0x0050 // Microsoft Corporation -#endif -#ifndef WAVE_FORMAT_MPEGLAYER3 -# define WAVE_FORMAT_MPEGLAYER3 0x0055 // ISO/MPEG Layer3 Format Tag -#endif -#define WAVE_FORMAT_AC3 0x2000 // ATSC/A-52 (Dolby AC3) - -typedef struct __attribute__((__packed__)) tw32WAVEFORMATEX { - uint16_le wFormatTag; // format type - uint16_le nChannels; // number of channels (i.e. mono, stereo...) - uint32_le nSamplesPerSec; // sample rate - uint32_le nAvgBytesPerSec; // for buffer estimation - uint16_le nBlockAlign; // block size of data - uint16_le wBitsPerSample; // Number of bits per sample of mono data - uint16_le cbSize; // The count in bytes of the size of extra information (after cbSize) -} w32WAVEFORMATEX; - -// Microsoft MPEG audio WAV definition -// -// MPEG-1 audio wave format (audio layer only). (0x0050) -typedef struct __attribute__((__packed__)) w32mpeg1waveformat_tag { - w32WAVEFORMATEX wfx; - uint16_le fwHeadLayer; - uint32_le dwHeadBitrate; - uint16_le fwHeadMode; - uint16_le fwHeadModeExt; - uint16_le wHeadEmphasis; - uint16_le fwHeadFlags; - uint32_le dwPTSLow; - uint32_le dwPTSHigh; -} w32MPEG1WAVEFORMAT; - -#define ACM_MPEG_LAYER1 (0x0001) -#define ACM_MPEG_LAYER2 (0x0002) -#define ACM_MPEG_LAYER3 (0x0004) -#define ACM_MPEG_STEREO (0x0001) -#define ACM_MPEG_JOINTSTEREO (0x0002) -#define ACM_MPEG_DUALCHANNEL (0x0004) -#define ACM_MPEG_SINGLECHANNEL (0x0008) -#define ACM_MPEG_PRIVATEBIT (0x0001) -#define ACM_MPEG_COPYRIGHT (0x0002) -#define ACM_MPEG_ORIGINALHOME (0x0004) -#define ACM_MPEG_PROTECTIONBIT (0x0008) -#define ACM_MPEG_ID_MPEG1 (0x0010) - -// MPEG Layer3 WAVEFORMATEX structure -// for WAVE_FORMAT_MPEGLAYER3 (0x0055) -// -#define MPEGLAYER3_WFX_EXTRA_BYTES 12 - -// WAVE_FORMAT_MPEGLAYER3 format sructure -// -typedef struct __attribute__((__packed__)) w32mpeglayer3waveformat_tag { - w32WAVEFORMATEX wfx; - uint16_le wID; - uint32_le fdwFlags; - uint16_le nBlockSize; - uint16_le nFramesPerBlock; - uint16_le nCodecDelay; -} w32MPEGLAYER3WAVEFORMAT; - -#define MPEGLAYER3_ID_UNKNOWN 0 -#define MPEGLAYER3_ID_MPEG 1 -#define MPEGLAYER3_ID_CONSTANTFRAMESIZE 2 - -#define MPEGLAYER3_FLAG_PADDING_ISO 0x00000000 -#define MPEGLAYER3_FLAG_PADDING_ON 0x00000001 -#define MPEGLAYER3_FLAG_PADDING_OFF 0x00000002 - -#endif // __TOOLS_COMMON_MMREG_H__ diff --git a/aviclasses/list.cpp b/aviclasses/list.cpp deleted file mode 100644 index 7c97dbedd..000000000 --- a/aviclasses/list.cpp +++ /dev/null @@ -1,93 +0,0 @@ -// VirtualDub 2.x (Nina) - Video processing and capture application -// Copyright (C) 1998-2001 Avery Lee, All Rights Reserved. -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. - -// -// Modified by Julien 'Cyrius' Coloos -// 20-09-2003 -// - -/////////////////////////////////////////////////////////////////////////// -// -// For those of you who say this looks familiar... it should. This is -// the same linked-list style that the Amiga Exec uses, with dummy head -// and tail nodes. It's really a very convienent way to implement -// doubly-linked lists. -// - -#include -#include "list.h" - -List::List() { - Init(); -} - -void List::Init() { - head.next = tail.prev = 0; - head.prev = &tail; - tail.next = &head; -} - -ListNode *List::RemoveHead() { - if (head.prev->prev) { - ListNode *t = head.prev; - - head.prev->Remove(); - return t; - } - - return 0; -} - -ListNode *List::RemoveTail() { - if (tail.next->next) { - ListNode *t = tail.next; - - tail.next->Remove(); - return t; - } - - return 0; -} - -void List::Take(List &from) { - if (from.IsEmpty()) - return; - - head.prev = from.head.prev; - tail.next = from.tail.next; - head.prev->next = &head; - tail.next->prev = &tail; - - from.Init(); -} - -void List::Swap(List &dst) { - if (IsEmpty()) - Take(dst); - else if (dst.IsEmpty()) - dst.Take(*this); - else { - std::swap(head.prev, dst.head.prev); - std::swap(tail.next, dst.tail.next); - - head.prev->next = &head; - tail.next->prev = &tail; - - dst.head.prev->next = &dst.head; - dst.tail.next->prev = &dst.tail; - } -} diff --git a/aviclasses/list.h b/aviclasses/list.h deleted file mode 100644 index 89d516528..000000000 --- a/aviclasses/list.h +++ /dev/null @@ -1,272 +0,0 @@ -// VirtualDub 2.x (Nina) - Video processing and capture application -// Copyright (C) 1998-2001 Avery Lee, All Rights Reserved. -// -// 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., 675 Mass Ave, Cambridge, MA 02139, USA. - -// -// Modified by Julien 'Cyrius' Coloos -// 20-09-2003 -// - -#ifndef f_LIST_H -#define f_LIST_H - -class ListNode { -public: - ListNode *next, *prev; - - void Remove() { - next->prev = prev; - prev->next = next; -#ifdef _DEBUG - prev = next = 0; -#endif - } - - void InsertAfter(ListNode *node) { - next = node; - prev = node->prev; - if (node->prev) node->prev->next = this; - node->prev = this; - } - - void InsertBefore(ListNode *node) { - next = node->next; - prev = node; - if (node->next) node->next->prev = this; - node->next = this; - } - - ListNode *NextFromHead() const { - return prev; - } - - ListNode *NextFromTail() const { - return next; - } -}; - -class List { -private: -public: - ListNode head, tail; - - // <--- next prev ---> - // - // head <-> node <-> node <-> tail - - List(); - List(int) {} - - void Init(); - - void AddHead(ListNode *node) { - node->InsertAfter(&head); - } - - void AddTail(ListNode *node) { - node->InsertBefore(&tail); - } - - ListNode *RemoveHead(); - ListNode *RemoveTail(); - - bool IsEmpty() const { - return !head.prev->prev; - } - - ListNode *AtHead() const { - return head.prev; - } - - ListNode *AtTail() const { - return tail.next; - } - - void Take(List& from); - void Swap(List& with); -}; - -// Templated classes... templated classes good. - -template class List2; - -template -class ListNode2 : public ListNode { -friend class List2; -public: - void InsertBefore(ListNode2 *node) { ListNode::InsertBefore(node); } - void InsertAfter(ListNode2 *node) { ListNode::InsertAfter(node); } - - void Remove() { ListNode::Remove(); } - T *NextFromHead() const { return static_cast(static_cast*>(ListNode::NextFromHead())); } - T *NextFromTail() const { return static_cast(static_cast*>(ListNode::NextFromTail())); } -}; - -template -class List2 : public List { -public: - List2() {} - - // This is a really lame, stupid way to postpone initialization of the - // list. - - List2(int v) : List(v) {} - - void AddHead(ListNode2 *node) { List::AddHead(node); } - void AddTail(ListNode2 *node) { List::AddTail(node); } - T *RemoveHead() { return static_cast(static_cast*>(List::RemoveHead())); } - T *RemoveTail() { return static_cast(static_cast*>(List::RemoveTail())); } - T *AtHead() const { return static_cast(static_cast*>(List::AtHead())); } - T *AtTail() const { return static_cast(static_cast*>(List::AtTail())); } - - // I must admit to being pampered by STL (end is different though!!) - - T *begin() const { return AtHead(); } - T *end() const { return AtTail(); } - - void take(List2& from) { List::Take(from); } - - class iterator { - protected: - ListNode2 *node; - ListNode2 *next; - - public: - iterator() {} - iterator(const iterator& src) throw() : node(src.node), next(src.next) {} - - bool operator!() const throw() { return 0 == next; } - T *operator->() const throw() { return (T *)node; } - operator bool() const throw() { return 0 != next; } - operator T *() const throw() { return (T *)node; } - T& operator *() const throw() { return *(T *)node; } - }; - - // fwit: forward iterator (SAFE if node disappears) - // rvit: reverse iterator (SAFE if node disappears) - - class fwit : public iterator { - public: - fwit() throw() {} - fwit(const fwit& src) throw() : iterator(src) {} - fwit(ListNode2 *start) throw() { - iterator::node = start; - iterator::next = start->NextFromHead(); - } - - const fwit& operator=(ListNode2 *start) throw() { - iterator::node = start; - iterator::next = start->NextFromHead(); - - return *this; - } - - fwit& operator++() throw() { - iterator::node = iterator::next; - iterator::next = iterator::node->NextFromHead(); - - return *this; - } - - const fwit& operator+=(int v) throw() { - while(iterator::next && v--) { - iterator::node = iterator::next; - iterator::next = iterator::node->NextFromHead(); - } - - return *this; - } - - fwit operator+(int v) const throw() { - fwit t(*this); - - t += v; - - return t; - } - - // This one's for my sanity. - - void operator++(int) throw() { - ++*this; - } - }; - - class rvit : public iterator { - public: - rvit() throw() {} - - rvit(ListNode2 *start) throw() { - iterator::node = iterator::start; - iterator::next = iterator::start->NextFromTail(); - } - - const rvit& operator=(ListNode2 *start) throw() { - iterator::node = iterator::start; - iterator::next = iterator::start->NextFromTail(); - - return *this; - } - - rvit& operator--() throw() { - iterator::node = iterator::next; - iterator::next = iterator::node->NextFromTail(); - - return *this; - } - - const rvit& operator-=(int v) throw() { - while(iterator::next && v--) { - iterator::node = iterator::next; - iterator::next = iterator::node->NextFromTail(); - } - - return *this; - } - - rvit operator-(int v) const throw() { - rvit t(*this); - - t -= v; - - return t; - } - - // This one's for my sanity. - - void operator--(int) throw() { - --*this; - } - }; -}; - -/* template */ -/* class ListAlloc : public List2 { */ -/* public: */ -/* ListAlloc() {} */ -/* ~ListAlloc() { */ -/* dispose(); */ -/* } */ - -/* void dispose() { */ -/* T *node; */ - -/* while(node = RemoveHead()) */ -/* delete node; */ -/* } */ -/* }; */ - -#endif diff --git a/configure.in b/configure.in index 8a43284c4..86d8012d0 100644 --- a/configure.in +++ b/configure.in @@ -641,69 +641,10 @@ AC_SUBST(WXWINDOWS_LIBS) AC_SUBST(MMG_SUBDIRS) AC_SUBST(USE_WXWINDOWS) - -dnl -dnl Option to use the (old) avilib library instead of the AVI classes -dnl -AC_ARG_WITH(avilib, - [ --with-avilib=version Which avilib should be used (noclasses, 0.6.10)], - with_avilib_given=yes, with_avilib_given=no) - - AC_MSG_CHECKING(which AVI libraries to use) - # Defaults: use aviclasses and prefer the new avilib. - if test x"`uname -s`" = x"Darwin"; then - have_aviclasses=no - else - have_aviclasses=yes - fi - if test "x$with_avilib_given" = "xyes"; then - set - `echo ${with_avilib} | sed 's/,/ /g'` - while test "x$1" != "x"; do - case "$1" in - noclasses) - have_aviclasses=no - ;; - "0.6.10") - have_avilib0_6_10=yes - ;; - *) - echo "" - echo "*** Unknown AVI library \"$1\" in \"${with_avilib}\". " - echo "*** Supported values are:" - echo "*** 0.6.10 - the new avilib with OpenDML support" - echo "*** noclasses - Do not use the AVI classes by Cyrius with " - echo "*** OpenDML support" - exit 1 - ;; - esac - shift - done - fi - if test "x$have_aviclasses" = "xyes"; then - AC_DEFINE(HAVE_AVICLASSES, 1, - [Define if the newer AVIclasses should be used.]) - AVICLASSES_LIBS="-laviclasses" - avi_libs_to_use="classes " - USE_AVICLASSES=yes - fi - AC_DEFINE(HAVE_AVILIB0_6_10, 1, - [Define if the newer avilib from transcode 0.6.10 should be used.]) - avi_libs_to_use="${avi_libs_to_use}0.6.10 " - have_avilib0_6_10=yes - USE_AVILIB0610=yes - AVILIB_LIBS="-lavi" - - AC_MSG_RESULT($avi_libs_to_use) - -AC_SUBST(AVILIB_LIBS) -AC_SUBST(AVICLASSES_LIBS) -AC_SUBST(USE_AVILIB0610) -AC_SUBST(USE_AVICLASSES) - CFLAGS="$USER_CPPFLAGS @EXTRA_CFLAGS@ $USER_CFLAGS -Wall -Wno-sign-compare -Wno-comment -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 @EXTRA_CFLAGS@ @DEBUG_CFLAGS@ @PROFILING_CFLAGS@ @MATROSKA_CFLAGS@ @EBML_CFLAGS@" CXXFLAGS="$USER_CPPFLAGS @EXTRA_CFLAGS@ $USER_CXXFLAGS -Wall -Wno-sign-compare -Wno-comment -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 @EXTRA_CFLAGS@ @DEBUG_CFLAGS@ @PROFILING_CFLAGS@ @MATROSKA_CFLAGS@ @EBML_CFLAGS@ @WXWINDOWS_CFLAGS@" LDFLAGS="$USER_LDFLAGS @EXTRA_LDFLAGS@" AC_SUBST(LDFLAGS) -AC_OUTPUT(Makefile avilib-0.6.10/Makefile aviclasses/Makefile librmff/Makefile src/Makefile src/common/Makefile src/input/Makefile src/output/Makefile src/mmg/Makefile) +AC_OUTPUT(Makefile avilib-0.6.10/Makefile librmff/Makefile src/Makefile src/common/Makefile src/input/Makefile src/output/Makefile src/mmg/Makefile) diff --git a/src/input/r_avi.cpp b/src/input/r_avi.cpp index 6dbdf4542..347448869 100644 --- a/src/input/r_avi.cpp +++ b/src/input/r_avi.cpp @@ -30,15 +30,9 @@ // This one goes out to haali ;) #include -#ifdef HAVE_AVICLASSES -#include "common_mmreg.h" -#include "common_gdivfw.h" -#include "AVIReadHandler.h" -#else extern "C" { #include } -#endif #include "mkvmerge.h" #include "aac_common.h" @@ -90,10 +84,6 @@ avi_reader_c::avi_reader_c(track_info_c *nti) long fsize, i; int64_t size, bps; vector::iterator demuxer; -#ifdef HAVE_AVICLASSES - w32AVISTREAMINFO stream_info; - long format_size; -#endif try { io = new mm_io_c(ti->fname, MODE_READ); @@ -113,48 +103,6 @@ avi_reader_c::avi_reader_c(track_info_c *nti) vptzr = -1; vheaders_set = false; -#ifdef HAVE_AVICLASSES - bih = NULL; - avi = CreateAVIReadHandler(io); - if (avi == NULL) - throw error_c(PFX "Could not initialize the AVI handler."); - s_video = avi->GetStream(streamtypeVIDEO, 0); - if (s_video == NULL) - throw error_c(PFX "No video stream found in file."); - - mxverb(2, "1: 0x%08x\n", (unsigned int)s_video); - if (s_video->Info(&stream_info, sizeof(stream_info)) != S_OK) - throw error_c(PFX "Could not get the video stream information."); - s_video->FormatSize(0, &format_size); - mxverb(2, "2: format_size %ld\n", format_size); - bih = (w32BITMAPINFOHEADER *)safemalloc(format_size); - if (s_video->ReadFormat(0, bih, &format_size) != S_OK) - throw error_c(PFX "Could not read the video format information."); - - frames = s_video->Start(); - maxframes = s_video->End(); - mxverb(2, "3: maxframes %d\n", maxframes); - fps = (float)stream_info.dwRate / (float)stream_info.dwScale; - mxverb(2, "4: fps %.3f\n", fps); - max_frame_size = 0; - for (i = 0; i < maxframes; i++) { - if (s_video->Read(i, 1, NULL, 0, &fsize, NULL) != S_OK) - break; - if (fsize > max_frame_size) - max_frame_size = fsize; - } - mxverb(2, "5: max_frame_size %d\n", max_frame_size); - - create_packetizers(); - - foreach(demuxer, ademuxers) { - bps = demuxer->samples_per_second * demuxer->channels * - demuxer->bits_per_sample / 8; - if (bps > max_frame_size) - max_frame_size = bps; - } - -#else frames = 0; delete io; if ((avi = AVI_open_input_file(ti->fname, 1)) == NULL) { @@ -181,7 +129,6 @@ avi_reader_c::avi_reader_c(track_info_c *nti) if (bps > fsize) fsize = bps; } -#endif if (video_fps < 0) video_fps = fps; @@ -200,14 +147,8 @@ avi_reader_c::avi_reader_c(track_info_c *nti) // {{{ D'TOR avi_reader_c::~avi_reader_c() { -#ifdef HAVE_AVICLASSES - avi->Release(); - delete io; - safefree(bih); -#else if (avi != NULL) AVI_close(avi); -#endif safefree(chunk); safefree(old_chunk); @@ -220,47 +161,6 @@ avi_reader_c::~avi_reader_c() { void avi_reader_c::create_packetizer(int64_t tid) { -#ifdef HAVE_AVICLASSES - char codec[4]; - - if ((tid == 0) && demuxing_requested('v', 0) && (vptzr == -1)) { - memcpy(codec, &bih->biCompression, 4); - codec[4] = 0; - if (!strcasecmp(codec, "DIV3") || - !strcasecmp(codec, "AP41") || // Angel Potion - !strcasecmp(codec, "MPG3") || - !strcasecmp(codec, "MP43")) - is_divx = RAVI_DIVX3; - else if (!strcasecmp(codec, "MP42") || - !strcasecmp(codec, "DIV2") || - !strcasecmp(codec, "DIVX") || - !strcasecmp(codec, "XVID") || - !strcasecmp(codec, "DX50")) - is_divx = RAVI_MPEG4; - else - is_divx = 0; - - ti->private_data = (unsigned char *)bih; - if (ti->private_data != NULL) - ti->private_size = get_uint32(&bih->biSize); - ti->id = 0; // ID for the video track. - vptzr = add_packetizer(new video_packetizer_c(this, NULL, fps, - get_uint32(&bih->biWidth), - get_uint32(&bih->biHeight), - false, ti)); - if (verbose) - mxinfo("+-> Using video output module for video track ID 0.\n"); - mxverb(2, "6: width %u, height %u\n", get_uint32(&bih->biWidth), - get_uint32(&bih->biHeight)); - } - if (tid == 0) - return; - - if ((avi->GetStream(streamtypeAUDIO, tid - 1) != NULL) && - demuxing_requested('a', tid)) - add_audio_demuxer(tid - 1); - -#else char *codec; if ((tid == 0) && demuxing_requested('v', 0) && (vptzr == -1)) { @@ -296,7 +196,6 @@ avi_reader_c::create_packetizer(int64_t tid) { if ((tid <= AVI_audio_tracks(avi)) && demuxing_requested('a', tid)) add_audio_demuxer(tid - 1); -#endif } void @@ -308,18 +207,8 @@ avi_reader_c::create_packetizers() { create_packetizer(0); -#ifdef HAVE_AVICLASSES - i = 0; - while (true) { - if (avi->GetStream(streamtypeAUDIO, i) == NULL) - break; - create_packetizer(i + 1); - i++; - } -#else for (i = 0; i < AVI_audio_tracks(avi); i++) create_packetizer(i + 1); -#endif } // {{{ FUNCTION avi_reader_c::add_audio_demuxer @@ -329,14 +218,7 @@ avi_reader_c::add_audio_demuxer(int aid) { generic_packetizer_c *packetizer; vector::iterator it; avi_demuxer_t demuxer; -#ifdef HAVE_AVICLASSES - w32AVISTREAMINFO stream_info; - long format_size; - w32WAVEFORMATEX *wfe; - IAVIReadStream *stream; -#else alWAVEFORMATEX *wfe; -#endif uint32_t audio_format; foreach(it, ademuxers) @@ -348,39 +230,6 @@ avi_reader_c::add_audio_demuxer(int aid) { demuxer.ptzr = -1; ti->id = aid + 1; // ID for this audio track. -#ifdef HAVE_AVICLASSES - stream = avi->GetStream(streamtypeAUDIO, aid); - if (stream == NULL) - die(PFX "stream == NULL in add_audio_demuxer. Should not have happened. " - "Please file a bug report.\n"); - demuxer.stream = stream; - if (stream->Info(&stream_info, sizeof(w32AVISTREAMINFO)) != S_OK) - mxerror(PFX "Could not read the stream information header for audio track " - "%d.\n", aid + 1); - stream->FormatSize(0, &format_size); - wfe = (w32WAVEFORMATEX *)safemalloc(format_size); - if (stream->ReadFormat(0, wfe, &format_size) != S_OK) - mxerror(PFX "Could not read the format information header for audio track " - "%d.\n", aid + 1); - audio_format = wfe->wFormatTag; - demuxer.samples_per_second = wfe->nSamplesPerSec; - demuxer.channels = wfe->nChannels; - demuxer.bits_per_sample = wfe->wBitsPerSample; - demuxer.frame = stream->Start(); - demuxer.maxframes = stream->End(); - ti->avi_block_align = wfe->nBlockAlign; - ti->avi_avg_bytes_per_sec = wfe->nAvgBytesPerSec; - mxverb(2, "7: sizeof(w32WAVE...) %d, sps %d, c %d, bps %d, mf %d\n", - sizeof(w32WAVEFORMATEX), demuxer.samples_per_second, - demuxer.channels, demuxer.bits_per_sample, demuxer.maxframes); - if (wfe->cbSize > 0) { - ti->private_data = (unsigned char *)(wfe + 1); - ti->private_size = wfe->cbSize; - } else { - ti->private_data = NULL; - ti->private_size = 0; - } -#else wfe = avi->wave_format_ex[aid]; AVI_set_audio_track(avi, aid); if (AVI_read_audio_chunk(avi, NULL) < 0) { @@ -403,7 +252,6 @@ avi_reader_c::add_audio_demuxer(int aid) { ti->private_data = NULL; ti->private_size = 0; } -#endif ti->avi_samples_per_sec = demuxer.samples_per_second; switch(audio_format) { @@ -462,10 +310,6 @@ avi_reader_c::add_audio_demuxer(int aid) { } demuxer.ptzr = add_packetizer(packetizer); -#ifdef HAVE_AVICLASSES - safefree(wfe); -#endif - ademuxers.push_back(demuxer); } @@ -515,16 +359,10 @@ avi_reader_c::is_keyframe(unsigned char *data, int avi_reader_c::read(generic_packetizer_c *ptzr) { vector::iterator demuxer; - int key, last_frame, frames_read; + int key, last_frame, frames_read, size; long nread; bool need_more_data, done; int64_t duration; -#ifdef HAVE_AVICLASSES - long blread; - int result; -#else - int size; -#endif key = 0; if ((vptzr != -1) && !video_done && (PTZR(vptzr) == ptzr)) { @@ -536,17 +374,9 @@ avi_reader_c::read(generic_packetizer_c *ptzr) { // Make sure we have a frame to work with. if (old_chunk == NULL) { -#ifdef HAVE_AVICLASSES - debug_enter("aviclasses->Read() video"); - key = s_video->IsKeyFrame(frames); - if (s_video->Read(frames, 1, chunk, 0x7FFFFFFF, &nread, &blread) != S_OK) - nread = -1; - debug_leave("aviclasses->Read() video"); -#else debug_enter("AVI_read_frame"); nread = AVI_read_frame(avi, (char *)chunk, &key); debug_leave("AVI_read_frame"); -#endif if (nread < 0) { frames = maxframes + 1; done = true; @@ -563,18 +393,9 @@ avi_reader_c::read(generic_packetizer_c *ptzr) { frames_read = 1; // Check whether we have identical frames while (!done && (frames <= (maxframes - 1))) { -#ifdef HAVE_AVICLASSES - debug_enter("aviclasses->Read() video"); - key = s_video->IsKeyFrame(frames); - if (s_video->Read(frames, 1, chunk, 0x7FFFFFFF, &nread, &blread) != - S_OK) - nread = -1; - debug_leave("aviclasses->Read() video"); -#else debug_enter("AVI_read_frame"); nread = AVI_read_frame(avi, (char *)chunk, &key); debug_leave("AVI_read_frame"); -#endif if (nread < 0) { memory_c mem(old_chunk, old_nread, true); PTZR(vptzr)->process(mem, -1, -1, @@ -636,29 +457,14 @@ avi_reader_c::read(generic_packetizer_c *ptzr) { } foreach(demuxer, ademuxers) { + unsigned char *audio_chunk; + if (PTZR(demuxer->ptzr) != ptzr) continue; debug_enter("avi_reader_c::read (audio)"); need_more_data = false; -#ifdef HAVE_AVICLASSES - if (demuxer->frame < demuxer->maxframes) { - debug_enter("aviclasses->Read() audio"); - result = demuxer->stream->Read(demuxer->frame, AVISTREAMREAD_CONVENIENT, - chunk, chunk_size, &nread, &blread); - debug_leave("aviclasses->Read() audio"); - demuxer->frame += blread; - if (result == S_OK) { - memory_c mem(chunk, nread, false); - PTZR(demuxer->ptzr)->add_avi_block_size(nread); - PTZR(demuxer->ptzr)->process(mem); - need_more_data = demuxer->frame < demuxer->maxframes; - } else - demuxer->frame = demuxer->maxframes; - } -#else - unsigned char *audio_chunk; AVI_set_audio_track(avi, demuxer->aid); size = AVI_read_audio_chunk(avi, NULL); @@ -679,7 +485,6 @@ avi_reader_c::read(generic_packetizer_c *ptzr) { } else safefree(audio_chunk); } -#endif debug_leave("avi_reader_c::read (audio)"); @@ -781,63 +586,8 @@ avi_reader_c::identify() { const char *type; uint32_t par_num, par_den; bool extended_info_shown; -#ifdef HAVE_AVICLASSES - w32AVISTREAMINFO stream_info; - w32WAVEFORMATEX *wfe; - IAVIReadStream *stream; - long format_size; - char codec[5]; -#endif mxinfo("File '%s': container: AVI\n", ti->fname); -#ifdef HAVE_AVICLASSES - stream = avi->GetStream(streamtypeVIDEO, 0); - if (stream->Info(&stream_info, sizeof(stream_info)) != S_OK) - mxerror(PFX "Could not get the video stream information."); - stream->FormatSize(0, &format_size); - mxverb(2, "2: format_size %ld\n", format_size); - bih = (w32BITMAPINFOHEADER *)safemalloc(format_size); - if (stream->ReadFormat(0, bih, &format_size) != S_OK) - mxerror(PFX "Could not read the video format information."); - memcpy(codec, &bih->biCompression, 4); - safefree(bih); - codec[4] = 0; - mxinfo("Track ID 0: video (%s)\n", codec); - - i = 0; - while (true) { - stream = avi->GetStream(streamtypeAUDIO, i); - if (stream == NULL) - break; - if (stream->Info(&stream_info, sizeof(w32AVISTREAMINFO)) != S_OK) - mxerror(PFX "Could not read the stream information header for audio " - "track %d.\n", i + 1); - stream->FormatSize(0, &format_size); - wfe = (w32WAVEFORMATEX *)safemalloc(format_size); - if (stream->ReadFormat(0, wfe, &format_size) != S_OK) - mxerror(PFX "Could not read the format information header for audio " - "track %d.\n", i + 1); - switch (wfe->wFormatTag) { - case 0x0001: - type = "PCM"; - break; - case 0x0055: - type = "MP3"; - break; - case 0x2000: - type = "AC3"; - break; - case 0x00ff: - type = "AAC"; - break; - default: - type = "unknown"; - } - mxinfo("Track ID %d: audio (%s)\n", i + 1, type); - safefree(wfe); - i++; - } -#else extended_info_shown = false; type = AVI_video_compressor(avi); if (!strncasecmp(type, "MP42", 4) || @@ -898,7 +648,6 @@ avi_reader_c::identify() { } mxinfo("Track ID %d: audio (%s)\n", i + 1, type); } -#endif } // }}} diff --git a/src/input/r_avi.h b/src/input/r_avi.h index bd01cc162..e7fde53b8 100644 --- a/src/input/r_avi.h +++ b/src/input/r_avi.h @@ -27,13 +27,9 @@ #include -#ifdef HAVE_AVICLASSES -#include -#else extern "C" { #include } -#endif #include "mm_io.h" #include "pr_generic.h" @@ -49,21 +45,12 @@ typedef struct avi_demuxer_t { bool headers_set; int channels, bits_per_sample, samples_per_second, aid; int64_t bytes_processed; -#ifdef HAVE_AVICLASSES - IAVIReadStream *stream; - int frame, maxframes; -#endif } avi_demuxer_t; class avi_reader_c: public generic_reader_c { private: unsigned char *chunk, *old_chunk; -#ifdef HAVE_AVICLASSES - IAVIReadHandler *avi; - IAVIReadStream *s_video; -#else avi_t *avi; -#endif mm_io_c *io; int vptzr; bool vheaders_set; @@ -71,9 +58,6 @@ private: double fps; int frames, max_frame_size, act_wchar, old_key, old_nread, dropped_frames; int video_done, maxframes, is_divx, rederive_keyframes, chunk_size; -#ifdef HAVE_AVICLASSES - w32BITMAPINFOHEADER *bih; -#endif public: avi_reader_c(track_info_c *nti) throw (error_c);