genindex-0.1.3/0040755000000000000000000000000010441064115012012 5ustar rootrootgenindex-0.1.3/COPYING0100644000000000000000000004313107523170754013062 0ustar rootroot GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 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 Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. genindex-0.1.3/Makefile0100644000000000000000000000373410441060145013455 0ustar rootroot# # A VDR index file generator # # (C) 2003-2006 Stefan Huelswitt # # This code 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 code is distributed in the hope that 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, point your browser to http://www.gnu.org/copyleft/gpl.html # CC ?= gcc CFLAGS ?= -O2 CXX ?= g++ CXXFLAGS ?= -g -O2 -Wall -Woverloaded-virtual DEFINES = -D_GNU_SOURCE OBJS = genindex.o file.o thread.o ringbuffer.o pes.o VERSION = $(shell grep 'define PRG_VERSION' version.h | awk '{ print $$3 }' | sed -e 's/[";]//g') TMPDIR = /tmp ARCHIVE = "genindex-$(VERSION)" all: genindex # Implicit rules: %.o: %.c $(CXX) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) $< # Dependencies: MAKEDEP = $(CXX) -MM -MG DEPFILE = .dependencies $(DEPFILE): Makefile @$(MAKEDEP) $(DEFINES) $(INCLUDES) $(OBJS:%.o=%.c) > $@ -include $(DEPFILE) # The main program: genindex: $(OBJS) $(CXX) $(CXXFLAGS) $^ -o $@ rmstream: rmstream.o thread.o ringbuffer.o pes.o $(CXX) $(CXXFLAGS) $^ -o $@ testindex: testindex.o file.o $(CXX) $(CXXFLAGS) $^ -o $@ # Housekeeping: clean: -rm -f $(OBJS) $(ARCHIVE).tar.gz $(DEPFILE) genindex rmstream rmstream.o testindex.o testindex core* *~ dist: clean @-rm -rf $(TMPDIR)/$(ARCHIVE) @mkdir $(TMPDIR)/$(ARCHIVE) @cp -a * $(TMPDIR)/$(ARCHIVE) @tar czf $(ARCHIVE).tar.gz -C $(TMPDIR) $(ARCHIVE) @-rm -rf $(TMPDIR)/$(ARCHIVE) @echo Distribution package created as $(ARCHIVE).tar.gz genindex-0.1.3/README0100644000000000000000000000671310441064061012676 0ustar rootroot Genindex (C) 2003-2006 Stefan Hülswitt s.huelswitt@gmx.de See the file COPYING for license information. ---------------------------------------------------------------------- This tool can be used to generate a VDR index file. Usefull if you lost the orginal index file or if you want to create an index file for some other video stuff. The tool is suitable for MPEG2 video (e.g. VDR recordings) and MPEG1 video (e.g. ripped VCD files). The VDR index format doesn't supports files larger than 2GB. If you have larger video files you have to split them up. If the tool is called without any commandline options, it searchs for VDR video files (001.vdr, 002.vdr ...) in the current directory. The generated index file will be named "index.vdr" or "index.vdr.generated" if there is already an "index.vdr". There are some commandline options to influence the behaviour of the tool: -q --quiet no output to the console, except errors. -r --rewrite enables rewrite mode, i.e. genindex reads all data contained in the input file(s), filters out any crap and/or data not usefull for VDR and writes the remaining data to new file(s). The output file(s) will be named 001.vdr, 002.vdr ... and will not exceed the 2GB limit. In no case any existing file will be overwritten, so you cannot rewrite files from the current directory to the current directory (use either -i or -d option). Only data which is actually used by VDR is written to output file(s), i.e. PES packets of type 0xE0-0xEF, 0xC0-0xCF, 0xBD and 0xBE. -d DIR --dest=DIR Writes output files to directory DIR. -i FILE --input=FILE Rather than scanning for input files, use FILE as single input file. -s SIZE --split=SIZE Split output files at a size of SIZE megabytes. Allowed input range is 1-2000. --skip=STR In addition to the normal stream filtering, skip PES packets of type STR too. The value has to be given in hexdecimal. You can give multiple --skip options, if you want to skip more than one stream. The rewrite mode is especially usefull if you want to prepare a single, huge file for replay with VDR e.g. a DVD rip. Assuming you have ripped the DVD to the file /tmp/rip.vob, you can prepare it with (creating VDR video files in current directoy): genindex -r -i /tmp/rip.vob If you additionaly want to skip any DolbyDigital audio stream: genindex -r -i /tmp/rip.vob --skip=0xBD Or limit output files to 1GB: genindex -r -i /tmp/rip.vob -s 1000 This work was inspired by and is based on the work from Werner Fink and Sascha Volkenandt (although virtualy no code pieces from their work made it into this work). ---------------------------------------------------------------------- HISTORY: 05.06.2006 - Version 0.1.3 - Added mode to rewrite video files (including file splitting and removing of PES streams). - Allow a single input file >2GB in rewrite mode. 17.10.2003 - Version 0.1.2 - Don't choke on files >2GB but give the user a hint about the limitation. 27.07.2003 - Version 0.1.1 - Fixed index creation behond the first video file. - Fixed index creation for broken video files (e.g. with skipped bytes). 26.07.2003 - Version 0.1.0 - Initial release. genindex-0.1.3/file.c0100644000000000000000000001376310437644546013125 0ustar rootroot/* * A VDR index file generator (C++) * * (C) 2003-2006 Stefan Huelswitt * * This code 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 code is distributed in the hope that 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, point your browser to http://www.gnu.org/copyleft/gpl.html */ #define _LARGEFILE64_SOURCE #include #include #include #include #include #include #include #include #include "file.h" #define INDEX "index.vdr" #define INDEX_ALT "index.vdr.generated" #define FILENAME "%03d.vdr" extern bool quiet; // --- cString --------------------------------------------------------------- class cString { private: char *s; public: cString(const char *S = NULL, bool TakePointer = false); cString(const cString &String); virtual ~cString(); operator const char * () const { return s; } // for use in (const char *) context const char * operator*() const { return s; } // for use in (const void *) context (printf() etc.) cString &operator=(const cString &String); static cString sprintf(const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); }; cString::cString(const char *S, bool TakePointer) { s = TakePointer ? (char *)S : S ? strdup(S) : NULL; } cString::cString(const cString &String) { s = String.s ? strdup(String.s) : NULL; } cString::~cString() { free(s); } cString &cString::operator=(const cString &String) { if (this == &String) return *this; free(s); s = String.s ? strdup(String.s) : NULL; return *this; } cString cString::sprintf(const char *fmt, ...) { va_list ap; va_start(ap, fmt); char *buffer; vasprintf(&buffer, fmt, ap); return cString(buffer, true); } // ----------------------------------------------------------------------------- cString AddDirectory(const char *DirName, const char *FileName) { char *buf; asprintf(&buf, "%s/%s", DirName && *DirName ? DirName : ".", FileName); return cString(buf, true); } // --- cIndex ------------------------------------------------------------------ cIndex::cIndex(const char *Dir) { dir=Dir; f=0; } cIndex::~cIndex() { if(f) fclose(f); } bool cIndex::Open(bool Read) { int r; cString name=AddDirectory(dir,INDEX); r=access(name,F_OK); read=Read; if(!Read) { if(r==0) { if(!quiet) printf("There is an existing index file. Trying alternative filename.\n"); name=AddDirectory(dir,INDEX_ALT); r=access(name,F_OK); if(r==0) printf("Alternative index file exists too. Aborting.\n"); } if(r<0) { if(errno==ENOENT) { f=fopen(name,"w"); if(f) return true; else printf("index file open: %s\n",strerror(errno)); } else printf("index file check: %s\n",strerror(errno)); } } else { if(r==0) { f=fopen(name,"r"); if(f) return true; else printf("index file open: %s\n",strerror(errno)); } else printf("index file check: %s\n",strerror(errno)); } return false; } bool cIndex::Write(int fileNr, int fileOff, int picType) { if(f && !read) { struct tIndex in; in.offset=fileOff; in.number=fileNr; in.type=picType; in.reserved=0; if(fwrite(&in,sizeof(in),1,f)==1) return true; else printf("index write failed\n"); } else printf("internal: no open write index file\n"); return false; } bool cIndex::Read(int &fileNr, int &fileOff) { if(f && read) { struct tIndex in; if(fread(&in,sizeof(in),1,f)==1) { fileOff=in.offset; fileNr=in.number; return true; } else if(!feof(f)) printf("index read failed\n"); } else printf("internal: no open read index file\n"); return false; } // --- cFileName --------------------------------------------------------------- cFileName::cFileName(const char *Input, bool LargeOK) { input=Input; largeOK=LargeOK; fd=-1; fileno=1; } cFileName::~cFileName() { close(fd); } int cFileName::Open(void) { close(fd); fd=-1; cString filename; if(input) filename=input; else filename=cString::sprintf(FILENAME,fileno); fd=open64(filename,O_RDONLY); if(fd>=0) { struct stat64 st; if(fstat64(fd,&st)==0) { if(!(st.st_size>>31) || largeOK) { size=st.st_size; if(!quiet) printf("reading from %s \n",*filename); } else { printf("%s: filesize exceeds 2GB limit\n",*filename); close(fd); fd=-1; } } else { printf("fstat: %s\n",strerror(errno)); close(fd); fd=-1; } } else if(fileno==1 || errno!=ENOENT) printf("open %s: %s\n",*filename,strerror(errno)); return fd; } int cFileName::OpenWrite(void) { close(fd); fd=-1; cString filename=AddDirectory(input,cString::sprintf(FILENAME,fileno)); if(access(filename,F_OK)!=0) { fd=open64(filename,O_RDWR|O_CREAT,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); if(fd>=0) { size=0; if(!quiet) printf("writing to %s \n",*filename); } else printf("open %s: %s\n",*filename,strerror(errno)); } else printf("%s: file already exists\n",*filename); return fd; } int cFileName::NextFile(void) { if(!input) { fileno++; return Open(); } return -1; } int cFileName::NextWriteFile(void) { fileno++; return OpenWrite(); } int cFileName::Skip(int nr, int off) { if(fileno!=nr || fd<0) { fileno=nr; if(Open()<0) return -1; } if(lseek(fd,off,SEEK_SET)<0) { printf("seek: %s\n",strerror(errno)); return -1; } return fd; } genindex-0.1.3/file.h0100644000000000000000000000344610437601731013114 0ustar rootroot/* * A VDR index file generator (C++) * * (C) 2003-2006 Stefan Huelswitt * * This code 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 code is distributed in the hope that 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, point your browser to http://www.gnu.org/copyleft/gpl.html */ #ifndef __FILE_H #define __FILE_H #include #include "tools.h" // ------------------------------------------------------------------- class cIndex { private: FILE *f; bool read; const char *dir; struct tIndex { int offset; uchar type; uchar number; short reserved; }; public: cIndex(const char *Dir); ~cIndex(); bool Open(bool Read=false); bool Write(int fileNr, int fileOff, int picType); bool Read(int &fileNr, int &fileOff); }; // ------------------------------------------------------------------- class cFileName { private: const char *input; bool largeOK; int fd; int fileno; long long size; char filename[64]; public: cFileName(const char *Input, bool LargeOK); ~cFileName(); int Open(void); int NextFile(void); int OpenWrite(void); int NextWriteFile(void); int Skip(int nr, int off); int FileNumber(void) { return fileno; } long long FileSize(void) { return size; } }; #endif genindex-0.1.3/genindex.c0100644000000000000000000002361210440040277013762 0ustar rootroot/* * A VDR index file generator (C++) * * (C) 2003-2006 Stefan Huelswitt * * This code 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 code is distributed in the hope that 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, point your browser to http://www.gnu.org/copyleft/gpl.html */ #include #include #include #include #include #include #include #include "file.h" #include "pes.h" #include "version.h" #define MAX_FILE_NR 99 // Picture types: #define I_FRAME 1 #define P_FRAME 2 #define B_FRAME 3 char *destdir=0; char *input=0; int splitsize=2000; bool rewrite=false; bool quiet=false; // --- cGenIndex --------------------------------------------------------------- class cGenIndex : public cPES { private: cFileName *fileName, *writeName; cIndex *index; // int replayFile, writeFile; int fileNo, fileOffset, packetOffset, packetNo; bool eof, scan, error; int state, skip; int readNo; long long readOffset; long long fileSize[MAX_FILE_NR+1]; // unsigned int sSize; int splitOffset; bool pstart; // unsigned char buff[KILOBYTE(256)]; uchar store[KILOBYTE(66)]; // bool NextFile(void); void Count(int len); bool SafeWrite(int fd, const unsigned char *data, int len); protected: virtual int Output(const uchar *data, int len); virtual int Action1(uchar type, uchar *data, int len); virtual int Action2(uchar type, uchar *data, int len); virtual void Skipped(uchar *data, int len); public: cGenIndex(void); ~cGenIndex(); void Work(void); void Skip(int type); }; cGenIndex::cGenIndex(void) { index=new cIndex(destdir); fileName=new cFileName(input,input && rewrite); writeName=new cFileName(destdir,true); if(rewrite) { SetDefaultRule(prSkip); SetRuleR(0xE0,0xEF,prAct2); SetRuleR(0xC0,0xCF,prAct1); SetRule(0xBD,prAct1); SetRule(0xBE,prAct1); } else { SetDefaultRule(prAct1); SetRuleR(0xE0,0xEF,prAct2); } } cGenIndex::~cGenIndex() { delete fileName; delete writeName; delete index; } void cGenIndex::Skip(int type) { if(rewrite) SetRule(type,prSkip); } bool cGenIndex::NextFile(void) { if(replayFile>=0 && eof) { replayFile=fileName->NextFile(); readNo=fileName->FileNumber(); readOffset=0; fileSize[readNo]=fileName->FileSize(); } eof=false; return replayFile>=0; } void cGenIndex::Work(void) { eof=error=pstart=false; memset(fileSize,0,sizeof(fileSize)); if(rewrite) { writeFile=writeName->OpenWrite(); if(writeFile<0) { printf("Failed to open output file(s)\n"); return; } } replayFile=fileName->Open(); readNo=fileName->FileNumber(); fileSize[readNo]=fileName->FileSize(); readOffset=0; fileNo=rewrite ? 1 : readNo; fileOffset=0; splitOffset=splitsize*MEGABYTE(1); sSize=0; if(replayFile>=0) { if(index->Open()) { int lastoff=0; while(!error && NextFile()) { int count=read(replayFile,buff,sizeof(buff)); if(count<0) { printf("read vdr: %s\n",strerror(errno)); return; } else if(count==0) { if(fileSize[readNo]!=readOffset) printf("file %d read/size mismatch\n",readNo); eof=true; continue; } else { readOffset+=count; if(!quiet && (readOffsetlastoff+KILOBYTE(256)) && fileSize[readNo]) { printf("offset %lld %d%%\r",readOffset,(int)(readOffset*100/fileSize[readNo])); fflush(stdout); lastoff=readOffset; } int used=Process(buff,count); if(used<0) { error=true; break; } if(count-used) printf("bummer, count!=0\n"); } } if(!error && !quiet) Statistics(); } } else printf("Failed to open input file(s)\n"); } void cGenIndex::Count(int len) { fileOffset+=len; if(!rewrite && fileOffset>=fileSize[fileNo]) { fileOffset-=fileSize[fileNo]; fileNo++; } } int cGenIndex::Output(const uchar *data, int len) { if(rewrite && pstart && sSize>0) { if(!SafeWrite(writeFile,store,sSize)) { error=true; return -1; } sSize=0; } int ftype=0; if(scan) { const uchar *d=data; for(int i=len ; i>0 ; i--) { uchar c=*d++; if(skip>0) { skip--; continue; } // searching for sequence 00 00 01 00 xx PIC switch(state) { case 0: case 1: case 3: if(c==0x00) state++; else state=0; break; case 2: if(c==0x01) state++; else if(c!=0x00) state=0; break; case 4: state++; break; case 5: ftype=(c>>3)&0x07; if(ftypeB_FRAME) { printf("unknown picture type %d at %d\n",ftype,packetOffset); ftype=0; } scan=false; state=0; i=0; break; } } } if(rewrite) { if(scan && fileOffset>=splitOffset && (pstart || sSize)) { if(sSize+len>sizeof(store)) { printf("Oops! Packet buffer overflow\n"); error=true; return -1; } memcpy(store+sSize,data,len); sSize+=len; } else { if(fileOffset>=splitOffset && sSize && ftype==I_FRAME) { writeFile=writeName->NextWriteFile(); if(writeFile<0) { printf("Failed to open output file(s)\n"); error=true; return -1; } packetNo=fileNo=writeName->FileNumber(); packetOffset=0; fileOffset=sSize; } if(ftype>=I_FRAME) { index->Write(packetNo,packetOffset,ftype); } if(sSize>0) { if(!SafeWrite(writeFile,store,sSize)) { error=true; return -1; } sSize=0; } if(!SafeWrite(writeFile,data,len)) { error=true; return -1; } } } else { if(ftype>=I_FRAME) index->Write(packetNo,packetOffset,ftype); } Count(len); pstart=false; return len; } int cGenIndex::Action1(uchar type, uchar *data, int len) { if(SOP) { scan=false; pstart=true; } return len; } int cGenIndex::Action2(uchar type, uchar *data, int len) { if(SOP) { packetOffset=fileOffset; packetNo=fileNo; scan=true; pstart=true; skip=headerSize; state=0; } return len; } void cGenIndex::Skipped(uchar *data, int len) { if(!rewrite) Count(len); } bool cGenIndex::SafeWrite(int fd, const unsigned char *data, int len) { while(len>0) { int r=write(fd,data,len); if(r<0) { if(errno==EINTR) { printf("EINTR on write. Retrying\n"); continue; } printf("write failed: %s\n",strerror(errno)); return false; } data+=r; len-=r; } return true; } // --- MAIN -------------------------------------------------------------------- void about(void) { static bool done=false; if(!quiet && !done) { printf("This is %s %s (%s), (C) 2003-2006 Stefan Hülswitt\n" "Released under the GNU Public License\n\n", PRG_NAME,PRG_VERSION,__DATE__); done=true; } } #define MAX_STR 16 int main(int argc, char *argv[]) { static struct option long_options[] = { { "rewrite", no_argument, NULL, 'r' }, { "quiet", no_argument, NULL, 'q' }, { "dest", required_argument, NULL, 'd' }, { "split", required_argument, NULL, 's' }, { "input", required_argument, NULL, 'i' }, { "skip", required_argument, NULL, 's'|0x100 }, { NULL } }; int s=0, str[MAX_STR]; int c; while((c=getopt_long(argc,argv,"rqd:s:i:",long_options,NULL))!=-1) { switch (c) { case 'r': rewrite=true; break; case 'q': quiet=true; break; case 'd': destdir=optarg; break; case 'i': input=optarg; break; case 's': splitsize=atoi(optarg); if(splitsize<1 || splitsize>2000) { about(); printf("Splitsize must be between 1 and 2.000 MB\n"); return 2; } break; case 's'|0x100: { int n=strtol(optarg,0,16); if(n<0 || n>255) { about(); printf("Stream type out of range\n"); return 2; } if(s>=MAX_STR) { about(); printf("Too many streams\n"); return 2; } str[s]=n; s++; break; } case '?': case ':': about(); printf("\nUsage: genindex [-r] [-d DIR] [-s SIZE]\n\n" " -i FILE, --input FILE use a single input file\n" " -r, --rewrite rewrite video files\n" " -d DIR, --dest=DIR set destination dir\n" " -s SIZE, --split=SIZE split files at megabyte count\n" " --skip=STR skip stream STR (hex)\n" " -q, --quiet no output, except errors\n" "\n"); default: return 2; } } about(); cGenIndex gi; if(s>0) { if(!rewrite) { printf("Cannot skip streams in non-rewrite mode\n"); return 2; } if(!quiet) printf("Skipping stream"); for(int i=0; i #include "pes.h" #include "ringbuffer.h" #define DEBUG(x...) printf(x) //#define DEBUG(x...) //#define PD(x...) printf(x) #define PD(x...) // --- cPES -------------------------------------------------------------------- cPES::cPES(eRule ru) { rb=new cRingBufferFrame(KILOBYTE(50)); defaultRule=ru; Reset(); } cPES::~cPES() { delete rb; } void cPES::Reset(void) { for(int i=0 ; iClear(); Unlock(); } bool cPES::ValidRuleset(const int num) { if(num>=0 && num0) { skipped++; if(!*data++) zeros++; count--; } } else if(skipped) { totalSkipped+=skipped; if(skipped==zeros) totalZeros+=zeros; else DEBUG("PES: skipped %d bytes\n",skipped); skipped=zeros=0; } } void cPES::Statistics(void) { if(totalBytes) { DEBUG("PES: Stats %lld bytes total, %lld skipped, %lld zero-gaps\n", totalBytes,totalSkipped,totalZeros); for(int type=0 ; type<=0xFF ; type++) if(seen[type]) DEBUG("PES: Stats %02X: %d packets\n",type,seen[type]); } } void cPES::ModifyPaketSize(int mod) { if(SOP) { int size=header[4]*256+header[5]+mod; header[4]=(size>>8)&0xFF; header[5]=(size )&0xFF; } else DEBUG("PES: modify paket size called in middle of packet\n"); } void cPES::Redirect(eRule ru) { if(SOP) { currRule=ru; redirect=true; } else DEBUG("PES: redirect called in middle of packet\n"); } int cPES::HeaderSize(uchar *head, int len) { if(len=len) return -(index+1); } if((head[index]&0xC0)==0x80) { // mpeg2 mpegType=2; index+=2; if(index>=len) return -(index+1); return index+1+head[index]; // mpeg2 header data bytes } mpegType=1; if((head[index]&0xC0)==0x40) { // mpeg1 buff size index+=2; if(index>=len) return -(index+1); } switch(head[index]&0x30) { case 0x30: index+=9; break; // mpeg1 pts&dts case 0x20: index+=4; break; // mpeg1 pts case 0x10: DEBUG("PES: bad pts/dts flags in MPEG1 header (0x%02x)\n",head[index]); break; } return index+1; } } int cPES::PacketSize(uchar *head, int len) { switch(head[3]) { default: // video stream start codes case 0x00 ... 0xB8: // Program end case 0xB9: // Pack header case 0xBA: // System header case 0xBB: // Programm stream map case 0xBC: // reserved case 0xF0 ... 0xFF: return len; // packet size = header size // Private stream1 case 0xBD: // Padding stream case 0xBE: // Private stream2 (navigation data) case 0xBF: // all the rest (the real packets) case 0xC0 ... 0xCF: case 0xD0 ... 0xDF: case 0xE0 ... 0xEF: return 6+head[4]*256+head[5]; } } int cPES::Return(int used, int len) { PD("PES: return used=%d len=%d mode=%d\n",used,len,mode); if(SOP && unsavedHeader && used>=len) { // if we are about to finish the current data packet and we have // an unsaved header inside, we must save the header to the buffer memcpy(hbuff,header,headerSize); header=hbuff; unsavedHeader=false; PD("PES: header saved\n"); } if(used>len) { DEBUG("PES: BUG! used %d > len %d\n",used,len); used=len; } if(used>0) totalBytes+=used; Unlock(); // release lock from Process() return used; } int cPES::Process(const uchar *data, int len) { Lock(); // lock is released in Return() PD("PES: enter data=%p len=%d mode=%d have=%d need=%d old=%d\n", data,len,mode,have,need,old); int used=0; while(used=PES_MIN_SIZE) { PD("PES: fastsync try used=%d: %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", used,c[0],c[1],c[2],c[3],c[4],c[5],c[6],c[7],c[8]); if(c[2]==0x01 && c[1]==0x00 && c[0]==0x00) { headerSize=HeaderSize(c,rest); if(headerSize>0 && rest>=headerSize) { // found a packet start :-) PD("PES: fastsync hit used=%d headerSize=%d rest=%d\n",used,headerSize,rest); header=c; unsavedHeader=true; used+=headerSize; mode=pmHeaderOk; continue; } } else if(c[2]!=0x00) { used+=3; Skip(c,3); continue; } else { used++; Skip(c); continue; } } // copy remaining bytes to buffer memcpy(hbuff,c,rest); have=old=rest; used+=rest; mode=pmSync; PD("PES: buffering started old=%d\n",old); break; case pmSync: PD("PES: slowsync have=%d old=%d\n",have,old); if(have=1) { hbuff[have++]=c[0]; used++; continue; } if(have>=PES_MIN_SIZE) { PD("PES: slowsync try used=%d: %02x %02x %02x %02x\n", used,hbuff[0],hbuff[1],hbuff[2],hbuff[3]); if(hbuff[0]==0x00 && hbuff[1]==0x00&& hbuff[2]==0x01) { need=abs(HeaderSize(hbuff,have)); mode=pmGetHeader; continue; } // no sync found, move buffer one position ahead have--; Skip(hbuff); memmove(hbuff,hbuff+1,have); // if all bytes from previous data block used up, switch to FastSync if(!--old) { used=0; mode=pmFastSync; PD("PES: buffering ended\n"); } continue; } break; case pmGetHeader: if(have=need) { need=abs(HeaderSize(hbuff,have)); if(haveneed) DEBUG("PES: bug, buffered too much. have=%d need=%d\n",have,need); if(have>(int)sizeof(hbuff)) DEBUG("PES: bug, header buffer overflow. have=%d size=%d\n",have,sizeof(hbuff)); headerSize=need; header=hbuff; mode=pmHeaderOk; } break; case pmHeaderOk: type=header[3]; seen[type]++; Skip(0); if(type<=0xB8) { // packet types 0x00-0xb8 are video stream start codes DEBUG("PES: invalid packet type 0x%02x, skipping\n",type); mode=pmNewSync; break; } payloadSize=PacketSize(header,headerSize)-headerSize; if(payloadSize<0) { DEBUG("PES: invalid payloadsize %d, skipping\n",payloadSize); mode=pmNewSync; break; } PD("PES: found sync at offset %d, type %02x, length %d, next expected %d\n", used-headerSize,type,headerSize+payloadSize,used+payloadSize); PD("PES: header type=%02x mpeg=%d header=%d payload=%d:", type,mpegType,headerSize,payloadSize); for(int i=0 ; iGet(); if(frame) { outCount=frame->Count(); outData=(uchar *)frame->Data(); PD("PES: ringbuffer got frame %p count=%d\n",frame,outCount); nextMode=pmRingDrop; mode=pmOutput; break; } mode=pmDataPut; // fall through case pmDataPut: if(need<0) { need=-need; outputHeader=false; mode=pmDataReady; continue; } if(outputHeader) { outData=header; outCount=headerSize; outputHeader=false; nextMode=pmDataPut; } else if(payloadSize) { outData=c; outCount=need; nextMode=pmDataReady; } else { mode=pmDataReady; continue; } mode=pmOutput; // fall through case pmOutput: for(;;) { PD("PES: output data=%p count=%d -> ",outData,outCount); n=Output(outData,outCount); PD("n=%d\n",n); if(n<0) return Return(-1,len); if(n==0) return Return(used,len); outCount-=n; outData+=n; if(outCount<=0) { mode=nextMode; break; } } break; case pmDataReady: if(payloadSize) { used+=need; have+=need; } PD("PES: data ready need=%d have=%d paySize=%d used=%d\n", need,have,payloadSize,used); if(have>=payloadSize) { PD("PES: packet finished\n"); if(have>payloadSize) DEBUG("PES: payload exceeded, size=%d have=%d\n",payloadSize,have); mode=pmNewSync; } else mode=pmPayload; break; case pmRingDrop: PD("PES: ringbuffer drop %p\n",frame); rb->Drop(frame); frame=0; mode=pmRingGet; break; default: DEBUG("PES: bug, bad mode %d\n",mode); return Return(-1,len); } } PD("PES: leave\n"); return Return(used,len); } genindex-0.1.3/pes.h0100644000000000000000000000573307710574253012775 0ustar rootroot/* * pes.h: * * See the main source file 'vdr.c' for copyright information and * how to reach the author. * */ #ifndef __PES_H #define __PES_H #include "thread.h" #include "tools.h" #define PES_MIN_SIZE 4 // min. number of bytes to identify a packet #define PES_HDR_SIZE 6 // length of PES header #define PES_EXT_SIZE 3 // length of PES extension #define NUM_RULESETS 4 // number of rule sets #define NUM_RULES 256 // how many rules in every set class cFrame; class cRingBufferFrame; class cPES : public cMutex { protected: enum eRule { prPass, prSkip, prAct1, prAct2, prAct3, prAct4, prAct5, prAct6, prAct7, prAct8 }; private: eRule rules[NUM_RULESETS][NUM_RULES], *currRules, currRule, defaultRule; int currNum; // Statistics unsigned int seen[256]; int skipped, zeros; long long totalBytes, totalSkipped, totalZeros; // enum eMode { pmNewSync, pmFastSync, pmSync, pmGetHeader, pmHeaderOk, pmPayload, pmRingGet, pmRingDrop, pmDataPut, pmDataReady, pmOutput }; eMode mode, nextMode; uchar hbuff[PES_HDR_SIZE+PES_EXT_SIZE+256]; uchar type; int have, need, old; bool unsavedHeader, outputHeader, redirect; // cFrame *frame; const uchar *outData; int outCount; // bool ValidRuleset(const int num); void Skip(uchar *data, int count=1); int Return(int used, int len); int HeaderSize(uchar *head, int len); int PacketSize(uchar *head, int len); protected: bool SOP; // true if we process the start of packet int headerSize; // size of the header including additional header data uchar *header; // the actual header int mpegType; // gives type of packet 1=mpeg1 2=mpeg2 int payloadSize; // number of data bytes in the packet // cRingBufferFrame *rb; // // Rule Management void UseRuleset(int num); int CurrentRuleset(void); void SetDefaultRule(eRule ru, const int num=0); void SetRule(uchar type, eRule ru, const int num=0); void SetRuleR(uchar ltype, uchar htype, eRule ru, const int num=0); void Reset(void); // Misc unsigned int Seen(uchar type) const; void ClearSeen(void); void Statistics(void); void ModifyPaketSize(int mod); // Data Processing int Process(const uchar *data, int len); void Redirect(eRule ru); void Clear(void); virtual int Output(const uchar *data, int len) { return len; } virtual int Action1(uchar type, uchar *data, int len) { return len; } virtual int Action2(uchar type, uchar *data, int len) { return len; } virtual int Action3(uchar type, uchar *data, int len) { return len; } virtual int Action4(uchar type, uchar *data, int len) { return len; } virtual int Action5(uchar type, uchar *data, int len) { return len; } virtual int Action6(uchar type, uchar *data, int len) { return len; } virtual int Action7(uchar type, uchar *data, int len) { return len; } virtual int Action8(uchar type, uchar *data, int len) { return len; } virtual void Skipped(uchar *data, int len) {} public: cPES(eRule ru=prPass); virtual ~cPES(); }; #endif genindex-0.1.3/ringbuffer.c0100644000000000000000000000303407710550076014317 0ustar rootroot/* * ringbuffer.c: A ring buffer * * See the main source file 'vdr.c' for copyright information and * how to reach the author. * * Parts of this file were inspired by the 'ringbuffy.c' from the * LinuxDVB driver (see linuxtv.org). * * $Id: ringbuffer.c 1.17 2003/05/12 17:38:11 kls Exp $ * * This was taken from the VDR package, which was released under the GPL. * Stripped down to make the PES parser happy */ #include "ringbuffer.h" #include #include #include "tools.h" // --- cRingBuffer ----------------------------------------------------------- cRingBuffer::cRingBuffer(int Size, bool Statistics) { } cRingBuffer::~cRingBuffer() { } void cRingBuffer::WaitForPut(void) { } void cRingBuffer::WaitForGet(void) { } void cRingBuffer::EnablePut(void) { } void cRingBuffer::EnableGet(void) { } void cRingBuffer::SetTimeouts(int PutTimeout, int GetTimeout) { } // --- cFrame ---------------------------------------------------------------- cFrame::cFrame(const uchar *Data, int Count, eFrameType Type, int Index) { } cFrame::~cFrame() { } // --- cRingBufferFrame ------------------------------------------------------ cRingBufferFrame::cRingBufferFrame(int Size, bool Statistics) :cRingBuffer(Size, Statistics) { } cRingBufferFrame::~cRingBufferFrame() { } void cRingBufferFrame::Clear(void) { } bool cRingBufferFrame::Put(cFrame *Frame) { return false; } cFrame *cRingBufferFrame::Get(void) { return 0; } void cRingBufferFrame::Drop(cFrame *Frame) { } int cRingBufferFrame::Available(void) { return 0; } genindex-0.1.3/ringbuffer.h0100644000000000000000000000353107710550046014323 0ustar rootroot/* * ringbuffer.h: A ring buffer * * See the main source file 'vdr.c' for copyright information and * how to reach the author. * * $Id: ringbuffer.h 1.12 2003/05/12 17:35:10 kls Exp $ * * This was taken from the VDR package, which was released under the GPL. * Stripped down to make the PES parser happy */ #ifndef __RINGBUFFER_H #define __RINGBUFFER_H #include "thread.h" #include "tools.h" class cRingBuffer { private: protected: void WaitForPut(void); void WaitForGet(void); void EnablePut(void); void EnableGet(void); virtual void Clear(void) = 0; virtual int Available(void) = 0; int Free(void) { return 0; } void Lock(void) { } void Unlock(void) { } int Size(void) { return 0; } public: cRingBuffer(int Size, bool Statistics = false); virtual ~cRingBuffer(); void SetTimeouts(int PutTimeout, int GetTimeout); }; enum eFrameType { ftUnknown, ftVideo, ftAudio, ftDolby }; class cFrame { friend class cRingBufferFrame; private: public: cFrame(const uchar *Data, int Count, eFrameType = ftUnknown, int Index = -1); ~cFrame(); uchar *Data(void) const { return 0; } int Count(void) const { return 0; } eFrameType Type(void) const { return ftUnknown; } int Index(void) const { return 0; } }; class cRingBufferFrame : public cRingBuffer { private: public: cRingBufferFrame(int Size, bool Statistics = false); virtual ~cRingBufferFrame(); virtual int Available(void); virtual void Clear(void); // Immediately clears the ring buffer. bool Put(cFrame *Frame); // Puts the Frame into the ring buffer. // Returns true if this was possible. cFrame *Get(void); // Gets the next frame from the ring buffer. // The actual data still remains in the buffer until Drop() is called. void Drop(cFrame *Frame); // Drops the Frame that has just been fetched with Get(). }; #endif // __RINGBUFFER_H genindex-0.1.3/rmstream.c0100644000000000000000000000677110217330336014022 0ustar rootroot/* * A VDR stream removing tool (C++) * * (C) 2005 Stefan Huelswitt * * This code 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 code is distributed in the hope that 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, point your browser to http://www.gnu.org/copyleft/gpl.html */ #include #include #include #include #include #include #include "pes.h" #include "version.h" // --- cRmStream --------------------------------------------------------------- class cRmStream : public cPES { private: int infile, outfile; unsigned char buff[KILOBYTE(256)]; protected: virtual int Output(const uchar *data, int len); public: cRmStream(void); void Work(const char *inName, const char *outName); void Skip(int type); }; cRmStream::cRmStream(void) { SetDefaultRule(prPass); } void cRmStream::Skip(int type) { SetRule(type,prSkip); } void cRmStream::Work(const char *inName, const char *outName) { infile=open(inName,O_RDONLY); if(infile>=0) { if(access(outName,F_OK)<0) { if(errno==ENOENT) { outfile=open(outName,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); if(outfile>=0) { while(1) { int c=read(infile,buff,sizeof(buff)); if(c>0) { int u=Process(buff,c); if(c!=u) printf("bummer, count!=0\n"); } else { if(c<0) printf("read failed: %s\n",strerror(errno)); break; } } close(outfile); Statistics(); } else printf("open failed: %s: %s\n",outName,strerror(errno)); } else printf("access failed: %s: %s\n",outName,strerror(errno)); } else printf("file exists: %s\n",outName); close(infile); } else printf("open failed: %s: %s\n",inName,strerror(errno)); } int cRmStream::Output(const uchar *data, int len) { int c=write(outfile,data,len); if(c<0) printf("write failed: %s\n",strerror(errno)); return c; } // --- MAIN -------------------------------------------------------------------- void usage(void) { printf("Usage: rmstream -d str [-o outfile] infile\n"); exit(1); } int main(int argc, char *argv[]) { printf("This is %s %s (%s), (C) 2005 Stefan Hülswitt\n" "Released under the GNU Public License\n", "rmstream",PRG_VERSION,__DATE__); cRmStream gi; char *inName=0, *outName=0; int c, num=0; while((c=getopt(argc,argv,"d:o:"))!=-1) { switch(c) { case 'd': { int type=strtol(optarg,0,0); gi.Skip(type); printf("skipping stream 0x%x\n",type); num++; break; } case 'o': outName=optarg; break; case '?': usage(); } } if(optind * * This code 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 code is distributed in the hope that 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, point your browser to http://www.gnu.org/copyleft/gpl.html */ #include #include #include #include #include #include #include "file.h" // Picture types: #define I_FRAME 1 #define P_FRAME 2 #define B_FRAME 3 // --- MAIN -------------------------------------------------------------------- int main(int argc, char *argv[]) { cFileName fileName; cIndex index; int startNo=1; if(argc>1) { startNo=atoi(argv[1]); if(startNo<1) startNo=1; if(startNo>=99) startNo=99; } if(index.Open(true)) { int nr, off, fd; unsigned char buff[64]; while(index.Read(nr,off)) { if(nr // --- cMutex ---------------------------------------------------------------- cMutex::cMutex(void) { lockingPid = 0; locked = 0; pthread_mutex_init(&mutex, NULL); } cMutex::~cMutex() { pthread_mutex_destroy(&mutex); } void cMutex::Lock(void) { if (getpid() != lockingPid || !locked) { pthread_mutex_lock(&mutex); lockingPid = getpid(); } locked++; } void cMutex::Unlock(void) { if (!--locked) { lockingPid = 0; pthread_mutex_unlock(&mutex); } } genindex-0.1.3/thread.h0100644000000000000000000000114407710550115013434 0ustar rootroot/* * thread.h: A simple thread base class * * See the main source file 'vdr.c' for copyright information and * how to reach the author. * * $Id: thread.h 1.15 2003/05/03 14:03:36 kls Exp $ * * This was taken from the VDR package, which was released under the GPL. * Stripped down to make the PES parser happy */ #ifndef __THREAD_H #define __THREAD_H #include #include #include class cMutex { private: pthread_mutex_t mutex; pid_t lockingPid; int locked; public: cMutex(void); ~cMutex(); void Lock(void); void Unlock(void); }; #endif //__THREAD_H genindex-0.1.3/tools.h0100644000000000000000000000172310437602666013341 0ustar rootroot/* * tools.h: Various tools * * See the main source file 'vdr.c' for copyright information and * how to reach the author. * * $Id: tools.h 1.54 2002/12/15 14:59:53 kls Exp $ * * This was taken from the VDR package, which was released under the GPL. * Stripped down to make the PES parser happy */ #ifndef __TOOLS_H #define __TOOLS_H #include #include #include #include #include #include #include #include typedef unsigned char uchar; #define KILOBYTE(n) ((n) * 1024) #define MEGABYTE(n) ((n) * 1024 * 1024) #ifndef __STL_CONFIG_H // in case some plugin needs to use the STL template inline T min(T a, T b) { return a <= b ? a : b; } template inline T max(T a, T b) { return a >= b ? a : b; } template inline int sgn(T a) { return a < 0 ? -1 : a > 0 ? 1 : 0; } template inline void swap(T &a, T &b) { T t = a; a = b; b = t; } #endif #endif genindex-0.1.3/version.h0100644000000000000000000000175410441060257013657 0ustar rootroot/* * A VDR index file generator (C++) * * (C) 2003-2006 Stefan Huelswitt * * This code 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 code is distributed in the hope that 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, point your browser to http://www.gnu.org/copyleft/gpl.html */ #ifndef ___VERSION_H #define ___VERSION_H #define PRG_NAME "genindex" #define PRG_VERSION "0.1.3" #endif //___VERSION_H