Diffstat (limited to 'core/multimedia/opieplayer/libmpeg3') (more/less context) (ignore whitespace changes)
86 files changed, 23521 insertions, 0 deletions
diff --git a/core/multimedia/opieplayer/libmpeg3/.cvsignore b/core/multimedia/opieplayer/libmpeg3/.cvsignore new file mode 100644 index 0000000..d7bb3c1 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/.cvsignore @@ -0,0 +1,5 @@ +global_config +dump +mpeg3toc +mpeg3cat +Makefile diff --git a/core/multimedia/opieplayer/libmpeg3/COPYING b/core/multimedia/opieplayer/libmpeg3/COPYING new file mode 100644 index 0000000..60549be --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/COPYING @@ -0,0 +1,340 @@ + 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. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) 19yy <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 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) 19yy name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/core/multimedia/opieplayer/libmpeg3/Makefile.in b/core/multimedia/opieplayer/libmpeg3/Makefile.in new file mode 100644 index 0000000..1817902 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/Makefile.in @@ -0,0 +1,774 @@ +############################################################################# + +####### Compiler, tools and options + +CXX = $(SYSCONF_CXX) $(QT_CXX_MT) +CXXFLAGS= $(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS) $(SYSCONF_CXXFLAGS_LIB) -DQCONFIG=\"qpe\" +CC = $(SYSCONF_CC) $(QT_C_MT) +CFLAGS = $(SYSCONF_CFLAGS) $(SYSCONF_CFLAGS_LIB) -DQCONFIG=\"qpe\" +INCPATH = -I$(QPEDIR)/include -I.. +LFLAGS = $(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT) +LIBS = $(SUBLIBS) -lqpe -lpthread -lm $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS_QTAPP) +MOC = $(SYSCONF_MOC) +UIC = $(SYSCONF_UIC) + +####### Target + +DESTDIR = ../../plugins/codecs/ +VER_MAJ = 1 +VER_MIN = 0 +VER_PATCH = 0 +TARGET = mpeg3plugin +TARGET1 = lib$(TARGET).so.$(VER_MAJ) + +####### Files + +HEADERS = libmpeg3plugin.h \ + libmpeg3pluginimpl.h +SOURCES = libmpeg3plugin.cpp \ + libmpeg3pluginimpl.cpp \ + bitstream.c \ + libmpeg3.c \ + mpeg3atrack.c \ + mpeg3css.c \ + mpeg3demux.c \ + mpeg3io.c \ + mpeg3title.c \ + mpeg3vtrack.c \ + audio/ac3.c \ + audio/bit_allocation.c \ + audio/dct.c \ + audio/exponents.c \ + audio/header.c \ + audio/layer2.c \ + audio/layer3.c \ + audio/mantissa.c \ + audio/mpeg3audio.c \ + audio/pcm.c \ + audio/synthesizers.c \ + audio/tables.c \ + video/getpicture.c \ + video/headers.c \ + video/idct.c \ + video/macroblocks.c \ + video/mmxtest.c \ + video/motion.c \ + video/mpeg3video.c \ + video/output.c \ + video/reconstruct.c \ + video/seek.c \ + video/slice.c \ + video/vlc.c +OBJECTS = libmpeg3plugin.o \ + libmpeg3pluginimpl.o \ + bitstream.o \ + libmpeg3.o \ + mpeg3atrack.o \ + mpeg3css.o \ + mpeg3demux.o \ + mpeg3io.o \ + mpeg3title.o \ + mpeg3vtrack.o \ + audio/ac3.o \ + audio/bit_allocation.o \ + audio/dct.o \ + audio/exponents.o \ + audio/header.o \ + audio/layer2.o \ + audio/layer3.o \ + audio/mantissa.o \ + audio/mpeg3audio.o \ + audio/pcm.o \ + audio/synthesizers.o \ + audio/tables.o \ + video/getpicture.o \ + video/headers.o \ + video/idct.o \ + video/macroblocks.o \ + video/mmxtest.o \ + video/motion.o \ + video/mpeg3video.o \ + video/output.o \ + video/reconstruct.o \ + video/seek.o \ + video/slice.o \ + video/vlc.o +INTERFACES = +UICDECLS = +UICIMPLS = +SRCMOC = +OBJMOC = + + +####### Implicit rules + +.SUFFIXES: .cpp .cxx .cc .C .c + +.cpp.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.cxx.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.cc.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.C.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $< + +.c.o: + $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $< + +####### Build rules + + +all: $(DESTDIR)$(SYSCONF_LINK_TARGET) + +$(DESTDIR)$(SYSCONF_LINK_TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS) + $(SYSCONF_LINK_LIB) + +moc: $(SRCMOC) + +tmake: + tmake libmpeg3.pro + +clean: + -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS) + -rm -f *~ core + -rm -f allmoc.cpp + +####### Extension Modules + +listpromodules: + @echo + +listallmodules: + @echo + +listaddonpromodules: + @echo + +listaddonentmodules: + @echo + + +REQUIRES= + +####### Sub-libraries + + +###### Combined headers + + + +####### Compile + +libmpeg3plugin.o: libmpeg3plugin.cpp \ + libmpeg3plugin.h \ + libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + mpeg3protos.h \ + ../mediaplayerplugininterface.h + +libmpeg3pluginimpl.o: libmpeg3pluginimpl.cpp \ + libmpeg3plugin.h \ + libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + mpeg3protos.h \ + ../mediaplayerplugininterface.h \ + libmpeg3pluginimpl.h \ + ../mediaplayerplugininterface.h + +bitstream.o: bitstream.c \ + mpeg3private.h \ + mpeg3atrack.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + mpeg3protos.h + +libmpeg3.o: libmpeg3.c \ + libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + mpeg3protos.h + +mpeg3atrack.o: mpeg3atrack.c \ + libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + mpeg3protos.h + +mpeg3css.o: mpeg3css.c \ + mpeg3css.h \ + mpeg3private.h \ + mpeg3atrack.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3private.inc \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h + +mpeg3demux.o: mpeg3demux.c \ + libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + mpeg3protos.h + +mpeg3io.o: mpeg3io.c \ + mpeg3private.h \ + mpeg3atrack.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + mpeg3protos.h + +mpeg3title.o: mpeg3title.c \ + mpeg3private.h \ + mpeg3atrack.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + mpeg3protos.h + +mpeg3vtrack.o: mpeg3vtrack.c \ + libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + mpeg3protos.h + +audio/ac3.o: audio/ac3.c \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + audio/../mpeg3protos.h + +audio/bit_allocation.o: audio/bit_allocation.c \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + audio/../mpeg3protos.h + +audio/dct.o: audio/dct.c \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + audio/../mpeg3protos.h \ + audio/tables.h \ + audio/fptables.h + +audio/exponents.o: audio/exponents.c \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + audio/../mpeg3protos.h + +audio/header.o: audio/header.c \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/tables.h \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + audio/../mpeg3protos.h + +audio/layer2.o: audio/layer2.c \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + audio/../mpeg3protos.h \ + audio/tables.h + +audio/layer3.o: audio/layer3.c \ + audio/huffman.h \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + audio/../mpeg3protos.h \ + audio/tables.h + +audio/mantissa.o: audio/mantissa.c \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + audio/../mpeg3protos.h + +audio/mpeg3audio.o: audio/mpeg3audio.c \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + audio/../mpeg3protos.h \ + audio/mpeg3audio.h \ + audio/tables.h + +audio/pcm.o: audio/pcm.c \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + audio/../mpeg3protos.h + +audio/synthesizers.o: audio/synthesizers.c \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + audio/../mpeg3protos.h \ + audio/tables.h + +audio/tables.o: audio/tables.c \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + audio/mpeg3audio.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + audio/../mpeg3protos.h \ + audio/tables.h \ + audio/fptables.h + +video/getpicture.o: video/getpicture.c \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + video/../mpeg3private.inc \ + video/idct.h \ + video/slice.h \ + video/../timecode.h \ + video/../mpeg3protos.h \ + video/mpeg3video.h \ + video/vlc.h + +video/headers.o: video/headers.c \ + video/../mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + mpeg3demux.h \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + video/../mpeg3private.inc \ + video/idct.h \ + video/slice.h \ + video/../timecode.h \ + video/../mpeg3protos.h \ + video/mpeg3video.h + +video/idct.o: video/idct.c \ + video/idct.h + +video/macroblocks.o: video/macroblocks.c \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + video/../mpeg3private.inc \ + video/idct.h \ + video/slice.h \ + video/../timecode.h \ + video/../mpeg3protos.h \ + video/mpeg3video.h \ + video/vlc.h + +video/mmxtest.o: video/mmxtest.c \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + video/../mpeg3private.inc \ + video/idct.h \ + video/slice.h \ + video/../timecode.h \ + video/../mpeg3protos.h + +video/motion.o: video/motion.c \ + video/mpeg3video.h \ + audio/../bitstream.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + video/../mpeg3private.inc \ + video/idct.h \ + video/slice.h \ + video/../timecode.h \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + video/../mpeg3protos.h \ + video/vlc.h + +video/mpeg3video.o: video/mpeg3video.c \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + video/../mpeg3private.inc \ + video/idct.h \ + video/slice.h \ + video/../timecode.h \ + video/../mpeg3protos.h \ + video/mpeg3video.h \ + video/mpeg3videoprotos.h + +video/output.o: video/output.c \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + video/../mpeg3private.inc \ + video/idct.h \ + video/slice.h \ + video/../timecode.h \ + video/../mpeg3protos.h \ + video/mpeg3video.h + +video/reconstruct.o: video/reconstruct.c \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + video/../mpeg3private.inc \ + video/idct.h \ + video/slice.h \ + video/../timecode.h \ + video/../mpeg3protos.h \ + video/mpeg3video.h + +video/seek.o: video/seek.c \ + video/../mpeg3private.h \ + mpeg3atrack.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + video/../mpeg3private.inc \ + video/idct.h \ + video/slice.h \ + video/../timecode.h \ + video/../mpeg3protos.h \ + video/mpeg3video.h + +video/slice.o: video/slice.c \ + audio/../libmpeg3.h \ + mpeg3private.h \ + mpeg3atrack.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + audio/mpeg3audio.h \ + audio/ac3.h \ + audio/mpeg3real.h \ + audio/../bitstream.h \ + mpeg3vtrack.h \ + video/mpeg3video.h \ + video/../mpeg3private.inc \ + video/idct.h \ + video/slice.h \ + video/../timecode.h \ + video/../mpeg3protos.h \ + video/mpeg3video.h \ + video/mpeg3videoprotos.h + +video/vlc.o: video/vlc.c \ + video/mpeg3video.h \ + audio/../bitstream.h \ + mpeg3demux.h \ + mpeg3title.h \ + mpeg3io.h \ + mpeg3css.h \ + mpeg3private.inc \ + video/../mpeg3private.inc \ + video/idct.h \ + video/slice.h \ + video/../timecode.h \ + video/vlc.h + + diff --git a/core/multimedia/opieplayer/libmpeg3/README b/core/multimedia/opieplayer/libmpeg3/README new file mode 100644 index 0000000..7a2a061 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/README @@ -0,0 +1,35 @@ +/******************************************************** + * LibMPEG3 + * Author: Adam Williams <broadcast@earthling.net> + * Page: heroine.linuxbox.com + * + * libmpeg3 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * libmpeg3 is distributed in the hope that 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 GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * + *******************************************************/ + + +/********************************************************** + * Credits: + *********************************************************/ + +AC3 decoder: + + Written by Aaron Holtzman (aholtzma@engr.uvic.ca) + + + +Problems: + + Streams where the multiplexing packet size changes at random. diff --git a/core/multimedia/opieplayer/libmpeg3/VERSION b/core/multimedia/opieplayer/libmpeg3/VERSION new file mode 100644 index 0000000..55772e2 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/VERSION @@ -0,0 +1 @@ +libmpeg3-1.2.1 diff --git a/core/multimedia/opieplayer/libmpeg3/audio/Makefile b/core/multimedia/opieplayer/libmpeg3/audio/Makefile new file mode 100644 index 0000000..eaa0e0b --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/Makefile @@ -0,0 +1,35 @@ +include ../global_config +export CFLAGS +export CFLAGS_lessopt + +OBJS = \ + ac3.o \ + bit_allocation.o \ + dct.o \ + exponents.o \ + header.o \ + layer2.o \ + layer3.o \ + mantissa.o \ + mpeg3audio.o \ + pcm.o \ + synthesizers.o \ + tables.o + +all: $(OBJS) + +dct.o: dct.c + $(CC) -c `./c_flags dct.c` -o $@ $< + +synthesizers.o: synthesizers.c + $(CC) -c `./c_flags synthesizers.c` -o $@ $< + + +.c.o: + $(CC) -c `./c_flags` -o $@ $< + +.s.o: + $(CC) -f elf $*.s + +clean: + rm -f *.o diff --git a/core/multimedia/opieplayer/libmpeg3/audio/ac3.c b/core/multimedia/opieplayer/libmpeg3/audio/ac3.c new file mode 100644 index 0000000..7a3b664 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/ac3.c @@ -0,0 +1,691 @@ +/* + * + * ac3.c Copyright (C) Aaron Holtzman - May 1999 + * + * + * This file is part of libmpeg3 + * + * libmpeg3 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * libmpeg3 is distributed in the hope that 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 GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include "mpeg3audio.h" +#include "../libmpeg3.h" +#include "../mpeg3protos.h" + +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#define MPEG3AC3_MAGIC_NUMBER 0xdeadbeef + + +int mpeg3_ac3_samplerates[] = { 48000, 44100, 32000 }; + +struct mpeg3_framesize_s +{ + unsigned short bit_rate; + unsigned short frm_size[3]; +}; + +struct mpeg3_framesize_s framesize_codes[] = +{ + { 32 ,{64 ,69 ,96 } }, + { 32 ,{64 ,70 ,96 } }, + { 40 ,{80 ,87 ,120 } }, + { 40 ,{80 ,88 ,120 } }, + { 48 ,{96 ,104 ,144 } }, + { 48 ,{96 ,105 ,144 } }, + { 56 ,{112 ,121 ,168 } }, + { 56 ,{112 ,122 ,168 } }, + { 64 ,{128 ,139 ,192 } }, + { 64 ,{128 ,140 ,192 } }, + { 80 ,{160 ,174 ,240 } }, + { 80 ,{160 ,175 ,240 } }, + { 96 ,{192 ,208 ,288 } }, + { 96 ,{192 ,209 ,288 } }, + { 112 ,{224 ,243 ,336 } }, + { 112 ,{224 ,244 ,336 } }, + { 128 ,{256 ,278 ,384 } }, + { 128 ,{256 ,279 ,384 } }, + { 160 ,{320 ,348 ,480 } }, + { 160 ,{320 ,349 ,480 } }, + { 192 ,{384 ,417 ,576 } }, + { 192 ,{384 ,418 ,576 } }, + { 224 ,{448 ,487 ,672 } }, + { 224 ,{448 ,488 ,672 } }, + { 256 ,{512 ,557 ,768 } }, + { 256 ,{512 ,558 ,768 } }, + { 320 ,{640 ,696 ,960 } }, + { 320 ,{640 ,697 ,960 } }, + { 384 ,{768 ,835 ,1152 } }, + { 384 ,{768 ,836 ,1152 } }, + { 448 ,{896 ,975 ,1344 } }, + { 448 ,{896 ,976 ,1344 } }, + { 512 ,{1024 ,1114 ,1536 } }, + { 512 ,{1024 ,1115 ,1536 } }, + { 576 ,{1152 ,1253 ,1728 } }, + { 576 ,{1152 ,1254 ,1728 } }, + { 640 ,{1280 ,1393 ,1920 } }, + { 640 ,{1280 ,1394 ,1920 } } +}; + +/* Audio channel modes */ +short mpeg3_ac3_acmodes[] = {2, 1, 2, 3, 3, 4, 4, 5}; + +/* Rematrix tables */ +struct rematrix_band_s +{ + int start; + int end; +}; + +struct rematrix_band_s mpeg3_rematrix_band[] = +{ + {13, 24}, + {25, 36}, + {37, 60}, + {61, 252} +}; + +int mpeg3_min(int x, int y) +{ + return (x < y) ? x : y; +} + +int mpeg3_max(int x, int y) +{ + return (x > y) ? x : y; +} + +int mpeg3audio_read_ac3_header(mpeg3audio_t *audio) +{ + unsigned int code, crc; + unsigned int i; + mpeg3_ac3bsi_t *bsi = &(audio->ac3_bsi); + +/* Get the sync code */ + code = mpeg3bits_getbits(audio->astream, 16); + while(!mpeg3bits_eof(audio->astream) && code != MPEG3_AC3_START_CODE) + { + code <<= 8; + code &= 0xffff; + code |= mpeg3bits_getbits(audio->astream, 8); + } + + if(mpeg3bits_eof(audio->astream)) return 1; + +/* Get crc1 - we don't actually use this data though */ +/* The crc can be the same as the sync code or come after a sync code repeated twice */ + crc = mpeg3bits_getbits(audio->astream, 16); + +/* Got the sync code. Read the entire frame into a buffer if possible. */ + if(audio->avg_framesize > 0) + { + if(mpeg3bits_read_buffer(audio->astream, audio->ac3_buffer, audio->framesize - 4)) + return 1; + mpeg3bits_use_ptr(audio->astream, audio->ac3_buffer); + } + +/* Get the sampling rate code */ + audio->sampling_frequency_code = mpeg3bits_getbits(audio->astream, 2); + +/* Get the frame size code */ + audio->ac3_framesize_code = mpeg3bits_getbits(audio->astream, 6); + + audio->bitrate = framesize_codes[audio->ac3_framesize_code].bit_rate; + audio->avg_framesize = audio->framesize = 2 * framesize_codes[audio->ac3_framesize_code].frm_size[audio->sampling_frequency_code]; + +/* Check the AC-3 version number */ + bsi->bsid = mpeg3bits_getbits(audio->astream, 5); + +/* Get the audio service provided by the steram */ + bsi->bsmod = mpeg3bits_getbits(audio->astream, 3); + +/* Get the audio coding mode (ie how many channels)*/ + bsi->acmod = mpeg3bits_getbits(audio->astream, 3); + +/* Predecode the number of full bandwidth channels as we use this + * number a lot */ + bsi->nfchans = mpeg3_ac3_acmodes[bsi->acmod]; + audio->channels = bsi->nfchans; + +/* If it is in use, get the centre channel mix level */ + if((bsi->acmod & 0x1) && (bsi->acmod != 0x1)) + bsi->cmixlev = mpeg3bits_getbits(audio->astream, 2); + +/* If it is in use, get the surround channel mix level */ + if(bsi->acmod & 0x4) + bsi->surmixlev = mpeg3bits_getbits(audio->astream, 2); + +/* Get the dolby surround mode if in 2/0 mode */ + if(bsi->acmod == 0x2) + bsi->dsurmod= mpeg3bits_getbits(audio->astream, 2); + +/* Is the low frequency effects channel on? */ + bsi->lfeon = mpeg3bits_getbits(audio->astream, 1); + +/* Get the dialogue normalization level */ + bsi->dialnorm = mpeg3bits_getbits(audio->astream, 5); + +/* Does compression gain exist? */ + bsi->compre = mpeg3bits_getbits(audio->astream, 1); + if (bsi->compre) + { +/* Get compression gain */ + bsi->compr = mpeg3bits_getbits(audio->astream, 8); + } + +/* Does language code exist? */ + bsi->langcode = mpeg3bits_getbits(audio->astream, 1); + if (bsi->langcode) + { +/* Get langauge code */ + bsi->langcod = mpeg3bits_getbits(audio->astream, 8); + } + +/* Does audio production info exist? */ + bsi->audprodie = mpeg3bits_getbits(audio->astream, 1); + if (bsi->audprodie) + { +/* Get mix level */ + bsi->mixlevel = mpeg3bits_getbits(audio->astream, 5); + +/* Get room type */ + bsi->roomtyp = mpeg3bits_getbits(audio->astream, 2); + } + +/* If we're in dual mono mode then get some extra info */ + if (bsi->acmod == 0) + { +/* Get the dialogue normalization level two */ + bsi->dialnorm2 = mpeg3bits_getbits(audio->astream, 5); + +/* Does compression gain two exist? */ + bsi->compr2e = mpeg3bits_getbits(audio->astream, 1); + if (bsi->compr2e) + { +/* Get compression gain two */ + bsi->compr2 = mpeg3bits_getbits(audio->astream, 8); + } + +/* Does language code two exist? */ + bsi->langcod2e = mpeg3bits_getbits(audio->astream, 1); + if (bsi->langcod2e) + { +/* Get langauge code two */ + bsi->langcod2 = mpeg3bits_getbits(audio->astream, 8); + } + +/* Does audio production info two exist? */ + bsi->audprodi2e = mpeg3bits_getbits(audio->astream, 1); + if (bsi->audprodi2e) + { +/* Get mix level two */ + bsi->mixlevel2 = mpeg3bits_getbits(audio->astream, 5); + +/* Get room type two */ + bsi->roomtyp2 = mpeg3bits_getbits(audio->astream, 2); + } + } + +/* Get the copyright bit */ + bsi->copyrightb = mpeg3bits_getbits(audio->astream, 1); + +/* Get the original bit */ + bsi->origbs = mpeg3bits_getbits(audio->astream, 1); + +/* Does timecode one exist? */ + bsi->timecod1e = mpeg3bits_getbits(audio->astream, 1); + + if(bsi->timecod1e) + bsi->timecod1 = mpeg3bits_getbits(audio->astream, 14); + +/* Does timecode two exist? */ + bsi->timecod2e = mpeg3bits_getbits(audio->astream, 1); + + if(bsi->timecod2e) + bsi->timecod2 = mpeg3bits_getbits(audio->astream, 14); + +/* Does addition info exist? */ + bsi->addbsie = mpeg3bits_getbits(audio->astream, 1); + + if(bsi->addbsie) + { +/* Get how much info is there */ + bsi->addbsil = mpeg3bits_getbits(audio->astream, 6); + +/* Get the additional info */ + for(i = 0; i < (bsi->addbsil + 1); i++) + bsi->addbsi[i] = mpeg3bits_getbits(audio->astream, 8); + } + + if(mpeg3bits_eof(audio->astream)) + { + mpeg3bits_use_demuxer(audio->astream); + return 1; + } +// return mpeg3bits_error(audio->astream); +} + +int mpeg3audio_read_ac3_audblk(mpeg3audio_t *audio) +{ + int i, j; + mpeg3_ac3bsi_t *bsi = &(audio->ac3_bsi); + mpeg3_ac3audblk_t *audblk = &(audio->ac3_audblk); + + for(i = 0; i < bsi->nfchans; i++) + { +/* Is this channel an interleaved 256 + 256 block ? */ + audblk->blksw[i] = mpeg3bits_getbits(audio->astream, 1); + } + + for(i = 0; i < bsi->nfchans; i++) + { +/* Should we dither this channel? */ + audblk->dithflag[i] = mpeg3bits_getbits(audio->astream, 1); + } + +/* Does dynamic range control exist? */ + audblk->dynrnge = mpeg3bits_getbits(audio->astream, 1); + if(audblk->dynrnge) + { +/* Get dynamic range info */ + audblk->dynrng = mpeg3bits_getbits(audio->astream, 8); + } + +/* If we're in dual mono mode then get the second channel DR info */ + if(bsi->acmod == 0) + { +/* Does dynamic range control two exist? */ + audblk->dynrng2e = mpeg3bits_getbits(audio->astream, 1); + if (audblk->dynrng2e) + { +/* Get dynamic range info */ + audblk->dynrng2 = mpeg3bits_getbits(audio->astream, 8); + } + } + +/* Does coupling strategy exist? */ + audblk->cplstre = mpeg3bits_getbits(audio->astream, 1); + if(audblk->cplstre) + { +/* Is coupling turned on? */ + audblk->cplinu = mpeg3bits_getbits(audio->astream, 1); + if(audblk->cplinu) + { + for(i = 0; i < bsi->nfchans; i++) + audblk->chincpl[i] = mpeg3bits_getbits(audio->astream, 1); + + if(bsi->acmod == 0x2) + audblk->phsflginu = mpeg3bits_getbits(audio->astream, 1); + + audblk->cplbegf = mpeg3bits_getbits(audio->astream, 4); + audblk->cplendf = mpeg3bits_getbits(audio->astream, 4); + audblk->ncplsubnd = (audblk->cplendf + 2) - audblk->cplbegf + 1; + +/* Calculate the start and end bins of the coupling channel */ + audblk->cplstrtmant = (audblk->cplbegf * 12) + 37 ; + audblk->cplendmant = ((audblk->cplendf + 3) * 12) + 37; + +/* The number of combined subbands is ncplsubnd minus each combined band */ + audblk->ncplbnd = audblk->ncplsubnd; + + for(i = 1; i < audblk->ncplsubnd; i++) + { + audblk->cplbndstrc[i] = mpeg3bits_getbits(audio->astream, 1); + audblk->ncplbnd -= audblk->cplbndstrc[i]; + } + } + } + + if(audblk->cplinu) + { +/* Loop through all the channels and get their coupling co-ords */ + for(i = 0; i < bsi->nfchans; i++) + { + if(!audblk->chincpl[i]) + continue; + +/* Is there new coupling co-ordinate info? */ + audblk->cplcoe[i] = mpeg3bits_getbits(audio->astream, 1); + + if(audblk->cplcoe[i]) + { + audblk->mstrcplco[i] = mpeg3bits_getbits(audio->astream, 2); + for(j = 0; j < audblk->ncplbnd; j++) + { + audblk->cplcoexp[i][j] = mpeg3bits_getbits(audio->astream, 4); + audblk->cplcomant[i][j] = mpeg3bits_getbits(audio->astream, 4); + } + } + } + +/* If we're in dual mono mode, there's going to be some phase info */ + if((bsi->acmod == 0x2) && audblk->phsflginu && + (audblk->cplcoe[0] || audblk->cplcoe[1])) + { + for(j = 0; j < audblk->ncplbnd; j++) + { + audblk->phsflg[j] = mpeg3bits_getbits(audio->astream, 1); + } + } + } + +/* If we're in dual mono mode, there may be a rematrix strategy */ + if(bsi->acmod == 0x2) + { + audblk->rematstr = mpeg3bits_getbits(audio->astream, 1); + if(audblk->rematstr) + { + if (audblk->cplinu == 0) + { + for(i = 0; i < 4; i++) + audblk->rematflg[i] = mpeg3bits_getbits(audio->astream, 1); + } + if((audblk->cplbegf > 2) && audblk->cplinu) + { + for(i = 0; i < 4; i++) + audblk->rematflg[i] = mpeg3bits_getbits(audio->astream, 1); + } + if((audblk->cplbegf <= 2) && audblk->cplinu) + { + for(i = 0; i < 3; i++) + audblk->rematflg[i] = mpeg3bits_getbits(audio->astream, 1); + } + if((audblk->cplbegf == 0) && audblk->cplinu) + for(i = 0; i < 2; i++) + audblk->rematflg[i] = mpeg3bits_getbits(audio->astream, 1); + + } + } + + if (audblk->cplinu) + { +/* Get the coupling channel exponent strategy */ + audblk->cplexpstr = mpeg3bits_getbits(audio->astream, 2); + + if(audblk->cplexpstr == 0) + audblk->ncplgrps = 0; + else + audblk->ncplgrps = (audblk->cplendmant - audblk->cplstrtmant) / + (3 << (audblk->cplexpstr - 1)); + + } + + for(i = 0; i < bsi->nfchans; i++) + { + audblk->chexpstr[i] = mpeg3bits_getbits(audio->astream, 2); + } + +/* Get the exponent strategy for lfe channel */ + if(bsi->lfeon) + audblk->lfeexpstr = mpeg3bits_getbits(audio->astream, 1); + +/* Determine the bandwidths of all the fbw channels */ + for(i = 0; i < bsi->nfchans; i++) + { + unsigned short grp_size; + + if(audblk->chexpstr[i] != MPEG3_EXP_REUSE) + { + if (audblk->cplinu && audblk->chincpl[i]) + { + audblk->endmant[i] = audblk->cplstrtmant; + } + else + { + audblk->chbwcod[i] = mpeg3bits_getbits(audio->astream, 6); + audblk->endmant[i] = ((audblk->chbwcod[i] + 12) * 3) + 37; + } + +/* Calculate the number of exponent groups to fetch */ + grp_size = 3 * (1 << (audblk->chexpstr[i] - 1)); + audblk->nchgrps[i] = (audblk->endmant[i] - 1 + (grp_size - 3)) / grp_size; + } + } + +/* Get the coupling exponents if they exist */ + if(audblk->cplinu && (audblk->cplexpstr != MPEG3_EXP_REUSE)) + { + audblk->cplabsexp = mpeg3bits_getbits(audio->astream, 4); + for(i = 0; i< audblk->ncplgrps; i++) + audblk->cplexps[i] = mpeg3bits_getbits(audio->astream, 7); + } + +/* Get the fwb channel exponents */ + for(i = 0; i < bsi->nfchans; i++) + { + if(audblk->chexpstr[i] != MPEG3_EXP_REUSE) + { + audblk->exps[i][0] = mpeg3bits_getbits(audio->astream, 4); + for(j = 1; j <= audblk->nchgrps[i]; j++) + audblk->exps[i][j] = mpeg3bits_getbits(audio->astream, 7); + audblk->gainrng[i] = mpeg3bits_getbits(audio->astream, 2); + } + } + +/* Get the lfe channel exponents */ + if(bsi->lfeon && (audblk->lfeexpstr != MPEG3_EXP_REUSE)) + { + audblk->lfeexps[0] = mpeg3bits_getbits(audio->astream, 4); + audblk->lfeexps[1] = mpeg3bits_getbits(audio->astream, 7); + audblk->lfeexps[2] = mpeg3bits_getbits(audio->astream, 7); + } + +/* Get the parametric bit allocation parameters */ + audblk->baie = mpeg3bits_getbits(audio->astream, 1); + + if(audblk->baie) + { + audblk->sdcycod = mpeg3bits_getbits(audio->astream, 2); + audblk->fdcycod = mpeg3bits_getbits(audio->astream, 2); + audblk->sgaincod = mpeg3bits_getbits(audio->astream, 2); + audblk->dbpbcod = mpeg3bits_getbits(audio->astream, 2); + audblk->floorcod = mpeg3bits_getbits(audio->astream, 3); + } + + +/* Get the SNR off set info if it exists */ + audblk->snroffste = mpeg3bits_getbits(audio->astream, 1); + + if(audblk->snroffste) + { + audblk->csnroffst = mpeg3bits_getbits(audio->astream, 6); + + if(audblk->cplinu) + { + audblk->cplfsnroffst = mpeg3bits_getbits(audio->astream, 4); + audblk->cplfgaincod = mpeg3bits_getbits(audio->astream, 3); + } + + for(i = 0; i < bsi->nfchans; i++) + { + audblk->fsnroffst[i] = mpeg3bits_getbits(audio->astream, 4); + audblk->fgaincod[i] = mpeg3bits_getbits(audio->astream, 3); + } + if(bsi->lfeon) + { + + audblk->lfefsnroffst = mpeg3bits_getbits(audio->astream, 4); + audblk->lfefgaincod = mpeg3bits_getbits(audio->astream, 3); + } + } + +/* Get coupling leakage info if it exists */ + if(audblk->cplinu) + { + audblk->cplleake = mpeg3bits_getbits(audio->astream, 1); + + if(audblk->cplleake) + { + audblk->cplfleak = mpeg3bits_getbits(audio->astream, 3); + audblk->cplsleak = mpeg3bits_getbits(audio->astream, 3); + } + } + +/* Get the delta bit alloaction info */ + audblk->deltbaie = mpeg3bits_getbits(audio->astream, 1); + + if(audblk->deltbaie) + { + if(audblk->cplinu) + audblk->cpldeltbae = mpeg3bits_getbits(audio->astream, 2); + + for(i = 0; i < bsi->nfchans; i++) + audblk->deltbae[i] = mpeg3bits_getbits(audio->astream, 2); + + if (audblk->cplinu && (audblk->cpldeltbae == DELTA_BIT_NEW)) + { + audblk->cpldeltnseg = mpeg3bits_getbits(audio->astream, 3); + for(i = 0; i < audblk->cpldeltnseg + 1; i++) + { + audblk->cpldeltoffst[i] = mpeg3bits_getbits(audio->astream, 5); + audblk->cpldeltlen[i] = mpeg3bits_getbits(audio->astream, 4); + audblk->cpldeltba[i] = mpeg3bits_getbits(audio->astream, 3); + } + } + + for(i = 0; i < bsi->nfchans; i++) + { + if (audblk->deltbae[i] == DELTA_BIT_NEW) + { + audblk->deltnseg[i] = mpeg3bits_getbits(audio->astream, 3); + for(j = 0; j < audblk->deltnseg[i] + 1; j++) + { + audblk->deltoffst[i][j] = mpeg3bits_getbits(audio->astream, 5); + audblk->deltlen[i][j] = mpeg3bits_getbits(audio->astream, 4); + audblk->deltba[i][j] = mpeg3bits_getbits(audio->astream, 3); + } + } + } + } + +/* Check to see if there's any dummy info to get */ + if((audblk->skiple = mpeg3bits_getbits(audio->astream, 1))) + { + unsigned int skip_data; + audblk->skipl = mpeg3bits_getbits(audio->astream, 9); + for(i = 0; i < audblk->skipl ; i++) + { + skip_data = mpeg3bits_getbits(audio->astream, 8); + } + } + + return mpeg3bits_error(audio->astream); +} + + +/* This routine simply does stereo rematrixing for the 2 channel + * stereo mode */ +int mpeg3audio_ac3_rematrix(mpeg3_ac3audblk_t *audblk, + mpeg3ac3_stream_samples_t samples) +{ + int num_bands; + int start; + int end; + int i, j; + mpeg3_real_t left, right; + + if(audblk->cplinu || audblk->cplbegf > 2) + num_bands = 4; + else if (audblk->cplbegf > 0) + num_bands = 3; + else + num_bands = 2; + + for(i = 0; i < num_bands; i++) + { + if(!audblk->rematflg[i]) + continue; + + start = mpeg3_rematrix_band[i].start; + end = mpeg3_min(mpeg3_rematrix_band[i].end, 12 * audblk->cplbegf + 36); + + for(j = start; j < end; j++) + { + left = samples[0][j] + samples[1][j]; + right = samples[0][j] - samples[1][j]; + samples[0][j] = left; + samples[1][j] = right; + } + } + return 0; +} + + +int mpeg3audio_ac3_reset_frame(mpeg3audio_t *audio) +{ + memset(&audio->ac3_bit_allocation, 0, sizeof(mpeg3_ac3_bitallocation_t)); + memset(&audio->ac3_mantissa, 0, sizeof(mpeg3_ac3_mantissa_t)); + memset(&audio->ac3_audblk, 0, sizeof(mpeg3_ac3audblk_t)); + + return 0; +} + +int mpeg3audio_do_ac3(mpeg3audio_t *audio) +{ + int result = 0, i; + +/* Reset the coefficients and exponents */ + mpeg3audio_ac3_reset_frame(audio); + + for(i = 0; i < 6 && !result; i++) + { + memset(audio->ac3_samples, 0, sizeof(mpeg3_real_t) * 256 * (audio->ac3_bsi.nfchans + audio->ac3_bsi.lfeon)); +/* Extract most of the audblk info from the bitstream + * (minus the mantissas */ + result |= mpeg3audio_read_ac3_audblk(audio); + +/* Take the differential exponent data and turn it into + * absolute exponents */ + if(!result) result |= mpeg3audio_ac3_exponent_unpack(audio, + &(audio->ac3_bsi), + &(audio->ac3_audblk)); + +/* Figure out how many bits per mantissa */ + if(!result) result |= mpeg3audio_ac3_bit_allocate(audio, + audio->sampling_frequency_code, + &(audio->ac3_bsi), + &(audio->ac3_audblk)); + +/* Extract the mantissas from the data stream */ + if(!result) result |= mpeg3audio_ac3_coeff_unpack(audio, + &(audio->ac3_bsi), + &(audio->ac3_audblk), + audio->ac3_samples); + + if(audio->ac3_bsi.acmod == 0x2) + if(!result) result |= mpeg3audio_ac3_rematrix(&(audio->ac3_audblk), + audio->ac3_samples); + +/* Convert the frequency data into time samples */ + if(!result) result |= mpeg3audio_ac3_imdct(audio, + &(audio->ac3_bsi), + &(audio->ac3_audblk), + audio->ac3_samples); + + if(audio->pcm_point / audio->channels >= audio->pcm_allocated - MPEG3AUDIO_PADDING * audio->channels) + { +/* Need more room */ + mpeg3audio_replace_buffer(audio, audio->pcm_allocated + MPEG3AUDIO_PADDING * audio->channels); + } + } + + mpeg3bits_use_demuxer(audio->astream); + + return result; +} diff --git a/core/multimedia/opieplayer/libmpeg3/audio/ac3.h b/core/multimedia/opieplayer/libmpeg3/audio/ac3.h new file mode 100644 index 0000000..9161c36 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/ac3.h @@ -0,0 +1,308 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef AC3_H +#define AC3_H + +#include "mpeg3real.h" + +#define MAX_AC3_FRAMESIZE 1920 * 2 + 512 + +extern int mpeg3_ac3_samplerates[3]; + +/* Exponent strategy constants */ +#define MPEG3_EXP_REUSE (0) +#define MPEG3_EXP_D15 (1) +#define MPEG3_EXP_D25 (2) +#define MPEG3_EXP_D45 (3) + +/* Delta bit allocation constants */ +#define DELTA_BIT_REUSE (0) +#define DELTA_BIT_NEW (1) +#define DELTA_BIT_NONE (2) +#define DELTA_BIT_RESERVED (3) + + +typedef mpeg3_real_t mpeg3ac3_stream_samples_t[6][256]; + +typedef struct +{ +/* Bit stream identification == 0x8 */ + int bsid; +/* Bit stream mode */ + int bsmod; +/* Audio coding mode */ + int acmod; +/* If we're using the centre channel then */ +/* centre mix level */ + int cmixlev; +/* If we're using the surround channel then */ +/* surround mix level */ + int surmixlev; +/* If we're in 2/0 mode then */ +/* Dolby surround mix level - NOT USED - */ + int dsurmod; +/* Low frequency effects on */ + int lfeon; +/* Dialogue Normalization level */ + int dialnorm; +/* Compression exists */ + int compre; +/* Compression level */ + int compr; +/* Language code exists */ + int langcode; +/* Language code */ + int langcod; +/* Audio production info exists*/ + unsigned int audprodie; + int mixlevel; + int roomtyp; +/* If we're in dual mono mode (acmod == 0) then extra stuff */ + int dialnorm2; + int compr2e; + int compr2; + int langcod2e; + int langcod2; + int audprodi2e; + int mixlevel2; + int roomtyp2; +/* Copyright bit */ + int copyrightb; +/* Original bit */ + int origbs; +/* Timecode 1 exists */ + int timecod1e; +/* Timecode 1 */ + unsigned int timecod1; +/* Timecode 2 exists */ + int timecod2e; +/* Timecode 2 */ + unsigned int timecod2; +/* Additional bit stream info exists */ + int addbsie; +/* Additional bit stream length - 1 (in bytes) */ + int addbsil; +/* Additional bit stream information (max 64 bytes) */ + unsigned char addbsi[64]; + +/* Information not in the AC-3 bitstream, but derived */ +/* Number of channels (excluding LFE) + * Derived from acmod */ + int nfchans; +} mpeg3_ac3bsi_t; + +typedef struct +{ +/* block switch bit indexed by channel num */ + unsigned short blksw[5]; +/* dither enable bit indexed by channel num */ + unsigned short dithflag[5]; +/* dynamic range gain exists */ + int dynrnge; +/* dynamic range gain */ + int dynrng; +/* if acmod==0 then */ +/* dynamic range 2 gain exists */ + int dynrng2e; +/* dynamic range 2 gain */ + int dynrng2; +/* coupling strategy exists */ + int cplstre; +/* coupling in use */ + int cplinu; +/* channel coupled */ + unsigned short chincpl[5]; +/* if acmod==2 then */ +/* Phase flags in use */ + int phsflginu; +/* coupling begin frequency code */ + int cplbegf; +/* coupling end frequency code */ + int cplendf; +/* coupling band structure bits */ + unsigned short cplbndstrc[18]; +/* Do coupling co-ords exist for this channel? */ + unsigned short cplcoe[5]; +/* Master coupling co-ordinate */ + unsigned short mstrcplco[5]; +/* Per coupling band coupling co-ordinates */ + unsigned short cplcoexp[5][18]; + unsigned short cplcomant[5][18]; +/* Phase flags for dual mono */ + unsigned short phsflg[18]; +/* Is there a rematrixing strategy */ + unsigned int rematstr; +/* Rematrixing bits */ + unsigned short rematflg[4]; +/* Coupling exponent strategy */ + int cplexpstr; +/* Exponent strategy for full bandwidth channels */ + unsigned short chexpstr[5]; +/* Exponent strategy for lfe channel */ + int lfeexpstr; +/* Channel bandwidth for independent channels */ + unsigned short chbwcod[5]; +/* The absolute coupling exponent */ + int cplabsexp; +/* Coupling channel exponents (D15 mode gives 18 * 12 /3 encoded exponents */ + unsigned short cplexps[18 * 12 / 3]; +/* fbw channel exponents */ + unsigned short exps[5][252 / 3]; +/* channel gain range */ + unsigned short gainrng[5]; +/* low frequency exponents */ + unsigned short lfeexps[3]; + +/* Bit allocation info */ + int baie; +/* Slow decay code */ + int sdcycod; +/* Fast decay code */ + int fdcycod; +/* Slow gain code */ + int sgaincod; +/* dB per bit code */ + int dbpbcod; +/* masking floor code */ + int floorcod; + +/* SNR offset info */ + int snroffste; +/* coarse SNR offset */ + int csnroffst; +/* coupling fine SNR offset */ + int cplfsnroffst; +/* coupling fast gain code */ + int cplfgaincod; +/* fbw fine SNR offset */ + unsigned short fsnroffst[5]; +/* fbw fast gain code */ + unsigned short fgaincod[5]; +/* lfe fine SNR offset */ + int lfefsnroffst; +/* lfe fast gain code */ + int lfefgaincod; + +/* Coupling leak info */ + int cplleake; +/* coupling fast leak initialization */ + int cplfleak; +/* coupling slow leak initialization */ + int cplsleak; + +/* delta bit allocation info */ + int deltbaie; +/* coupling delta bit allocation exists */ + int cpldeltbae; +/* fbw delta bit allocation exists */ + unsigned short deltbae[5]; +/* number of cpl delta bit segments */ + int cpldeltnseg; +/* coupling delta bit allocation offset */ + short cpldeltoffst[8]; +/* coupling delta bit allocation length */ + short cpldeltlen[8]; +/* coupling delta bit allocation length */ + short cpldeltba[8]; +/* number of delta bit segments */ + unsigned short deltnseg[5]; +/* fbw delta bit allocation offset */ + short deltoffst[5][8]; +/* fbw delta bit allocation length */ + short deltlen[5][8]; +/* fbw delta bit allocation length */ + short deltba[5][8]; + +/* skip length exists */ + int skiple; +/* skip length */ + int skipl; + +/* channel mantissas */ + short chmant[5][256]; + +/* coupling mantissas */ + unsigned short cplmant[256]; + +/* coupling mantissas */ + unsigned short lfemant[7]; + +/* -- Information not in the bitstream, but derived thereof -- */ + +/* Number of coupling sub-bands */ + int ncplsubnd; + +/* Number of combined coupling sub-bands + * Derived from ncplsubnd and cplbndstrc */ + int ncplbnd; + +/* Number of exponent groups by channel + * Derived from strmant, endmant */ + int nchgrps[5]; + +/* Number of coupling exponent groups + * Derived from cplbegf, cplendf, cplexpstr */ + int ncplgrps; + +/* End mantissa numbers of fbw channels */ + unsigned short endmant[5]; + +/* Start and end mantissa numbers for the coupling channel */ + int cplstrtmant; + int cplendmant; + +/* Decoded exponent info */ + unsigned short fbw_exp[5][256]; + unsigned short cpl_exp[256]; + unsigned short lfe_exp[7]; + +/* Bit allocation pointer results */ + short fbw_bap[5][256]; +/*FIXME figure out exactly how many entries there should be (253-37?) */ + short cpl_bap[256]; + short lfe_bap[7]; +} mpeg3_ac3audblk_t; + +/* Bit allocation data */ +typedef struct +{ + int sdecay; + int fdecay; + int sgain; + int dbknee; + int floor; + short psd[256]; + short bndpsd[256]; + short excite[256]; + short mask[256]; +} mpeg3_ac3_bitallocation_t; + +/* Mantissa data */ +typedef struct +{ + unsigned short m_1[3]; + unsigned short m_2[3]; + unsigned short m_4[2]; + unsigned short m_1_pointer; + unsigned short m_2_pointer; + unsigned short m_4_pointer; +} mpeg3_ac3_mantissa_t; + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/audio/bit_allocation.c b/core/multimedia/opieplayer/libmpeg3/audio/bit_allocation.c new file mode 100644 index 0000000..29df7d7 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/bit_allocation.c @@ -0,0 +1,586 @@ +/* + * + * Copyright (C) Aaron Holtzman - May 1999 + * + * + * This file is part of libmpeg3 + * + * libmpeg3 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * libmpeg3 is distributed in the hope that 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 GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include "mpeg3audio.h" +#include "../libmpeg3.h" +#include "../mpeg3protos.h" +#include <string.h> +#include <stdlib.h> + +/* Bit allocation tables */ + +static short mpeg3_slowdec[] = { 0x0f, 0x11, 0x13, 0x15 }; +static short mpeg3_fastdec[] = { 0x3f, 0x53, 0x67, 0x7b }; +static short mpeg3_slowgain[] = { 0x540, 0x4d8, 0x478, 0x410 }; +static short mpeg3_dbpbtab[] = { 0x000, 0x700, 0x900, 0xb00 }; + +static unsigned short mpeg3_floortab[] = { 0x2f0, 0x2b0, 0x270, 0x230, 0x1f0, 0x170, 0x0f0, 0xf800 }; +static short mpeg3_fastgain[] = { 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x400 }; + + +static short mpeg3_bndtab[] = +{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 31, + 34, 37, 40, 43, 46, 49, 55, 61, 67, 73, + 79, 85, 97, 109, 121, 133, 157, 181, 205, 229 +}; + +static short mpeg3_bndsz[] = +{ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, + 3, 3, 3, 3, 3, 6, 6, 6, 6, 6, + 6, 12, 12, 12, 12, 24, 24, 24, 24, 24 +}; + +static short mpeg3_masktab[] = +{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 28, 28, 29, + 29, 29, 30, 30, 30, 31, 31, 31, 32, 32, 32, 33, 33, 33, 34, 34, + 34, 35, 35, 35, 35, 35, 35, 36, 36, 36, 36, 36, 36, 37, 37, 37, + 37, 37, 37, 38, 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, 39, 40, + 40, 40, 40, 40, 40, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, + 41, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 42, 43, 43, 43, + 43, 43, 43, 43, 43, 43, 43, 43, 43, 44, 44, 44, 44, 44, 44, 44, + 44, 44, 44, 44, 44, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, + 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 46, 46, 46, + 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, + 46, 46, 46, 46, 46, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, + 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 47, 48, 48, 48, + 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, + 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, + 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 0, 0, 0 +}; + + +static short mpeg3_latab[] = +{ + 0x0040, 0x003f, 0x003e, 0x003d, 0x003c, 0x003b, 0x003a, 0x0039, + 0x0038, 0x0037, 0x0036, 0x0035, 0x0034, 0x0034, 0x0033, 0x0032, + 0x0031, 0x0030, 0x002f, 0x002f, 0x002e, 0x002d, 0x002c, 0x002c, + 0x002b, 0x002a, 0x0029, 0x0029, 0x0028, 0x0027, 0x0026, 0x0026, + 0x0025, 0x0024, 0x0024, 0x0023, 0x0023, 0x0022, 0x0021, 0x0021, + 0x0020, 0x0020, 0x001f, 0x001e, 0x001e, 0x001d, 0x001d, 0x001c, + 0x001c, 0x001b, 0x001b, 0x001a, 0x001a, 0x0019, 0x0019, 0x0018, + 0x0018, 0x0017, 0x0017, 0x0016, 0x0016, 0x0015, 0x0015, 0x0015, + 0x0014, 0x0014, 0x0013, 0x0013, 0x0013, 0x0012, 0x0012, 0x0012, + 0x0011, 0x0011, 0x0011, 0x0010, 0x0010, 0x0010, 0x000f, 0x000f, + 0x000f, 0x000e, 0x000e, 0x000e, 0x000d, 0x000d, 0x000d, 0x000d, + 0x000c, 0x000c, 0x000c, 0x000c, 0x000b, 0x000b, 0x000b, 0x000b, + 0x000a, 0x000a, 0x000a, 0x000a, 0x000a, 0x0009, 0x0009, 0x0009, + 0x0009, 0x0009, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, 0x0008, + 0x0007, 0x0007, 0x0007, 0x0007, 0x0007, 0x0007, 0x0006, 0x0006, + 0x0006, 0x0006, 0x0006, 0x0006, 0x0006, 0x0006, 0x0005, 0x0005, + 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0005, 0x0004, 0x0004, + 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, 0x0004, + 0x0004, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, + 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0003, 0x0002, + 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, + 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, + 0x0002, 0x0002, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, + 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, + 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, + 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, + 0x0001, 0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000 +}; + +static short mpeg3_hth[][50] = +{ + { + 0x04d0, 0x04d0, 0x0440, 0x0400, 0x03e0, 0x03c0, 0x03b0, 0x03b0, + 0x03a0, 0x03a0, 0x03a0, 0x03a0, 0x03a0, 0x0390, 0x0390, 0x0390, + 0x0380, 0x0380, 0x0370, 0x0370, 0x0360, 0x0360, 0x0350, 0x0350, + 0x0340, 0x0340, 0x0330, 0x0320, 0x0310, 0x0300, 0x02f0, 0x02f0, + 0x02f0, 0x02f0, 0x0300, 0x0310, 0x0340, 0x0390, 0x03e0, 0x0420, + 0x0460, 0x0490, 0x04a0, 0x0460, 0x0440, 0x0440, 0x0520, 0x0800, + 0x0840, 0x0840 + }, + + { + 0x04f0, 0x04f0, 0x0460, 0x0410, 0x03e0, 0x03d0, 0x03c0, 0x03b0, + 0x03b0, 0x03a0, 0x03a0, 0x03a0, 0x03a0, 0x03a0, 0x0390, 0x0390, + 0x0390, 0x0380, 0x0380, 0x0380, 0x0370, 0x0370, 0x0360, 0x0360, + 0x0350, 0x0350, 0x0340, 0x0340, 0x0320, 0x0310, 0x0300, 0x02f0, + 0x02f0, 0x02f0, 0x02f0, 0x0300, 0x0320, 0x0350, 0x0390, 0x03e0, + 0x0420, 0x0450, 0x04a0, 0x0490, 0x0460, 0x0440, 0x0480, 0x0630, + 0x0840, 0x0840 + }, + + { + 0x0580, 0x0580, 0x04b0, 0x0450, 0x0420, 0x03f0, 0x03e0, 0x03d0, + 0x03c0, 0x03b0, 0x03b0, 0x03b0, 0x03a0, 0x03a0, 0x03a0, 0x03a0, + 0x03a0, 0x03a0, 0x03a0, 0x03a0, 0x0390, 0x0390, 0x0390, 0x0390, + 0x0380, 0x0380, 0x0380, 0x0370, 0x0360, 0x0350, 0x0340, 0x0330, + 0x0320, 0x0310, 0x0300, 0x02f0, 0x02f0, 0x02f0, 0x0300, 0x0310, + 0x0330, 0x0350, 0x03c0, 0x0410, 0x0470, 0x04a0, 0x0460, 0x0440, + 0x0450, 0x04e0 + } +}; + + +static short mpeg3_baptab[] = +{ + 0, 1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, + 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 10, + 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 12, 13, 13, 13, 13, 14, + 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15 +}; + + +inline int logadd(int a, int b) +{ + int c; + int address; + + c = a - b; + address = mpeg3_min((abs(c) >> 1), 255); + + if(c >= 0) + return(a + mpeg3_latab[address]); + else + return(b + mpeg3_latab[address]); +} + + +int mpeg3audio_ac3_calc_lowcomp(int a, int b0, int b1, int bin) +{ + if(bin < 7) + { + if((b0 + 256) == b1) + a = 384; + else + if(b0 > b1) + a = mpeg3_max(0, a - 64); + } + else if(bin < 20) + { + if((b0 + 256) == b1) + a = 320; + else if(b0 > b1) + a = mpeg3_max(0, a - 64) ; + } + else + a = mpeg3_max(0, a - 128); + + return(a); +} + +void mpeg3audio_ac3_ba_compute_psd(int start, + int end, + unsigned short exps[], + short psd[], + short bndpsd[]) +{ + int bin,i,j,k; + int lastbin = 0; + +/* Map the exponents into dBs */ + for (bin = start; bin < end; bin++) + { + psd[bin] = (3072 - (exps[bin] << 7)); + } + +/* Integrate the psd function over each bit allocation band */ + j = start; + k = mpeg3_masktab[start]; + + do + { + lastbin = mpeg3_min(mpeg3_bndtab[k] + mpeg3_bndsz[k], end); + bndpsd[k] = psd[j]; + j++; + + for(i = j; i < lastbin; i++) + { + bndpsd[k] = logadd(bndpsd[k], psd[j]); + j++; + } + + k++; + }while(end > lastbin); +} + +void mpeg3audio_ac3_ba_compute_excitation(mpeg3audio_t *audio, + int start, + int end, + int fgain, + int fastleak, + int slowleak, + int is_lfe, + short bndpsd[], + short excite[]) +{ + int bin; + int bndstrt; + int bndend; + int lowcomp = 0; + int begin = 0; + +/* Compute excitation function */ + bndstrt = mpeg3_masktab[start]; + bndend = mpeg3_masktab[end - 1] + 1; + + if(bndstrt == 0) /* For fbw and lfe channels */ + { + lowcomp = mpeg3audio_ac3_calc_lowcomp(lowcomp, bndpsd[0], bndpsd[1], 0); + excite[0] = bndpsd[0] - fgain - lowcomp; + lowcomp = mpeg3audio_ac3_calc_lowcomp(lowcomp, bndpsd[1], bndpsd[2], 1); + excite[1] = bndpsd[1] - fgain - lowcomp; + begin = 7 ; + +/* Note: Do not call mpeg3audio_ac3_calc_lowcomp() for the last band of the lfe channel, (bin = 6) */ + for (bin = 2; bin < 7; bin++) + { + if(!(is_lfe && (bin == 6))) + lowcomp = mpeg3audio_ac3_calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin+1], bin); + fastleak = bndpsd[bin] - fgain; + slowleak = bndpsd[bin] - audio->ac3_bit_allocation.sgain; + excite[bin] = fastleak - lowcomp; + + if(!(is_lfe && (bin == 6))) + { + if(bndpsd[bin] <= bndpsd[bin+1]) + { + begin = bin + 1 ; + break; + } + } + } + + for (bin = begin; bin < mpeg3_min(bndend, 22); bin++) + { + if (!(is_lfe && (bin == 6))) + lowcomp = mpeg3audio_ac3_calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin+1], bin); + fastleak -= audio->ac3_bit_allocation.fdecay; + fastleak = mpeg3_max(fastleak, bndpsd[bin] - fgain); + slowleak -= audio->ac3_bit_allocation.sdecay; + slowleak = mpeg3_max(slowleak, bndpsd[bin] - audio->ac3_bit_allocation.sgain); + excite[bin] = mpeg3_max(fastleak - lowcomp, slowleak); + } + begin = 22; + } + else /* For coupling channel */ + { + begin = bndstrt; + } + + for (bin = begin; bin < bndend; bin++) + { + fastleak -= audio->ac3_bit_allocation.fdecay; + fastleak = mpeg3_max(fastleak, bndpsd[bin] - fgain); + slowleak -= audio->ac3_bit_allocation.sdecay; + slowleak = mpeg3_max(slowleak, bndpsd[bin] - audio->ac3_bit_allocation.sgain); + excite[bin] = mpeg3_max(fastleak, slowleak) ; + } +} + +void mpeg3audio_ac3_ba_compute_mask(mpeg3audio_t *audio, + int start, + int end, + int fscod, + int deltbae, + int deltnseg, + short deltoffst[], + short deltba[], + short deltlen[], + short excite[], + short mask[]) +{ + int bin, k; + int bndstrt; + int bndend; + int delta; + + bndstrt = mpeg3_masktab[start]; + bndend = mpeg3_masktab[end - 1] + 1; + +/* Compute the masking curve */ + + for (bin = bndstrt; bin < bndend; bin++) + { + if (audio->ac3_bit_allocation.bndpsd[bin] < audio->ac3_bit_allocation.dbknee) + { + excite[bin] += ((audio->ac3_bit_allocation.dbknee - audio->ac3_bit_allocation.bndpsd[bin]) >> 2); + } + mask[bin] = mpeg3_max(excite[bin], mpeg3_hth[fscod][bin]); + } + +/* Perform delta bit modulation if necessary */ + if ((deltbae == DELTA_BIT_REUSE) || (deltbae == DELTA_BIT_NEW)) + { + int band = 0; + int seg = 0; + + for (seg = 0; seg < deltnseg + 1; seg++) + { + band += deltoffst[seg]; + if (deltba[seg] >= 4) + { + delta = (deltba[seg] - 3) << 7; + } + else + { + delta = (deltba[seg] - 4) << 7; + } + + for (k = 0; k < deltlen[seg]; k++) + { + mask[band] += delta; + band++; + } + } + } +} + +void mpeg3audio_ac3_ba_compute_bap(mpeg3audio_t *audio, + int start, + int end, + int snroffset, + short psd[], + short mask[], + short bap[]) +{ + int i, j, k; + short lastbin = 0; + short address = 0; + +/* Compute the bit allocation pointer for each bin */ + i = start; + j = mpeg3_masktab[start]; + + do + { + lastbin = mpeg3_min(mpeg3_bndtab[j] + mpeg3_bndsz[j], end); + mask[j] -= snroffset; + mask[j] -= audio->ac3_bit_allocation.floor; + + if(mask[j] < 0) + mask[j] = 0; + + mask[j] &= 0x1fe0; + mask[j] += audio->ac3_bit_allocation.floor; + for(k = i; k < lastbin; k++) + { + address = (psd[i] - mask[j]) >> 5; + address = mpeg3_min(63, mpeg3_max(0, address)); + bap[i] = mpeg3_baptab[address]; + i++; + } + j++; + }while (end > lastbin); +} + +int mpeg3audio_ac3_bit_allocate(mpeg3audio_t *audio, + unsigned int fscod, + mpeg3_ac3bsi_t *bsi, + mpeg3_ac3audblk_t *audblk) +{ + int result = 0; + int i; + int fgain; + int snroffset; + int start; + int end; + int fastleak; + int slowleak; + +/*printf("mpeg3audio_ac3_bit_allocate %d %d %d %d %d\n", audblk->sdcycod, audblk->fdcycod, audblk->sgaincod, audblk->dbpbcod, audblk->floorcod); */ +/* Only perform bit_allocation if the exponents have changed or we + * have new sideband information */ + if(audblk->chexpstr[0] == 0 && audblk->chexpstr[1] == 0 && + audblk->chexpstr[2] == 0 && audblk->chexpstr[3] == 0 && + audblk->chexpstr[4] == 0 && audblk->cplexpstr == 0 && + audblk->lfeexpstr == 0 && audblk->baie == 0 && + audblk->snroffste == 0 && audblk->deltbaie == 0) + return 0; + +/* Do some setup before we do the bit alloc */ + audio->ac3_bit_allocation.sdecay = mpeg3_slowdec[audblk->sdcycod]; + audio->ac3_bit_allocation.fdecay = mpeg3_fastdec[audblk->fdcycod]; + audio->ac3_bit_allocation.sgain = mpeg3_slowgain[audblk->sgaincod]; + audio->ac3_bit_allocation.dbknee = mpeg3_dbpbtab[audblk->dbpbcod]; + audio->ac3_bit_allocation.floor = mpeg3_floortab[audblk->floorcod]; + +/* if all the SNR offset constants are zero then the whole block is zero */ + if(!audblk->csnroffst && !audblk->fsnroffst[0] && + !audblk->fsnroffst[1] && !audblk->fsnroffst[2] && + !audblk->fsnroffst[3] && !audblk->fsnroffst[4] && + !audblk->cplfsnroffst && !audblk->lfefsnroffst) + { + memset(audblk->fbw_bap, 0, sizeof(short) * 256 * 5); + memset(audblk->cpl_bap, 0, sizeof(short) * 256); + memset(audblk->lfe_bap, 0, sizeof(short) * 7); + return 0; + } + + for(i = 0; i < bsi->nfchans; i++) + { + start = 0; + end = audblk->endmant[i]; + fgain = mpeg3_fastgain[audblk->fgaincod[i]]; + snroffset = (((audblk->csnroffst - 15) << 4) + audblk->fsnroffst[i]) << 2 ; + fastleak = 0; + slowleak = 0; + + mpeg3audio_ac3_ba_compute_psd(start, + end, + audblk->fbw_exp[i], + audio->ac3_bit_allocation.psd, + audio->ac3_bit_allocation.bndpsd); + + mpeg3audio_ac3_ba_compute_excitation(audio, + start, + end , + fgain, + fastleak, + slowleak, + 0, + audio->ac3_bit_allocation.bndpsd, + audio->ac3_bit_allocation.excite); + + mpeg3audio_ac3_ba_compute_mask(audio, + start, + end, + fscod, + audblk->deltbae[i], + audblk->deltnseg[i], + audblk->deltoffst[i], + audblk->deltba[i], + audblk->deltlen[i], + audio->ac3_bit_allocation.excite, + audio->ac3_bit_allocation.mask); + + mpeg3audio_ac3_ba_compute_bap(audio, + start, + end, + snroffset, + audio->ac3_bit_allocation.psd, + audio->ac3_bit_allocation.mask, + audblk->fbw_bap[i]); + } + + if(audblk->cplinu) + { + start = audblk->cplstrtmant; + end = audblk->cplendmant; + fgain = mpeg3_fastgain[audblk->cplfgaincod]; + snroffset = (((audblk->csnroffst - 15) << 4) + audblk->cplfsnroffst) << 2 ; + fastleak = (audblk->cplfleak << 8) + 768; + slowleak = (audblk->cplsleak << 8) + 768; + + mpeg3audio_ac3_ba_compute_psd(start, + end, + audblk->cpl_exp, + audio->ac3_bit_allocation.psd, + audio->ac3_bit_allocation.bndpsd); + + mpeg3audio_ac3_ba_compute_excitation(audio, + start, + end , + fgain, + fastleak, + slowleak, + 0, + audio->ac3_bit_allocation.bndpsd, + audio->ac3_bit_allocation.excite); + + mpeg3audio_ac3_ba_compute_mask(audio, + start, + end, + fscod, + audblk->cpldeltbae, + audblk->cpldeltnseg, + audblk->cpldeltoffst, + audblk->cpldeltba, + audblk->cpldeltlen, + audio->ac3_bit_allocation.excite, + audio->ac3_bit_allocation.mask); + + mpeg3audio_ac3_ba_compute_bap(audio, + start, + end, + snroffset, + audio->ac3_bit_allocation.psd, + audio->ac3_bit_allocation.mask, + audblk->cpl_bap); + } + + if(bsi->lfeon) + { + start = 0; + end = 7; + fgain = mpeg3_fastgain[audblk->lfefgaincod]; + snroffset = (((audblk->csnroffst - 15) << 4) + audblk->lfefsnroffst) << 2 ; + fastleak = 0; + slowleak = 0; + + mpeg3audio_ac3_ba_compute_psd(start, + end, + audblk->lfe_exp, + audio->ac3_bit_allocation.psd, + audio->ac3_bit_allocation.bndpsd); + + mpeg3audio_ac3_ba_compute_excitation(audio, + start, + end , + fgain, + fastleak, + slowleak, + 1, + audio->ac3_bit_allocation.bndpsd, + audio->ac3_bit_allocation.excite); + +/* Perform no delta bit allocation for lfe */ + mpeg3audio_ac3_ba_compute_mask(audio, + start, + end, + fscod, + 2, + 0, + 0, + 0, + 0, + audio->ac3_bit_allocation.excite, + audio->ac3_bit_allocation.mask); + + mpeg3audio_ac3_ba_compute_bap(audio, + start, + end, + snroffset, + audio->ac3_bit_allocation.psd, + audio->ac3_bit_allocation.mask, + audblk->lfe_bap); + } + + return result; +} diff --git a/core/multimedia/opieplayer/libmpeg3/audio/c_flags b/core/multimedia/opieplayer/libmpeg3/audio/c_flags new file mode 100755 index 0000000..d7943d0 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/c_flags @@ -0,0 +1 @@ +echo $CFLAGS diff --git a/core/multimedia/opieplayer/libmpeg3/audio/dct.c b/core/multimedia/opieplayer/libmpeg3/audio/dct.c new file mode 100644 index 0000000..1fd52ce --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/dct.c @@ -0,0 +1,1135 @@ +/* + * + * This file is part of libmpeg3 + * + * libmpeg3 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * libmpeg3 is distributed in the hope that 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 GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +/* + * Discrete Cosine Tansform (DCT) for subband synthesis + * optimized for machines with no auto-increment. + * The performance is highly compiler dependend. Maybe + * the dct64.c version for 'normal' processor may be faster + * even for Intel processors. + */ + +#include "mpeg3audio.h" +#include "../libmpeg3.h" +#include "../mpeg3protos.h" +#include "tables.h" + +#include <math.h> + +int mpeg3audio_dct64_1(mpeg3_real_t *out0, mpeg3_real_t *out1, mpeg3_real_t *b1, mpeg3_real_t *b2, mpeg3_real_t *samples) +{ + register mpeg3_real_t *costab = mpeg3_pnts[0]; + + b1[0x00] = samples[0x00] + samples[0x1F]; + b1[0x01] = samples[0x01] + samples[0x1E]; + b1[0x1F] = (samples[0x00] - samples[0x1F]) * costab[0x0]; + b1[0x1E] = (samples[0x01] - samples[0x1E]) * costab[0x1]; + + b1[0x02] = samples[0x02] + samples[0x1D]; + b1[0x03] = samples[0x03] + samples[0x1C]; + b1[0x1D] = (samples[0x02] - samples[0x1D]) * costab[0x2]; + b1[0x1C] = (samples[0x03] - samples[0x1C]) * costab[0x3]; + + b1[0x04] = samples[0x04] + samples[0x1B]; + b1[0x05] = samples[0x05] + samples[0x1A]; + b1[0x1B] = (samples[0x04] - samples[0x1B]) * costab[0x4]; + b1[0x1A] = (samples[0x05] - samples[0x1A]) * costab[0x5]; + + b1[0x06] = samples[0x06] + samples[0x19]; + b1[0x07] = samples[0x07] + samples[0x18]; + b1[0x19] = (samples[0x06] - samples[0x19]) * costab[0x6]; + b1[0x18] = (samples[0x07] - samples[0x18]) * costab[0x7]; + + b1[0x08] = samples[0x08] + samples[0x17]; + b1[0x09] = samples[0x09] + samples[0x16]; + b1[0x17] = (samples[0x08] - samples[0x17]) * costab[0x8]; + b1[0x16] = (samples[0x09] - samples[0x16]) * costab[0x9]; + + b1[0x0A] = samples[0x0A] + samples[0x15]; + b1[0x0B] = samples[0x0B] + samples[0x14]; + b1[0x15] = (samples[0x0A] - samples[0x15]) * costab[0xA]; + b1[0x14] = (samples[0x0B] - samples[0x14]) * costab[0xB]; + + b1[0x0C] = samples[0x0C] + samples[0x13]; + b1[0x0D] = samples[0x0D] + samples[0x12]; + b1[0x13] = (samples[0x0C] - samples[0x13]) * costab[0xC]; + b1[0x12] = (samples[0x0D] - samples[0x12]) * costab[0xD]; + + b1[0x0E] = samples[0x0E] + samples[0x11]; + b1[0x0F] = samples[0x0F] + samples[0x10]; + b1[0x11] = (samples[0x0E] - samples[0x11]) * costab[0xE]; + b1[0x10] = (samples[0x0F] - samples[0x10]) * costab[0xF]; + + costab = mpeg3_pnts[1]; + + b2[0x00] = b1[0x00] + b1[0x0F]; + b2[0x01] = b1[0x01] + b1[0x0E]; + b2[0x0F] = (b1[0x00] - b1[0x0F]) * costab[0]; + b2[0x0E] = (b1[0x01] - b1[0x0E]) * costab[1]; + + b2[0x02] = b1[0x02] + b1[0x0D]; + b2[0x03] = b1[0x03] + b1[0x0C]; + b2[0x0D] = (b1[0x02] - b1[0x0D]) * costab[2]; + b2[0x0C] = (b1[0x03] - b1[0x0C]) * costab[3]; + + b2[0x04] = b1[0x04] + b1[0x0B]; + b2[0x05] = b1[0x05] + b1[0x0A]; + b2[0x0B] = (b1[0x04] - b1[0x0B]) * costab[4]; + b2[0x0A] = (b1[0x05] - b1[0x0A]) * costab[5]; + + b2[0x06] = b1[0x06] + b1[0x09]; + b2[0x07] = b1[0x07] + b1[0x08]; + b2[0x09] = (b1[0x06] - b1[0x09]) * costab[6]; + b2[0x08] = (b1[0x07] - b1[0x08]) * costab[7]; + + /* */ + + b2[0x10] = b1[0x10] + b1[0x1F]; + b2[0x11] = b1[0x11] + b1[0x1E]; + b2[0x1F] = (b1[0x1F] - b1[0x10]) * costab[0]; + b2[0x1E] = (b1[0x1E] - b1[0x11]) * costab[1]; + + b2[0x12] = b1[0x12] + b1[0x1D]; + b2[0x13] = b1[0x13] + b1[0x1C]; + b2[0x1D] = (b1[0x1D] - b1[0x12]) * costab[2]; + b2[0x1C] = (b1[0x1C] - b1[0x13]) * costab[3]; + + b2[0x14] = b1[0x14] + b1[0x1B]; + b2[0x15] = b1[0x15] + b1[0x1A]; + b2[0x1B] = (b1[0x1B] - b1[0x14]) * costab[4]; + b2[0x1A] = (b1[0x1A] - b1[0x15]) * costab[5]; + + b2[0x16] = b1[0x16] + b1[0x19]; + b2[0x17] = b1[0x17] + b1[0x18]; + b2[0x19] = (b1[0x19] - b1[0x16]) * costab[6]; + b2[0x18] = (b1[0x18] - b1[0x17]) * costab[7]; + + costab = mpeg3_pnts[2]; + + b1[0x00] = b2[0x00] + b2[0x07]; + b1[0x07] = (b2[0x00] - b2[0x07]) * costab[0]; + b1[0x01] = b2[0x01] + b2[0x06]; + b1[0x06] = (b2[0x01] - b2[0x06]) * costab[1]; + b1[0x02] = b2[0x02] + b2[0x05]; + b1[0x05] = (b2[0x02] - b2[0x05]) * costab[2]; + b1[0x03] = b2[0x03] + b2[0x04]; + b1[0x04] = (b2[0x03] - b2[0x04]) * costab[3]; + + b1[0x08] = b2[0x08] + b2[0x0F]; + b1[0x0F] = (b2[0x0F] - b2[0x08]) * costab[0]; + b1[0x09] = b2[0x09] + b2[0x0E]; + b1[0x0E] = (b2[0x0E] - b2[0x09]) * costab[1]; + b1[0x0A] = b2[0x0A] + b2[0x0D]; + b1[0x0D] = (b2[0x0D] - b2[0x0A]) * costab[2]; + b1[0x0B] = b2[0x0B] + b2[0x0C]; + b1[0x0C] = (b2[0x0C] - b2[0x0B]) * costab[3]; + + b1[0x10] = b2[0x10] + b2[0x17]; + b1[0x17] = (b2[0x10] - b2[0x17]) * costab[0]; + b1[0x11] = b2[0x11] + b2[0x16]; + b1[0x16] = (b2[0x11] - b2[0x16]) * costab[1]; + b1[0x12] = b2[0x12] + b2[0x15]; + b1[0x15] = (b2[0x12] - b2[0x15]) * costab[2]; + b1[0x13] = b2[0x13] + b2[0x14]; + b1[0x14] = (b2[0x13] - b2[0x14]) * costab[3]; + + b1[0x18] = b2[0x18] + b2[0x1F]; + b1[0x1F] = (b2[0x1F] - b2[0x18]) * costab[0]; + b1[0x19] = b2[0x19] + b2[0x1E]; + b1[0x1E] = (b2[0x1E] - b2[0x19]) * costab[1]; + b1[0x1A] = b2[0x1A] + b2[0x1D]; + b1[0x1D] = (b2[0x1D] - b2[0x1A]) * costab[2]; + b1[0x1B] = b2[0x1B] + b2[0x1C]; + b1[0x1C] = (b2[0x1C] - b2[0x1B]) * costab[3]; + + { + register mpeg3_real_t const cos0 = mpeg3_pnts[3][0]; + register mpeg3_real_t const cos1 = mpeg3_pnts[3][1]; + + b2[0x00] = b1[0x00] + b1[0x03]; + b2[0x03] = (b1[0x00] - b1[0x03]) * cos0; + b2[0x01] = b1[0x01] + b1[0x02]; + b2[0x02] = (b1[0x01] - b1[0x02]) * cos1; + + b2[0x04] = b1[0x04] + b1[0x07]; + b2[0x07] = (b1[0x07] - b1[0x04]) * cos0; + b2[0x05] = b1[0x05] + b1[0x06]; + b2[0x06] = (b1[0x06] - b1[0x05]) * cos1; + + b2[0x08] = b1[0x08] + b1[0x0B]; + b2[0x0B] = (b1[0x08] - b1[0x0B]) * cos0; + b2[0x09] = b1[0x09] + b1[0x0A]; + b2[0x0A] = (b1[0x09] - b1[0x0A]) * cos1; + + b2[0x0C] = b1[0x0C] + b1[0x0F]; + b2[0x0F] = (b1[0x0F] - b1[0x0C]) * cos0; + b2[0x0D] = b1[0x0D] + b1[0x0E]; + b2[0x0E] = (b1[0x0E] - b1[0x0D]) * cos1; + + b2[0x10] = b1[0x10] + b1[0x13]; + b2[0x13] = (b1[0x10] - b1[0x13]) * cos0; + b2[0x11] = b1[0x11] + b1[0x12]; + b2[0x12] = (b1[0x11] - b1[0x12]) * cos1; + + b2[0x14] = b1[0x14] + b1[0x17]; + b2[0x17] = (b1[0x17] - b1[0x14]) * cos0; + b2[0x15] = b1[0x15] + b1[0x16]; + b2[0x16] = (b1[0x16] - b1[0x15]) * cos1; + + b2[0x18] = b1[0x18] + b1[0x1B]; + b2[0x1B] = (b1[0x18] - b1[0x1B]) * cos0; + b2[0x19] = b1[0x19] + b1[0x1A]; + b2[0x1A] = (b1[0x19] - b1[0x1A]) * cos1; + + b2[0x1C] = b1[0x1C] + b1[0x1F]; + b2[0x1F] = (b1[0x1F] - b1[0x1C]) * cos0; + b2[0x1D] = b1[0x1D] + b1[0x1E]; + b2[0x1E] = (b1[0x1E] - b1[0x1D]) * cos1; + } + + { + register mpeg3_real_t const cos0 = mpeg3_pnts[4][0]; + + b1[0x00] = b2[0x00] + b2[0x01]; + b1[0x01] = (b2[0x00] - b2[0x01]) * cos0; + b1[0x02] = b2[0x02] + b2[0x03]; + b1[0x03] = (b2[0x03] - b2[0x02]) * cos0; + b1[0x02] += b1[0x03]; + + b1[0x04] = b2[0x04] + b2[0x05]; + b1[0x05] = (b2[0x04] - b2[0x05]) * cos0; + b1[0x06] = b2[0x06] + b2[0x07]; + b1[0x07] = (b2[0x07] - b2[0x06]) * cos0; + b1[0x06] += b1[0x07]; + b1[0x04] += b1[0x06]; + b1[0x06] += b1[0x05]; + b1[0x05] += b1[0x07]; + + b1[0x08] = b2[0x08] + b2[0x09]; + b1[0x09] = (b2[0x08] - b2[0x09]) * cos0; + b1[0x0A] = b2[0x0A] + b2[0x0B]; + b1[0x0B] = (b2[0x0B] - b2[0x0A]) * cos0; + b1[0x0A] += b1[0x0B]; + + b1[0x0C] = b2[0x0C] + b2[0x0D]; + b1[0x0D] = (b2[0x0C] - b2[0x0D]) * cos0; + b1[0x0E] = b2[0x0E] + b2[0x0F]; + b1[0x0F] = (b2[0x0F] - b2[0x0E]) * cos0; + b1[0x0E] += b1[0x0F]; + b1[0x0C] += b1[0x0E]; + b1[0x0E] += b1[0x0D]; + b1[0x0D] += b1[0x0F]; + + b1[0x10] = b2[0x10] + b2[0x11]; + b1[0x11] = (b2[0x10] - b2[0x11]) * cos0; + b1[0x12] = b2[0x12] + b2[0x13]; + b1[0x13] = (b2[0x13] - b2[0x12]) * cos0; + b1[0x12] += b1[0x13]; + + b1[0x14] = b2[0x14] + b2[0x15]; + b1[0x15] = (b2[0x14] - b2[0x15]) * cos0; + b1[0x16] = b2[0x16] + b2[0x17]; + b1[0x17] = (b2[0x17] - b2[0x16]) * cos0; + b1[0x16] += b1[0x17]; + b1[0x14] += b1[0x16]; + b1[0x16] += b1[0x15]; + b1[0x15] += b1[0x17]; + + b1[0x18] = b2[0x18] + b2[0x19]; + b1[0x19] = (b2[0x18] - b2[0x19]) * cos0; + b1[0x1A] = b2[0x1A] + b2[0x1B]; + b1[0x1B] = (b2[0x1B] - b2[0x1A]) * cos0; + b1[0x1A] += b1[0x1B]; + + b1[0x1C] = b2[0x1C] + b2[0x1D]; + b1[0x1D] = (b2[0x1C] - b2[0x1D]) * cos0; + b1[0x1E] = b2[0x1E] + b2[0x1F]; + b1[0x1F] = (b2[0x1F] - b2[0x1E]) * cos0; + b1[0x1E] += b1[0x1F]; + b1[0x1C] += b1[0x1E]; + b1[0x1E] += b1[0x1D]; + b1[0x1D] += b1[0x1F]; + } + + out0[0x10*16] = b1[0x00]; + out0[0x10*12] = b1[0x04]; + out0[0x10* 8] = b1[0x02]; + out0[0x10* 4] = b1[0x06]; + out0[0x10* 0] = b1[0x01]; + out1[0x10* 0] = b1[0x01]; + out1[0x10* 4] = b1[0x05]; + out1[0x10* 8] = b1[0x03]; + out1[0x10*12] = b1[0x07]; + + out0[0x10*14] = b1[0x08] + b1[0x0C]; + out0[0x10*10] = b1[0x0C] + b1[0x0a]; + out0[0x10* 6] = b1[0x0A] + b1[0x0E]; + out0[0x10* 2] = b1[0x0E] + b1[0x09]; + out1[0x10* 2] = b1[0x09] + b1[0x0D]; + out1[0x10* 6] = b1[0x0D] + b1[0x0B]; + out1[0x10*10] = b1[0x0B] + b1[0x0F]; + out1[0x10*14] = b1[0x0F]; + + { + register mpeg3_real_t tmp; + tmp = b1[0x18] + b1[0x1C]; + out0[0x10*15] = tmp + b1[0x10]; + out0[0x10*13] = tmp + b1[0x14]; + tmp = b1[0x1C] + b1[0x1A]; + out0[0x10*11] = tmp + b1[0x14]; + out0[0x10* 9] = tmp + b1[0x12]; + tmp = b1[0x1A] + b1[0x1E]; + out0[0x10* 7] = tmp + b1[0x12]; + out0[0x10* 5] = tmp + b1[0x16]; + tmp = b1[0x1E] + b1[0x19]; + out0[0x10* 3] = tmp + b1[0x16]; + out0[0x10* 1] = tmp + b1[0x11]; + tmp = b1[0x19] + b1[0x1D]; + out1[0x10* 1] = tmp + b1[0x11]; + out1[0x10* 3] = tmp + b1[0x15]; + tmp = b1[0x1D] + b1[0x1B]; + out1[0x10* 5] = tmp + b1[0x15]; + out1[0x10* 7] = tmp + b1[0x13]; + tmp = b1[0x1B] + b1[0x1F]; + out1[0x10* 9] = tmp + b1[0x13]; + out1[0x10*11] = tmp + b1[0x17]; + out1[0x10*13] = b1[0x17] + b1[0x1F]; + out1[0x10*15] = b1[0x1F]; + } + return 0; +} + +/* + * the call via dct64 is a trick to force GCC to use + * (new) registers for the b1,b2 pointer to the bufs[xx] field + */ +int mpeg3audio_dct64(mpeg3_real_t *a, mpeg3_real_t *b, mpeg3_real_t *c) +{ + mpeg3_real_t bufs[0x40]; + return mpeg3audio_dct64_1(a, b, bufs, bufs + 0x20, c); +} + +/*//////////////////////////////////////////////////////////////// */ +/* */ +/* 9 Point Inverse Discrete Cosine Transform */ +/* */ +/* This piece of code is Copyright 1997 Mikko Tommila and is freely usable */ +/* by anybody. The algorithm itself is of course in the public domain. */ +/* */ +/* Again derived heuristically from the 9-point WFTA. */ +/* */ +/* The algorithm is optimized (?) for speed, not for small rounding errors or */ +/* good readability. */ +/* */ +/* 36 additions, 11 multiplications */ +/* */ +/* Again this is very likely sub-optimal. */ +/* */ +/* The code is optimized to use a minimum number of temporary variables, */ +/* so it should compile quite well even on 8-register Intel x86 processors. */ +/* This makes the code quite obfuscated and very difficult to understand. */ +/* */ +/* References: */ +/* [1] S. Winograd: "On Computing the Discrete Fourier Transform", */ +/* Mathematics of Computation, Volume 32, Number 141, January 1978, */ +/* Pages 175-199 */ + + +/*------------------------------------------------------------------*/ +/* */ +/* Function: Calculation of the inverse MDCT */ +/* */ +/*------------------------------------------------------------------*/ + +int mpeg3audio_dct36(mpeg3_real_t *inbuf, mpeg3_real_t *o1, mpeg3_real_t *o2, mpeg3_real_t *wintab, mpeg3_real_t *tsbuf) +{ + mpeg3_real_t tmp[18]; + + { + register mpeg3_real_t *in = inbuf; + + in[17]+=in[16]; in[16]+=in[15]; in[15]+=in[14]; + in[14]+=in[13]; in[13]+=in[12]; in[12]+=in[11]; + in[11]+=in[10]; in[10]+=in[9]; in[9] +=in[8]; + in[8] +=in[7]; in[7] +=in[6]; in[6] +=in[5]; + in[5] +=in[4]; in[4] +=in[3]; in[3] +=in[2]; + in[2] +=in[1]; in[1] +=in[0]; + + in[17]+=in[15]; in[15]+=in[13]; in[13]+=in[11]; in[11]+=in[9]; + in[9] +=in[7]; in[7] +=in[5]; in[5] +=in[3]; in[3] +=in[1]; + + + { + mpeg3_real_t t3; + { + mpeg3_real_t t0, t1, t2; + + t0 = mpeg3_COS6_2 * (in[8] + in[16] - in[4]); + t1 = mpeg3_COS6_2 * in[12]; + + t3 = in[0]; + t2 = t3 - t1 - t1; + tmp[1] = tmp[7] = t2 - t0; + tmp[4] = t2 + t0 + t0; + t3 += t1; + + t2 = mpeg3_COS6_1 * (in[10] + in[14] - in[2]); + tmp[1] -= t2; + tmp[7] += t2; + } + { + mpeg3_real_t t0, t1, t2; + + t0 = mpeg3_cos9[0] * (in[4] + in[8] ); + t1 = mpeg3_cos9[1] * (in[8] - in[16]); + t2 = mpeg3_cos9[2] * (in[4] + in[16]); + + tmp[2] = tmp[6] = t3 - t0 - t2; + tmp[0] = tmp[8] = t3 + t0 + t1; + tmp[3] = tmp[5] = t3 - t1 + t2; + } + } + { + mpeg3_real_t t1, t2, t3; + + t1 = mpeg3_cos18[0] * (in[2] + in[10]); + t2 = mpeg3_cos18[1] * (in[10] - in[14]); + t3 = mpeg3_COS6_1 * in[6]; + + { + mpeg3_real_t t0 = t1 + t2 + t3; + tmp[0] += t0; + tmp[8] -= t0; + } + + t2 -= t3; + t1 -= t3; + + t3 = mpeg3_cos18[2] * (in[2] + in[14]); + + t1 += t3; + tmp[3] += t1; + tmp[5] -= t1; + + t2 -= t3; + tmp[2] += t2; + tmp[6] -= t2; + } + + + { + mpeg3_real_t t0, t1, t2, t3, t4, t5, t6, t7; + + t1 = mpeg3_COS6_2 * in[13]; + t2 = mpeg3_COS6_2 * (in[9] + in[17] - in[5]); + + t3 = in[1] + t1; + t4 = in[1] - t1 - t1; + t5 = t4 - t2; + + t0 = mpeg3_cos9[0] * (in[5] + in[9]); + t1 = mpeg3_cos9[1] * (in[9] - in[17]); + + tmp[13] = (t4 + t2 + t2) * mpeg3_tfcos36[17-13]; + t2 = mpeg3_cos9[2] * (in[5] + in[17]); + + t6 = t3 - t0 - t2; + t0 += t3 + t1; + t3 += t2 - t1; + + t2 = mpeg3_cos18[0] * (in[3] + in[11]); + t4 = mpeg3_cos18[1] * (in[11] - in[15]); + t7 = mpeg3_COS6_1 * in[7]; + + t1 = t2 + t4 + t7; + tmp[17] = (t0 + t1) * mpeg3_tfcos36[17-17]; + tmp[9] = (t0 - t1) * mpeg3_tfcos36[17-9]; + t1 = mpeg3_cos18[2] * (in[3] + in[15]); + t2 += t1 - t7; + + tmp[14] = (t3 + t2) * mpeg3_tfcos36[17-14]; + t0 = mpeg3_COS6_1 * (in[11] + in[15] - in[3]); + tmp[12] = (t3 - t2) * mpeg3_tfcos36[17-12]; + + t4 -= t1 + t7; + + tmp[16] = (t5 - t0) * mpeg3_tfcos36[17-16]; + tmp[10] = (t5 + t0) * mpeg3_tfcos36[17-10]; + tmp[15] = (t6 + t4) * mpeg3_tfcos36[17-15]; + tmp[11] = (t6 - t4) * mpeg3_tfcos36[17-11]; + } + +#define MACRO(v) \ + { \ + mpeg3_real_t tmpval; \ + tmpval = tmp[(v)] + tmp[17-(v)]; \ + out2[9+(v)] = tmpval * w[27+(v)]; \ + out2[8-(v)] = tmpval * w[26-(v)]; \ + tmpval = tmp[(v)] - tmp[17-(v)]; \ + ts[SBLIMIT*(8-(v))] = out1[8-(v)] + tmpval * w[8-(v)]; \ + ts[SBLIMIT*(9+(v))] = out1[9+(v)] + tmpval * w[9+(v)]; \ + } + + { + register mpeg3_real_t *out2 = o2; + register mpeg3_real_t *w = wintab; + register mpeg3_real_t *out1 = o1; + register mpeg3_real_t *ts = tsbuf; + + MACRO(0); + MACRO(1); + MACRO(2); + MACRO(3); + MACRO(4); + MACRO(5); + MACRO(6); + MACRO(7); + MACRO(8); + } + } + return 0; +} + +/* + * new DCT12 + */ +int mpeg3audio_dct12(mpeg3_real_t *in,mpeg3_real_t *rawout1,mpeg3_real_t *rawout2,register mpeg3_real_t *wi,register mpeg3_real_t *ts) +{ +#define DCT12_PART1 \ + in5 = in[5*3]; \ + in5 += (in4 = in[4*3]); \ + in4 += (in3 = in[3*3]); \ + in3 += (in2 = in[2*3]); \ + in2 += (in1 = in[1*3]); \ + in1 += (in0 = in[0*3]); \ + \ + in5 += in3; in3 += in1; \ + \ + in2 *= mpeg3_COS6_1; \ + in3 *= mpeg3_COS6_1; \ + +#define DCT12_PART2 \ + in0 += in4 * mpeg3_COS6_2; \ + \ + in4 = in0 + in2; \ + in0 -= in2; \ + \ + in1 += in5 * mpeg3_COS6_2; \ + \ + in5 = (in1 + in3) * mpeg3_tfcos12[0]; \ + in1 = (in1 - in3) * mpeg3_tfcos12[2]; \ + \ + in3 = in4 + in5; \ + in4 -= in5; \ + \ + in2 = in0 + in1; \ + in0 -= in1; + + + { + mpeg3_real_t in0,in1,in2,in3,in4,in5; + register mpeg3_real_t *out1 = rawout1; + ts[SBLIMIT*0] = out1[0]; ts[SBLIMIT*1] = out1[1]; ts[SBLIMIT*2] = out1[2]; + ts[SBLIMIT*3] = out1[3]; ts[SBLIMIT*4] = out1[4]; ts[SBLIMIT*5] = out1[5]; + + DCT12_PART1 + + { + mpeg3_real_t tmp0,tmp1 = (in0 - in4); + { + mpeg3_real_t tmp2 = (in1 - in5) * mpeg3_tfcos12[1]; + tmp0 = tmp1 + tmp2; + tmp1 -= tmp2; + } + ts[(17-1)*SBLIMIT] = out1[17-1] + tmp0 * wi[11-1]; + ts[(12+1)*SBLIMIT] = out1[12+1] + tmp0 * wi[6+1]; + ts[(6 +1)*SBLIMIT] = out1[6 +1] + tmp1 * wi[1]; + ts[(11-1)*SBLIMIT] = out1[11-1] + tmp1 * wi[5-1]; + } + + DCT12_PART2 + + ts[(17-0)*SBLIMIT] = out1[17-0] + in2 * wi[11-0]; + ts[(12+0)*SBLIMIT] = out1[12+0] + in2 * wi[6+0]; + ts[(12+2)*SBLIMIT] = out1[12+2] + in3 * wi[6+2]; + ts[(17-2)*SBLIMIT] = out1[17-2] + in3 * wi[11-2]; + + ts[(6+0)*SBLIMIT] = out1[6+0] + in0 * wi[0]; + ts[(11-0)*SBLIMIT] = out1[11-0] + in0 * wi[5-0]; + ts[(6+2)*SBLIMIT] = out1[6+2] + in4 * wi[2]; + ts[(11-2)*SBLIMIT] = out1[11-2] + in4 * wi[5-2]; + } + + in++; + + { + mpeg3_real_t in0,in1,in2,in3,in4,in5; + register mpeg3_real_t *out2 = rawout2; + + DCT12_PART1 + + { + mpeg3_real_t tmp0,tmp1 = (in0 - in4); + { + mpeg3_real_t tmp2 = (in1 - in5) * mpeg3_tfcos12[1]; + tmp0 = tmp1 + tmp2; + tmp1 -= tmp2; + } + out2[5-1] = tmp0 * wi[11-1]; + out2[0+1] = tmp0 * wi[6+1]; + ts[(12+1)*SBLIMIT] += tmp1 * wi[1]; + ts[(17-1)*SBLIMIT] += tmp1 * wi[5-1]; + } + + DCT12_PART2 + + out2[5-0] = in2 * wi[11-0]; + out2[0+0] = in2 * wi[6+0]; + out2[0+2] = in3 * wi[6+2]; + out2[5-2] = in3 * wi[11-2]; + + ts[(12+0)*SBLIMIT] += in0 * wi[0]; + ts[(17-0)*SBLIMIT] += in0 * wi[5-0]; + ts[(12+2)*SBLIMIT] += in4 * wi[2]; + ts[(17-2)*SBLIMIT] += in4 * wi[5-2]; + } + + in++; + + { + mpeg3_real_t in0,in1,in2,in3,in4,in5; + register mpeg3_real_t *out2 = rawout2; + out2[12]=out2[13]=out2[14]=out2[15]=out2[16]=out2[17]=0.0; + + DCT12_PART1 + + { + mpeg3_real_t tmp0,tmp1 = (in0 - in4); + { + mpeg3_real_t tmp2 = (in1 - in5) * mpeg3_tfcos12[1]; + tmp0 = tmp1 + tmp2; + tmp1 -= tmp2; + } + out2[11-1] = tmp0 * wi[11-1]; + out2[6 +1] = tmp0 * wi[6+1]; + out2[0+1] += tmp1 * wi[1]; + out2[5-1] += tmp1 * wi[5-1]; + } + + DCT12_PART2 + + out2[11-0] = in2 * wi[11-0]; + out2[6 +0] = in2 * wi[6+0]; + out2[6 +2] = in3 * wi[6+2]; + out2[11-2] = in3 * wi[11-2]; + + out2[0+0] += in0 * wi[0]; + out2[5-0] += in0 * wi[5-0]; + out2[0+2] += in4 * wi[2]; + out2[5-2] += in4 * wi[5-2]; + } + return 0; +} + +/* AC3 IMDCT tables */ + +/* Twiddle factors for IMDCT */ +#if !defined(USE_FIXED_POINT) || defined(PRINT_FIXED_POINT_TABLES) +static mpeg3_real_t mpeg3_xcos1[AC3_N / 4]; +static mpeg3_real_t mpeg3_xsin1[AC3_N / 4]; +static mpeg3_real_t mpeg3_xcos2[AC3_N / 8]; +static mpeg3_real_t mpeg3_xsin2[AC3_N / 8]; +#else +#define USE_FP_TABLES +#include "fptables.h" +#endif + +/* 128 point bit-reverse LUT */ +static unsigned char mpeg3_bit_reverse_512[] = +{ + 0x00, 0x40, 0x20, 0x60, 0x10, 0x50, 0x30, 0x70, + 0x08, 0x48, 0x28, 0x68, 0x18, 0x58, 0x38, 0x78, + 0x04, 0x44, 0x24, 0x64, 0x14, 0x54, 0x34, 0x74, + 0x0c, 0x4c, 0x2c, 0x6c, 0x1c, 0x5c, 0x3c, 0x7c, + 0x02, 0x42, 0x22, 0x62, 0x12, 0x52, 0x32, 0x72, + 0x0a, 0x4a, 0x2a, 0x6a, 0x1a, 0x5a, 0x3a, 0x7a, + 0x06, 0x46, 0x26, 0x66, 0x16, 0x56, 0x36, 0x76, + 0x0e, 0x4e, 0x2e, 0x6e, 0x1e, 0x5e, 0x3e, 0x7e, + 0x01, 0x41, 0x21, 0x61, 0x11, 0x51, 0x31, 0x71, + 0x09, 0x49, 0x29, 0x69, 0x19, 0x59, 0x39, 0x79, + 0x05, 0x45, 0x25, 0x65, 0x15, 0x55, 0x35, 0x75, + 0x0d, 0x4d, 0x2d, 0x6d, 0x1d, 0x5d, 0x3d, 0x7d, + 0x03, 0x43, 0x23, 0x63, 0x13, 0x53, 0x33, 0x73, + 0x0b, 0x4b, 0x2b, 0x6b, 0x1b, 0x5b, 0x3b, 0x7b, + 0x07, 0x47, 0x27, 0x67, 0x17, 0x57, 0x37, 0x77, + 0x0f, 0x4f, 0x2f, 0x6f, 0x1f, 0x5f, 0x3f, 0x7f +}; + +static unsigned char mpeg3_bit_reverse_256[] = +{ + 0x00, 0x20, 0x10, 0x30, 0x08, 0x28, 0x18, 0x38, + 0x04, 0x24, 0x14, 0x34, 0x0c, 0x2c, 0x1c, 0x3c, + 0x02, 0x22, 0x12, 0x32, 0x0a, 0x2a, 0x1a, 0x3a, + 0x06, 0x26, 0x16, 0x36, 0x0e, 0x2e, 0x1e, 0x3e, + 0x01, 0x21, 0x11, 0x31, 0x09, 0x29, 0x19, 0x39, + 0x05, 0x25, 0x15, 0x35, 0x0d, 0x2d, 0x1d, 0x3d, + 0x03, 0x23, 0x13, 0x33, 0x0b, 0x2b, 0x1b, 0x3b, + 0x07, 0x27, 0x17, 0x37, 0x0f, 0x2f, 0x1f, 0x3f +}; + +/* Windowing function for Modified DCT - Thank you acroread */ +static mpeg3_real_t mpeg3_window[] = +{ + 0.00014, 0.00024, 0.00037, 0.00051, 0.00067, 0.00086, 0.00107, 0.00130, + 0.00157, 0.00187, 0.00220, 0.00256, 0.00297, 0.00341, 0.00390, 0.00443, + 0.00501, 0.00564, 0.00632, 0.00706, 0.00785, 0.00871, 0.00962, 0.01061, + 0.01166, 0.01279, 0.01399, 0.01526, 0.01662, 0.01806, 0.01959, 0.02121, + 0.02292, 0.02472, 0.02662, 0.02863, 0.03073, 0.03294, 0.03527, 0.03770, + 0.04025, 0.04292, 0.04571, 0.04862, 0.05165, 0.05481, 0.05810, 0.06153, + 0.06508, 0.06878, 0.07261, 0.07658, 0.08069, 0.08495, 0.08935, 0.09389, + 0.09859, 0.10343, 0.10842, 0.11356, 0.11885, 0.12429, 0.12988, 0.13563, + 0.14152, 0.14757, 0.15376, 0.16011, 0.16661, 0.17325, 0.18005, 0.18699, + 0.19407, 0.20130, 0.20867, 0.21618, 0.22382, 0.23161, 0.23952, 0.24757, + 0.25574, 0.26404, 0.27246, 0.28100, 0.28965, 0.29841, 0.30729, 0.31626, + 0.32533, 0.33450, 0.34376, 0.35311, 0.36253, 0.37204, 0.38161, 0.39126, + 0.40096, 0.41072, 0.42054, 0.43040, 0.44030, 0.45023, 0.46020, 0.47019, + 0.48020, 0.49022, 0.50025, 0.51028, 0.52031, 0.53033, 0.54033, 0.55031, + 0.56026, 0.57019, 0.58007, 0.58991, 0.59970, 0.60944, 0.61912, 0.62873, + 0.63827, 0.64774, 0.65713, 0.66643, 0.67564, 0.68476, 0.69377, 0.70269, + 0.71150, 0.72019, 0.72877, 0.73723, 0.74557, 0.75378, 0.76186, 0.76981, + 0.77762, 0.78530, 0.79283, 0.80022, 0.80747, 0.81457, 0.82151, 0.82831, + 0.83496, 0.84145, 0.84779, 0.85398, 0.86001, 0.86588, 0.87160, 0.87716, + 0.88257, 0.88782, 0.89291, 0.89785, 0.90264, 0.90728, 0.91176, 0.91610, + 0.92028, 0.92432, 0.92822, 0.93197, 0.93558, 0.93906, 0.94240, 0.94560, + 0.94867, 0.95162, 0.95444, 0.95713, 0.95971, 0.96217, 0.96451, 0.96674, + 0.96887, 0.97089, 0.97281, 0.97463, 0.97635, 0.97799, 0.97953, 0.98099, + 0.98236, 0.98366, 0.98488, 0.98602, 0.98710, 0.98811, 0.98905, 0.98994, + 0.99076, 0.99153, 0.99225, 0.99291, 0.99353, 0.99411, 0.99464, 0.99513, + 0.99558, 0.99600, 0.99639, 0.99674, 0.99706, 0.99736, 0.99763, 0.99788, + 0.99811, 0.99831, 0.99850, 0.99867, 0.99882, 0.99895, 0.99908, 0.99919, + 0.99929, 0.99938, 0.99946, 0.99953, 0.99959, 0.99965, 0.99969, 0.99974, + 0.99978, 0.99981, 0.99984, 0.99986, 0.99988, 0.99990, 0.99992, 0.99993, + 0.99994, 0.99995, 0.99996, 0.99997, 0.99998, 0.99998, 0.99998, 0.99999, + 0.99999, 0.99999, 0.99999, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, + 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000, 1.00000 +}; + +mpeg3_complex_t cmplx_mult(mpeg3_complex_t a, mpeg3_complex_t b) +{ + mpeg3_complex_t ret; + + ret.real = a.real * b.real - a.imag * b.imag; + ret.imag = a.real * b.imag + a.imag * b.real; + + return ret; +} + +int mpeg3audio_imdct_init(mpeg3audio_t *audio) +{ + int i, k; + mpeg3_complex_t angle_step; + mpeg3_complex_t current_angle; + +/* Twiddle factors to turn IFFT into IMDCT */ + for(i = 0; i < AC3_N / 4; i++) + { + mpeg3_xcos1[i] = -cos(2.0f * M_PI * (8 * i + 1 ) / ( 8 * AC3_N)); + mpeg3_xsin1[i] = -sin(2.0f * M_PI * (8 * i + 1 ) / ( 8 * AC3_N)); + } + +/* More twiddle factors to turn IFFT into IMDCT */ + for(i = 0; i < AC3_N / 8; i++) + { + mpeg3_xcos2[i] = -cos(2.0f * M_PI * (8 * i + 1 ) / ( 4 * AC3_N)); + mpeg3_xsin2[i] = -sin(2.0f * M_PI * (8 * i + 1 ) / ( 4 * AC3_N)); + } + +/* Canonical twiddle factors for FFT */ +#if defined(USE_FIXED_POINT) && !defined(PRINT_FIXED_POINT_TABLES) + for(i = 0; i < 7; i++) + { + audio->ac3_w[i] = (mpeg3_complex_t*)ac3_w_fixedpoints[i]; + } +#else + audio->ac3_w[0] = audio->ac3_w_1; + audio->ac3_w[1] = audio->ac3_w_2; + audio->ac3_w[2] = audio->ac3_w_4; + audio->ac3_w[3] = audio->ac3_w_8; + audio->ac3_w[4] = audio->ac3_w_16; + audio->ac3_w[5] = audio->ac3_w_32; + audio->ac3_w[6] = audio->ac3_w_64; + + for(i = 0; i < 7; i++) + { + angle_step.real = cos(-2.0f * M_PI / (1 << (i + 1))); + angle_step.imag = sin(-2.0f * M_PI / (1 << (i + 1))); + + current_angle.real = 1.0f; + current_angle.imag = 0.0f; + + for (k = 0; k < 1 << i; k++) + { + audio->ac3_w[i][k] = current_angle; + current_angle = cmplx_mult(current_angle, angle_step); + } + } + +#ifdef PRINT_FIXED_POINT_TABLES + printf("#ifdef USE_FP_TABLES\n"); + printf("static long mpeg3_xcos1_fixedpoints[] = {"); + for(i = 0; i < AC3_N / 4; i++) { + printf("%c0x%08x,", i%8?' ':'\n', mpeg3_xcos1[i].fixedPoint()); + } + printf("\n};\nstatic mpeg3_real_t *mpeg3_xcos1 = \n" + "(mpeg3_real_t*)mpeg3_xcos1_fixedpoints;\n"); + + printf("static long mpeg3_xsin1_fixedpoints[] = {"); + for(i = 0; i < AC3_N / 4; i++) { + printf("%c0x%08x,", i%8?' ':'\n', mpeg3_xsin1[i].fixedPoint()); + } + printf("\n};\nstatic mpeg3_real_t *mpeg3_xsin1 = \n" + "(mpeg3_real_t*)mpeg3_xsin1_fixedpoints;\n"); + + + printf("static long mpeg3_xcos2_fixedpoints[] = {"); + for(i = 0; i < AC3_N / 4; i++) { + printf("%c0x%08x,", i%8?' ':'\n', mpeg3_xcos2[i].fixedPoint()); + } + printf("\n};\nstatic mpeg3_real_t *mpeg3_xcos2 = \n" + "(mpeg3_real_t*)mpeg3_xcos2_fixedpoints;\n"); + + printf("static long mpeg3_xsin2_fixedpoints[] = {"); + for(i = 0; i < AC3_N / 4; i++) { + printf("%c0x%08x,", i%8?' ':'\n', mpeg3_xsin2[i].fixedPoint()); + } + printf("\n};\nstatic mpeg3_real_t *mpeg3_xsin2 = \n" + "(mpeg3_real_t*)mpeg3_xsin2_fixedpoints;\n"); + + + printf("typedef struct { long r, i; } fixed_cmplx;\n"); + for(i = 0; i < 7; i++) + { + printf("fixed_cmplx ac3_w_d%d[] = { ", 1<<i); + for (k = 0; k < 1 << i; k++) + { + printf("%s{ 0x%08x, 0x%08x },", k%4?" ":"\n ", + audio->ac3_w[i][k].real.fixedPoint(), + audio->ac3_w[i][k].imag.fixedPoint()); + } + printf("};\n"); + } + + printf("fixed_cmplx *ac3_w_fixedpoints[] = {\n"); + for(i = 0; i < 7; i++) + { + printf("ac3_w_d%d, ", 1<<i); + } + printf("};\n"); + printf("#endif\n"); +#endif +#endif + + return 0; +} + + +inline void swap_cmplx(mpeg3_complex_t *a, mpeg3_complex_t *b) +{ + mpeg3_complex_t tmp; + + tmp = *a; + *a = *b; + *b = tmp; +} + +void mpeg3audio_ac3_imdct_do_512(mpeg3audio_t *audio, + mpeg3_real_t data[], + mpeg3_real_t *y, + int step, + mpeg3_real_t *delay) +{ + int i, k; + int p, q; + int m; + int two_m; + int two_m_plus_one; + + mpeg3_real_t tmp_a_i; + mpeg3_real_t tmp_a_r; + mpeg3_real_t tmp_b_i; + mpeg3_real_t tmp_b_r; + + mpeg3_real_t *y_ptr; + mpeg3_real_t *delay_ptr; + mpeg3_real_t *window_ptr; + mpeg3_complex_t *buf = audio->ac3_imdct_buf; + +/* Pre IFFT complex multiply plus IFFT cmplx conjugate */ + for(i = 0; i < AC3_N / 4; i++) + { + buf[i].real = (data[AC3_N / 2 - 2 * i - 1] * mpeg3_xcos1[i]) - (data[2 * i] * mpeg3_xsin1[i]); + buf[i].imag = -((data[2 * i] * mpeg3_xcos1[i]) + (data[AC3_N / 2 - 2 * i - 1] * mpeg3_xsin1[i])); + } + +/* Bit reversed shuffling */ + for(i = 0; i < AC3_N / 4; i++) + { + k = mpeg3_bit_reverse_512[i]; + if(k < i) + swap_cmplx(&buf[i], &buf[k]); + } + +/* FFT Merge */ + for(m = 0; m < 7; m++) + { + if(m) + two_m = (1 << m); + else + two_m = 1; + + two_m_plus_one = (1 << (m + 1)); + + for(k = 0; k < two_m; k++) + { + for(i = 0; i < AC3_N / 4; i += two_m_plus_one) + { + p = k + i; + q = p + two_m; + tmp_a_r = buf[p].real; + tmp_a_i = buf[p].imag; + tmp_b_r = buf[q].real * audio->ac3_w[m][k].real - buf[q].imag * audio->ac3_w[m][k].imag; + tmp_b_i = buf[q].imag * audio->ac3_w[m][k].real + buf[q].real * audio->ac3_w[m][k].imag; + buf[p].real = tmp_a_r + tmp_b_r; + buf[p].imag = tmp_a_i + tmp_b_i; + buf[q].real = tmp_a_r - tmp_b_r; + buf[q].imag = tmp_a_i - tmp_b_i; + } + } + } + +/* Post IFFT complex multiply plus IFFT complex conjugate*/ + for(i = 0; i < AC3_N / 4; i++) + { + tmp_a_r = buf[i].real; + tmp_a_i = -buf[i].imag; + buf[i].real = (tmp_a_r * mpeg3_xcos1[i]) - (tmp_a_i * mpeg3_xsin1[i]); + buf[i].imag = (tmp_a_r * mpeg3_xsin1[i]) + (tmp_a_i * mpeg3_xcos1[i]); + } + + y_ptr = y; + delay_ptr = delay; + window_ptr = mpeg3_window; + +/* Window and convert to real valued signal */ + for(i = 0; i < AC3_N / 8; i++) + { + *y_ptr = -buf[AC3_N / 8 + i].imag * *window_ptr++ + *delay_ptr++; + y_ptr += step; + *y_ptr = buf[AC3_N / 8 - i - 1].real * *window_ptr++ + *delay_ptr++; + y_ptr += step; + } + + for(i = 0; i < AC3_N / 8; i++) + { + *y_ptr = -buf[i].real * *window_ptr++ + *delay_ptr++; + y_ptr += step; + *y_ptr = buf[AC3_N / 4 - i - 1].imag * *window_ptr++ + *delay_ptr++; + y_ptr += step; + } + +/* The trailing edge of the window goes into the delay line */ + delay_ptr = delay; + + for(i = 0; i < AC3_N / 8; i++) + { + *delay_ptr++ = -buf[AC3_N / 8 + i].real * *--window_ptr; + *delay_ptr++ = buf[AC3_N / 8 - i - 1].imag * *--window_ptr; + } + + for(i = 0; i < AC3_N / 8; i++) + { + *delay_ptr++ = buf[i].imag * *--window_ptr; + *delay_ptr++ = -buf[AC3_N / 4 - i - 1].real * *--window_ptr; + } +} + +void mpeg3audio_ac3_imdct_do_256(mpeg3audio_t *audio, + mpeg3_real_t data[], + mpeg3_real_t *y, + int step, + mpeg3_real_t *delay) +{ + int i, k; + int p, q; + int m; + int two_m; + int two_m_plus_one; + mpeg3_complex_t *buf = audio->ac3_imdct_buf; + mpeg3_real_t *y_ptr; + mpeg3_real_t *delay_ptr; + mpeg3_real_t *window_ptr; + + mpeg3_real_t tmp_a_i; + mpeg3_real_t tmp_a_r; + mpeg3_real_t tmp_b_i; + mpeg3_real_t tmp_b_r; + + mpeg3_complex_t *buf_1, *buf_2; + + buf_1 = &buf[0]; + buf_2 = &buf[64]; + +/* Pre IFFT complex multiply plus IFFT cmplx conjugate */ + for(k = 0; k < AC3_N / 8; k++) + { + p = 2 * (AC3_N / 4 - 2 * k - 1); + q = 2 * (2 * k); + + buf_1[k].real = data[p] * mpeg3_xcos2[k] - data[q] * mpeg3_xsin2[k]; + buf_1[k].imag = - (data[q] * mpeg3_xcos2[k] + data[p] * mpeg3_xsin2[k]); + buf_2[k].real = data[p + 1] * mpeg3_xcos2[k] - data[q + 1] * mpeg3_xsin2[k]; + buf_2[k].imag = - (data[q + 1] * mpeg3_xcos2[k] + data[p + 1] * mpeg3_xsin2[k]); + } + +/* IFFT Bit reversed shuffling */ + for(i = 0; i < AC3_N / 8; i++) + { + k = mpeg3_bit_reverse_256[i]; + if(k < i) + { + swap_cmplx(&buf_1[i], &buf_1[k]); + swap_cmplx(&buf_2[i], &buf_2[k]); + } + } + +/* FFT Merge */ + for(m = 0; m < 6; m++) + { + if(m) + two_m = (1 << m); + else + two_m = 1; + + two_m_plus_one = (1 << (m + 1)); + + for(k = 0; k < two_m; k++) + { + for(i = 0; i < AC3_N / 8; i += two_m_plus_one) + { + p = k + i; + q = p + two_m; +/* Do block 1 */ + tmp_a_r = buf_1[p].real; + tmp_a_i = buf_1[p].imag; + tmp_b_r = buf_1[q].real * audio->ac3_w[m][k].real - buf_1[q].imag * audio->ac3_w[m][k].imag; + tmp_b_i = buf_1[q].imag * audio->ac3_w[m][k].real + buf_1[q].real * audio->ac3_w[m][k].imag; + buf_1[p].real = tmp_a_r + tmp_b_r; + buf_1[p].imag = tmp_a_i + tmp_b_i; + buf_1[q].real = tmp_a_r - tmp_b_r; + buf_1[q].imag = tmp_a_i - tmp_b_i; + +/* Do block 2 */ + tmp_a_r = buf_2[p].real; + tmp_a_i = buf_2[p].imag; + tmp_b_r = buf_2[q].real * audio->ac3_w[m][k].real - buf_2[q].imag * audio->ac3_w[m][k].imag; + tmp_b_i = buf_2[q].imag * audio->ac3_w[m][k].real + buf_2[q].real * audio->ac3_w[m][k].imag; + buf_2[p].real = tmp_a_r + tmp_b_r; + buf_2[p].imag = tmp_a_i + tmp_b_i; + buf_2[q].real = tmp_a_r - tmp_b_r; + buf_2[q].imag = tmp_a_i - tmp_b_i; + } + } + } + +/* Post IFFT complex multiply */ + for(i = 0; i < AC3_N / 8; i++) + { + tmp_a_r = buf_1[i].real; + tmp_a_i = -buf_1[i].imag; + buf_1[i].real = (tmp_a_r * mpeg3_xcos2[i]) - (tmp_a_i * mpeg3_xsin2[i]); + buf_1[i].imag = (tmp_a_r * mpeg3_xsin2[i]) + (tmp_a_i * mpeg3_xcos2[i]); + tmp_a_r = buf_2[i].real; + tmp_a_i = -buf_2[i].imag; + buf_2[i].real = (tmp_a_r * mpeg3_xcos2[i]) - (tmp_a_i * mpeg3_xsin2[i]); + buf_2[i].imag = (tmp_a_r * mpeg3_xsin2[i]) + (tmp_a_i * mpeg3_xcos2[i]); + } + +/* Window and convert to real valued signal */ + y_ptr = y; + delay_ptr = delay; + window_ptr = mpeg3_window; + + for(i = 0; i < AC3_N / 8; i++) + { + *y_ptr = -buf[AC3_N / 8 + i].imag * *window_ptr++ + *delay_ptr++; + y_ptr += step; + *y_ptr = buf[AC3_N / 8 - i - 1].real * *window_ptr++ + *delay_ptr++; + y_ptr += step; + } + + for(i = 0; i < AC3_N / 8; i++) + { + *y_ptr = -buf[i].real * *window_ptr++ + *delay_ptr++; + y_ptr += step; + *y_ptr = buf[AC3_N / 4 - i - 1].imag * *window_ptr++ + *delay_ptr++; + y_ptr += step; + } + +/* The trailing edge of the window goes into the delay line */ + delay_ptr = delay; + + for(i = 0; i < AC3_N / 8; i++) + { + *delay_ptr++ = -buf[AC3_N / 8 + i].real * *--window_ptr; + *delay_ptr++ = buf[AC3_N / 8 - i - 1].imag * *--window_ptr; + } + + for(i = 0; i < AC3_N / 8; i++) + { + *delay_ptr++ = buf[i].imag * *--window_ptr; + *delay_ptr++ = -buf[AC3_N / 4 - i - 1].real * *--window_ptr; + } +} + +int mpeg3audio_ac3_imdct(mpeg3audio_t *audio, + mpeg3_ac3bsi_t *bsi, + mpeg3_ac3audblk_t *audblk, + mpeg3ac3_stream_samples_t samples) +{ + int i; + + for(i = 0; i < bsi->nfchans; i++) + { + if(audblk->blksw[i]) + mpeg3audio_ac3_imdct_do_256(audio, + samples[i], + audio->pcm_sample + audio->pcm_point + i, + bsi->nfchans, + audio->ac3_delay[i]); + else + mpeg3audio_ac3_imdct_do_512(audio, + samples[i], + audio->pcm_sample + audio->pcm_point + i, + bsi->nfchans, + audio->ac3_delay[i]); + } + audio->pcm_point += AC3_N / 2 * bsi->nfchans; + return 0; +} diff --git a/core/multimedia/opieplayer/libmpeg3/audio/exponents.c b/core/multimedia/opieplayer/libmpeg3/audio/exponents.c new file mode 100644 index 0000000..deda9b9 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/exponents.c @@ -0,0 +1,141 @@ +/* + * + * exponents.c Copyright (C) Aaron Holtzman - May 1999 + * + * This file is part of libmpeg3 + * + * libmpeg3 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * libmpeg3 is distributed in the hope that 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 GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include "mpeg3audio.h" +#include "../libmpeg3.h" +#include "../mpeg3protos.h" +#include <stdio.h> + +/* Exponent defines */ +#define UNPACK_FBW 1 +#define UNPACK_CPL 2 +#define UNPACK_LFE 4 + +static inline int mpeg3audio_ac3_exp_unpack_ch(unsigned int type, + unsigned int expstr, + unsigned int ngrps, + unsigned int initial_exp, + unsigned short exps[], + unsigned short *dest) +{ + int i, j; + int exp_acc; + int exp_1, exp_2, exp_3; + + if(expstr == MPEG3_EXP_REUSE) + return 0; + +/* Handle the initial absolute exponent */ + exp_acc = initial_exp; + j = 0; + +/* In the case of a fbw channel then the initial absolute value is + * also an exponent */ + if(type != UNPACK_CPL) + dest[j++] = exp_acc; + +/* Loop through the groups and fill the dest array appropriately */ + for(i = 0; i < ngrps; i++) + { + if(exps[i] > 124) + { + fprintf(stderr, "mpeg3audio_ac3_exp_unpack_ch: Invalid exponent %d\n", exps[i]); + return 1; + } + + exp_1 = exps[i] / 25; + exp_2 = (exps[i] % 25) / 5; + exp_3 = (exps[i] % 25) % 5; + + exp_acc += (exp_1 - 2); + + switch(expstr) + { + case MPEG3_EXP_D45: + dest[j++] = exp_acc; + dest[j++] = exp_acc; + case MPEG3_EXP_D25: + dest[j++] = exp_acc; + case MPEG3_EXP_D15: + dest[j++] = exp_acc; + } + + exp_acc += (exp_2 - 2); + + switch(expstr) + { + case MPEG3_EXP_D45: + dest[j++] = exp_acc; + dest[j++] = exp_acc; + case MPEG3_EXP_D25: + dest[j++] = exp_acc; + case MPEG3_EXP_D15: + dest[j++] = exp_acc; + } + + exp_acc += (exp_3 - 2); + + switch(expstr) + { + case MPEG3_EXP_D45: + dest[j++] = exp_acc; + dest[j++] = exp_acc; + case MPEG3_EXP_D25: + dest[j++] = exp_acc; + case MPEG3_EXP_D15: + dest[j++] = exp_acc; + } + } + return 0; +} + +int mpeg3audio_ac3_exponent_unpack(mpeg3audio_t *audio, + mpeg3_ac3bsi_t *bsi, + mpeg3_ac3audblk_t *audblk) +{ + int i, result = 0; + + for(i = 0; i < bsi->nfchans; i++) + result |= mpeg3audio_ac3_exp_unpack_ch(UNPACK_FBW, + audblk->chexpstr[i], + audblk->nchgrps[i], + audblk->exps[i][0], + &audblk->exps[i][1], + audblk->fbw_exp[i]); + + if(audblk->cplinu && !result) + result |= mpeg3audio_ac3_exp_unpack_ch(UNPACK_CPL, + audblk->cplexpstr, + audblk->ncplgrps, + audblk->cplabsexp << 1, + audblk->cplexps, + &audblk->cpl_exp[audblk->cplstrtmant]); + + if(bsi->lfeon && !result) + result |= mpeg3audio_ac3_exp_unpack_ch(UNPACK_LFE, + audblk->lfeexpstr, + 2, + audblk->lfeexps[0], + &audblk->lfeexps[1], + audblk->lfe_exp); + return result; +} diff --git a/core/multimedia/opieplayer/libmpeg3/audio/fptables.h b/core/multimedia/opieplayer/libmpeg3/audio/fptables.h new file mode 100644 index 0000000..2836984 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/fptables.h @@ -0,0 +1,1556 @@ +#ifdef USE_FP_TABLES +static long mpeg3_xcos1_fixedpoints[] = { +0xffff8001, 0xffff8004, 0xffff800c, 0xffff8019, 0xffff802a, 0xffff8041, 0xffff805d, 0xffff807e, +0xffff80a3, 0xffff80ce, 0xffff80fd, 0xffff8131, 0xffff816b, 0xffff81a9, 0xffff81ec, 0xffff8233, +0xffff8280, 0xffff82d1, 0xffff8328, 0xffff8383, 0xffff83e3, 0xffff8447, 0xffff84b1, 0xffff851f, +0xffff8592, 0xffff860a, 0xffff8686, 0xffff8707, 0xffff878d, 0xffff8817, 0xffff88a6, 0xffff893a, +0xffff89d2, 0xffff8a6f, 0xffff8b10, 0xffff8bb6, 0xffff8c60, 0xffff8d0f, 0xffff8dc2, 0xffff8e7a, +0xffff8f35, 0xffff8ff6, 0xffff90ba, 0xffff9183, 0xffff9250, 0xffff9322, 0xffff93f7, 0xffff94d1, +0xffff95af, 0xffff9691, 0xffff9777, 0xffff9861, 0xffff994f, 0xffff9a41, 0xffff9b37, 0xffff9c31, +0xffff9d2e, 0xffff9e30, 0xffff9f35, 0xffffa03e, 0xffffa14b, 0xffffa25b, 0xffffa36f, 0xffffa487, +0xffffa5a2, 0xffffa6c0, 0xffffa7e2, 0xffffa907, 0xffffaa30, 0xffffab5c, 0xffffac8b, 0xffffadbe, +0xffffaef4, 0xffffb02c, 0xffffb168, 0xffffb2a7, 0xffffb3e9, 0xffffb52e, 0xffffb676, 0xffffb7c0, +0xffffb90d, 0xffffba5d, 0xffffbbb0, 0xffffbd06, 0xffffbe5e, 0xffffbfb8, 0xffffc115, 0xffffc274, +0xffffc3d6, 0xffffc53a, 0xffffc6a1, 0xffffc809, 0xffffc974, 0xffffcae1, 0xffffcc50, 0xffffcdc0, +0xffffcf33, 0xffffd0a8, 0xffffd21e, 0xffffd397, 0xffffd511, 0xffffd68c, 0xffffd80a, 0xffffd988, +0xffffdb09, 0xffffdc8a, 0xffffde0d, 0xffffdf92, 0xffffe117, 0xffffe29e, 0xffffe426, 0xffffe5af, +0xffffe739, 0xffffe8c4, 0xffffea50, 0xffffebdd, 0xffffed6a, 0xffffeef8, 0xfffff087, 0xfffff217, +0xfffff3a7, 0xfffff537, 0xfffff6c8, 0xfffff859, 0xfffff9eb, 0xfffffb7d, 0xfffffd0f, 0xfffffea1, +}; +static mpeg3_real_t *mpeg3_xcos1 = +(mpeg3_real_t*)mpeg3_xcos1_fixedpoints; +static long mpeg3_xsin1_fixedpoints[] = { +0xffffffce, 0xfffffe3c, 0xfffffcaa, 0xfffffb18, 0xfffff986, 0xfffff7f5, 0xfffff664, 0xfffff4d3, +0xfffff343, 0xfffff1b3, 0xfffff023, 0xffffee95, 0xffffed07, 0xffffeb79, 0xffffe9ed, 0xffffe861, +0xffffe6d6, 0xffffe54d, 0xffffe3c4, 0xffffe23c, 0xffffe0b6, 0xffffdf30, 0xffffddac, 0xffffdc2a, +0xffffdaa8, 0xffffd928, 0xffffd7aa, 0xffffd62d, 0xffffd4b2, 0xffffd338, 0xffffd1c1, 0xffffd04b, +0xffffced6, 0xffffcd64, 0xffffcbf4, 0xffffca85, 0xffffc919, 0xffffc7af, 0xffffc647, 0xffffc4e1, +0xffffc37d, 0xffffc21c, 0xffffc0bd, 0xffffbf61, 0xffffbe07, 0xffffbcb0, 0xffffbb5b, 0xffffba09, +0xffffb8ba, 0xffffb76d, 0xffffb623, 0xffffb4dc, 0xffffb398, 0xffffb257, 0xffffb119, 0xffffafde, +0xffffaea6, 0xffffad71, 0xffffac3f, 0xffffab11, 0xffffa9e6, 0xffffa8be, 0xffffa799, 0xffffa678, +0xffffa55b, 0xffffa440, 0xffffa32a, 0xffffa217, 0xffffa107, 0xffff9ffc, 0xffff9ef3, 0xffff9def, +0xffff9cef, 0xffff9bf2, 0xffff9af9, 0xffff9a04, 0xffff9913, 0xffff9826, 0xffff973d, 0xffff9658, +0xffff9577, 0xffff949a, 0xffff93c1, 0xffff92ed, 0xffff921d, 0xffff9151, 0xffff9089, 0xffff8fc5, +0xffff8f06, 0xffff8e4b, 0xffff8d95, 0xffff8ce3, 0xffff8c35, 0xffff8b8c, 0xffff8ae7, 0xffff8a47, +0xffff89ac, 0xffff8915, 0xffff8882, 0xffff87f4, 0xffff876b, 0xffff86e7, 0xffff8667, 0xffff85eb, +0xffff8575, 0xffff8503, 0xffff8496, 0xffff842e, 0xffff83ca, 0xffff836c, 0xffff8312, 0xffff82bd, +0xffff826c, 0xffff8221, 0xffff81da, 0xffff8199, 0xffff815c, 0xffff8124, 0xffff80f1, 0xffff80c3, +0xffff8099, 0xffff8075, 0xffff8056, 0xffff803b, 0xffff8026, 0xffff8015, 0xffff8009, 0xffff8002, +}; +static mpeg3_real_t *mpeg3_xsin1 = +(mpeg3_real_t*)mpeg3_xsin1_fixedpoints; +static long mpeg3_xcos2_fixedpoints[] = { +0xffff8001, 0xffff800d, 0xffff802d, 0xffff8061, 0xffff80a8, 0xffff8103, 0xffff8172, 0xffff81f4, +0xffff828a, 0xffff8333, 0xffff83ef, 0xffff84be, 0xffff85a1, 0xffff8696, 0xffff879e, 0xffff88b9, +0xffff89e5, 0xffff8b25, 0xffff8c76, 0xffff8dd9, 0xffff8f4d, 0xffff90d3, 0xffff926a, 0xffff9412, +0xffff95cb, 0xffff9794, 0xffff996d, 0xffff9b56, 0xffff9d4e, 0xffff9f56, 0xffffa16d, 0xffffa392, +0xffffa5c5, 0xffffa807, 0xffffaa55, 0xffffacb2, 0xffffaf1b, 0xffffb190, 0xffffb411, 0xffffb69f, +0xffffb937, 0xffffbbdb, 0xffffbe89, 0xffffc141, 0xffffc403, 0xffffc6ce, 0xffffc9a1, 0xffffcc7e, +0xffffcf62, 0xffffd24d, 0xffffd540, 0xffffd839, 0xffffdb39, 0xffffde3e, 0xffffe148, 0xffffe457, +0xffffe76a, 0xffffea81, 0xffffed9c, 0xfffff0b9, 0xfffff3d9, 0xfffff6fa, 0xfffffa1d, 0xfffffd41, +0xffffff9c, 0xfffffc78, 0xfffff954, 0xfffff632, 0xfffff311, 0xffffeff2, 0xffffecd5, 0xffffe9bb, +0xffffe6a5, 0xffffe393, 0xffffe085, 0xffffdd7c, 0xffffda78, 0xffffd77a, 0xffffd483, 0xffffd192, +0xffffcea8, 0xffffcbc6, 0xffffc8ec, 0xffffc61a, 0xffffc351, 0xffffc092, 0xffffbddc, 0xffffbb31, +0xffffb890, 0xffffb5fa, 0xffffb370, 0xffffb0f1, 0xffffae7f, 0xffffac19, 0xffffa9c0, 0xffffa775, +0xffffa537, 0xffffa307, 0xffffa0e6, 0xffff9ed3, 0xffff9ccf, 0xffff9ada, 0xffff98f5, 0xffff9720, +0xffff955b, 0xffff93a7, 0xffff9203, 0xffff9070, 0xffff8eee, 0xffff8d7e, 0xffff8c20, 0xffff8ad3, +0xffff8998, 0xffff8870, 0xffff875a, 0xffff8657, 0xffff8566, 0xffff8489, 0xffff83be, 0xffff8307, +0xffff8263, 0xffff81d2, 0xffff8155, 0xffff80eb, 0xffff8095, 0xffff8052, 0xffff8023, 0xffff8008, +}; +static mpeg3_real_t *mpeg3_xcos2 = +(mpeg3_real_t*)mpeg3_xcos2_fixedpoints; +static long mpeg3_xsin2_fixedpoints[] = { +0xffffff9c, 0xfffffc78, 0xfffff954, 0xfffff632, 0xfffff311, 0xffffeff2, 0xffffecd5, 0xffffe9bb, +0xffffe6a5, 0xffffe393, 0xffffe085, 0xffffdd7c, 0xffffda78, 0xffffd77a, 0xffffd483, 0xffffd192, +0xffffcea8, 0xffffcbc6, 0xffffc8ec, 0xffffc61a, 0xffffc351, 0xffffc092, 0xffffbddc, 0xffffbb31, +0xffffb890, 0xffffb5fa, 0xffffb370, 0xffffb0f1, 0xffffae7f, 0xffffac19, 0xffffa9c0, 0xffffa775, +0xffffa537, 0xffffa307, 0xffffa0e6, 0xffff9ed3, 0xffff9ccf, 0xffff9ada, 0xffff98f5, 0xffff9720, +0xffff955b, 0xffff93a7, 0xffff9203, 0xffff9070, 0xffff8eee, 0xffff8d7e, 0xffff8c20, 0xffff8ad3, +0xffff8998, 0xffff8870, 0xffff875a, 0xffff8657, 0xffff8566, 0xffff8489, 0xffff83be, 0xffff8307, +0xffff8263, 0xffff81d2, 0xffff8155, 0xffff80eb, 0xffff8095, 0xffff8052, 0xffff8023, 0xffff8008, +0x00000004, 0x00000007, 0x0000000c, 0x00000010, 0x00000015, 0x0000001c, 0x00000023, 0x0000002a, +0x00000033, 0x0000003d, 0x00000048, 0x00000053, 0x00000061, 0x0000006f, 0x0000007f, 0x00000091, +0x000000a4, 0x000000b8, 0x000000cf, 0x000000e7, 0x00000101, 0x0000011d, 0x0000013b, 0x0000015b, +0x0000017e, 0x000001a3, 0x000001ca, 0x000001f4, 0x00000220, 0x0000024f, 0x00000281, 0x000002b7, +0x000002ef, 0x0000032a, 0x00000368, 0x000003aa, 0x000003ee, 0x00000437, 0x00000483, 0x000004d3, +0x00000526, 0x0000057e, 0x000005d9, 0x00000639, 0x0000069c, 0x00000704, 0x0000076f, 0x000007e0, +0x00000854, 0x000008cd, 0x0000094b, 0x000009cd, 0x00000a54, 0x00000adf, 0x00000b6f, 0x00000c04, +0x00000c9e, 0x00000d3d, 0x00000de0, 0x00000e89, 0x00000f36, 0x00000fe8, 0x0000109f, 0x0000115c, +}; +static mpeg3_real_t *mpeg3_xsin2 = +(mpeg3_real_t*)mpeg3_xsin2_fixedpoints; +typedef struct { long r, i; } fixed_cmplx; +fixed_cmplx ac3_w_d1[] = { + { 0x00008000, 0x00000000 },}; +fixed_cmplx ac3_w_d2[] = { + { 0x00008000, 0x00000000 }, { 0x00000000, 0xffff8000 },}; +fixed_cmplx ac3_w_d4[] = { + { 0x00008000, 0x00000000 }, { 0x00005a82, 0xffffa57e }, { 0x00000000, 0xffff8002 }, { 0xffffa580, 0xffffa580 },}; +fixed_cmplx ac3_w_d8[] = { + { 0x00008000, 0x00000000 }, { 0x00007641, 0xffffcf05 }, { 0x00005a81, 0xffffa580 }, { 0x000030fb, 0xffff89c4 }, + { 0x00000002, 0xffff8007 }, { 0xffffcf09, 0xffff89c6 }, { 0xffffa587, 0xffffa583 }, { 0xffff89cb, 0xffffcf05 },}; +fixed_cmplx ac3_w_d16[] = { + { 0x00008000, 0x00000000 }, { 0x00007d8a, 0xffffe708 }, { 0x00007642, 0xffffcf06 }, { 0x00006a6e, 0xffffb8e7 }, + { 0x00005a84, 0xffffa583 }, { 0x00004720, 0xffff9599 }, { 0x00003100, 0xffff89c6 }, { 0x000018ff, 0xffff827e }, + { 0x00000008, 0xffff8008 }, { 0xffffe711, 0xffff827d }, { 0xffffcf11, 0xffff89c4 }, { 0xffffb8f2, 0xffff9595 }, + { 0xffffa58e, 0xffffa57d }, { 0xffff95a5, 0xffffb8df }, { 0xffff89d2, 0xffffcefd }, { 0xffff8289, 0xffffe6fc },}; +fixed_cmplx ac3_w_d32[] = { + { 0x00008000, 0x00000000 }, { 0x00007f62, 0xfffff375 }, { 0x00007d8a, 0xffffe70a }, { 0x00007a7d, 0xffffdadc }, + { 0x00007642, 0xffffcf0a }, { 0x000070e4, 0xffffc3b1 }, { 0x00006a70, 0xffffb8ed }, { 0x000062f6, 0xffffaed7 }, + { 0x00005a88, 0xffffa58a }, { 0x0000513b, 0xffff9d1b }, { 0x00004726, 0xffff95a1 }, { 0x00003c62, 0xffff8f2d }, + { 0x00003109, 0xffff89cf }, { 0x00002538, 0xffff8593 }, { 0x0000190b, 0xffff8286 }, { 0x00000ca1, 0xffff80ad }, + { 0x00000017, 0xffff800f }, { 0xfffff38d, 0xffff80ab }, { 0xffffe723, 0xffff8281 }, { 0xffffdaf6, 0xffff858b }, + { 0xffffcf25, 0xffff89c4 }, { 0xffffc3cc, 0xffff8f1f }, { 0xffffb908, 0xffff9591 }, { 0xffffaef3, 0xffff9d09 }, + { 0xffffa5a6, 0xffffa575 }, { 0xffff9d37, 0xffffaebf }, { 0xffff95bb, 0xffffb8d2 }, { 0xffff8f46, 0xffffc393 }, + { 0xffff89e7, 0xffffcee9 }, { 0xffff85aa, 0xffffdab8 }, { 0xffff829b, 0xffffe6e3 }, { 0xffff80c1, 0xfffff34b },}; +fixed_cmplx ac3_w_d64[] = { + { 0x00008000, 0x00000000 }, { 0x00007fd8, 0xfffff9b9 }, { 0x00007f62, 0xfffff376 }, { 0x00007e9d, 0xffffed3b }, + { 0x00007d8a, 0xffffe70c }, { 0x00007c29, 0xffffe0ec }, { 0x00007a7c, 0xffffdae0 }, { 0x00007883, 0xffffd4eb }, + { 0x00007641, 0xffffcf11 }, { 0x000073b6, 0xffffc955 }, { 0x000070e3, 0xffffc3bb }, { 0x00006dcb, 0xffffbe45 }, + { 0x00006a6f, 0xffffb8f8 }, { 0x000066d2, 0xffffb3d7 }, { 0x000062f5, 0xffffaee5 }, { 0x00005edc, 0xffffaa25 }, + { 0x00005a89, 0xffffa59a }, { 0x000055fe, 0xffffa147 }, { 0x0000513e, 0xffff9d2e }, { 0x00004c4c, 0xffff9952 }, + { 0x0000472b, 0xffff95b6 }, { 0x000041de, 0xffff925b }, { 0x00003c69, 0xffff8f44 }, { 0x000036cf, 0xffff8c72 }, + { 0x00003113, 0xffff89e7 }, { 0x00002b39, 0xffff87a4 }, { 0x00002544, 0xffff85ac }, { 0x00001f39, 0xffff8400 }, + { 0x0000191b, 0xffff82a0 }, { 0x000012ed, 0xffff818d }, { 0x00000cb4, 0xffff80c8 }, { 0x00000673, 0xffff8051 }, + { 0x0000002d, 0xffff8029 }, { 0xfffff9e8, 0xffff804f }, { 0xfffff3a7, 0xffff80c3 }, { 0xffffed6e, 0xffff8186 }, + { 0xffffe741, 0xffff8297 }, { 0xffffe123, 0xffff83f5 }, { 0xffffdb18, 0xffff859f }, { 0xffffd524, 0xffff8795 }, + { 0xffffcf4b, 0xffff89d5 }, { 0xffffc990, 0xffff8c5d }, { 0xffffc3f7, 0xffff8f2d }, { 0xffffbe82, 0xffff9242 }, + { 0xffffb936, 0xffff959b }, { 0xffffb416, 0xffff9935 }, { 0xffffaf24, 0xffff9d0f }, { 0xffffaa64, 0xffffa125 }, + { 0xffffa5d9, 0xffffa575 }, { 0xffffa186, 0xffffa9fd }, { 0xffff9d6d, 0xffffaeba }, { 0xffff9990, 0xffffb3a9 }, + { 0xffff95f3, 0xffffb8c7 }, { 0xffff9297, 0xffffbe11 }, { 0xffff8f7f, 0xffffc383 }, { 0xffff8cac, 0xffffc91a }, + { 0xffff8a20, 0xffffced3 }, { 0xffff87dc, 0xffffd4aa }, { 0xffff85e2, 0xffffda9c }, { 0xffff8434, 0xffffe0a5 }, + { 0xffff82d2, 0xffffe6c1 }, { 0xffff81be, 0xffffecec }, { 0xffff80f7, 0xfffff323 }, { 0xffff807e, 0xfffff962 },}; +fixed_cmplx *ac3_w_fixedpoints[] = { +ac3_w_d1, ac3_w_d2, ac3_w_d4, ac3_w_d8, ac3_w_d16, ac3_w_d32, ac3_w_d64, }; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_muls_data[] = { +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xffff5556, 0xffff788b, 0xffff947d, 0xffffaaab, 0xffffbc46, 0xffffca3f, 0xffffd556, 0xffffde23, +0xffffe520, 0xffffeaab, 0xffffef12, 0xfffff290, 0xfffff556, 0xfffff789, 0xfffff948, 0xfffffaab, +0xfffffbc5, 0xfffffca4, 0xfffffd56, 0xfffffde3, 0xfffffe52, 0xfffffeab, 0xfffffef2, 0xffffff29, +0xffffff56, 0xffffff79, 0xffffff95, 0xffffffab, 0xffffffbd, 0xffffffcb, 0xffffffd6, 0xffffffdf, +0xffffffe6, 0xffffffeb, 0xfffffff0, 0xfffffff3, 0xfffffff6, 0xfffffff8, 0xfffffffa, 0xfffffffb, +0xfffffffc, 0xfffffffd, 0xfffffffe, 0xfffffffe, 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x0000aaaa, 0x00008775, 0x00006b83, 0x00005555, 0x000043ba, 0x000035c1, 0x00002aaa, 0x000021dd, +0x00001ae0, 0x00001555, 0x000010ee, 0x00000d70, 0x00000aaa, 0x00000877, 0x000006b8, 0x00000555, +0x0000043b, 0x0000035c, 0x000002aa, 0x0000021d, 0x000001ae, 0x00000155, 0x0000010e, 0x000000d7, +0x000000aa, 0x00000087, 0x0000006b, 0x00000055, 0x00000043, 0x00000035, 0x0000002a, 0x00000021, +0x0000001a, 0x00000015, 0x00000010, 0x0000000d, 0x0000000a, 0x00000008, 0x00000006, 0x00000005, +0x00000004, 0x00000003, 0x00000002, 0x00000002, 0x00000001, 0x00000001, 0x00000001, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00004924, 0x00003a0d, 0x00002e13, 0x00002492, 0x00001d06, 0x00001709, 0x00001249, 0x00000e83, +0x00000b84, 0x00000924, 0x00000741, 0x000005c2, 0x00000492, 0x000003a0, 0x000002e1, 0x00000249, +0x000001d0, 0x00000170, 0x00000124, 0x000000e8, 0x000000b8, 0x00000092, 0x00000074, 0x0000005c, +0x00000049, 0x0000003a, 0x0000002e, 0x00000024, 0x0000001d, 0x00000017, 0x00000012, 0x0000000e, +0x0000000b, 0x00000009, 0x00000007, 0x00000005, 0x00000004, 0x00000003, 0x00000002, 0x00000002, +0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00002222, 0x00001b17, 0x00001580, 0x00001111, 0x00000d8b, 0x00000ac0, 0x00000888, 0x000006c5, +0x00000560, 0x00000444, 0x00000362, 0x000002b0, 0x00000222, 0x000001b1, 0x00000158, 0x00000111, +0x000000d8, 0x000000ac, 0x00000088, 0x0000006c, 0x00000056, 0x00000044, 0x00000036, 0x0000002b, +0x00000022, 0x0000001b, 0x00000015, 0x00000011, 0x0000000d, 0x0000000a, 0x00000008, 0x00000006, +0x00000005, 0x00000004, 0x00000003, 0x00000002, 0x00000002, 0x00000001, 0x00000001, 0x00000001, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00001084, 0x00000d1b, 0x00000a67, 0x00000842, 0x0000068d, 0x00000533, 0x00000421, 0x00000346, +0x00000299, 0x00000210, 0x000001a3, 0x0000014c, 0x00000108, 0x000000d1, 0x000000a6, 0x00000084, +0x00000068, 0x00000053, 0x00000042, 0x00000034, 0x00000029, 0x00000021, 0x0000001a, 0x00000014, +0x00000010, 0x0000000d, 0x0000000a, 0x00000008, 0x00000006, 0x00000005, 0x00000004, 0x00000003, +0x00000002, 0x00000002, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000820, 0x00000673, 0x0000051e, 0x00000410, 0x00000339, 0x0000028f, 0x00000208, 0x0000019c, +0x00000147, 0x00000104, 0x000000ce, 0x000000a3, 0x00000082, 0x00000067, 0x00000051, 0x00000041, +0x00000033, 0x00000028, 0x00000020, 0x00000019, 0x00000014, 0x00000010, 0x0000000c, 0x0000000a, +0x00000008, 0x00000006, 0x00000005, 0x00000004, 0x00000003, 0x00000002, 0x00000002, 0x00000001, +0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000408, 0x00000333, 0x0000028a, 0x00000204, 0x00000199, 0x00000145, 0x00000102, 0x000000cc, +0x000000a2, 0x00000081, 0x00000066, 0x00000051, 0x00000040, 0x00000033, 0x00000028, 0x00000020, +0x00000019, 0x00000014, 0x00000010, 0x0000000c, 0x0000000a, 0x00000008, 0x00000006, 0x00000005, +0x00000004, 0x00000003, 0x00000002, 0x00000002, 0x00000001, 0x00000001, 0x00000001, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000202, 0x00000197, 0x00000143, 0x00000101, 0x000000cb, 0x000000a1, 0x00000080, 0x00000065, +0x00000050, 0x00000040, 0x00000032, 0x00000028, 0x00000020, 0x00000019, 0x00000014, 0x00000010, +0x0000000c, 0x0000000a, 0x00000008, 0x00000006, 0x00000005, 0x00000004, 0x00000003, 0x00000002, +0x00000002, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000100, 0x000000cb, 0x000000a1, 0x00000080, 0x00000065, 0x00000050, 0x00000040, 0x00000032, +0x00000028, 0x00000020, 0x00000019, 0x00000014, 0x00000010, 0x0000000c, 0x0000000a, 0x00000008, +0x00000006, 0x00000005, 0x00000004, 0x00000003, 0x00000002, 0x00000002, 0x00000001, 0x00000001, +0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000080, 0x00000065, 0x00000050, 0x00000040, 0x00000032, 0x00000028, 0x00000020, 0x00000019, +0x00000014, 0x00000010, 0x0000000c, 0x0000000a, 0x00000008, 0x00000006, 0x00000005, 0x00000004, +0x00000003, 0x00000002, 0x00000002, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000040, 0x00000032, 0x00000028, 0x00000020, 0x00000019, 0x00000014, 0x00000010, 0x0000000c, +0x0000000a, 0x00000008, 0x00000006, 0x00000005, 0x00000004, 0x00000003, 0x00000002, 0x00000002, +0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000020, 0x00000019, 0x00000014, 0x00000010, 0x0000000c, 0x0000000a, 0x00000008, 0x00000006, +0x00000005, 0x00000004, 0x00000003, 0x00000002, 0x00000002, 0x00000001, 0x00000001, 0x00000001, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000010, 0x0000000c, 0x0000000a, 0x00000008, 0x00000006, 0x00000005, 0x00000004, 0x00000003, +0x00000002, 0x00000002, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000008, 0x00000006, 0x00000005, 0x00000004, 0x00000003, 0x00000002, 0x00000002, 0x00000001, +0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000004, 0x00000003, 0x00000002, 0x00000002, 0x00000001, 0x00000001, 0x00000001, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000002, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xffff3334, 0xffff5d74, 0xffff7efc, 0xffff999a, 0xffffaeba, 0xffffbf7e, 0xffffcccd, 0xffffd75d, +0xffffdfbf, 0xffffe667, 0xffffebaf, 0xffffefe0, 0xfffff334, 0xfffff5d8, 0xfffff7f0, 0xfffff99a, +0xfffffaec, 0xfffffbf8, 0xfffffccd, 0xfffffd76, 0xfffffdfc, 0xfffffe67, 0xfffffebb, 0xfffffefe, +0xffffff34, 0xffffff5e, 0xffffff7f, 0xffffff9a, 0xffffffaf, 0xffffffc0, 0xffffffcd, 0xffffffd8, +0xffffffe0, 0xffffffe7, 0xffffffec, 0xfffffff0, 0xfffffff4, 0xfffffff6, 0xfffffff8, 0xfffffffa, +0xfffffffb, 0xfffffffc, 0xfffffffd, 0xfffffffe, 0xfffffffe, 0xffffffff, 0xffffffff, 0xffffffff, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xffff999a, 0xffffaeba, 0xffffbf7e, 0xffffcccd, 0xffffd75d, 0xffffdfbf, 0xffffe667, 0xffffebaf, +0xffffefe0, 0xfffff334, 0xfffff5d8, 0xfffff7f0, 0xfffff99a, 0xfffffaec, 0xfffffbf8, 0xfffffccd, +0xfffffd76, 0xfffffdfc, 0xfffffe67, 0xfffffebb, 0xfffffefe, 0xffffff34, 0xffffff5e, 0xffffff7f, +0xffffff9a, 0xffffffaf, 0xffffffc0, 0xffffffcd, 0xffffffd8, 0xffffffe0, 0xffffffe7, 0xffffffec, +0xfffffff0, 0xfffffff4, 0xfffffff6, 0xfffffff8, 0xfffffffa, 0xfffffffb, 0xfffffffc, 0xfffffffd, +0xfffffffe, 0xfffffffe, 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00006666, 0x00005146, 0x00004082, 0x00003333, 0x000028a3, 0x00002041, 0x00001999, 0x00001451, +0x00001020, 0x00000ccc, 0x00000a28, 0x00000810, 0x00000666, 0x00000514, 0x00000408, 0x00000333, +0x0000028a, 0x00000204, 0x00000199, 0x00000145, 0x00000102, 0x000000cc, 0x000000a2, 0x00000081, +0x00000066, 0x00000051, 0x00000040, 0x00000033, 0x00000028, 0x00000020, 0x00000019, 0x00000014, +0x00000010, 0x0000000c, 0x0000000a, 0x00000008, 0x00000006, 0x00000005, 0x00000004, 0x00000003, +0x00000002, 0x00000002, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x0000cccc, 0x0000a28c, 0x00008104, 0x00006666, 0x00005146, 0x00004082, 0x00003333, 0x000028a3, +0x00002041, 0x00001999, 0x00001451, 0x00001020, 0x00000ccc, 0x00000a28, 0x00000810, 0x00000666, +0x00000514, 0x00000408, 0x00000333, 0x0000028a, 0x00000204, 0x00000199, 0x00000145, 0x00000102, +0x000000cc, 0x000000a2, 0x00000081, 0x00000066, 0x00000051, 0x00000040, 0x00000033, 0x00000028, +0x00000020, 0x00000019, 0x00000014, 0x00000010, 0x0000000c, 0x0000000a, 0x00000008, 0x00000006, +0x00000005, 0x00000004, 0x00000003, 0x00000002, 0x00000002, 0x00000001, 0x00000001, 0x00000001, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xffff1c72, 0xffff4b64, 0xffff70a7, 0xffff8e39, 0xffffa5b2, 0xffffb854, 0xffffc71d, 0xffffd2d9, +0xffffdc2a, 0xffffe38f, 0xffffe96d, 0xffffee15, 0xfffff1c8, 0xfffff4b7, 0xfffff70b, 0xfffff8e4, +0xfffffa5c, 0xfffffb86, 0xfffffc72, 0xfffffd2e, 0xfffffdc3, 0xfffffe39, 0xfffffe97, 0xfffffee2, +0xffffff1d, 0xffffff4c, 0xffffff71, 0xffffff8f, 0xffffffa6, 0xffffffb9, 0xffffffc8, 0xffffffd3, +0xffffffdd, 0xffffffe4, 0xffffffea, 0xffffffef, 0xfffffff2, 0xfffffff5, 0xfffffff8, 0xfffffff9, +0xfffffffb, 0xfffffffc, 0xfffffffd, 0xfffffffe, 0xfffffffe, 0xffffffff, 0xffffffff, 0xffffffff, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xffff8e39, 0xffffa5b2, 0xffffb854, 0xffffc71d, 0xffffd2d9, 0xffffdc2a, 0xffffe38f, 0xffffe96d, +0xffffee15, 0xfffff1c8, 0xfffff4b7, 0xfffff70b, 0xfffff8e4, 0xfffffa5c, 0xfffffb86, 0xfffffc72, +0xfffffd2e, 0xfffffdc3, 0xfffffe39, 0xfffffe97, 0xfffffee2, 0xffffff1d, 0xffffff4c, 0xffffff71, +0xffffff8f, 0xffffffa6, 0xffffffb9, 0xffffffc8, 0xffffffd3, 0xffffffdd, 0xffffffe4, 0xffffffea, +0xffffffef, 0xfffffff2, 0xfffffff5, 0xfffffff8, 0xfffffff9, 0xfffffffb, 0xfffffffc, 0xfffffffd, +0xfffffffe, 0xfffffffe, 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0xffffc71d, 0xffffd2d9, 0xffffdc2a, 0xffffe38f, 0xffffe96d, 0xffffee15, 0xfffff1c8, 0xfffff4b7, +0xfffff70b, 0xfffff8e4, 0xfffffa5c, 0xfffffb86, 0xfffffc72, 0xfffffd2e, 0xfffffdc3, 0xfffffe39, +0xfffffe97, 0xfffffee2, 0xffffff1d, 0xffffff4c, 0xffffff71, 0xffffff8f, 0xffffffa6, 0xffffffb9, +0xffffffc8, 0xffffffd3, 0xffffffdd, 0xffffffe4, 0xffffffea, 0xffffffef, 0xfffffff2, 0xfffffff5, +0xfffffff8, 0xfffffff9, 0xfffffffb, 0xfffffffc, 0xfffffffd, 0xfffffffe, 0xfffffffe, 0xffffffff, +0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x000038e3, 0x00002d27, 0x000023d6, 0x00001c71, 0x00001693, 0x000011eb, 0x00000e38, 0x00000b49, +0x000008f5, 0x0000071c, 0x000005a4, 0x0000047a, 0x0000038e, 0x000002d2, 0x0000023d, 0x000001c7, +0x00000169, 0x0000011e, 0x000000e3, 0x000000b4, 0x0000008f, 0x00000071, 0x0000005a, 0x00000047, +0x00000038, 0x0000002d, 0x00000023, 0x0000001c, 0x00000016, 0x00000011, 0x0000000e, 0x0000000b, +0x00000008, 0x00000007, 0x00000005, 0x00000004, 0x00000003, 0x00000002, 0x00000002, 0x00000001, +0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x000071c7, 0x00005a4e, 0x000047ac, 0x000038e3, 0x00002d27, 0x000023d6, 0x00001c71, 0x00001693, +0x000011eb, 0x00000e38, 0x00000b49, 0x000008f5, 0x0000071c, 0x000005a4, 0x0000047a, 0x0000038e, +0x000002d2, 0x0000023d, 0x000001c7, 0x00000169, 0x0000011e, 0x000000e3, 0x000000b4, 0x0000008f, +0x00000071, 0x0000005a, 0x00000047, 0x00000038, 0x0000002d, 0x00000023, 0x0000001c, 0x00000016, +0x00000011, 0x0000000e, 0x0000000b, 0x00000008, 0x00000007, 0x00000005, 0x00000004, 0x00000003, +0x00000002, 0x00000002, 0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x0000e38e, 0x0000b49c, 0x00008f59, 0x000071c7, 0x00005a4e, 0x000047ac, 0x000038e3, 0x00002d27, +0x000023d6, 0x00001c71, 0x00001693, 0x000011eb, 0x00000e38, 0x00000b49, 0x000008f5, 0x0000071c, +0x000005a4, 0x0000047a, 0x0000038e, 0x000002d2, 0x0000023d, 0x000001c7, 0x00000169, 0x0000011e, +0x000000e3, 0x000000b4, 0x0000008f, 0x00000071, 0x0000005a, 0x00000047, 0x00000038, 0x0000002d, +0x00000023, 0x0000001c, 0x00000016, 0x00000011, 0x0000000e, 0x0000000b, 0x00000008, 0x00000007, +0x00000005, 0x00000004, 0x00000003, 0x00000002, 0x00000002, 0x00000001, 0x00000001, 0x00000001, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,}; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_gainpow2_data[] = { +0x05a82799, 0x04c1bf82, 0x04000000, 0x035d13f3, 0x02d413cc, 0x0260dfc1, 0x02000000, 0x01ae89f9, +0x016a09e6, 0x01306fe0, 0x01000000, 0x00d744fc, 0x00b504f3, 0x009837f0, 0x00800000, 0x006ba27e, +0x005a8279, 0x004c1bf8, 0x00400000, 0x0035d13f, 0x002d413c, 0x00260dfc, 0x00200000, 0x001ae89f, +0x0016a09e, 0x001306fe, 0x00100000, 0x000d744f, 0x000b504f, 0x0009837f, 0x00080000, 0x0006ba27, +0x0005a827, 0x0004c1bf, 0x00040000, 0x00035d13, 0x0002d413, 0x000260df, 0x00020000, 0x0001ae89, +0x00016a09, 0x0001306f, 0x00010000, 0x0000d744, 0x0000b504, 0x00009837, 0x00008000, 0x00006ba2, +0x00005a82, 0x00004c1b, 0x00004000, 0x000035d1, 0x00002d41, 0x0000260d, 0x00002000, 0x00001ae8, +0x000016a0, 0x00001306, 0x00001000, 0x00000d74, 0x00000b50, 0x00000983, 0x00000800, 0x000006ba, +0x000005a8, 0x000004c1, 0x00000400, 0x0000035d, 0x000002d4, 0x00000260, 0x00000200, 0x000001ae, +0x0000016a, 0x00000130, 0x00000100, 0x000000d7, 0x000000b5, 0x00000098, 0x00000080, 0x0000006b, +0x0000005a, 0x0000004c, 0x00000040, 0x00000035, 0x0000002d, 0x00000026, 0x00000020, 0x0000001a, +0x00000016, 0x00000013, 0x00000010, 0x0000000d, 0x0000000b, 0x00000009, 0x00000008, 0x00000006, +0x00000005, 0x00000004, 0x00000004, 0x00000003, 0x00000002, 0x00000002, 0x00000002, 0x00000001, +0x00000001, 0x00000001, 0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000,}; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_ispow_data[] = { +0x00000000, 0x00008000, 0x0001428a, 0x000229d2, 0x00032cbf, 0x00044662, 0x0005738c, 0x0006b1fc, +0x0007ffff, 0x00095c41, 0x000ac5ad, 0x000c3b5d, 0x000dbc8f, 0x000f489e, 0x0010def9, 0x00127f20, +0x001428a2, 0x0015db1b, 0x00179630, 0x0019598d, 0x001b24e8, 0x001cf7fc, 0x001ed28a, 0x0020b458, +0x00229d2e, 0x00248cdb, 0x0026832f, 0x00287fff, 0x002a8322, 0x002c8c70, 0x002e9bc5, 0x0030b0ff, +0x0032cbfd, 0x0034eca0, 0x003712ca, 0x00393e60, 0x003b6f47, 0x003da567, 0x003fe0a5, 0x004220ed, +0x00446627, 0x0046b03e, 0x0048ff1e, 0x004b52b3, 0x004daaeb, 0x005007b4, 0x005268fc, 0x0054ceb2, +0x005738c7, 0x0059a72a, 0x005c19cd, 0x005e90a1, 0x00610b98, 0x00638aa4, 0x00660db9, 0x006894c9, +0x006b1fc8, 0x006daeaa, 0x00704163, 0x0072d7e8, 0x0075722e, 0x0078102b, 0x007ab1d3, 0x007d571e, +0x007fffff, 0x0082ac70, 0x00855c65, 0x00880fd6, 0x008ac6b9, 0x008d8107, 0x00903eb7, 0x0092ffc0, +0x0095c41a, 0x00988bbe, 0x009b56a4, 0x009e24c4, 0x00a0f617, 0x00a3ca96, 0x00a6a239, 0x00a97cfa, +0x00ac5ad2, 0x00af3bbb, 0x00b21fad, 0x00b506a3, 0x00b7f096, 0x00badd81, 0x00bdcd5d, 0x00c0c025, +0x00c3b5d2, 0x00c6ae60, 0x00c9a9c8, 0x00cca805, 0x00cfa912, 0x00d2acea, 0x00d5b387, 0x00d8bce5, +0x00dbc8fe, 0x00ded7ce, 0x00e1e950, 0x00e4fd7e, 0x00e81456, 0x00eb2dd1, 0x00ee49ec, 0x00f168a2, +0x00f489ef, 0x00f7adce, 0x00fad43c, 0x00fdfd34, 0x010128b2, 0x010456b2, 0x01078731, 0x010aba29, +0x010def99, 0x0111277b, 0x011461cc, 0x01179e89, 0x011addae, 0x011e1f37, 0x01216320, 0x0124a967, +0x0127f208, 0x012b3d00, 0x012e8a4b, 0x0131d9e6, 0x01352bce, 0x01387fff, 0x013bd678, 0x013f2f33, +0x01428a2f, 0x0145e768, 0x014946dc, 0x014ca888, 0x01500c68, 0x01537279, 0x0156daba, 0x015a4527, +0x015db1bd, 0x0161207a, 0x0164915b, 0x0168045d, 0x016b797e, 0x016ef0bb, 0x01726a12, 0x0175e580, +0x01796302, 0x017ce297, 0x0180643b, 0x0183e7ec, 0x01876da9, 0x018af56e, 0x018e7f38, 0x01920b07, +0x019598d8, 0x019928a8, 0x019cba74, 0x01a04e3c, 0x01a3e3fd, 0x01a77bb4, 0x01ab155f, 0x01aeb0fd, +0x01b24e8b, 0x01b5ee07, 0x01b98f70, 0x01bd32c2, 0x01c0d7fc, 0x01c47f1d, 0x01c82821, 0x01cbd308, +0x01cf7fcf, 0x01d32e74, 0x01d6def6, 0x01da9153, 0x01de4588, 0x01e1fb94, 0x01e5b375, 0x01e96d29, +0x01ed28af, 0x01f0e604, 0x01f4a528, 0x01f86617, 0x01fc28d2, 0x01ffed55, 0x0203b39f, 0x02077baf, +0x020b4582, 0x020f1118, 0x0212de6e, 0x0216ad83, 0x021a7e56, 0x021e50e4, 0x0222252d, 0x0225fb2e, +0x0229d2e6, 0x022dac54, 0x02318776, 0x0235644b, 0x023942d1, 0x023d2306, 0x024104e9, 0x0244e879, +0x0248cdb5, 0x024cb49a, 0x02509d28, 0x0254875c, 0x02587337, 0x025c60b5, 0x02604fd7, 0x0264409a, +0x026832fd, 0x026c26ff, 0x02701c9f, 0x027413db, 0x02780cb1, 0x027c0722, 0x0280032a, 0x028400ca, +0x0287ffff, 0x028c00ca, 0x02900327, 0x02940716, 0x02980c97, 0x029c13a7, 0x02a01c45, 0x02a42670, +0x02a83228, 0x02ac3f6a, 0x02b04e36, 0x02b45e8b, 0x02b87067, 0x02bc83c9, 0x02c098b1, 0x02c4af1c, +0x02c8c70a, 0x02cce07a, 0x02d0fb6a, 0x02d517da, 0x02d935c9, 0x02dd5534, 0x02e1761c, 0x02e59880, +0x02e9bc5d, 0x02ede1b3, 0x02f20882, 0x02f630c8, 0x02fa5a83, 0x02fe85b4, 0x0302b258, 0x0306e070, +0x030b0ff9, 0x030f40f3, 0x0313735e, 0x0317a737, 0x031bdc7e, 0x03201333, 0x03244b53, 0x032884de, +0x032cbfd4, 0x0330fc33, 0x033539fa, 0x03397929, 0x033db9be, 0x0341fbb8, 0x03463f17, 0x034a83da, +0x034eca00, 0x03531187, 0x03575a6f, 0x035ba4b8, 0x035ff060, 0x03643d66, 0x03688bc9, 0x036cdb8a, +0x03712ca6, 0x03757f1d, 0x0379d2ee, 0x037e2818, 0x03827e9a, 0x0386d674, 0x038b2fa5, 0x038f8a2c, +0x0393e608, 0x03984338, 0x039ca1bc, 0x03a10192, 0x03a562ba, 0x03a9c533, 0x03ae28fd, 0x03b28e16, +0x03b6f47e, 0x03bb5c33, 0x03bfc536, 0x03c42f85, 0x03c89b20, 0x03cd0806, 0x03d17636, 0x03d5e5af, +0x03da5671, 0x03dec87b, 0x03e33bcc, 0x03e7b063, 0x03ec2640, 0x03f09d62, 0x03f515c9, 0x03f98f73, +0x03fe0a5f, 0x0402868e, 0x040703fe, 0x040b82af, 0x041002a0, 0x041483d1, 0x04190640, 0x041d89ec, +0x04220ed7, 0x042694fd, 0x042b1c60, 0x042fa4fe, 0x04342ed6, 0x0438b9e9, 0x043d4635, 0x0441d3b9, +0x04466275, 0x044af269, 0x044f8393, 0x045415f3, 0x0458a988, 0x045d3e53, 0x0461d451, 0x04666b83, +0x046b03e7, 0x046f9d7e, 0x04743846, 0x0478d440, 0x047d716a, 0x04820fc3, 0x0486af4c, 0x048b5003, +0x048ff1e8, 0x049494fa, 0x04993939, 0x049ddea5, 0x04a2853c, 0x04a72cfd, 0x04abd5ea, 0x04b07fff, +0x04b52b3f, 0x04b9d7a6, 0x04be8536, 0x04c333ee, 0x04c7e3cc, 0x04cc94d1, 0x04d146fb, 0x04d5fa4b, +0x04daaebf, 0x04df6458, 0x04e41b14, 0x04e8d2f3, 0x04ed8bf5, 0x04f24618, 0x04f7015d, 0x04fbbdc3, +0x05007b49, 0x050539ef, 0x0509f9b4, 0x050eba98, 0x05137c9a, 0x05183fba, 0x051d03f6, 0x0521c950, +0x05268fc6, 0x052b5757, 0x05302003, 0x0534e9ca, 0x0539b4ab, 0x053e80a5, 0x05434db9, 0x05481be5, +0x054ceb29, 0x0551bb85, 0x05568cf8, 0x055b5f81, 0x05603321, 0x056507d6, 0x0569dda0, 0x056eb47f, +0x05738c72, 0x05786578, 0x057d3f92, 0x05821abe, 0x0586f6fd, 0x058bd44e, 0x0590b2af, 0x05959222, +0x059a72a5, 0x059f5438, 0x05a436da, 0x05a91a8c, 0x05adff4b, 0x05b2e519, 0x05b7cbf5, 0x05bcb3dd, +0x05c19cd3, 0x05c686d4, 0x05cb71e2, 0x05d05dfb, 0x05d54b1f, 0x05da394d, 0x05df2885, 0x05e418c7, +0x05e90a12, 0x05edfc66, 0x05f2efc2, 0x05f7e426, 0x05fcd992, 0x0601d004, 0x0606c77d, 0x060bbffd, +0x0610b982, 0x0615b40c, 0x061aaf9b, 0x061fac2f, 0x0624a9c7, 0x0629a863, 0x062ea802, 0x0633a8a3, +0x0638aa47, 0x063dacee, 0x0642b095, 0x0647b53f, 0x064cbae8, 0x0651c193, 0x0656c93d, 0x065bd1e7, +0x0660db90, 0x0665e639, 0x066af1df, 0x066ffe84, 0x06750c26, 0x067a1ac6, 0x067f2a62, 0x06843afb, +0x06894c90, 0x068e5f21, 0x069372ad, 0x06988735, 0x069d9cb6, 0x06a2b332, 0x06a7caa8, 0x06ace318, +0x06b1fc80, 0x06b716e2, 0x06bc323b, 0x06c14e8d, 0x06c66bd6, 0x06cb8a17, 0x06d0a94e, 0x06d5c97c, +0x06daeaa0, 0x06e00cba, 0x06e52fca, 0x06ea53ce, 0x06ef78c8, 0x06f49eb5, 0x06f9c597, 0x06feed6d, +0x07041635, 0x07093ff1, 0x070e6aa0, 0x07139640, 0x0718c2d3, 0x071df057, 0x07231ecd, 0x07284e33, +0x072d7e8a, 0x0732afd2, 0x0737e209, 0x073d1530, 0x07424946, 0x07477e4a, 0x074cb43e, 0x0751eb20, +0x075722ef, 0x075c5bac, 0x07619556, 0x0766cfee, 0x076c0b71, 0x077147e1, 0x0776853d, 0x077bc385, +0x078102b8, 0x078642d6, 0x078b83de, 0x0790c5d1, 0x079608ae, 0x079b4c74, 0x07a09124, 0x07a5d6bd, +0x07ab1d3e, 0x07b064a8, 0x07b5acfa, 0x07baf634, 0x07c04056, 0x07c58b5e, 0x07cad74e, 0x07d02424, +0x07d571e0, 0x07dac082, 0x07e0100a, 0x07e56077, 0x07eab1ca, 0x07f00401, 0x07f5571c, 0x07faab1c, +0x07ffffff, 0x080555c7, 0x080aac71, 0x081003fe, 0x08155c6e, 0x081ab5c0, 0x08200ff5, 0x08256b0b, +0x082ac703, 0x083023dc, 0x08358196, 0x083ae030, 0x08403fab, 0x0845a006, 0x084b0141, 0x0850635b, +0x0855c654, 0x085b2a2d, 0x08608ee4, 0x0865f479, 0x086b5aed, 0x0870c23e, 0x08762a6d, 0x087b9379, +0x0880fd62, 0x08866828, 0x088bd3ca, 0x08914048, 0x0896ada3, 0x089c1bd8, 0x08a18aea, 0x08a6fad6, +0x08ac6b9d, 0x08b1dd3f, 0x08b74fbb, 0x08bcc311, 0x08c23741, 0x08c7ac4a, 0x08cd222c, 0x08d298e8, +0x08d8107c, 0x08dd88e8, 0x08e3022d, 0x08e87c49, 0x08edf73d, 0x08f37309, 0x08f8efac, 0x08fe6d25, +0x0903eb75, 0x09096a9c, 0x090eea99, 0x09146b6b, 0x0919ed13, 0x091f6f91, 0x0924f2e3, 0x092a770b, +0x092ffc06, 0x093581d7, 0x093b087b, 0x09408ff3, 0x0946183f, 0x094ba15e, 0x09512b51, 0x0956b616, +0x095c41ae, 0x0961ce18, 0x09675b54, 0x096ce962, 0x09727842, 0x097807f3, 0x097d9876, 0x098329c9, +0x0988bbed, 0x098e4ee1, 0x0993e2a6, 0x0999773a, 0x099f0c9f, 0x09a4a2d3, 0x09aa39d6, 0x09afd1a8, +0x09b56a49, 0x09bb03b8, 0x09c09df6, 0x09c63902, 0x09cbd4dc, 0x09d17183, 0x09d70ef8, 0x09dcad3a, +0x09e24c49, 0x09e7ec25, 0x09ed8ccd, 0x09f32e41, 0x09f8d082, 0x09fe738e, 0x0a041766, 0x0a09bc09, +0x0a0f6178, 0x0a1507b1, 0x0a1aaeb5, 0x0a205684, 0x0a25ff1c, 0x0a2ba87f, 0x0a3152ac, 0x0a36fda2, +0x0a3ca962, 0x0a4255ea, 0x0a48033c, 0x0a4db157, 0x0a536039, 0x0a590fe5, 0x0a5ec058, 0x0a647193, +0x0a6a2396, 0x0a6fd660, 0x0a7589f2, 0x0a7b3e4b, 0x0a80f36a, 0x0a86a950, 0x0a8c5ffc, 0x0a92176f, +0x0a97cfa7, 0x0a9d88a5, 0x0aa34269, 0x0aa8fcf2, 0x0aaeb840, 0x0ab47453, 0x0aba312b, 0x0abfeec8, +0x0ac5ad28, 0x0acb6c4d, 0x0ad12c36, 0x0ad6ece2, 0x0adcae52, 0x0ae27085, 0x0ae8337b, 0x0aedf734, +0x0af3bbb0, 0x0af980ee, 0x0aff46ef, 0x0b050db2, 0x0b0ad536, 0x0b109d7c, 0x0b166684, 0x0b1c304d, +0x0b21fad7, 0x0b27c622, 0x0b2d922e, 0x0b335efa, 0x0b392c87, 0x0b3efad3, 0x0b44c9e0, 0x0b4a99ac, +0x0b506a38, 0x0b563b83, 0x0b5c0d8e, 0x0b61e057, 0x0b67b3df, 0x0b6d8826, 0x0b735d2b, 0x0b7932ee, +0x0b7f096f, 0x0b84e0ae, 0x0b8ab8ab, 0x0b909165, 0x0b966add, 0x0b9c4511, 0x0ba22003, 0x0ba7fbb1, +0x0badd81b, 0x0bb3b542, 0x0bb99326, 0x0bbf71c5, 0x0bc55120, 0x0bcb3136, 0x0bd11208, 0x0bd6f395, +0x0bdcd5dd, 0x0be2b8e0, 0x0be89c9e, 0x0bee8116, 0x0bf46649, 0x0bfa4c36, 0x0c0032dc, 0x0c061a3d, +0x0c0c0257, 0x0c11eb2a, 0x0c17d4b7, 0x0c1dbefd, 0x0c23a9fc, 0x0c2995b3, 0x0c2f8223, 0x0c356f4c, +0x0c3b5d2c, 0x0c414bc5, 0x0c473b16, 0x0c4d2b1e, 0x0c531bde, 0x0c590d55, 0x0c5eff83, 0x0c64f268, +0x0c6ae604, 0x0c70da57, 0x0c76cf60, 0x0c7cc51f, 0x0c82bb95, 0x0c88b2c1, 0x0c8eaaa2, 0x0c94a339, +0x0c9a9c85, 0x0ca09687, 0x0ca6913e, 0x0cac8caa, 0x0cb288ca, 0x0cb885a0, 0x0cbe8329, 0x0cc48167, +0x0cca8059, 0x0cd07fff, 0x0cd68059, 0x0cdc8167, 0x0ce28328, 0x0ce8859c, 0x0cee88c4, 0x0cf48c9e, +0x0cfa912b, 0x0d00966b, 0x0d069c5d, 0x0d0ca302, 0x0d12aa59, 0x0d18b262, 0x0d1ebb1d, 0x0d24c489, +0x0d2acea7, 0x0d30d976, 0x0d36e4f7, 0x0d3cf128, 0x0d42fe0b, 0x0d490b9e, 0x0d4f19e2, 0x0d5528d6, +0x0d5b387b, 0x0d6148cf, 0x0d6759d4, 0x0d6d6b88, 0x0d737dec, 0x0d799100, 0x0d7fa4c3, 0x0d85b935, +0x0d8bce56, 0x0d91e426, 0x0d97faa4, 0x0d9e11d1, 0x0da429ad, 0x0daa4237, 0x0db05b6f, 0x0db67555, +0x0dbc8fe9, 0x0dc2ab2a, 0x0dc8c719, 0x0dcee3b5, 0x0dd500ff, 0x0ddb1ef5, 0x0de13d99, 0x0de75ce9, +0x0ded7ce6, 0x0df39d8f, 0x0df9bee5, 0x0dffe0e7, 0x0e060394, 0x0e0c26ee, 0x0e124af4, 0x0e186fa5, +0x0e1e9501, 0x0e24bb09, 0x0e2ae1bb, 0x0e310919, 0x0e373122, 0x0e3d59d5, 0x0e438333, 0x0e49ad3c, +0x0e4fd7ee, 0x0e56034b, 0x0e5c2f52, 0x0e625c02, 0x0e68895d, 0x0e6eb761, 0x0e74e60e, 0x0e7b1564, +0x0e814564, 0x0e87760d, 0x0e8da75e, 0x0e93d959, 0x0e9a0bfb, 0x0ea03f47, 0x0ea6733a, 0x0eaca7d6, +0x0eb2dd1a, 0x0eb91305, 0x0ebf4999, 0x0ec580d4, 0x0ecbb8b6, 0x0ed1f140, 0x0ed82a71, 0x0ede6449, +0x0ee49ec8, 0x0eead9ed, 0x0ef115ba, 0x0ef7522d, 0x0efd8f46, 0x0f03cd05, 0x0f0a0b6b, 0x0f104a76, +0x0f168a28, 0x0f1cca7f, 0x0f230b7b, 0x0f294d1d, 0x0f2f8f65, 0x0f35d251, 0x0f3c15e3, 0x0f425a19, +0x0f489ef4, 0x0f4ee474, 0x0f552a98, 0x0f5b7161, 0x0f61b8ce, 0x0f6800df, 0x0f6e4994, 0x0f7492ed, +0x0f7adce9, 0x0f81278a, 0x0f8772cd, 0x0f8dbeb4, 0x0f940b3e, 0x0f9a586b, 0x0fa0a63c, 0x0fa6f4af, +0x0fad43c4, 0x0fb3937c, 0x0fb9e3d7, 0x0fc034d4, 0x0fc68673, 0x0fccd8b4, 0x0fd32b97, 0x0fd97f1c, +0x0fdfd343, 0x0fe6280b, 0x0fec7d74, 0x0ff2d37f, 0x0ff92a2b, 0x0fff8178, 0x1005d966, 0x100c31f5, +0x10128b24, 0x1018e4f4, 0x101f3f64, 0x10259a75, 0x102bf626, 0x10325277, 0x1038af67, 0x103f0cf8, +0x10456b28, 0x104bc9f8, 0x10522967, 0x10588976, 0x105eea24, 0x10654b70, 0x106bad5c, 0x10720fe7, +0x10787310, 0x107ed6d8, 0x10853b3f, 0x108ba043, 0x109205e6, 0x10986c27, 0x109ed307, 0x10a53a83, +0x10aba29e, 0x10b20b57, 0x10b874ac, 0x10bedea0, 0x10c54930, 0x10cbb45e, 0x10d22029, 0x10d88c90, +0x10def995, 0x10e56736, 0x10ebd574, 0x10f2444e, 0x10f8b3c5, 0x10ff23d8, 0x11059487, 0x110c05d2, +0x111277b9, 0x1118ea3b, 0x111f5d59, 0x1125d113, 0x112c4568, 0x1132ba59, 0x11392fe5, 0x113fa60c, +0x11461ccd, 0x114c942a, 0x11530c22, 0x115984b4, 0x115ffde0, 0x116677a7, 0x116cf209, 0x11736d04, +0x1179e89a, 0x118064c9, 0x1186e192, 0x118d5ef5, 0x1193dcf2, 0x119a5b88, 0x11a0dab8, 0x11a75a81, +0x11addae3, 0x11b45bde, 0x11badd72, 0x11c15f9f, 0x11c7e265, 0x11ce65c4, 0x11d4e9bb, 0x11db6e4a, +0x11e1f372, 0x11e87931, 0x11eeff89, 0x11f58679, 0x11fc0e01, 0x12029621, 0x12091ed8, 0x120fa827, +0x1216320d, 0x121cbc8a, 0x1223479f, 0x1229d34b, 0x12305f8e, 0x1236ec68, 0x123d79d9, 0x124407e0, +0x124a967e, 0x125125b2, 0x1257b57d, 0x125e45de, 0x1264d6d6, 0x126b6863, 0x1271fa86, 0x12788d40, +0x127f208f, 0x1285b473, 0x128c48ed, 0x1292ddfd, 0x129973a2, 0x12a009dc, 0x12a6a0ab, 0x12ad3810, +0x12b3d009, 0x12ba6897, 0x12c101ba, 0x12c79b71, 0x12ce35bd, 0x12d4d09e, 0x12db6c13, 0x12e2081b, +0x12e8a4b9, 0x12ef41ea, 0x12f5dfaf, 0x12fc7e07, 0x13031cf4, 0x1309bc74, 0x13105c88, 0x1316fd2f, +0x131d9e69, 0x13244036, 0x132ae297, 0x1331858b, 0x13382911, 0x133ecd2b, 0x134571d7, 0x134c1716, +0x1352bce7, 0x1359634a, 0x13600a40, 0x1366b1c9, 0x136d59e3, 0x1374028f, 0x137aabce, 0x1381559e, +0x1387ffff, 0x138eaaf3, 0x13955678, 0x139c028e, 0x13a2af36, 0x13a95c6f, 0x13b00a39, 0x13b6b895, +0x13bd6781, 0x13c416fe, 0x13cac70c, 0x13d177aa, 0x13d828d9, 0x13deda99, 0x13e58ce9, 0x13ec3fc9, +0x13f2f33a, 0x13f9a73a, 0x14005bcb, 0x140710eb, 0x140dc69c, 0x14147cdc, 0x141b33ab, 0x1421eb0a, +0x1428a2f9, 0x142f5b77, 0x14361484, 0x143cce21, 0x1443884c, 0x144a4307, 0x1450fe50, 0x1457ba28, +0x145e768f, 0x14653384, 0x146bf108, 0x1472af1b, 0x14796dbb, 0x14802cea, 0x1486eca8, 0x148dacf3, +0x14946dcc, 0x149b2f33, 0x14a1f128, 0x14a8b3aa, 0x14af76ba, 0x14b63a58, 0x14bcfe83, 0x14c3c33b, +0x14ca8881, 0x14d14e54, 0x14d814b4, 0x14dedba0, 0x14e5a31a, 0x14ec6b21, 0x14f333b4, 0x14f9fcd4, +0x1500c680, 0x150790b9, 0x150e5b7e, 0x151526cf, 0x151bf2ad, 0x1522bf17, 0x15298c0c, 0x1530598e, +0x1537279b, 0x153df634, 0x1544c559, 0x154b950a, 0x15526545, 0x1559360d, 0x1560075f, 0x1566d93d, +0x156daba6, 0x15747e99, 0x157b5218, 0x15822622, 0x1588fab6, 0x158fcfd6, 0x1596a57f, 0x159d7bb4, +0x15a45272, 0x15ab29bc, 0x15b2018f, 0x15b8d9ed, 0x15bfb2d4, 0x15c68c46, 0x15cd6641, 0x15d440c7, +0x15db1bd6, 0x15e1f76f, 0x15e8d391, 0x15efb03d, 0x15f68d73, 0x15fd6b31, 0x16044979, 0x160b284a, +0x161207a5, 0x1618e788, 0x161fc7f4, 0x1626a8e9, 0x162d8a67, 0x16346c6d, 0x163b4efc, 0x16423213, +0x164915b3, 0x164ff9dc, 0x1656de8c, 0x165dc3c5, 0x1664a985, 0x166b8fce, 0x1672769f, 0x16795df7, +0x168045d8, 0x16872e40, 0x168e172f, 0x169500a7, 0x169beaa5, 0x16a2d52b, 0x16a9c038, 0x16b0abcd, +0x16b797e8, 0x16be848b, 0x16c571b4, 0x16cc5f65, 0x16d34d9c, 0x16da3c5a, 0x16e12b9e, 0x16e81b69, +0x16ef0bbb, 0x16f5fc93, 0x16fcedf1, 0x1703dfd6, 0x170ad241, 0x1711c531, 0x1718b8a8, 0x171faca5, +0x1726a127, 0x172d9630, 0x17348bbe, 0x173b81d1, 0x1742786b, 0x17496f89, 0x1750672d, 0x17575f56, +0x175e5805, 0x17655139, 0x176c4af1, 0x1773452f, 0x177a3ff2, 0x17813b39, 0x17883705, 0x178f3356, +0x1796302c, 0x179d2d86, 0x17a42b64, 0x17ab29c7, 0x17b228ae, 0x17b92819, 0x17c02809, 0x17c7287c, +0x17ce2974, 0x17d52aef, 0x17dc2cef, 0x17e32f72, 0x17ea3278, 0x17f13603, 0x17f83a11, 0x17ff3ea2, +0x180643b7, 0x180d494f, 0x18144f6a, 0x181b5609, 0x18225d2a, 0x182964cf, 0x18306cf6, 0x183775a1, +0x183e7ece, 0x1845887e, 0x184c92b0, 0x18539d65, 0x185aa89d, 0x1861b457, 0x1868c093, 0x186fcd52, +0x1876da93, 0x187de856, 0x1884f69b, 0x188c0562, 0x189314aa, 0x189a2475, 0x18a134c2, 0x18a84590, +0x18af56e0, 0x18b668b1, 0x18bd7b04, 0x18c48dd8, 0x18cba12d, 0x18d2b504, 0x18d9c95c, 0x18e0de35, +0x18e7f38f, 0x18ef096b, 0x18f61fc7, 0x18fd36a3, 0x19044e01, 0x190b65df, 0x19127e3e, 0x1919971d, +0x1920b07d, 0x1927ca5d, 0x192ee4be, 0x1935ff9f, 0x193d1b00, 0x194436e1, 0x194b5342, 0x19527023, +0x19598d84, 0x1960ab65, 0x1967c9c6, 0x196ee8a6, 0x19760806, 0x197d27e6, 0x19844845, 0x198b6923, +0x19928a81, 0x1999ac5e, 0x19a0ceba, 0x19a7f196, 0x19af14f0, 0x19b638ca, 0x19bd5d22, 0x19c481f9, +0x19cba74f, 0x19d2cd24, 0x19d9f378, 0x19e11a4a, 0x19e8419a, 0x19ef6969, 0x19f691b6, 0x19fdba82, +0x1a04e3cc, 0x1a0c0d94, 0x1a1337da, 0x1a1a629f, 0x1a218de1, 0x1a28b9a1, 0x1a2fe5df, 0x1a37129b, +0x1a3e3fd4, 0x1a456d8b, 0x1a4c9bc0, 0x1a53ca72, 0x1a5af9a2, 0x1a62294f, 0x1a695979, 0x1a708a21, +0x1a77bb45, 0x1a7eece7, 0x1a861f06, 0x1a8d51a2, 0x1a9484bb, 0x1a9bb850, 0x1aa2ec62, 0x1aaa20f1, +0x1ab155fd, 0x1ab88b85, 0x1abfc18a, 0x1ac6f80b, 0x1ace2f09, 0x1ad56683, 0x1adc9e79, 0x1ae3d6eb, +0x1aeb0fda, 0x1af24944, 0x1af9832b, 0x1b00bd8d, 0x1b07f86c, 0x1b0f33c6, 0x1b166f9c, 0x1b1dabed, +0x1b24e8ba, 0x1b2c2603, 0x1b3363c7, 0x1b3aa206, 0x1b41e0c1, 0x1b491ff7, 0x1b505fa9, 0x1b579fd5, +0x1b5ee07d, 0x1b66219f, 0x1b6d633d, 0x1b74a555, 0x1b7be7e9, 0x1b832af7, 0x1b8a6e7f, 0x1b91b283, +0x1b98f701, 0x1ba03bf9, 0x1ba7816c, 0x1baec75a, 0x1bb60dc1, 0x1bbd54a3, 0x1bc49bff, 0x1bcbe3d6, +0x1bd32c26, 0x1bda74f1, 0x1be1be35, 0x1be907f3, 0x1bf0522b, 0x1bf79cdd, 0x1bfee809, 0x1c0633ae, +0x1c0d7fcc, 0x1c14cc65, 0x1c1c1976, 0x1c236702, 0x1c2ab506, 0x1c320384, 0x1c39527b, 0x1c40a1eb, +0x1c47f1d4, 0x1c4f4236, 0x1c569311, 0x1c5de466, 0x1c653632, 0x1c6c8878, 0x1c73db37, 0x1c7b2e6e, +0x1c82821d, 0x1c89d646, 0x1c912ae6, 0x1c987fff, 0x1c9fd591, 0x1ca72b9b, 0x1cae821d, 0x1cb5d917, +0x1cbd3089, 0x1cc48874, 0x1ccbe0d6, 0x1cd339b1, 0x1cda9303, 0x1ce1eccd, 0x1ce9470f, 0x1cf0a1c8, +0x1cf7fcf9, 0x1cff58a2, 0x1d06b4c2, 0x1d0e115a, 0x1d156e69, 0x1d1ccbf0, 0x1d2429ed, 0x1d2b8862, +0x1d32e74e, 0x1d3a46b2, 0x1d41a68c, 0x1d4906dd, 0x1d5067a6, 0x1d57c8e5, 0x1d5f2a9b, 0x1d668cc7, +0x1d6def6b, 0x1d755285, 0x1d7cb615, 0x1d841a1c, 0x1d8b7e9a, 0x1d92e38e, 0x1d9a48f9, 0x1da1aed9, +0x1da91530, 0x1db07bfd, 0x1db7e340, 0x1dbf4afa, 0x1dc6b329, 0x1dce1bce, 0x1dd584e9, 0x1ddcee7a, +0x1de45881, 0x1debc2fe, 0x1df32df0, 0x1dfa9957, 0x1e020535, 0x1e097187, 0x1e10de50, 0x1e184b8d, +0x1e1fb940, 0x1e272768, 0x1e2e9606, 0x1e360518, 0x1e3d74a0, 0x1e44e49d, 0x1e4c550e, 0x1e53c5f5, +0x1e5b3750, 0x1e62a921, 0x1e6a1b66, 0x1e718e20, 0x1e79014e, 0x1e8074f1, 0x1e87e909, 0x1e8f5d95, +0x1e96d295, 0x1e9e480a, 0x1ea5bdf3, 0x1ead3450, 0x1eb4ab22, 0x1ebc2268, 0x1ec39a22, 0x1ecb1250, +0x1ed28af1, 0x1eda0407, 0x1ee17d91, 0x1ee8f78f, 0x1ef07200, 0x1ef7ece5, 0x1eff683d, 0x1f06e40a, +0x1f0e604a, 0x1f15dcfd, 0x1f1d5a24, 0x1f24d7be, 0x1f2c55cb, 0x1f33d44c, 0x1f3b5340, 0x1f42d2a7, +0x1f4a5281, 0x1f51d2ce, 0x1f59538f, 0x1f60d4c2, 0x1f685668, 0x1f6fd881, 0x1f775b0d, 0x1f7ede0c, +0x1f86617d, 0x1f8de561, 0x1f9569b7, 0x1f9cee80, 0x1fa473bb, 0x1fabf969, 0x1fb37f8a, 0x1fbb061c, +0x1fc28d21, 0x1fca1498, 0x1fd19c81, 0x1fd924dc, 0x1fe0ada9, 0x1fe836e9, 0x1fefc09a, 0x1ff74abd, +0x1ffed552, 0x20066059, 0x200debd1, 0x201577bc, 0x201d0417, 0x202490e5, 0x202c1e24, 0x2033abd4, +0x203b39f6, 0x2042c889, 0x204a578d, 0x2051e703, 0x205976ea, 0x20610742, 0x2068980b, 0x20702946, +0x2077baf1, 0x207f4d0d, 0x2086df9a, 0x208e7298, 0x20960607, 0x209d99e7, 0x20a52e37, 0x20acc2f8, +0x20b45829, 0x20bbedcb, 0x20c383de, 0x20cb1a61, 0x20d2b154, 0x20da48b8, 0x20e1e08c, 0x20e978d0, +0x20f11185, 0x20f8aaa9, 0x2100443e, 0x2107de43, 0x210f78b7, 0x2117139c, 0x211eaef0, 0x21264ab5, +0x212de6e9, 0x2135838d, 0x213d20a0, 0x2144be24, 0x214c5c16, 0x2153fa79, 0x215b994b, 0x2163388c, +0x216ad83d, 0x2172785d, 0x217a18ec, 0x2181b9ea, 0x21895b58, 0x2190fd35, 0x21989f81, 0x21a0423c, +0x21a7e566, 0x21af88ff, 0x21b72d06, 0x21bed17d, 0x21c67663, 0x21ce1bb7, 0x21d5c17a, 0x21dd67ab, +0x21e50e4b, 0x21ecb55a, 0x21f45cd7, 0x21fc04c3, 0x2203ad1d, 0x220b55e5, 0x2212ff1c, 0x221aa8c1, +0x222252d4, 0x2229fd56, 0x2231a845, 0x223953a3, 0x2240ff6e, 0x2248aba8, 0x2250584f, 0x22580565, +0x225fb2e8, 0x226760d9, 0x226f0f37, 0x2276be04, 0x227e6d3e, 0x22861ce5, 0x228dccfa, 0x22957d7d, +0x229d2e6d, 0x22a4dfcb, 0x22ac9195, 0x22b443cd, 0x22bbf673, 0x22c3a985, 0x22cb5d05, 0x22d310f2, +0x22dac54c, 0x22e27a13, 0x22ea2f47, 0x22f1e4e8, 0x22f99af5, 0x23015170, 0x23090857, 0x2310bfab, +0x2318776c, 0x23202f99, 0x2327e833, 0x232fa13a, 0x23375aad, 0x233f148c, 0x2346ced8, 0x234e8991, +0x235644b5, 0x235e0046, 0x2365bc43, 0x236d78ac, 0x23753582, 0x237cf2c3, 0x2384b071, 0x238c6e8a, +0x23942d10, 0x239bec01, 0x23a3ab5e, 0x23ab6b28, 0x23b32b5c, 0x23baebfd, 0x23c2ad09, 0x23ca6e81, +0x23d23064, 0x23d9f2b3, 0x23e1b56e, 0x23e97894, 0x23f13c25, 0x23f90022, 0x2400c48a, 0x2408895d, +0x24104e9b, 0x24181445, 0x241fda5a, 0x2427a0da, 0x242f67c5, 0x24372f1a, 0x243ef6db, 0x2446bf07, +0x244e879e, 0x2456509f, 0x245e1a0b, 0x2465e3e2, 0x246dae24, 0x247578d0, 0x247d43e7, 0x24850f68, +0x248cdb54, 0x2494a7ab, 0x249c746b, 0x24a44197, 0x24ac0f2c, 0x24b3dd2c, 0x24bbab96, 0x24c37a6a, +0x24cb49a8, 0x24d31951, 0x24dae963, 0x24e2b9e0, 0x24ea8ac6, 0x24f25c17, 0x24fa2dd1, 0x2501fff5, +0x2509d283, 0x2511a57b, 0x251978dc, 0x25214ca7, 0x252920dc, 0x2530f57b, 0x2538ca82, 0x25409ff4, +0x254875cf, 0x25504c13, 0x255822c0, 0x255ff9d7, 0x2567d157, 0x256fa941, 0x25778193, 0x257f5a4f, +0x25873374, 0x258f0d02, 0x2596e6f9, 0x259ec159, 0x25a69c22, 0x25ae7753, 0x25b652ee, 0x25be2ef1, +0x25c60b5e, 0x25cde833, 0x25d5c570, 0x25dda316, 0x25e58125, 0x25ed5f9d, 0x25f53e7c, 0x25fd1dc5, +0x2604fd76, 0x260cdd8f, 0x2614be10, 0x261c9efa, 0x2624804c, 0x262c6206, 0x26344429, 0x263c26b3, +0x264409a6, 0x264bed01, 0x2653d0c3, 0x265bb4ee, 0x26639980, 0x266b7e7b, 0x267363dd, 0x267b49a7, +0x26832fd9, 0x268b1673, 0x2692fd74, 0x269ae4dd, 0x26a2ccad, 0x26aab4e5, 0x26b29d85, 0x26ba868c, +0x26c26ffa, 0x26ca59d0, 0x26d2440d, 0x26da2eb1, 0x26e219bd, 0x26ea0530, 0x26f1f10a, 0x26f9dd4b, +0x2701c9f4, 0x2709b703, 0x2711a479, 0x27199257, 0x2721809b, 0x27296f46, 0x27315e58, 0x27394dd1, +0x27413db0, 0x27492df7, 0x27511ea4, 0x27590fb7, 0x27610132, 0x2768f312, 0x2770e55a, 0x2778d808, +0x2780cb1c, 0x2788be96, 0x2790b277, 0x2798a6bf, 0x27a09b6c, 0x27a89080, 0x27b085fa, 0x27b87bdb, +0x27c07221, 0x27c868cd, 0x27d05fe0, 0x27d85758, 0x27e04f37, 0x27e8477b, 0x27f04026, 0x27f83936, +0x280032ac, 0x28082c87, 0x281026c9, 0x28182170, 0x28201c7d, 0x282817ef, 0x283013c7, 0x28381004, +0x28400ca7, 0x284809b0, 0x2850071d, 0x285804f1, 0x28600329, 0x286801c7, 0x287000ca, 0x28780032, +0x287fffff, 0x28880032, 0x289000ca, 0x289801c6, 0x28a00328, 0x28a804ef, 0x28b0071b, 0x28b809ab, +0x28c00ca1, 0x28c80ffb, 0x28d013ba, 0x28d817de, 0x28e01c66, 0x28e82153, 0x28f026a5, 0x28f82c5b, +0x29003276, 0x290838f6, 0x29103fda, 0x29184722, 0x29204ecf, 0x292856e0, 0x29305f55, 0x2938682f, +0x2940716d, 0x29487b0f, 0x29508516, 0x29588f80, 0x29609a4f, 0x2968a582, 0x2970b118, 0x2978bd13, +0x2980c972, 0x2988d634, 0x2990e35a, 0x2998f0e5, 0x29a0fed3, 0x29a90d24, 0x29b11bda, 0x29b92af3, +0x29c13a70, 0x29c94a50, 0x29d15a94, 0x29d96b3c, 0x29e17c47, 0x29e98db5, 0x29f19f87, 0x29f9b1bc, +0x2a01c455, 0x2a09d751, 0x2a11eab0, 0x2a19fe72, 0x2a221298, 0x2a2a2721, 0x2a323c0d, 0x2a3a515c, +0x2a42670e, 0x2a4a7d23, 0x2a52939b, 0x2a5aaa75, 0x2a62c1b3, 0x2a6ad954, 0x2a72f157, 0x2a7b09be, +0x2a832287, 0x2a8b3bb2, 0x2a935541, 0x2a9b6f32, 0x2aa38986, 0x2aaba43c, 0x2ab3bf55, 0x2abbdad0, +0x2ac3f6ad, 0x2acc12ee, 0x2ad42f90, 0x2adc4c95, 0x2ae469fc, 0x2aec87c6, 0x2af4a5f1, 0x2afcc47f, +0x2b04e36f, 0x2b0d02c1, 0x2b152276, 0x2b1d428c, 0x2b256304, 0x2b2d83df, 0x2b35a51b, 0x2b3dc6b9, +0x2b45e8b9, 0x2b4e0b1b, 0x2b562ddf, 0x2b5e5104, 0x2b66748c, 0x2b6e9875, 0x2b76bcbf, 0x2b7ee16b, +0x2b870679, 0x2b8f2be9, 0x2b9751b9, 0x2b9f77ec, 0x2ba79e80, 0x2bafc575, 0x2bb7eccb, 0x2bc01483, +0x2bc83c9d, 0x2bd06517, 0x2bd88df3, 0x2be0b730, 0x2be8e0ce, 0x2bf10acd, 0x2bf9352e, 0x2c015fef, +0x2c098b11, 0x2c11b695, 0x2c19e279, 0x2c220ebf, 0x2c2a3b65, 0x2c32686c, 0x2c3a95d4, 0x2c42c39c, +0x2c4af1c6, 0x2c532050, 0x2c5b4f3a, 0x2c637e86, 0x2c6bae32, 0x2c73de3e, 0x2c7c0eab, 0x2c843f79, +0x2c8c70a7, 0x2c94a236, 0x2c9cd424, 0x2ca50674, 0x2cad3923, 0x2cb56c33, 0x2cbd9fa3, 0x2cc5d374, +0x2cce07a4, 0x2cd63c35, 0x2cde7126, 0x2ce6a677, 0x2ceedc28, 0x2cf71238, 0x2cff48a9, 0x2d077f7a, +0x2d0fb6ab, 0x2d17ee3c, 0x2d20262c, 0x2d285e7d, 0x2d30972d, 0x2d38d03d, 0x2d4109ac, 0x2d49437c, +0x2d517daa, 0x2d59b839, 0x2d61f327, 0x2d6a2e75, 0x2d726a22, 0x2d7aa62e, 0x2d82e29b, 0x2d8b1f66, +0x2d935c91, 0x2d9b9a1b, 0x2da3d804, 0x2dac164d, 0x2db454f5, 0x2dbc93fc, 0x2dc4d363, 0x2dcd1328, +0x2dd5534d, 0x2ddd93d0, 0x2de5d4b3, 0x2dee15f5, 0x2df65795, 0x2dfe9995, 0x2e06dbf4, 0x2e0f1eb1, +0x2e1761cd, 0x2e1fa548, 0x2e27e922, 0x2e302d5a, 0x2e3871f2, 0x2e40b6e8, 0x2e48fc3c, 0x2e5141ef, +0x2e598801, 0x2e61ce71, 0x2e6a1540, 0x2e725c6d, 0x2e7aa3f9, 0x2e82ebe3, 0x2e8b342b, 0x2e937cd2, +0x2e9bc5d7, 0x2ea40f3b, 0x2eac58fc, 0x2eb4a31c, 0x2ebced9a, 0x2ec53876, 0x2ecd83b0, 0x2ed5cf49, +0x2ede1b3f, 0x2ee66794, 0x2eeeb446, 0x2ef70156, 0x2eff4ec5, 0x2f079c91, 0x2f0feabb, 0x2f183942, +0x2f208828, 0x2f28d76b, 0x2f31270c, 0x2f39770b, 0x2f41c768, 0x2f4a1822, 0x2f526939, 0x2f5abaaf, +0x2f630c81, 0x2f6b5eb2, 0x2f73b13f, 0x2f7c042a, 0x2f845773, 0x2f8cab19, 0x2f94ff1c, 0x2f9d537d, +0x2fa5a83a, 0x2fadfd56, 0x2fb652ce, 0x2fbea8a3, 0x2fc6fed6, 0x2fcf5566, 0x2fd7ac52, 0x2fe0039c, +0x2fe85b43, 0x2ff0b347, 0x2ff90ba8, 0x30016466, 0x3009bd80, 0x301216f8, 0x301a70cc, 0x3022cafd, +0x302b258b, 0x30338076, 0x303bdbbd, 0x30443761, 0x304c9362, 0x3054efbf, 0x305d4c79, 0x3065a98f, +0x306e0702, 0x307664d2, 0x307ec2fe, 0x30872186, 0x308f806b, 0x3097dfac, 0x30a03f49, 0x30a89f43, +0x30b0ff99, 0x30b9604b, 0x30c1c159, 0x30ca22c4, 0x30d2848a, 0x30dae6ad, 0x30e3492c, 0x30ebac07, +0x30f40f3e, 0x30fc72d1, 0x3104d6c0, 0x310d3b0b, 0x31159fb1, 0x311e04b4, 0x31266a12, 0x312ecfcd, +0x313735e3, 0x313f9c55, 0x31480322, 0x31506a4b, 0x3158d1d0, 0x316139b0, 0x3169a1ed, 0x31720a84, +0x317a7377, 0x3182dcc6, 0x318b4670, 0x3193b076, 0x319c1ad6, 0x31a48593, 0x31acf0aa, 0x31b55c1d, +0x31bdc7ec, 0x31c63415, 0x31cea09a, 0x31d70d7a, 0x31df7ab5, 0x31e7e84b, 0x31f0563d, 0x31f8c489, +0x32013331, 0x3209a233, 0x32121191, 0x321a8149, 0x3222f15d, 0x322b61cb, 0x3233d294, 0x323c43b8, +0x3244b537, 0x324d2711, 0x32559945, 0x325e0bd4, 0x32667ebe, 0x326ef202, 0x327765a1, 0x327fd99b, +0x32884def, 0x3290c29e, 0x329937a7, 0x32a1ad0b, 0x32aa22c9, 0x32b298e2, 0x32bb0f55, 0x32c38622, +0x32cbfd4a, 0x32d474cc, 0x32dceca8, 0x32e564df, 0x32eddd70, 0x32f6565b, 0x32fecfa0, 0x3307493f, +0x330fc338, 0x33183d8c, 0x3320b839, 0x33293341, 0x3331aea2, 0x333a2a5e, 0x3342a673, 0x334b22e2, +0x33539fab, 0x335c1cce, 0x33649a4b, 0x336d1821, 0x33759652, 0x337e14dc, 0x338693bf, 0x338f12fd, +0x33979294, 0x33a01284, 0x33a892cf, 0x33b11372, 0x33b9946f, 0x33c215c6, 0x33ca9776, 0x33d31980, +0x33db9be3, 0x33e41ea0, 0x33eca1b5, 0x33f52524, 0x33fda8ed, 0x34062d0e, 0x340eb189, 0x3417365d, +0x341fbb8b, 0x34284111, 0x3430c6f1, 0x34394d29, 0x3441d3bb, 0x344a5aa6, 0x3452e1e9, 0x345b6986, +0x3463f17c, 0x346c79ca, 0x34750272, 0x347d8b72, 0x348614cb, 0x348e9e7d, 0x34972888, 0x349fb2eb, +0x34a83da8, 0x34b0c8bd, 0x34b9542a, 0x34c1dff0, 0x34ca6c0f, 0x34d2f887, 0x34db8557, 0x34e4127f, +0x34eca000, 0x34f52dda, 0x34fdbc0c, 0x35064a96, 0x350ed979, 0x351768b4, 0x351ff847, 0x35288833, +0x35311877, 0x3539a913, 0x35423a08, 0x354acb54, 0x35535cf9, 0x355beef6, 0x3564814b, 0x356d13f8, +0x3575a6fe, 0x357e3a5b, 0x3586ce10, 0x358f621d, 0x3597f682, 0x35a08b40, 0x35a92055, 0x35b1b5c1, +0x35ba4b86, 0x35c2e1a3, 0x35cb7817, 0x35d40ee3, 0x35dca607, 0x35e53d82, 0x35edd555, 0x35f66d80, +0x35ff0602, 0x36079edc, 0x3610380e, 0x3618d197, 0x36216b77, 0x362a05af, 0x3632a03f, 0x363b3b26, +0x3643d664, 0x364c71fa, 0x36550de7, 0x365daa2b, 0x366646c7, 0x366ee3ba, 0x36778104, 0x36801ea5, +0x3688bc9e, 0x36915aee, 0x3699f994, 0x36a29892, 0x36ab37e7, 0x36b3d793, 0x36bc7796, 0x36c517f1, +0x36cdb8a2, 0x36d659aa, 0x36defb08, 0x36e79cbe, 0x36f03ecb, 0x36f8e12e, 0x370183e9, 0x370a26fa, +0x3712ca62, 0x371b6e20, 0x37241235, 0x372cb6a1, 0x37355b64, 0x373e007d, 0x3746a5ed, 0x374f4bb3, +0x3757f1d0, 0x37609844, 0x37693f0e, 0x3771e62e, 0x377a8da5, 0x37833572, 0x378bdd96, 0x37948610, +0x379d2ee0, 0x37a5d807, 0x37ae8183, 0x37b72b57, 0x37bfd580, 0x37c87fff, 0x37d12ad5, 0x37d9d601, +0x37e28183, 0x37eb2d5b, 0x37f3d989, 0x37fc860e, 0x380532e8, 0x380de018, 0x38168d9e, 0x381f3b7b, +0x3827e9ad, 0x38309835, 0x38394712, 0x3841f646, 0x384aa5d0, 0x385355af, 0x385c05e4, 0x3864b66f, +0x386d674f, 0x38761885, 0x387eca11, 0x38877bf2, 0x38902e29, 0x3898e0b6, 0x38a19398, 0x38aa46d0, +0x38b2fa5d, 0x38bbae40, 0x38c46278, 0x38cd1705, 0x38d5cbe8, 0x38de8120, 0x38e736ae, 0x38efec91, +0x38f8a2c9, 0x39015957, 0x390a103a, 0x3912c772, 0x391b7eff, 0x392436e1, 0x392cef19, 0x3935a7a5, +0x393e6087, 0x394719be, 0x394fd34a, 0x39588d2b, 0x39614760, 0x396a01eb, 0x3972bccb, 0x397b7800, +0x39843389, 0x398cef68, 0x3995ab9b, 0x399e6823, 0x39a72500, 0x39afe232, 0x39b89fb8, 0x39c15d93, +0x39ca1bc3, 0x39d2da47, 0x39db9921, 0x39e4584e, 0x39ed17d1, 0x39f5d7a8, 0x39fe97d3, 0x3a075853, +0x3a101927, 0x3a18da50, 0x3a219bce, 0x3a2a5d9f, 0x3a331fc5, 0x3a3be240, 0x3a44a50f, 0x3a4d6832, +0x3a562ba9, 0x3a5eef75, 0x3a67b395, 0x3a707809, 0x3a793cd2, 0x3a8201ee, 0x3a8ac75f, 0x3a938d24, +0x3a9c533d, 0x3aa519aa, 0x3aade06b, 0x3ab6a780, 0x3abf6ee9, 0x3ac836a6, 0x3ad0feb7, 0x3ad9c71c, +0x3ae28fd5, 0x3aeb58e1, 0x3af42242, 0x3afcebf6, 0x3b05b5fe, 0x3b0e805a, 0x3b174b0a, 0x3b20160d, +0x3b28e164, 0x3b31ad0f, 0x3b3a790e, 0x3b434560, 0x3b4c1205, 0x3b54deff, 0x3b5dac4b, 0x3b6679ec, +0x3b6f47e0, 0x3b781627, 0x3b80e4c2, 0x3b89b3b0, 0x3b9282f2, 0x3b9b5287, 0x3ba4226f, 0x3bacf2ab, +0x3bb5c33a, 0x3bbe941c, 0x3bc76552, 0x3bd036db, 0x3bd908b7, 0x3be1dae6, 0x3beaad69, 0x3bf3803e, +0x3bfc5367, 0x3c0526e3, 0x3c0dfab2, 0x3c16ced4, 0x3c1fa349, 0x3c287811, 0x3c314d2c, 0x3c3a229a, +0x3c42f85b, 0x3c4bce6f, 0x3c54a4d5, 0x3c5d7b8f, 0x3c66529b, 0x3c6f29fa, 0x3c7801ac, 0x3c80d9b1, +0x3c89b209, 0x3c928ab3, 0x3c9b63b0, 0x3ca43cff, 0x3cad16a2, 0x3cb5f097, 0x3cbecade, 0x3cc7a578, +0x3cd08065, 0x3cd95ba4, 0x3ce23736, 0x3ceb131a, 0x3cf3ef50, 0x3cfccbd9, 0x3d05a8b5, 0x3d0e85e3, +0x3d176363, 0x3d204136, 0x3d291f5b, 0x3d31fdd2, 0x3d3adc9b, 0x3d43bbb7, 0x3d4c9b25, 0x3d557ae5, +0x3d5e5af7, 0x3d673b5c, 0x3d701c13, 0x3d78fd1b, 0x3d81de76, 0x3d8ac023, 0x3d93a222, 0x3d9c8473, +0x3da56716, 0x3dae4a0b, 0x3db72d52, 0x3dc010eb, 0x3dc8f4d6, 0x3dd1d912, 0x3ddabda1, 0x3de3a281, +0x3dec87b3, 0x3df56d37, 0x3dfe530d, 0x3e073934, 0x3e101fad, 0x3e190678, 0x3e21ed95, 0x3e2ad503, +0x3e33bcc3, 0x3e3ca4d4, 0x3e458d37, 0x3e4e75ec, 0x3e575ef2, 0x3e60484a, 0x3e6931f3, 0x3e721bed, +0x3e7b0639, 0x3e83f0d7, 0x3e8cdbc6, 0x3e95c706, 0x3e9eb298, 0x3ea79e7a, 0x3eb08aaf, 0x3eb97734, +0x3ec2640b, 0x3ecb5133, 0x3ed43eac, 0x3edd2c77, 0x3ee61a93, 0x3eef08ff, 0x3ef7f7bd, 0x3f00e6cc, +0x3f09d62c, 0x3f12c5de, 0x3f1bb5e0, 0x3f24a633, 0x3f2d96d7, 0x3f3687cd, 0x3f3f7913, 0x3f486aaa, +0x3f515c92, 0x3f5a4ecb, 0x3f634155, 0x3f6c342f, 0x3f75275b, 0x3f7e1ad7, 0x3f870ea4, 0x3f9002c2, +0x3f98f730, 0x3fa1ebef, 0x3faae0ff, 0x3fb3d660, 0x3fbccc11, 0x3fc5c213, 0x3fceb865, 0x3fd7af08, +0x3fe0a5fc, 0x3fe99d40, 0x3ff294d4, 0x3ffb8cb9, 0x400484ef, 0x400d7d75, 0x4016764b, 0x401f6f72, +0x402868e9, 0x403162b1, 0x403a5cc8, 0x40435730, 0x404c51e9, 0x40554cf2, 0x405e484b, 0x406743f4, +0x40703fed, 0x40793c37, 0x408238d0, 0x408b35ba, 0x409432f4, 0x409d307e, 0x40a62e58, 0x40af2c82, +0x40b82afd, 0x40c129c7, 0x40ca28e1, 0x40d3284b, 0x40dc2805, 0x40e5280f, 0x40ee2869, 0x40f72913, +0x41002a0c, 0x41092b56, 0x41122cef, 0x411b2ed8, 0x41243111, 0x412d3399, 0x41363672, 0x413f399a, +0x41483d11, 0x415140d9, 0x415a44f0, 0x41634956, 0x416c4e0c, 0x41755312, 0x417e5867, 0x41875e0c, +0x41906401, 0x41996a44, 0x41a270d8, 0x41ab77ba, 0x41b47eed, 0x41bd866e, 0x41c68e3f, 0x41cf965f, +0x41d89ecf, 0x41e1a78e, 0x41eab09c, 0x41f3b9fa, 0x41fcc3a6, 0x4205cda2, 0x420ed7ee, 0x4217e288, +0x4220ed72, 0x4229f8aa, 0x42330432, 0x423c1009, 0x42451c2f, 0x424e28a4, 0x42573569, 0x4260427c, +0x42694fde, 0x42725d8f, 0x427b6b8f, 0x428479de, 0x428d887c, 0x42969769, 0x429fa6a5, 0x42a8b62f, +0x42b1c609, 0x42bad631, 0x42c3e6a8, 0x42ccf76e, 0x42d60882, 0x42df19e5, 0x42e82b97, 0x42f13d98, +0x42fa4fe7, 0x43036285, 0x430c7572, 0x431588ad, 0x431e9c37, 0x4327b00f, 0x4330c436, 0x4339d8ab, +0x4342ed6f, 0x434c0282, 0x435517e3, 0x435e2d92, 0x4367438f, 0x437059dc, 0x43797076, 0x4382875f, +0x438b9e96, 0x4394b61b, 0x439dcdef, 0x43a6e611, 0x43affe81, 0x43b91740, 0x43c2304d, 0x43cb49a8, +0x43d46351, 0x43dd7d48, 0x43e6978d, 0x43efb221, 0x43f8cd02, 0x4401e832, 0x440b03af, 0x44141f7b, +0x441d3b95, 0x442657fc, 0x442f74b2, 0x443891b6, 0x4441af07, 0x444acca7, 0x4453ea94, 0x445d08cf, +0x44662758, 0x446f462f, 0x44786553, 0x448184c6, 0x448aa486, 0x4493c494, 0x449ce4f0, 0x44a60599, +0x44af2690, 0x44b847d5, 0x44c16967, 0x44ca8b47, 0x44d3ad74, 0x44dccfef, 0x44e5f2b8, 0x44ef15ce, +0x44f83932, 0x45015ce3, 0x450a80e2, 0x4513a52e, 0x451cc9c8, 0x4525eeaf, 0x452f13e3, 0x45383965, +0x45415f34, 0x454a8551, 0x4553abbb, 0x455cd272, 0x4565f976, 0x456f20c8, 0x45784867, 0x45817053, +0x458a988c, 0x4593c113, 0x459ce9e7, 0x45a61307, 0x45af3c75, 0x45b86630, 0x45c19039, 0x45caba8e, +0x45d3e530, 0x45dd101f, 0x45e63b5c, 0x45ef66e5, 0x45f892bb, 0x4601bede, 0x460aeb4e, 0x4614180b, +0x461d4515, 0x4626726c, 0x462fa00f, 0x4638ce00, 0x4641fc3d, 0x464b2ac7, 0x4654599e, 0x465d88c1, +0x4666b832, 0x466fe7ef, 0x467917f8, 0x4682484e, 0x468b78f1, 0x4694a9e1, 0x469ddb1d, 0x46a70ca6, +0x46b03e7b, 0x46b9709d, 0x46c2a30c, 0x46cbd5c7, 0x46d508ce, 0x46de3c22, 0x46e76fc2, 0x46f0a3af, +0x46f9d7e9, 0x47030c6e, 0x470c4140, 0x4715765f, 0x471eabc9, 0x4727e180, 0x47311784, 0x473a4dd3, +0x4743846f, 0x474cbb57, 0x4755f28c, 0x475f2a0c, 0x476861d9, 0x477199f2, 0x477ad257, 0x47840b08, +0x478d4405, 0x47967d4f, 0x479fb6e4, 0x47a8f0c5, 0x47b22af3, 0x47bb656c, 0x47c4a032, 0x47cddb43, +0x47d716a1, 0x47e0524a, 0x47e98e40, 0x47f2ca81, 0x47fc070e, 0x480543e7, 0x480e810c, 0x4817be7c, +0x4820fc39, 0x482a3a41, 0x48337895, 0x483cb735, 0x4845f620, 0x484f3557, 0x485874da, 0x4861b4a8, +0x486af4c3, 0x48743528, 0x487d75da, 0x4886b6d7, 0x488ff81f, 0x489939b3, 0x48a27b93, 0x48abbdbe, +0x48b50035, 0x48be42f7, 0x48c78605, 0x48d0c95e, 0x48da0d02, 0x48e350f2, 0x48ec952e, 0x48f5d9b4, +0x48ff1e86, 0x490863a4, 0x4911a90c, 0x491aeec0, 0x492434bf, 0x492d7b0a, 0x4936c1a0, 0x49400881, +0x49494fad, 0x49529724, 0x495bdee7, 0x496526f4, 0x496e6f4d, 0x4977b7f1, 0x498100e0, 0x498a4a1a, +0x4993939f, 0x499cdd6f, 0x49a6278a, 0x49af71f0, 0x49b8bca2, 0x49c2079e, 0x49cb52e5, 0x49d49e77, +0x49ddea53, 0x49e7367b, 0x49f082ee, 0x49f9cfab, 0x4a031cb4, 0x4a0c6a07, 0x4a15b7a5, 0x4a1f058d, +0x4a2853c1, 0x4a31a23f, 0x4a3af108, 0x4a44401b, 0x4a4d8f7a, 0x4a56df23, 0x4a602f16, 0x4a697f55, +0x4a72cfdd, 0x4a7c20b1, 0x4a8571cf, 0x4a8ec337, 0x4a9814eb, 0x4aa166e8, 0x4aaab930, 0x4ab40bc3, +0x4abd5ea0, 0x4ac6b1c8, 0x4ad0053a, 0x4ad958f6, 0x4ae2acfd, 0x4aec014e, 0x4af555e9, 0x4afeaacf, +0x4b07ffff, 0x4b11557a, 0x4b1aab3f, 0x4b24014e, 0x4b2d57a7, 0x4b36ae4b, 0x4b400538, 0x4b495c70, +0x4b52b3f2, 0x4b5c0bbf, 0x4b6563d5, 0x4b6ebc36, 0x4b7814e0, 0x4b816dd5, 0x4b8ac714, 0x4b94209d, +0x4b9d7a6f, 0x4ba6d48c, 0x4bb02ef3, 0x4bb989a4, 0x4bc2e49f, 0x4bcc3fe4, 0x4bd59b72, 0x4bdef74b, +0x4be8536e, 0x4bf1afda, 0x4bfb0c90, 0x4c046990, 0x4c0dc6da, 0x4c17246e, 0x4c20824b, 0x4c29e073, +0x4c333ee4, 0x4c3c9d9e, 0x4c45fca3, 0x4c4f5bf1, 0x4c58bb89, 0x4c621b6a, 0x4c6b7b95, 0x4c74dc0a, +0x4c7e3cc9, 0x4c879dd0, 0x4c90ff22, 0x4c9a60bd, 0x4ca3c2a2, 0x4cad24d0, 0x4cb68747, 0x4cbfea09, +0x4cc94d13, 0x4cd2b067, 0x4cdc1405, 0x4ce577ec, 0x4ceedc1c, 0x4cf84096, 0x4d01a559, 0x4d0b0a65, +0x4d146fbb, 0x4d1dd55a, 0x4d273b42, 0x4d30a174, 0x4d3a07ee, 0x4d436eb2, 0x4d4cd5c0, 0x4d563d16, +0x4d5fa4b6, 0x4d690c9f, 0x4d7274d1, 0x4d7bdd4c, 0x4d854610, 0x4d8eaf1e, 0x4d981874, 0x4da18214, +0x4daaebfc, 0x4db4562e, 0x4dbdc0a8, 0x4dc72b6c, 0x4dd09679, 0x4dda01ce, 0x4de36d6d, 0x4decd954, +0x4df64584, 0x4dffb1fe, 0x4e091ec0, 0x4e128bcb, 0x4e1bf91f, 0x4e2566bb, 0x4e2ed4a1, 0x4e3842cf, +0x4e41b146, 0x4e4b2006, 0x4e548f0e, 0x4e5dfe5f, 0x4e676df9, 0x4e70dddc, 0x4e7a4e07, 0x4e83be7b, +0x4e8d2f38, 0x4e96a03d, 0x4ea0118b, 0x4ea98321, 0x4eb2f500, 0x4ebc6728, 0x4ec5d998, 0x4ecf4c50, +0x4ed8bf51, 0x4ee2329b, 0x4eeba62d, 0x4ef51a07, 0x4efe8e2a, 0x4f080296, 0x4f117749, 0x4f1aec45, +0x4f24618a, 0x4f2dd717, 0x4f374cec, 0x4f40c309, 0x4f4a396f, 0x4f53b01d, 0x4f5d2713, 0x4f669e52, +0x4f7015d9, 0x4f798da8, 0x4f8305bf, 0x4f8c7e1e, 0x4f95f6c6, 0x4f9f6fb5, 0x4fa8e8ed, 0x4fb2626d, +0x4fbbdc35, 0x4fc55645, 0x4fced09d, 0x4fd84b3e, 0x4fe1c626, 0x4feb4156, 0x4ff4bcce, 0x4ffe388f, +0x5007b497, 0x501130e7, 0x501aad7f, 0x50242a5f, 0x502da787, 0x503724f7, 0x5040a2ae, 0x504a20ae, +0x50539ef5, 0x505d1d84, 0x50669c5b, 0x50701b7a, 0x50799ae0, 0x50831a8e, 0x508c9a84, 0x50961ac2, +0x509f9b47, 0x50a91c14, 0x50b29d29, 0x50bc1e85, 0x50c5a029, 0x50cf2215, 0x50d8a448, 0x50e226c2, +0x50eba985, 0x50f52c8f, 0x50feafe0, 0x51083379, 0x5111b759, 0x511b3b81, 0x5124bff1, 0x512e44a7, +0x5137c9a6, 0x51414eeb, 0x514ad478, 0x51545a4d, 0x515de069, 0x516766cc, 0x5170ed76, 0x517a7468, +0x5183fba1, 0x518d8322, 0x51970ae9, 0x51a092f8, 0x51aa1b4e, 0x51b3a3ec, 0x51bd2cd0, 0x51c6b5fc, +0x51d03f6f, 0x51d9c929, 0x51e3532b, 0x51ecdd73, 0x51f66802, 0x51fff2d9, 0x52097df7, 0x5213095b, +0x521c9507, 0x522620fa, 0x522fad34, 0x523939b5, 0x5242c67c, 0x524c538b, 0x5255e0e1, 0x525f6e7e, +0x5268fc61, 0x52728a8c, 0x527c18fd, 0x5285a7b5, 0x528f36b4, 0x5298c5fa, 0x52a25587, 0x52abe55a, +0x52b57575, 0x52bf05d6, 0x52c8967d, 0x52d2276c, 0x52dbb8a1, 0x52e54a1d, 0x52eedbe0, 0x52f86de9, +0x53020039, 0x530b92d0, 0x531525ad, 0x531eb8d1, 0x53284c3c, 0x5331dfed, 0x533b73e4, 0x53450823, +0x534e9ca7, 0x53583173, 0x5361c684, 0x536b5bdc, 0x5374f17b, 0x537e8760, 0x53881d8c, 0x5391b3fe, +0x539b4ab6, 0x53a4e1b5, 0x53ae78fa, 0x53b81086, 0x53c1a858, 0x53cb4070, 0x53d4d8ce, 0x53de7173, +0x53e80a5e, 0x53f1a390, 0x53fb3d07, 0x5404d6c5, 0x540e70c9, 0x54180b13, 0x5421a5a4, 0x542b407a, +0x5434db97, 0x543e76fa, 0x544812a3, 0x5451ae92, 0x545b4ac8, 0x5464e743, 0x546e8404, 0x5478210c, +0x5481be59, 0x548b5bed, 0x5494f9c6, 0x549e97e5, 0x54a8364b, 0x54b1d4f6, 0x54bb73e8, 0x54c5131f, +0x54ceb29c, 0x54d8525f, 0x54e1f268, 0x54eb92b6, 0x54f5334b, 0x54fed425, 0x55087546, 0x551216ac, +0x551bb858, 0x55255a49, 0x552efc80, 0x55389efe, 0x554241c0, 0x554be4c9, 0x55558817, 0x555f2bab, +0x5568cf84, 0x557273a3, 0x557c1808, 0x5585bcb3, 0x558f61a3, 0x559906d8, 0x55a2ac53, 0x55ac5214, +0x55b5f81a, 0x55bf9e66, 0x55c944f7, 0x55d2ebce, 0x55dc92ea, 0x55e63a4c, 0x55efe1f3, 0x55f989e0, +0x56033212, 0x560cda89, 0x56168346, 0x56202c48, 0x5629d58f, 0x56337f1c, 0x563d28ee, 0x5646d306, +0x56507d62, 0x565a2804, 0x5663d2ec, 0x566d7e18, 0x5677298a, 0x5680d541, 0x568a813d, 0x56942d7e, +0x569dda05, 0x56a786d1, 0x56b133e1, 0x56bae137, 0x56c48ed2, 0x56ce3cb3, 0x56d7ead8, 0x56e19942, +0x56eb47f1, 0x56f4f6e6, 0x56fea61f, 0x5708559e, 0x57120561, 0x571bb569, 0x572565b7, 0x572f1649, +0x5738c720, 0x5742783c, 0x574c299e, 0x5755db43, 0x575f8d2e, 0x57693f5e, 0x5772f1d2, 0x577ca48c, +0x5786578a, 0x57900acd, 0x5799be54, 0x57a37221, 0x57ad2632, 0x57b6da88, 0x57c08f23, 0x57ca4402, +0x57d3f926, 0x57ddae8f, 0x57e7643c, 0x57f11a2f, 0x57fad065, 0x580486e1, 0x580e3da1, 0x5817f4a5, +0x5821abee, 0x582b637c, 0x58351b4e, 0x583ed365, 0x58488bc0, 0x58524460, 0x585bfd44, 0x5865b66d, +0x586f6fda, 0x5879298b, 0x5882e381, 0x588c9dbc, 0x5896583b, 0x58a012fe, 0x58a9ce05, 0x58b38951, +0x58bd44e2, 0x58c700b6, 0x58d0bccf, 0x58da792c, 0x58e435ce, 0x58edf2b4, 0x58f7afde, 0x59016d4c, +0x590b2afe, 0x5914e8f5, 0x591ea730, 0x592865af, 0x59322472, 0x593be379, 0x5945a2c5, 0x594f6255, +0x59592228, 0x5962e240, 0x596ca29c, 0x5976633c, 0x59802420, 0x5989e548, 0x5993a6b4, 0x599d6864, +0x59a72a58, 0x59b0ec90, 0x59baaf0c, 0x59c471cc, 0x59ce34d0, 0x59d7f818, 0x59e1bba3, 0x59eb7f73, +0x59f54386, 0x59ff07dd, 0x5a08cc79, 0x5a129158, 0x5a1c567a, 0x5a261be1, 0x5a2fe18b, 0x5a39a779, +0x5a436dab, 0x5a4d3421, 0x5a56fada, 0x5a60c1d8, 0x5a6a8918, 0x5a74509d, 0x5a7e1865, 0x5a87e071, +0x5a91a8c0, 0x5a9b7153, 0x5aa53a2a, 0x5aaf0344, 0x5ab8cca2, 0x5ac29644, 0x5acc6029, 0x5ad62a51, +0x5adff4bd, 0x5ae9bf6d, 0x5af38a60, 0x5afd5597, 0x5b072111, 0x5b10ecce, 0x5b1ab8cf, 0x5b248514, +0x5b2e519c, 0x5b381e67, 0x5b41eb76, 0x5b4bb8c8, 0x5b55865d, 0x5b5f5436, 0x5b692252, 0x5b72f0b1, +0x5b7cbf54, 0x5b868e3a, 0x5b905d63, 0x5b9a2cd0, 0x5ba3fc7f, 0x5badcc72, 0x5bb79ca9, 0x5bc16d22, +0x5bcb3ddf, 0x5bd50ede, 0x5bdee021, 0x5be8b1a7, 0x5bf28371, 0x5bfc557d, 0x5c0627cc, 0x5c0ffa5f, +0x5c19cd35, 0x5c23a04d, 0x5c2d73a9, 0x5c374748, 0x5c411b2a, 0x5c4aef4e, 0x5c54c3b6, 0x5c5e9861, +0x5c686d4f, 0x5c724280, 0x5c7c17f3, 0x5c85edaa, 0x5c8fc3a3, 0x5c9999e0, 0x5ca3705f, 0x5cad4721, +0x5cb71e26, 0x5cc0f56e, 0x5ccaccf9, 0x5cd4a4c6, 0x5cde7cd7, 0x5ce8552a, 0x5cf22dbf, 0x5cfc0698, +0x5d05dfb3, 0x5d0fb912, 0x5d1992b2, 0x5d236c96, 0x5d2d46bc, 0x5d372125, 0x5d40fbd1, 0x5d4ad6bf, +0x5d54b1f0, 0x5d5e8d63, 0x5d686919, 0x5d724512, 0x5d7c214d, 0x5d85fdcb, 0x5d8fda8b, 0x5d99b78e, +0x5da394d4, 0x5dad725c, 0x5db75026, 0x5dc12e33, 0x5dcb0c82, 0x5dd4eb14, 0x5ddec9e9, 0x5de8a8ff, +0x5df28858, 0x5dfc67f4, 0x5e0647d2, 0x5e1027f2, 0x5e1a0855, 0x5e23e8fa, 0x5e2dc9e1, 0x5e37ab0b, +0x5e418c77, 0x5e4b6e25, 0x5e555016, 0x5e5f3249, 0x5e6914be, 0x5e72f775, 0x5e7cda6f, 0x5e86bdab, +0x5e90a129, 0x5e9a84e9, 0x5ea468eb, 0x5eae4d30, 0x5eb831b6, 0x5ec2167f, 0x5ecbfb8a, 0x5ed5e0d7, +0x5edfc666, 0x5ee9ac37, 0x5ef3924a, 0x5efd78a0, 0x5f075f37, 0x5f114610, 0x5f1b2d2c, 0x5f251489, +0x5f2efc28, 0x5f38e40a, 0x5f42cc2d, 0x5f4cb492, 0x5f569d39, 0x5f608622, 0x5f6a6f4d, 0x5f7458ba, +0x5f7e4269, 0x5f882c5a, 0x5f92168c, 0x5f9c0100, 0x5fa5ebb6, 0x5fafd6ae, 0x5fb9c1e8, 0x5fc3ad64, +0x5fcd9921, 0x5fd78520, 0x5fe17161, 0x5feb5de3, 0x5ff54aa7, 0x5fff37ad, 0x600924f5, 0x6013127e, +0x601d0049, 0x6026ee56, 0x6030dca4, 0x603acb34, 0x6044ba05, 0x604ea918, 0x6058986d, 0x60628803, +0x606c77db, 0x607667f4, 0x6080584f, 0x608a48ec, 0x609439ca, 0x609e2ae9, 0x60a81c4a, 0x60b20dec, +0x60bbffd0, 0x60c5f1f5, 0x60cfe45c, 0x60d9d704, 0x60e3c9ed, 0x60edbd18, 0x60f7b084, 0x6101a432, +0x610b9821, 0x61158c51, 0x611f80c3, 0x61297576, 0x61336a6a, 0x613d5f9f, 0x61475516, 0x61514ace, +0x615b40c7, 0x61653702, 0x616f2d7e, 0x6179243a, 0x61831b38, 0x618d1278, 0x619709f8, 0x61a101ba, +0x61aaf9bd, 0x61b4f200, 0x61beea85, 0x61c8e34b, 0x61d2dc53, 0x61dcd59b, 0x61e6cf24, 0x61f0c8ee, +0x61fac2fa, 0x6204bd46, 0x620eb7d4, 0x6218b2a2, 0x6222adb1, 0x622ca902, 0x6236a493, 0x6240a065, +0x624a9c78, 0x625498cd, 0x625e9562, 0x62689238, 0x62728f4e, 0x627c8ca6, 0x62868a3e, 0x62908818, +0x629a8632, 0x62a4848d, 0x62ae8329, 0x62b88205, 0x62c28123, 0x62cc8081, 0x62d68020, 0x62e07fff, +0x62ea8020, 0x62f48081, 0x62fe8123, 0x63088205, 0x63128328, 0x631c848c, 0x63268631, 0x63308816, +0x633a8a3b, 0x63448ca2, 0x634e8f49, 0x63589230, 0x63629558, 0x636c98c1, 0x63769c6a, 0x6380a054, +0x638aa47e, 0x6394a8e9, 0x639ead94, 0x63a8b280, 0x63b2b7ac, 0x63bcbd19, 0x63c6c2c6, 0x63d0c8b3, +0x63dacee1, 0x63e4d550, 0x63eedbff, 0x63f8e2ee, 0x6402ea1d, 0x640cf18d, 0x6416f93e, 0x6421012e, +0x642b095f, 0x643511d0, 0x643f1a82, 0x64492374, 0x64532ca6, 0x645d3618, 0x64673fcb, 0x647149bd, +0x647b53f0, 0x64855e64, 0x648f6917, 0x6499740b, 0x64a37f3e, 0x64ad8ab2, 0x64b79666, 0x64c1a25b, +0x64cbae8f, 0x64d5bb03, 0x64dfc7b8, 0x64e9d4ad, 0x64f3e1e1, 0x64fdef56, 0x6507fd0b, 0x65120b00, +0x651c1934, 0x652627a9, 0x6530365e, 0x653a4553, 0x65445488, 0x654e63fd, 0x655873b1, 0x656283a6, +0x656c93db, 0x6576a44f, 0x6580b503, 0x658ac5f8, 0x6594d72c, 0x659ee8a0, 0x65a8fa54, 0x65b30c47, +0x65bd1e7b, 0x65c730ee, 0x65d143a1, 0x65db5694, 0x65e569c7, 0x65ef7d39, 0x65f990eb, 0x6603a4dd, +0x660db90f, 0x6617cd80, 0x6621e231, 0x662bf722, 0x66360c52, 0x664021c2, 0x664a3772, 0x66544d62, +0x665e6390, 0x666879ff, 0x667290ad, 0x667ca79b, 0x6686bec8, 0x6690d635, 0x669aede2, 0x66a505ce, +0x66af1df9, 0x66b93664, 0x66c34f0f, 0x66cd67f9, 0x66d78123, 0x66e19a8c, 0x66ebb434, 0x66f5ce1c, +0x66ffe843, 0x670a02aa, 0x67141d50, 0x671e3836, 0x6728535b, 0x67326ebf, 0x673c8a63, 0x6746a646, +0x6750c268, 0x675adeca, 0x6764fb6b, 0x676f184b, 0x6779356a, 0x678352c9, 0x678d7067, 0x67978e45, +0x67a1ac61, 0x67abcabd, 0x67b5e958, 0x67c00832, 0x67ca274c, 0x67d446a4, 0x67de663c, 0x67e88613, +0x67f2a629, 0x67fcc67e, 0x6806e712, 0x681107e6, 0x681b28f8, 0x68254a4a, 0x682f6bda, 0x68398daa, +0x6843afb9, 0x684dd206, 0x6857f493, 0x6862175f, 0x686c3a6a, 0x68765db3, 0x6880813c, 0x688aa504, +0x6894c90a, 0x689eed50, 0x68a911d5, 0x68b33698, 0x68bd5b9a, 0x68c780dc, 0x68d1a65c, 0x68dbcc1b, +0x68e5f218, 0x68f01855, 0x68fa3ed0, 0x6904658b, 0x690e8c84, 0x6918b3bc, 0x6922db32, 0x692d02e8, +0x69372adc, 0x6941530f, 0x694b7b81, 0x6955a431, 0x695fcd20, 0x6969f64e, 0x69741fbb, 0x697e4966, +0x69887350, 0x69929d78, 0x699cc7df, 0x69a6f285, 0x69b11d69, 0x69bb488c, 0x69c573ee, 0x69cf9f8e, +0x69d9cb6d, 0x69e3f78a, 0x69ee23e6, 0x69f85080, 0x6a027d59, 0x6a0caa71, 0x6a16d7c7, 0x6a21055b, +0x6a2b332e, 0x6a35613f, 0x6a3f8f8f, 0x6a49be1d, 0x6a53ecea, 0x6a5e1bf5, 0x6a684b3f, 0x6a727ac7, +0x6a7caa8d, 0x6a86da91, 0x6a910ad4, 0x6a9b3b56, 0x6aa56c15, 0x6aaf9d13, 0x6ab9ce50, 0x6ac3ffca, +0x6ace3183, 0x6ad8637b, 0x6ae295b0, 0x6aecc824, 0x6af6fad6, 0x6b012dc6, 0x6b0b60f4, 0x6b159461, +0x6b1fc80c, 0x6b29fbf5, 0x6b34301c, 0x6b3e6481, 0x6b489925, 0x6b52ce06, 0x6b5d0326, 0x6b673884, +0x6b716e20, 0x6b7ba3fa, 0x6b85da12, 0x6b901068, 0x6b9a46fd, 0x6ba47dcf, 0x6baeb4df, 0x6bb8ec2e, +0x6bc323ba, 0x6bcd5b85, 0x6bd7938d, 0x6be1cbd3, 0x6bec0458, 0x6bf63d1a, 0x6c00761a, 0x6c0aaf58, +0x6c14e8d4, 0x6c1f228e, 0x6c295c86, 0x6c3396bc, 0x6c3dd130, 0x6c480be1, 0x6c5246d1, 0x6c5c81fe, +0x6c66bd69, 0x6c70f912, 0x6c7b34f8, 0x6c85711d, 0x6c8fad7f, 0x6c99ea1f, 0x6ca426fd, 0x6cae6418, +0x6cb8a172, 0x6cc2df09, 0x6ccd1cdd, 0x6cd75af0, 0x6ce19940, 0x6cebd7ce, 0x6cf61699, 0x6d0055a2, +0x6d0a94e9, 0x6d14d46d, 0x6d1f142f, 0x6d29542f, 0x6d33946c, 0x6d3dd4e7, 0x6d4815a0, 0x6d525695, +0x6d5c97c9, 0x6d66d93a, 0x6d711ae9, 0x6d7b5cd5, 0x6d859eff, 0x6d8fe166, 0x6d9a240a, 0x6da466ec, +0x6daeaa0c, 0x6db8ed69, 0x6dc33104, 0x6dcd74db, 0x6dd7b8f1, 0x6de1fd44, 0x6dec41d4, 0x6df686a1, +0x6e00cbac, 0x6e0b10f5, 0x6e15567a, 0x6e1f9c3d, 0x6e29e23d, 0x6e34287b, 0x6e3e6ef6, 0x6e48b5ae, +0x6e52fca4, 0x6e5d43d7, 0x6e678b47, 0x6e71d2f4, 0x6e7c1adf, 0x6e866307, 0x6e90ab6c, 0x6e9af40e, +0x6ea53ced, 0x6eaf860a, 0x6eb9cf64, 0x6ec418fb, 0x6ece62cf, 0x6ed8ace0, 0x6ee2f72e, 0x6eed41ba, +0x6ef78c83, 0x6f01d788, 0x6f0c22cb, 0x6f166e4b, 0x6f20ba08, 0x6f2b0602, 0x6f355239, 0x6f3f9ead, +0x6f49eb5e, 0x6f54384d, 0x6f5e8578, 0x6f68d2e0, 0x6f732085, 0x6f7d6e67, 0x6f87bc86, 0x6f920ae2, +0x6f9c597b, 0x6fa6a851, 0x6fb0f763, 0x6fbb46b3, 0x6fc59640, 0x6fcfe609, 0x6fda360f, 0x6fe48652, +0x6feed6d2, 0x6ff9278f, 0x70037889, 0x700dc9bf, 0x70181b32, 0x70226ce3, 0x702cbecf, 0x703710f9, +0x7041635f, 0x704bb602, 0x705608e2, 0x70605bff, 0x706aaf58, 0x707502ee, 0x707f56c1, 0x7089aad0, +0x7093ff1c, 0x709e53a5, 0x70a8a86a, 0x70b2fd6c, 0x70bd52ab, 0x70c7a826, 0x70d1fdde, 0x70dc53d2, +0x70e6aa03, 0x70f10071, 0x70fb571b, 0x7105ae02, 0x71100525, 0x711a5c85, 0x7124b421, 0x712f0bfa, +0x7139640f, 0x7143bc61, 0x714e14ef, 0x71586dba, 0x7162c6c1, 0x716d2004, 0x71777984, 0x7181d341, +0x718c2d3a, 0x7196876f, 0x71a0e1e1, 0x71ab3c8f, 0x71b59779, 0x71bff2a0, 0x71ca4e03, 0x71d4a9a3, +0x71df057e, 0x71e96197, 0x71f3bdeb, 0x71fe1a7c, 0x72087749, 0x7212d452, 0x721d3197, 0x72278f19, +0x7231ecd7, 0x723c4ad1, 0x7246a908, 0x7251077b, 0x725b6629, 0x7265c514, 0x7270243c, 0x727a839f, +0x7284e33f, 0x728f431a, 0x7299a332, 0x72a40386, 0x72ae6416, 0x72b8c4e2, 0x72c325eb, 0x72cd872f, +0x72d7e8af, 0x72e24a6c, 0x72ecac64, 0x72f70e99, 0x73017109, 0x730bd3b6, 0x7316369f, 0x732099c3, +0x732afd24, 0x733560c0, 0x733fc499, 0x734a28ad, 0x73548cfe, 0x735ef18a, 0x73695652, 0x7373bb57, +0x737e2097, 0x73888613, 0x7392ebca, 0x739d51be, 0x73a7b7ee, 0x73b21e59, 0x73bc8500, 0x73c6ebe4, +0x73d15302, 0x73dbba5d, 0x73e621f4, 0x73f089c6, 0x73faf1d4, 0x74055a1e, 0x740fc2a3, 0x741a2b65, +0x74249462, 0x742efd9b, 0x7439670f, 0x7443d0bf, 0x744e3aab, 0x7458a4d3, 0x74630f36, 0x746d79d5, +0x7477e4af, 0x74824fc6, 0x748cbb17, 0x749726a5, 0x74a1926e, 0x74abfe73, 0x74b66ab3, 0x74c0d72f, +0x74cb43e6, 0x74d5b0d9, 0x74e01e07, 0x74ea8b71, 0x74f4f917, 0x74ff66f8, 0x7509d514, 0x7514436c, +0x751eb200, 0x752920cf, 0x75338fd9, 0x753dff1f, 0x75486ea1, 0x7552de5d, 0x755d4e56, 0x7567be89, +0x75722ef8, 0x757c9fa3, 0x75871089, 0x759181aa, 0x759bf306, 0x75a6649e, 0x75b0d671, 0x75bb4880, +0x75c5baca, 0x75d02d4f, 0x75daa00f, 0x75e5130b, 0x75ef8642, 0x75f9f9b4, 0x76046d62, 0x760ee14b, +0x7619556f, 0x7623c9ce, 0x762e3e68, 0x7638b33e, 0x7643284f, 0x764d9d9b, 0x76581322, 0x766288e4, +0x766cfee2, 0x7677751b, 0x7681eb8e, 0x768c623d, 0x7696d927, 0x76a1504d, 0x76abc7ad, 0x76b63f48, +0x76c0b71f, 0x76cb2f30, 0x76d5a77d, 0x76e02004, 0x76ea98c7, 0x76f511c4, 0x76ff8afd, 0x770a0471, +0x77147e1f, 0x771ef809, 0x7729722d, 0x7733ec8d, 0x773e6727, 0x7748e1fd, 0x77535d0d, 0x775dd858, +0x776853df, 0x7772cfa0, 0x777d4b9c, 0x7787c7d2, 0x77924444, 0x779cc0f1, 0x77a73dd8, 0x77b1bafa, +0x77bc3858, 0x77c6b5ef, 0x77d133c2, 0x77dbb1d0, 0x77e63018, 0x77f0ae9b, 0x77fb2d59, 0x7805ac52, +0x78102b85, 0x781aaaf3, 0x78252a9c, 0x782faa80, 0x783a2a9e, 0x7844aaf7, 0x784f2b8a, 0x7859ac59, +0x78642d62, 0x786eaea5, 0x78793024, 0x7883b1dd, 0x788e33d0, 0x7898b5fe, 0x78a33867, 0x78adbb0b, +0x78b83de9, 0x78c2c101, 0x78cd4454, 0x78d7c7e2, 0x78e24baa, 0x78eccfad, 0x78f753ea, 0x7901d862, +0x790c5d15, 0x7916e202, 0x79216729, 0x792bec8b, 0x79367227, 0x7940f7fe, 0x794b7e0f, 0x7956045b, +0x79608ae1, 0x796b11a1, 0x7975989c, 0x79801fd1, 0x798aa741, 0x79952eeb, 0x799fb6d0, 0x79aa3eee, +0x79b4c748, 0x79bf4fdb, 0x79c9d8a9, 0x79d461b1, 0x79deeaf4, 0x79e97470, 0x79f3fe27, 0x79fe8819, +0x7a091244, 0x7a139caa, 0x7a1e274a, 0x7a28b225, 0x7a333d39, 0x7a3dc888, 0x7a485411, 0x7a52dfd4, +0x7a5d6bd2, 0x7a67f809, 0x7a72847b, 0x7a7d1127, 0x7a879e0d, 0x7a922b2e, 0x7a9cb888, 0x7aa7461d, +0x7ab1d3eb, 0x7abc61f4, 0x7ac6f037, 0x7ad17eb4, 0x7adc0d6b, 0x7ae69c5c, 0x7af12b87, 0x7afbbaec, +0x7b064a8b, 0x7b10da64, 0x7b1b6a78, 0x7b25fac5, 0x7b308b4c, 0x7b3b1c0e, 0x7b45ad09, 0x7b503e3e, +0x7b5acfad, 0x7b656156, 0x7b6ff339, 0x7b7a8556, 0x7b8517ad, 0x7b8faa3e, 0x7b9a3d09, 0x7ba4d00d, +0x7baf634c, 0x7bb9f6c4, 0x7bc48a76, 0x7bcf1e62, 0x7bd9b288, 0x7be446e8, 0x7beedb82, 0x7bf97055, +0x7c040562, 0x7c0e9aa9, 0x7c19302a, 0x7c23c5e5, 0x7c2e5bd9, 0x7c38f207, 0x7c43886f, 0x7c4e1f10, +0x7c58b5ec, 0x7c634d01, 0x7c6de450, 0x7c787bd8, 0x7c83139a, 0x7c8dab96, 0x7c9843cb, 0x7ca2dc3a, +0x7cad74e3, 0x7cb80dc6, 0x7cc2a6e2, 0x7ccd4037, 0x7cd7d9c7, 0x7ce27390, 0x7ced0d92, 0x7cf7a7ce, +0x7d024244, 0x7d0cdcf3, 0x7d1777dc, 0x7d2212fe, 0x7d2cae5a, 0x7d3749ef, 0x7d41e5be, 0x7d4c81c7, +0x7d571e08, 0x7d61ba84, 0x7d6c5739, 0x7d76f427, 0x7d81914f, 0x7d8c2eb0, 0x7d96cc4b, 0x7da16a1f, +0x7dac082d, 0x7db6a673, 0x7dc144f4, 0x7dcbe3ae, 0x7dd682a1, 0x7de121cd, 0x7debc133, 0x7df660d2, +0x7e0100ab, 0x7e0ba0bd, 0x7e164108, 0x7e20e18d, 0x7e2b824b, 0x7e362342, 0x7e40c472, 0x7e4b65dc, +0x7e56077f, 0x7e60a95b, 0x7e6b4b71, 0x7e75edc0, 0x7e809048, 0x7e8b3309, 0x7e95d603, 0x7ea07937, +0x7eab1ca4, 0x7eb5c04a, 0x7ec06429, 0x7ecb0842, 0x7ed5ac93, 0x7ee0511e, 0x7eeaf5e2, 0x7ef59adf, +0x7f004015, 0x7f0ae584, 0x7f158b2c, 0x7f20310e, 0x7f2ad728, 0x7f357d7c, 0x7f402409, 0x7f4acace, +0x7f5571cd, 0x7f601905, 0x7f6ac076, 0x7f75681f, 0x7f801002, 0x7f8ab81e, 0x7f956073, 0x7fa00901, +0x7faab1c7, 0x7fb55ac7, 0x7fc00400, 0x7fcaad71, 0x7fd5571c, 0x7fe00100, 0x7feaab1c, 0x7ff55571, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, +0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff, 0x7fffffff,}; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_aa_cs_data[] = { +0x00006dc2, 0x000070dc, 0x0000798d, 0x00007ddd, 0x00007f6d, 0x00007fe4, 0x00007ffc, 0x00007fff,}; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_aa_ca_data[] = { +0xffffbe26, 0xffffc39f, 0xffffd7e4, 0xffffe8b8, 0xfffff3e5, 0xfffffac2, 0xfffffe2f, 0xffffff87,}; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_win_data[] = { +0x00000421, 0x00000db8, 0x000019c7, 0x000029ad, 0x00003fff, 0x00006246, 0x00009ee0, 0x00012a7d, +0x0003df40, 0xfffbc63e, 0xfffe7b01, 0xffff069e, 0xffff4338, 0xffff657e, 0xffff7bd0, 0xffff8bb6, +0xffff97c5, 0xffffa15c, 0xffffa947, 0xffffb006, 0xffffb5eb, 0xffffbb30, 0xffffc000, 0xffffc47a, +0xffffc8b7, 0xffffccca, 0xffffd0c5, 0xffffd4b9, 0xffffd8b4, 0xffffdcc8, 0xffffe104, 0xffffe57e, +0xffffea4e, 0xffffef94, 0xfffff579, 0xfffffc37, 0x00000421, 0x00000db8, 0x000019c7, 0x000029ad, +0x00003fff, 0x00006246, 0x00009ee0, 0x00012a7d, 0x0003df40, 0xfffbc63e, 0xfffe7b01, 0xffff069e, +0xffff4338, 0xffff657e, 0xffff7bd0, 0xffff8bb6, 0xffff97c5, 0xffffa15c, 0xffffa932, 0xffffaf55, +0xffffb41e, 0xffffb7d9, 0xffffbabb, 0xffffbce5, 0xffffbf02, 0xffffc45d, 0xffffcd2e, 0xffffd901, +0xffffe74d, 0xfffff772, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000db8, 0x00003fff, 0x00012a7d, 0xfffe7b01, 0xffff657e, 0xffff97c5, 0xffffb006, 0xffffc000, +0xffffccca, 0xffffd8b4, 0xffffe57e, 0xfffff579, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00002698, 0x0000bba3, 0x00037d32, 0xfffb73f7, 0xfffe3b01, 0xfffedad6, +0xffff2b2b, 0xffff58c3, 0xffff7566, 0xffff88e3, 0xffff96df, 0xffffa145, 0xffffa947, 0xffffb006, +0xffffb5eb, 0xffffbb30, 0xffffc000, 0xffffc47a, 0xffffc8b7, 0xffffccca, 0xffffd0c5, 0xffffd4b9, +0xffffd8b4, 0xffffdcc8, 0xffffe104, 0xffffe57e, 0xffffea4e, 0xffffef94, 0xfffff579, 0xfffffc37,}; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_COS9_data[] = { +0x00008000, 0x00007e0e, 0x00007847, 0x00006ed9, 0x0000620d, 0x00005246, 0x00004000, 0x00002bc7, +0x0000163a,}; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_tfcos36_data[] = { +0x0000403e, 0x00004241, 0x0000469d, 0x00004e21, 0x00005a82, 0x00006f94, 0x0000976f, 0x0000f746, +0x0002de51,}; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_tfcos12_data[] = { +0x00004241, 0x00005a82, 0x0000f746,}; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_cos9_data[] = { +0x00007847, 0xffffe9c6, 0xffff9df3,}; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_cos18_data[] = { +0x00007e0e, 0xffffd439, 0xffffadba,}; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_COS1_data[] = { +0x00004deb, 0xffff89bf, 0xffffef4b, 0x00007ee7, 0xffffcf05, 0xffff9a74, 0x000030fb, 0xffff89bf, +0x00007641, 0xffffcf05, 0xffffcf05, 0x00007641, 0x000010b5, 0xffffcf05, 0x00004deb, 0xffff9a74, +0x00007641, 0xffff8119, 0xffffef4b, 0x000030fb, 0xffffb215, 0x0000658c, 0xffff89bf, 0x00007ee7, +0xffffcf05, 0x00007641, 0xffff89bf, 0x000030fb, 0x000030fb, 0xffff89bf, 0xffffb215, 0x00007641, +0x000010b5, 0xffff8119, 0x000030fb, 0x0000658c, 0xffff9a74, 0x000030fb, 0x00007ee7, 0x000010b5, +0xffff89bf, 0xffffb215, 0xffff89bf, 0xffffcf05, 0x000030fb, 0x00007641, 0x00007641, 0x000030fb, +0xffff8119, 0xffff89bf, 0xffff9a74, 0xffffb215, 0xffffcf05, 0xffffef4b, 0xffff8119, 0xffff89bf, +0xffff9a74, 0xffffb215, 0xffffcf05, 0xffffef4b, 0xffff89bf, 0xffffcf05, 0x000030fb, 0x00007641, +0x00007641, 0x000030fb, 0xffff9a74, 0x000030fb, 0x00007ee7, 0x000010b5, 0xffff89bf, 0xffffb215,}; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_win1_data[] = { +0x00000421, 0xfffff248, 0x000019c7, 0xffffd653, 0x00003fff, 0xffff9dba, 0x00009ee0, 0xfffed583, +0x0003df40, 0x000439c2, 0xfffe7b01, 0x0000f962, 0xffff4338, 0x00009a82, 0xffff7bd0, 0x0000744a, +0xffff97c5, 0x00005ea4, 0xffffa947, 0x00004ffa, 0xffffb5eb, 0x000044d0, 0xffffc000, 0x00003b86, +0xffffc8b7, 0x00003336, 0xffffd0c5, 0x00002b47, 0xffffd8b4, 0x00002338, 0xffffe104, 0x00001a82, +0xffffea4e, 0x0000106c, 0xfffff579, 0x000003c9, 0x00000421, 0xfffff248, 0x000019c7, 0xffffd653, +0x00003fff, 0xffff9dba, 0x00009ee0, 0xfffed583, 0x0003df40, 0x000439c2, 0xfffe7b01, 0x0000f962, +0xffff4338, 0x00009a82, 0xffff7bd0, 0x0000744a, 0xffff97c5, 0x00005ea4, 0xffffa932, 0x000050ab, +0xffffb41e, 0x00004827, 0xffffbabb, 0x0000431b, 0xffffbf02, 0x00003ba3, 0xffffcd2e, 0x000026ff, +0xffffe74d, 0x0000088e, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000db8, 0xffffc001, 0x00012a7d, 0x000184ff, 0xffff657e, 0x0000683b, 0xffffb006, 0x00004000, +0xffffccca, 0x0000274c, 0xffffe57e, 0x00000a87, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +0x00000000, 0x00000000, 0x00002698, 0xffff445d, 0x00037d32, 0x00048c09, 0xfffe3b01, 0x0001252a, +0xffff2b2b, 0x0000a73d, 0xffff7566, 0x0000771d, 0xffff96df, 0x00005ebb, 0xffffa947, 0x00004ffa, +0xffffb5eb, 0x000044d0, 0xffffc000, 0x00003b86, 0xffffc8b7, 0x00003336, 0xffffd0c5, 0x00002b47, +0xffffd8b4, 0x00002338, 0xffffe104, 0x00001a82, 0xffffea4e, 0x0000106c, 0xfffff579, 0x000003c9,}; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_tan1_1_data[] = { +0x00000000, 0x00001b0c, 0x00002ed9, 0x00003fff, 0x00005126, 0x000064f3, 0x00007fff, 0x0000aed9, +0x00012ed9, 0x7fffffff, 0xffff5127, 0xffffd127, 0x00000000, 0x00001b0c, 0x00002ed9, 0x00003fff,}; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_tan2_1_data[] = { +0x00008000, 0x000064f3, 0x00005126, 0x00004000, 0x00002ed9, 0x00001b0c, 0x00000000, 0xffffd127, +0xffff5127, 0x80000000, 0x00012ed9, 0x0000aed9, 0x00008000, 0x000064f3, 0x00005126, 0x00004000,}; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_tan1_2_data[] = { +0x00000000, 0x00002640, 0x00004241, 0x00005a82, 0x000072c2, 0x00008ec3, 0x0000b504, 0x0000f746, +0x0001ac4b, 0x7fffffff, 0xffff08ba, 0xffffbdbf, 0x00000000, 0x00002640, 0x00004241, 0x00005a82,}; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_tan2_2_data[] = { +0x0000b504, 0x00008ec3, 0x000072c2, 0x00005a82, 0x00004241, 0x00002640, 0x00000000, 0xffffbdbf, +0xffff08ba, 0x80000000, 0x0001ac4b, 0x0000f746, 0x0000b504, 0x00008ec3, 0x000072c2, 0x00005a82,}; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_pow1_1_data[] = { +0x00008000, 0x00006ba2, 0x00008000, 0x00005a82, 0x00008000, 0x00004c1b, 0x00008000, 0x00004000, +0x00008000, 0x000035d1, 0x00008000, 0x00002d41, 0x00008000, 0x0000260d, 0x00008000, 0x00002000, +0x00008000, 0x00005a82, 0x00008000, 0x00003fff, 0x00008000, 0x00002d41, 0x00008000, 0x00001fff, +0x00008000, 0x000016a0, 0x00008000, 0x00000fff, 0x00008000, 0x00000b50, 0x00008000, 0x000007ff,}; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_pow2_1_data[] = { +0x00008000, 0x00008000, 0x00006ba2, 0x00008000, 0x00005a82, 0x00008000, 0x00004c1b, 0x00008000, +0x00004000, 0x00008000, 0x000035d1, 0x00008000, 0x00002d41, 0x00008000, 0x0000260d, 0x00008000, +0x00008000, 0x00008000, 0x00005a82, 0x00008000, 0x00003fff, 0x00008000, 0x00002d41, 0x00008000, +0x00001fff, 0x00008000, 0x000016a0, 0x00008000, 0x00000fff, 0x00008000, 0x00000b50, 0x00008000,}; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_pow1_2_data[] = { +0x0000b504, 0x00009837, 0x0000b504, 0x00008000, 0x0000b504, 0x00006ba2, 0x0000b504, 0x00005a82, +0x0000b504, 0x00004c1b, 0x0000b504, 0x00004000, 0x0000b504, 0x000035d1, 0x0000b504, 0x00002d41, +0x0000b504, 0x00008000, 0x0000b504, 0x00005a82, 0x0000b504, 0x00003fff, 0x0000b504, 0x00002d41, +0x0000b504, 0x00001fff, 0x0000b504, 0x000016a0, 0x0000b504, 0x00000fff, 0x0000b504, 0x00000b50,}; +#endif +#ifdef USE_DATA_TABLES +static long mpeg3_pow2_2_data[] = { +0x0000b504, 0x0000b504, 0x00009837, 0x0000b504, 0x00008000, 0x0000b504, 0x00006ba2, 0x0000b504, +0x00005a82, 0x0000b504, 0x00004c1b, 0x0000b504, 0x00004000, 0x0000b504, 0x000035d1, 0x0000b504, +0x0000b504, 0x0000b504, 0x00008000, 0x0000b504, 0x00005a82, 0x0000b504, 0x00003fff, 0x0000b504, +0x00002d41, 0x0000b504, 0x00001fff, 0x0000b504, 0x000016a0, 0x0000b504, 0x00000fff, 0x0000b504,}; +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/audio/header.c b/core/multimedia/opieplayer/libmpeg3/audio/header.c new file mode 100644 index 0000000..02b5e7c --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/header.c @@ -0,0 +1,163 @@ +#include "mpeg3audio.h" +#include "tables.h" +#include "../libmpeg3.h" +#include "../mpeg3protos.h" + +#include <stdio.h> + +/* Return 1 if the head check doesn't find a header. */ +int mpeg3audio_head_check(unsigned long head) +{ + if((head & 0xffe00000) != 0xffe00000) return 1; + if(!((head >> 17) & 3)) return 1; + if(((head >> 12) & 0xf) == 0xf) return 1; + if(!((head >> 12) & 0xf)) return 1; + if(((head >> 10) & 0x3) == 0x3 ) return 1; + if(((head >> 19) & 1) == 1 && ((head >> 17) & 3) == 3 && ((head >> 16) & 1) == 1) + return 1; + if((head & 0xffff0000) == 0xfffe0000) return 1; + + return 0; +} + +int mpeg3audio_decode_header(mpeg3audio_t *audio) +{ + if(audio->newhead & (1 << 20)) + { + audio->lsf = (audio->newhead & (1 << 19)) ? 0x0 : 0x1; + audio->mpeg35 = 0; + } + else + { + audio->lsf = 1; + audio->mpeg35 = 1; + } + + audio->layer = 4 - ((audio->newhead >> 17) & 3); + if(audio->mpeg35) + audio->sampling_frequency_code = 6 + ((audio->newhead >> 10) & 0x3); + else + audio->sampling_frequency_code = ((audio->newhead >> 10) & 0x3) + (audio->lsf * 3); + + audio->error_protection = ((audio->newhead >> 16) & 0x1) ^ 0x1; + + audio->bitrate_index = ((audio->newhead >> 12) & 0xf); + audio->padding = ((audio->newhead >> 9) & 0x1); + audio->extension = ((audio->newhead >> 8) & 0x1); + audio->mode = ((audio->newhead >> 6) & 0x3); + audio->mode_ext = ((audio->newhead >> 4) & 0x3); + audio->copyright = ((audio->newhead >> 3) & 0x1); + audio->original = ((audio->newhead >> 2) & 0x1); + audio->emphasis = audio->newhead & 0x3; + audio->channels = (audio->mode == MPG_MD_MONO) ? 1 : 2; + if(audio->channels > 1) + audio->single = -1; + else + audio->single = 3; + + audio->prev_framesize = audio->framesize; + + if(!audio->bitrate_index) return 1; + audio->bitrate = 1000 * mpeg3_tabsel_123[audio->lsf][audio->layer - 1][audio->bitrate_index]; + + switch(audio->layer) + { + case 1: + audio->framesize = (long)mpeg3_tabsel_123[audio->lsf][0][audio->bitrate_index] * 12000; + audio->framesize /= mpeg3_freqs[audio->sampling_frequency_code]; + audio->framesize = ((audio->framesize + audio->padding) << 2) - 4; + break; + case 2: + audio->framesize = (long)mpeg3_tabsel_123[audio->lsf][1][audio->bitrate_index] * 144000; + audio->framesize /= mpeg3_freqs[audio->sampling_frequency_code]; + audio->framesize += audio->padding - 4; + break; + case 3: + if(audio->lsf) + audio->ssize = (audio->channels == 1) ? 9 : 17; + else + audio->ssize = (audio->channels == 1) ? 17 : 32; + if(audio->error_protection) + audio->ssize += 2; + audio->framesize = (long)mpeg3_tabsel_123[audio->lsf][2][audio->bitrate_index] * 144000; + audio->framesize /= mpeg3_freqs[audio->sampling_frequency_code] << (audio->lsf); + audio->framesize = audio->framesize + audio->padding - 4; + break; + default: + return 1; + } + + if(audio->framesize > MAXFRAMESIZE) return 1; + + return 0; +} + +int mpeg3audio_read_frame_body(mpeg3audio_t *audio) +{ + int i; + for(i = 0; i < audio->framesize; i++) + { + audio->bsbuf[i] = mpeg3bits_getbits(audio->astream, 8); + } + return 0; +} + +/* Seek to the start of the previous header */ +int mpeg3audio_prev_header(mpeg3audio_t *audio) +{ + int result = 0, i, len = (int)audio->avg_framesize; + + for(i = 0; i < len && !result; i++) + { + mpeg3bits_getbits_reverse(audio->astream, 8); + } +/* Get reading in the forward direction again. */ + result |= mpeg3bits_refill(audio->astream); + return result; +} + +/* Read the next header */ +int mpeg3audio_read_header(mpeg3audio_t *audio) +{ + unsigned int code; + int i; + int attempt = 0; + int result = 0; + + switch(audio->format) + { + case AUDIO_AC3: + result = mpeg3audio_read_ac3_header(audio); + break; + + case AUDIO_MPEG: +/* Layer 1 not supported */ + if(audio->layer == 1) + { + fprintf(stderr, "mpeg3audio_new: layer 1 not supported\n"); + result = 1; + } + audio->newhead = mpeg3bits_showbits(audio->astream, 32); + if(!mpeg3bits_eof(audio->astream) && + (mpeg3audio_head_check(audio->newhead) || mpeg3audio_decode_header(audio))) + { + do + { + attempt++; + mpeg3bits_getbyte_noptr(audio->astream); + audio->newhead = mpeg3bits_showbits(audio->astream, 32); + }while(!mpeg3bits_eof(audio->astream) && + attempt < 65536 && + (mpeg3audio_head_check(audio->newhead) || mpeg3audio_decode_header(audio))); + } + +/* Skip the 4 bytes containing the header */ + mpeg3bits_getbits(audio->astream, 32); + break; + + case AUDIO_PCM: + mpeg3audio_read_pcm_header(audio); + break; + } + return mpeg3bits_eof(audio->astream); +} diff --git a/core/multimedia/opieplayer/libmpeg3/audio/huffman.h b/core/multimedia/opieplayer/libmpeg3/audio/huffman.h new file mode 100644 index 0000000..a9c8fff --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/huffman.h @@ -0,0 +1,355 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef HUFFMAN_H +#define HUFFMAN_H + +/* + * huffman tables ... recalcualted to work with my optimzed + * decoder scheme (MH) + * + * probably we could save a few bytes of memory, because the + * smaller tables are often the part of a bigger table + */ + +struct newhuff +{ + unsigned int linbits; + short *table; +}; + +static short mpeg3_tab0[] = +{ + 0 +}; + +static short mpeg3_tab1[] = +{ + -5, -3, -1, 17, 1, 16, 0 +}; + +static short mpeg3_tab2[] = +{ + -15, -11, -9, -5, -3, -1, 34, 2, 18, -1, 33, 32, 17, -1, 1, + 16, 0 +}; + +static short mpeg3_tab3[] = +{ + -13, -11, -9, -5, -3, -1, 34, 2, 18, -1, 33, 32, 16, 17, -1, + 1, 0 +}; + +static short mpeg3_tab5[] = +{ + -29, -25, -23, -15, -7, -5, -3, -1, 51, 35, 50, 49, -3, -1, 19, + 3, -1, 48, 34, -3, -1, 18, 33, -1, 2, 32, 17, -1, 1, 16, + 0 +}; + +static short mpeg3_tab6[] = +{ + -25, -19, -13, -9, -5, -3, -1, 51, 3, 35, -1, 50, 48, -1, 19, + 49, -3, -1, 34, 2, 18, -3, -1, 33, 32, 1, -1, 17, -1, 16, + 0 +}; + +static short mpeg3_tab7[] = +{ + -69, -65, -57, -39, -29, -17, -11, -7, -3, -1, 85, 69, -1, 84, 83, + -1, 53, 68, -3, -1, 37, 82, 21, -5, -1, 81, -1, 5, 52, -1, + 80, -1, 67, 51, -5, -3, -1, 36, 66, 20, -1, 65, 64, -11, -7, + -3, -1, 4, 35, -1, 50, 3, -1, 19, 49, -3, -1, 48, 34, 18, + -5, -1, 33, -1, 2, 32, 17, -1, 1, 16, 0 +}; + +static short mpeg3_tab8[] = +{ + -65, -63, -59, -45, -31, -19, -13, -7, -5, -3, -1, 85, 84, 69, 83, + -3, -1, 53, 68, 37, -3, -1, 82, 5, 21, -5, -1, 81, -1, 52, + 67, -3, -1, 80, 51, 36, -5, -3, -1, 66, 20, 65, -3, -1, 4, + 64, -1, 35, 50, -9, -7, -3, -1, 19, 49, -1, 3, 48, 34, -1, + 2, 32, -1, 18, 33, 17, -3, -1, 1, 16, 0 +}; + +static short mpeg3_tab9[] = +{ + -63, -53, -41, -29, -19, -11, -5, -3, -1, 85, 69, 53, -1, 83, -1, + 84, 5, -3, -1, 68, 37, -1, 82, 21, -3, -1, 81, 52, -1, 67, + -1, 80, 4, -7, -3, -1, 36, 66, -1, 51, 64, -1, 20, 65, -5, + -3, -1, 35, 50, 19, -1, 49, -1, 3, 48, -5, -3, -1, 34, 2, + 18, -1, 33, 32, -3, -1, 17, 1, -1, 16, 0 +}; + +static short mpeg3_tab10[] = +{ +-125,-121,-111, -83, -55, -35, -21, -13, -7, -3, -1, 119, 103, -1, 118, + 87, -3, -1, 117, 102, 71, -3, -1, 116, 86, -1, 101, 55, -9, -3, + -1, 115, 70, -3, -1, 85, 84, 99, -1, 39, 114, -11, -5, -3, -1, + 100, 7, 112, -1, 98, -1, 69, 53, -5, -1, 6, -1, 83, 68, 23, + -17, -5, -1, 113, -1, 54, 38, -5, -3, -1, 37, 82, 21, -1, 81, + -1, 52, 67, -3, -1, 22, 97, -1, 96, -1, 5, 80, -19, -11, -7, + -3, -1, 36, 66, -1, 51, 4, -1, 20, 65, -3, -1, 64, 35, -1, + 50, 3, -3, -1, 19, 49, -1, 48, 34, -7, -3, -1, 18, 33, -1, + 2, 32, 17, -1, 1, 16, 0 +}; + +static short mpeg3_tab11[] = +{ +-121,-113, -89, -59, -43, -27, -17, -7, -3, -1, 119, 103, -1, 118, 117, + -3, -1, 102, 71, -1, 116, -1, 87, 85, -5, -3, -1, 86, 101, 55, + -1, 115, 70, -9, -7, -3, -1, 69, 84, -1, 53, 83, 39, -1, 114, + -1, 100, 7, -5, -1, 113, -1, 23, 112, -3, -1, 54, 99, -1, 96, + -1, 68, 37, -13, -7, -5, -3, -1, 82, 5, 21, 98, -3, -1, 38, + 6, 22, -5, -1, 97, -1, 81, 52, -5, -1, 80, -1, 67, 51, -1, + 36, 66, -15, -11, -7, -3, -1, 20, 65, -1, 4, 64, -1, 35, 50, + -1, 19, 49, -5, -3, -1, 3, 48, 34, 33, -5, -1, 18, -1, 2, + 32, 17, -3, -1, 1, 16, 0 +}; + +static short mpeg3_tab12[] = +{ +-115, -99, -73, -45, -27, -17, -9, -5, -3, -1, 119, 103, 118, -1, 87, + 117, -3, -1, 102, 71, -1, 116, 101, -3, -1, 86, 55, -3, -1, 115, + 85, 39, -7, -3, -1, 114, 70, -1, 100, 23, -5, -1, 113, -1, 7, + 112, -1, 54, 99, -13, -9, -3, -1, 69, 84, -1, 68, -1, 6, 5, + -1, 38, 98, -5, -1, 97, -1, 22, 96, -3, -1, 53, 83, -1, 37, + 82, -17, -7, -3, -1, 21, 81, -1, 52, 67, -5, -3, -1, 80, 4, + 36, -1, 66, 20, -3, -1, 51, 65, -1, 35, 50, -11, -7, -5, -3, + -1, 64, 3, 48, 19, -1, 49, 34, -1, 18, 33, -7, -5, -3, -1, + 2, 32, 0, 17, -1, 1, 16 +}; + +static short mpeg3_tab13[] = +{ +-509,-503,-475,-405,-333,-265,-205,-153,-115, -83, -53, -35, -21, -13, -9, + -7, -5, -3, -1, 254, 252, 253, 237, 255, -1, 239, 223, -3, -1, 238, + 207, -1, 222, 191, -9, -3, -1, 251, 206, -1, 220, -1, 175, 233, -1, + 236, 221, -9, -5, -3, -1, 250, 205, 190, -1, 235, 159, -3, -1, 249, + 234, -1, 189, 219, -17, -9, -3, -1, 143, 248, -1, 204, -1, 174, 158, + -5, -1, 142, -1, 127, 126, 247, -5, -1, 218, -1, 173, 188, -3, -1, + 203, 246, 111, -15, -7, -3, -1, 232, 95, -1, 157, 217, -3, -1, 245, + 231, -1, 172, 187, -9, -3, -1, 79, 244, -3, -1, 202, 230, 243, -1, + 63, -1, 141, 216, -21, -9, -3, -1, 47, 242, -3, -1, 110, 156, 15, + -5, -3, -1, 201, 94, 171, -3, -1, 125, 215, 78, -11, -5, -3, -1, + 200, 214, 62, -1, 185, -1, 155, 170, -1, 31, 241, -23, -13, -5, -1, + 240, -1, 186, 229, -3, -1, 228, 140, -1, 109, 227, -5, -1, 226, -1, + 46, 14, -1, 30, 225, -15, -7, -3, -1, 224, 93, -1, 213, 124, -3, + -1, 199, 77, -1, 139, 184, -7, -3, -1, 212, 154, -1, 169, 108, -1, + 198, 61, -37, -21, -9, -5, -3, -1, 211, 123, 45, -1, 210, 29, -5, + -1, 183, -1, 92, 197, -3, -1, 153, 122, 195, -7, -5, -3, -1, 167, + 151, 75, 209, -3, -1, 13, 208, -1, 138, 168, -11, -7, -3, -1, 76, + 196, -1, 107, 182, -1, 60, 44, -3, -1, 194, 91, -3, -1, 181, 137, + 28, -43, -23, -11, -5, -1, 193, -1, 152, 12, -1, 192, -1, 180, 106, + -5, -3, -1, 166, 121, 59, -1, 179, -1, 136, 90, -11, -5, -1, 43, + -1, 165, 105, -1, 164, -1, 120, 135, -5, -1, 148, -1, 119, 118, 178, + -11, -3, -1, 27, 177, -3, -1, 11, 176, -1, 150, 74, -7, -3, -1, + 58, 163, -1, 89, 149, -1, 42, 162, -47, -23, -9, -3, -1, 26, 161, + -3, -1, 10, 104, 160, -5, -3, -1, 134, 73, 147, -3, -1, 57, 88, + -1, 133, 103, -9, -3, -1, 41, 146, -3, -1, 87, 117, 56, -5, -1, + 131, -1, 102, 71, -3, -1, 116, 86, -1, 101, 115, -11, -3, -1, 25, + 145, -3, -1, 9, 144, -1, 72, 132, -7, -5, -1, 114, -1, 70, 100, + 40, -1, 130, 24, -41, -27, -11, -5, -3, -1, 55, 39, 23, -1, 113, + -1, 85, 7, -7, -3, -1, 112, 54, -1, 99, 69, -3, -1, 84, 38, + -1, 98, 53, -5, -1, 129, -1, 8, 128, -3, -1, 22, 97, -1, 6, + 96, -13, -9, -5, -3, -1, 83, 68, 37, -1, 82, 5, -1, 21, 81, + -7, -3, -1, 52, 67, -1, 80, 36, -3, -1, 66, 51, 20, -19, -11, + -5, -1, 65, -1, 4, 64, -3, -1, 35, 50, 19, -3, -1, 49, 3, + -1, 48, 34, -3, -1, 18, 33, -1, 2, 32, -3, -1, 17, 1, 16, + 0 +}; + +static short mpeg3_tab15[] = +{ +-495,-445,-355,-263,-183,-115, -77, -43, -27, -13, -7, -3, -1, 255, 239, + -1, 254, 223, -1, 238, -1, 253, 207, -7, -3, -1, 252, 222, -1, 237, + 191, -1, 251, -1, 206, 236, -7, -3, -1, 221, 175, -1, 250, 190, -3, + -1, 235, 205, -1, 220, 159, -15, -7, -3, -1, 249, 234, -1, 189, 219, + -3, -1, 143, 248, -1, 204, 158, -7, -3, -1, 233, 127, -1, 247, 173, + -3, -1, 218, 188, -1, 111, -1, 174, 15, -19, -11, -3, -1, 203, 246, + -3, -1, 142, 232, -1, 95, 157, -3, -1, 245, 126, -1, 231, 172, -9, + -3, -1, 202, 187, -3, -1, 217, 141, 79, -3, -1, 244, 63, -1, 243, + 216, -33, -17, -9, -3, -1, 230, 47, -1, 242, -1, 110, 240, -3, -1, + 31, 241, -1, 156, 201, -7, -3, -1, 94, 171, -1, 186, 229, -3, -1, + 125, 215, -1, 78, 228, -15, -7, -3, -1, 140, 200, -1, 62, 109, -3, + -1, 214, 227, -1, 155, 185, -7, -3, -1, 46, 170, -1, 226, 30, -5, + -1, 225, -1, 14, 224, -1, 93, 213, -45, -25, -13, -7, -3, -1, 124, + 199, -1, 77, 139, -1, 212, -1, 184, 154, -7, -3, -1, 169, 108, -1, + 198, 61, -1, 211, 210, -9, -5, -3, -1, 45, 13, 29, -1, 123, 183, + -5, -1, 209, -1, 92, 208, -1, 197, 138, -17, -7, -3, -1, 168, 76, + -1, 196, 107, -5, -1, 182, -1, 153, 12, -1, 60, 195, -9, -3, -1, + 122, 167, -1, 166, -1, 192, 11, -1, 194, -1, 44, 91, -55, -29, -15, + -7, -3, -1, 181, 28, -1, 137, 152, -3, -1, 193, 75, -1, 180, 106, + -5, -3, -1, 59, 121, 179, -3, -1, 151, 136, -1, 43, 90, -11, -5, + -1, 178, -1, 165, 27, -1, 177, -1, 176, 105, -7, -3, -1, 150, 74, + -1, 164, 120, -3, -1, 135, 58, 163, -17, -7, -3, -1, 89, 149, -1, + 42, 162, -3, -1, 26, 161, -3, -1, 10, 160, 104, -7, -3, -1, 134, + 73, -1, 148, 57, -5, -1, 147, -1, 119, 9, -1, 88, 133, -53, -29, + -13, -7, -3, -1, 41, 103, -1, 118, 146, -1, 145, -1, 25, 144, -7, + -3, -1, 72, 132, -1, 87, 117, -3, -1, 56, 131, -1, 102, 71, -7, + -3, -1, 40, 130, -1, 24, 129, -7, -3, -1, 116, 8, -1, 128, 86, + -3, -1, 101, 55, -1, 115, 70, -17, -7, -3, -1, 39, 114, -1, 100, + 23, -3, -1, 85, 113, -3, -1, 7, 112, 54, -7, -3, -1, 99, 69, + -1, 84, 38, -3, -1, 98, 22, -3, -1, 6, 96, 53, -33, -19, -9, + -5, -1, 97, -1, 83, 68, -1, 37, 82, -3, -1, 21, 81, -3, -1, + 5, 80, 52, -7, -3, -1, 67, 36, -1, 66, 51, -1, 65, -1, 20, + 4, -9, -3, -1, 35, 50, -3, -1, 64, 3, 19, -3, -1, 49, 48, + 34, -9, -7, -3, -1, 18, 33, -1, 2, 32, 17, -3, -1, 1, 16, + 0 +}; + +static short mpeg3_tab16[] = +{ +-509,-503,-461,-323,-103, -37, -27, -15, -7, -3, -1, 239, 254, -1, 223, + 253, -3, -1, 207, 252, -1, 191, 251, -5, -1, 175, -1, 250, 159, -3, + -1, 249, 248, 143, -7, -3, -1, 127, 247, -1, 111, 246, 255, -9, -5, + -3, -1, 95, 245, 79, -1, 244, 243, -53, -1, 240, -1, 63, -29, -19, + -13, -7, -5, -1, 206, -1, 236, 221, 222, -1, 233, -1, 234, 217, -1, + 238, -1, 237, 235, -3, -1, 190, 205, -3, -1, 220, 219, 174, -11, -5, + -1, 204, -1, 173, 218, -3, -1, 126, 172, 202, -5, -3, -1, 201, 125, + 94, 189, 242, -93, -5, -3, -1, 47, 15, 31, -1, 241, -49, -25, -13, + -5, -1, 158, -1, 188, 203, -3, -1, 142, 232, -1, 157, 231, -7, -3, + -1, 187, 141, -1, 216, 110, -1, 230, 156, -13, -7, -3, -1, 171, 186, + -1, 229, 215, -1, 78, -1, 228, 140, -3, -1, 200, 62, -1, 109, -1, + 214, 155, -19, -11, -5, -3, -1, 185, 170, 225, -1, 212, -1, 184, 169, + -5, -1, 123, -1, 183, 208, 227, -7, -3, -1, 14, 224, -1, 93, 213, + -3, -1, 124, 199, -1, 77, 139, -75, -45, -27, -13, -7, -3, -1, 154, + 108, -1, 198, 61, -3, -1, 92, 197, 13, -7, -3, -1, 138, 168, -1, + 153, 76, -3, -1, 182, 122, 60, -11, -5, -3, -1, 91, 137, 28, -1, + 192, -1, 152, 121, -1, 226, -1, 46, 30, -15, -7, -3, -1, 211, 45, + -1, 210, 209, -5, -1, 59, -1, 151, 136, 29, -7, -3, -1, 196, 107, + -1, 195, 167, -1, 44, -1, 194, 181, -23, -13, -7, -3, -1, 193, 12, + -1, 75, 180, -3, -1, 106, 166, 179, -5, -3, -1, 90, 165, 43, -1, + 178, 27, -13, -5, -1, 177, -1, 11, 176, -3, -1, 105, 150, -1, 74, + 164, -5, -3, -1, 120, 135, 163, -3, -1, 58, 89, 42, -97, -57, -33, + -19, -11, -5, -3, -1, 149, 104, 161, -3, -1, 134, 119, 148, -5, -3, + -1, 73, 87, 103, 162, -5, -1, 26, -1, 10, 160, -3, -1, 57, 147, + -1, 88, 133, -9, -3, -1, 41, 146, -3, -1, 118, 9, 25, -5, -1, + 145, -1, 144, 72, -3, -1, 132, 117, -1, 56, 131, -21, -11, -5, -3, + -1, 102, 40, 130, -3, -1, 71, 116, 24, -3, -1, 129, 128, -3, -1, + 8, 86, 55, -9, -5, -1, 115, -1, 101, 70, -1, 39, 114, -5, -3, + -1, 100, 85, 7, 23, -23, -13, -5, -1, 113, -1, 112, 54, -3, -1, + 99, 69, -1, 84, 38, -3, -1, 98, 22, -1, 97, -1, 6, 96, -9, + -5, -1, 83, -1, 53, 68, -1, 37, 82, -1, 81, -1, 21, 5, -33, + -23, -13, -7, -3, -1, 52, 67, -1, 80, 36, -3, -1, 66, 51, 20, + -5, -1, 65, -1, 4, 64, -1, 35, 50, -3, -1, 19, 49, -3, -1, + 3, 48, 34, -3, -1, 18, 33, -1, 2, 32, -3, -1, 17, 1, 16, + 0 +}; + +static short mpeg3_tab24[] = +{ +-451,-117, -43, -25, -15, -7, -3, -1, 239, 254, -1, 223, 253, -3, -1, + 207, 252, -1, 191, 251, -5, -1, 250, -1, 175, 159, -1, 249, 248, -9, + -5, -3, -1, 143, 127, 247, -1, 111, 246, -3, -1, 95, 245, -1, 79, + 244, -71, -7, -3, -1, 63, 243, -1, 47, 242, -5, -1, 241, -1, 31, + 240, -25, -9, -1, 15, -3, -1, 238, 222, -1, 237, 206, -7, -3, -1, + 236, 221, -1, 190, 235, -3, -1, 205, 220, -1, 174, 234, -15, -7, -3, + -1, 189, 219, -1, 204, 158, -3, -1, 233, 173, -1, 218, 188, -7, -3, + -1, 203, 142, -1, 232, 157, -3, -1, 217, 126, -1, 231, 172, 255,-235, +-143, -77, -45, -25, -15, -7, -3, -1, 202, 187, -1, 141, 216, -5, -3, + -1, 14, 224, 13, 230, -5, -3, -1, 110, 156, 201, -1, 94, 186, -9, + -5, -1, 229, -1, 171, 125, -1, 215, 228, -3, -1, 140, 200, -3, -1, + 78, 46, 62, -15, -7, -3, -1, 109, 214, -1, 227, 155, -3, -1, 185, + 170, -1, 226, 30, -7, -3, -1, 225, 93, -1, 213, 124, -3, -1, 199, + 77, -1, 139, 184, -31, -15, -7, -3, -1, 212, 154, -1, 169, 108, -3, + -1, 198, 61, -1, 211, 45, -7, -3, -1, 210, 29, -1, 123, 183, -3, + -1, 209, 92, -1, 197, 138, -17, -7, -3, -1, 168, 153, -1, 76, 196, + -3, -1, 107, 182, -3, -1, 208, 12, 60, -7, -3, -1, 195, 122, -1, + 167, 44, -3, -1, 194, 91, -1, 181, 28, -57, -35, -19, -7, -3, -1, + 137, 152, -1, 193, 75, -5, -3, -1, 192, 11, 59, -3, -1, 176, 10, + 26, -5, -1, 180, -1, 106, 166, -3, -1, 121, 151, -3, -1, 160, 9, + 144, -9, -3, -1, 179, 136, -3, -1, 43, 90, 178, -7, -3, -1, 165, + 27, -1, 177, 105, -1, 150, 164, -17, -9, -5, -3, -1, 74, 120, 135, + -1, 58, 163, -3, -1, 89, 149, -1, 42, 162, -7, -3, -1, 161, 104, + -1, 134, 119, -3, -1, 73, 148, -1, 57, 147, -63, -31, -15, -7, -3, + -1, 88, 133, -1, 41, 103, -3, -1, 118, 146, -1, 25, 145, -7, -3, + -1, 72, 132, -1, 87, 117, -3, -1, 56, 131, -1, 102, 40, -17, -7, + -3, -1, 130, 24, -1, 71, 116, -5, -1, 129, -1, 8, 128, -1, 86, + 101, -7, -5, -1, 23, -1, 7, 112, 115, -3, -1, 55, 39, 114, -15, + -7, -3, -1, 70, 100, -1, 85, 113, -3, -1, 54, 99, -1, 69, 84, + -7, -3, -1, 38, 98, -1, 22, 97, -5, -3, -1, 6, 96, 53, -1, + 83, 68, -51, -37, -23, -15, -9, -3, -1, 37, 82, -1, 21, -1, 5, + 80, -1, 81, -1, 52, 67, -3, -1, 36, 66, -1, 51, 20, -9, -5, + -1, 65, -1, 4, 64, -1, 35, 50, -1, 19, 49, -7, -5, -3, -1, + 3, 48, 34, 18, -1, 33, -1, 2, 32, -3, -1, 17, 1, -1, 16, + 0 +}; + +static short mpeg3_tab_c0[] = +{ + -29, -21, -13, -7, -3, -1, 11, 15, -1, 13, 14, -3, -1, 7, 5, + 9, -3, -1, 6, 3, -1, 10, 12, -3, -1, 2, 1, -1, 4, 8, + 0 +}; + +static short mpeg3_tab_c1[] = +{ + -15, -7, -3, -1, 15, 14, -1, 13, 12, -3, -1, 11, 10, -1, 9, + 8, -7, -3, -1, 7, 6, -1, 5, 4, -3, -1, 3, 2, -1, 1, + 0 +}; + + + +static struct newhuff mpeg3_ht[] = +{ + { /* 0 */ 0 , mpeg3_tab0 } , + { /* 2 */ 0 , mpeg3_tab1 } , + { /* 3 */ 0 , mpeg3_tab2 } , + { /* 3 */ 0 , mpeg3_tab3 } , + { /* 0 */ 0 , mpeg3_tab0 } , + { /* 4 */ 0 , mpeg3_tab5 } , + { /* 4 */ 0 , mpeg3_tab6 } , + { /* 6 */ 0 , mpeg3_tab7 } , + { /* 6 */ 0 , mpeg3_tab8 } , + { /* 6 */ 0 , mpeg3_tab9 } , + { /* 8 */ 0 , mpeg3_tab10 } , + { /* 8 */ 0 , mpeg3_tab11 } , + { /* 8 */ 0 , mpeg3_tab12 } , + { /* 16 */ 0 , mpeg3_tab13 } , + { /* 0 */ 0 , mpeg3_tab0 } , + { /* 16 */ 0 , mpeg3_tab15 } , + + { /* 16 */ 1 , mpeg3_tab16 } , + { /* 16 */ 2 , mpeg3_tab16 } , + { /* 16 */ 3 , mpeg3_tab16 } , + { /* 16 */ 4 , mpeg3_tab16 } , + { /* 16 */ 6 , mpeg3_tab16 } , + { /* 16 */ 8 , mpeg3_tab16 } , + { /* 16 */ 10, mpeg3_tab16 } , + { /* 16 */ 13, mpeg3_tab16 } , + { /* 16 */ 4 , mpeg3_tab24 } , + { /* 16 */ 5 , mpeg3_tab24 } , + { /* 16 */ 6 , mpeg3_tab24 } , + { /* 16 */ 7 , mpeg3_tab24 } , + { /* 16 */ 8 , mpeg3_tab24 } , + { /* 16 */ 9 , mpeg3_tab24 } , + { /* 16 */ 11, mpeg3_tab24 } , + { /* 16 */ 13, mpeg3_tab24 } +}; + +static struct newhuff mpeg3_htc[] = +{ + { /* 1 , 1 , */ 0 , mpeg3_tab_c0 } , + { /* 1 , 1 , */ 0 , mpeg3_tab_c1 } +}; + + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/audio/layer1.c b/core/multimedia/opieplayer/libmpeg3/audio/layer1.c new file mode 100644 index 0000000..0c355f3 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/layer1.c @@ -0,0 +1,6 @@ +#include "mpeg3audio.h" + +int mpeg3audio_dolayer1(mpeg3audio_t *audio) +{ + ; +} diff --git a/core/multimedia/opieplayer/libmpeg3/audio/layer2.c b/core/multimedia/opieplayer/libmpeg3/audio/layer2.c new file mode 100644 index 0000000..01582fe --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/layer2.c @@ -0,0 +1,418 @@ +/* + * most other tables are calculated on program start (which is (of course) + * not ISO-conform) .. + * Layer-3 huffman table is in huffman.h + */ + +#include "mpeg3audio.h" +#include "../libmpeg3.h" +#include "../mpeg3protos.h" +#include "tables.h" + +struct al_table alloc_0[] = { + {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511}, + {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767}, + {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511}, + {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767}, + {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511}, + {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767} }; + +struct al_table alloc_1[] = { + {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511}, + {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767}, + {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511}, + {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767}, + {4,0},{5,3},{3,-3},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255},{10,-511}, + {11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {3,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767}, + {2,0},{5,3},{7,5},{16,-32767} }; + +struct al_table alloc_2[] = { + {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255}, + {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383}, + {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255}, + {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63} }; + +struct al_table alloc_3[] = { + {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255}, + {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383}, + {4,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127},{9,-255}, + {10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191},{15,-16383}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63} }; + +struct al_table alloc_4[] = { + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191}, + {4,0},{5,3},{7,5},{3,-3},{10,9},{4,-7},{5,-15},{6,-31},{7,-63},{8,-127}, + {9,-255},{10,-511},{11,-1023},{12,-2047},{13,-4095},{14,-8191}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {3,0},{5,3},{7,5},{10,9},{4,-7},{5,-15},{6,-31},{7,-63}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9}, + {2,0},{5,3},{7,5},{10,9} }; + + +int mpeg3audio_II_select_table(mpeg3audio_t *audio) +{ + static int translate[3][2][16] = + {{{ 0,2,2,2,2,2,2,0,0,0,1,1,1,1,1,0}, + { 0,2,2,0,0,0,1,1,1,1,1,1,1,1,1,0}}, + {{ 0,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0}, + { 0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0}}, + {{ 0,3,3,3,3,3,3,0,0,0,1,1,1,1,1,0}, + { 0,3,3,0,0,0,1,1,1,1,1,1,1,1,1,0}}}; + int table, sblim; + static struct al_table *tables[5] = + {alloc_0, alloc_1, alloc_2, alloc_3, alloc_4}; + static int sblims[5] = {27, 30, 8, 12, 30}; + + if(audio->lsf) + table = 4; + else + table = translate[audio->sampling_frequency_code][2 - audio->channels][audio->bitrate_index]; + sblim = sblims[table]; + + audio->alloc = tables[table]; + audio->II_sblimit = sblim; + return 0; +} + +int mpeg3audio_II_step_one(mpeg3audio_t *audio, unsigned int *bit_alloc, int *scale) +{ + int stereo = audio->channels - 1; + int sblimit = audio->II_sblimit; + int jsbound = audio->jsbound; + int sblimit2 = audio->II_sblimit << stereo; + struct al_table *alloc1 = audio->alloc; + int i, result = 0; + unsigned int *scfsi_buf = audio->layer2_scfsi_buf; + unsigned int *scfsi, *bita; + int sc, step; + + bita = bit_alloc; + if(stereo) + { +/* Stereo */ + for(i = jsbound;i ; i--, alloc1 += (1 << step)) + { + *bita++ = (char)mpeg3bits_getbits(audio->astream, step = alloc1->bits); + *bita++ = (char)mpeg3bits_getbits(audio->astream, step); + } + for(i = sblimit-jsbound; i; i--, alloc1 += (1 << step)) + { + bita[0] = (char)mpeg3bits_getbits(audio->astream, step = alloc1->bits); + bita[1] = bita[0]; + bita += 2; + } + bita = bit_alloc; + scfsi = scfsi_buf; + for(i = sblimit2; i; i--) + if(*bita++) *scfsi++ = (char)mpeg3bits_getbits(audio->astream, 2); + } + else + { +/* mono */ + for(i = sblimit; i; i--, alloc1 += (1 << step)) + *bita++ = (char)mpeg3bits_getbits(audio->astream, step = alloc1->bits); + bita = bit_alloc; + scfsi = scfsi_buf; + for(i = sblimit; i; i--) if (*bita++) *scfsi++ = (char)mpeg3bits_getbits(audio->astream, 2); + } + + bita = bit_alloc; + scfsi = scfsi_buf; + for(i = sblimit2; i; i--) + { + if(*bita++) + switch(*scfsi++) + { + case 0: + *scale++ = mpeg3bits_getbits(audio->astream, 6); + *scale++ = mpeg3bits_getbits(audio->astream, 6); + *scale++ = mpeg3bits_getbits(audio->astream, 6); + break; + case 1 : + *scale++ = sc = mpeg3bits_getbits(audio->astream, 6); + *scale++ = sc; + *scale++ = mpeg3bits_getbits(audio->astream, 6); + break; + case 2: + *scale++ = sc = mpeg3bits_getbits(audio->astream, 6); + *scale++ = sc; + *scale++ = sc; + break; + default: /* case 3 */ + *scale++ = mpeg3bits_getbits(audio->astream, 6); + *scale++ = sc = mpeg3bits_getbits(audio->astream, 6); + *scale++ = sc; + break; + } + } + return result | mpeg3bits_error(audio->astream); +} + +int mpeg3audio_II_step_two(mpeg3audio_t *audio, unsigned int *bit_alloc, mpeg3_real_t fraction[2][4][SBLIMIT], int *scale, int x1) +{ + int i, j, k, ba, result = 0; + int channels = audio->channels; + int sblimit = audio->II_sblimit; + int jsbound = audio->jsbound; + struct al_table *alloc2, *alloc1 = audio->alloc; + unsigned int *bita = bit_alloc; + int d1, step, test; + + for(i = 0; i < jsbound; i++, alloc1 += (1 << step)) + { + step = alloc1->bits; + for(j = 0; j < channels; j++) + { + if(ba = *bita++) + { + k = (alloc2 = alloc1 + ba)->bits; + if((d1 = alloc2->d) < 0) + { + mpeg3_real_t cm = mpeg3_muls[k][scale[x1]]; + + fraction[j][0][i] = ((mpeg3_real_t)((int)mpeg3bits_getbits(audio->astream, k) + d1)) * cm; + fraction[j][1][i] = ((mpeg3_real_t)((int)mpeg3bits_getbits(audio->astream, k) + d1)) * cm; + fraction[j][2][i] = ((mpeg3_real_t)((int)mpeg3bits_getbits(audio->astream, k) + d1)) * cm; + } + else + { + static int *table[] = + {0, 0, 0, mpeg3_grp_3tab, 0, mpeg3_grp_5tab, 0, 0, 0, mpeg3_grp_9tab}; + unsigned int idx, *tab, m = scale[x1]; + + idx = (unsigned int)mpeg3bits_getbits(audio->astream, k); + tab = (unsigned int*)(table[d1] + idx + idx + idx); + fraction[j][0][i] = mpeg3_muls[*tab++][m]; + fraction[j][1][i] = mpeg3_muls[*tab++][m]; + fraction[j][2][i] = mpeg3_muls[*tab][m]; + } + scale += 3; + } + else + fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0; + } + } + + for(i = jsbound; i < sblimit; i++, alloc1 += (1 << step)) + { + step = alloc1->bits; +/* channel 1 and channel 2 bitalloc are the same */ + bita++; + if((ba = *bita++)) + { + k=(alloc2 = alloc1+ba)->bits; + if((d1 = alloc2->d) < 0) + { + mpeg3_real_t cm; + + cm = mpeg3_muls[k][scale[x1 + 3]]; + fraction[1][0][i] = (fraction[0][0][i] = (mpeg3_real_t)((int)mpeg3bits_getbits(audio->astream, k) + d1)) * cm; + fraction[1][1][i] = (fraction[0][1][i] = (mpeg3_real_t)((int)mpeg3bits_getbits(audio->astream, k) + d1)) * cm; + fraction[1][2][i] = (fraction[0][2][i] = (mpeg3_real_t)((int)mpeg3bits_getbits(audio->astream, k) + d1)) * cm; + cm = mpeg3_muls[k][scale[x1]]; + fraction[0][0][i] *= cm; + fraction[0][1][i] *= cm; + fraction[0][2][i] *= cm; + } + else + { + static int *table[] = {0, 0, 0, mpeg3_grp_3tab, 0, mpeg3_grp_5tab, 0, 0, 0, mpeg3_grp_9tab}; + unsigned int idx, *tab, m1, m2; + + m1 = scale[x1]; + m2 = scale[x1+3]; + idx = (unsigned int)mpeg3bits_getbits(audio->astream, k); + tab = (unsigned int*)(table[d1] + idx + idx + idx); + fraction[0][0][i] = mpeg3_muls[*tab][m1]; + fraction[1][0][i] = mpeg3_muls[*tab++][m2]; + fraction[0][1][i] = mpeg3_muls[*tab][m1]; + fraction[1][1][i] = mpeg3_muls[*tab++][m2]; + fraction[0][2][i] = mpeg3_muls[*tab][m1]; + fraction[1][2][i] = mpeg3_muls[*tab][m2]; + } + scale += 6; + } + else + { + fraction[0][0][i] = fraction[0][1][i] = fraction[0][2][i] = + fraction[1][0][i] = fraction[1][1][i] = fraction[1][2][i] = 0.0; + } +/* + should we use individual scalefac for channel 2 or + is the current way the right one , where we just copy channel 1 to + channel 2 ?? + The current 'strange' thing is, that we throw away the scalefac + values for the second channel ...!! +-> changed .. now we use the scalefac values of channel one !! +*/ + } + + if(sblimit > SBLIMIT) sblimit = SBLIMIT; + + for(i = sblimit; i < SBLIMIT; i++) + for(j = 0; j < channels; j++) + fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0; + + return result | mpeg3bits_error(audio->astream); +} + +int mpeg3audio_dolayer2(mpeg3audio_t *audio) +{ + int i, j, result = 0; + int channels = audio->channels; + mpeg3_real_t fraction[2][4][SBLIMIT]; /* pick_table clears unused subbands */ + unsigned int bit_alloc[64]; + int scale[192]; + int single = audio->single; + + if(audio->error_protection) + mpeg3bits_getbits(audio->astream, 16); + + mpeg3audio_II_select_table(audio); + + audio->jsbound = (audio->mode == MPG_MD_JOINT_STEREO) ? + (audio->mode_ext << 2) + 4 : audio->II_sblimit; + + if(channels == 1 || single == 3) + single = 0; + + result |= mpeg3audio_II_step_one(audio, bit_alloc, scale); + + for(i = 0; i < SCALE_BLOCK && !result; i++) + { + result |= mpeg3audio_II_step_two(audio, bit_alloc, fraction, scale, i >> 2); + + for(j = 0; j < 3; j++) + { + if(single >= 0) + { +/* Monaural */ + mpeg3audio_synth_mono(audio, fraction[single][j], audio->pcm_sample, &(audio->pcm_point)); + } + else + { +/* Stereo */ + int p1 = audio->pcm_point; + mpeg3audio_synth_stereo(audio, fraction[0][j], 0, audio->pcm_sample, &p1); + mpeg3audio_synth_stereo(audio, fraction[1][j], 1, audio->pcm_sample, &(audio->pcm_point)); + } + + if(audio->pcm_point / audio->channels >= audio->pcm_allocated - MPEG3AUDIO_PADDING * audio->channels) + { +/* Need more room */ + mpeg3audio_replace_buffer(audio, audio->pcm_allocated + MPEG3AUDIO_PADDING * audio->channels); + } + } + } + + + return result; +} diff --git a/core/multimedia/opieplayer/libmpeg3/audio/layer3.c b/core/multimedia/opieplayer/libmpeg3/audio/layer3.c new file mode 100644 index 0000000..b8a5f06 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/layer3.c @@ -0,0 +1,1254 @@ +#include "huffman.h" +#include "mpeg3audio.h" +#include "../libmpeg3.h" +#include "../mpeg3protos.h" +#include "tables.h" + +#include <stdio.h> +#include <string.h> + +struct gr_info_s { + int scfsi; + unsigned part2_3_length; + unsigned big_values; + unsigned scalefac_compress; + unsigned block_type; + unsigned mixed_block_flag; + unsigned table_select[3]; + unsigned subblock_gain[3]; + unsigned maxband[3]; + unsigned maxbandl; + unsigned maxb; + unsigned region1start; + unsigned region2start; + unsigned preflag; + unsigned scalefac_scale; + unsigned count1table_select; + mpeg3_real_t *full_gain[3]; + mpeg3_real_t *pow2gain; +}; + +struct mpeg3_III_sideinfo +{ + unsigned main_data_begin; + unsigned private_bits; + struct + { + struct gr_info_s gr[2]; + } ch[2]; +}; + +int mpeg3audio_III_get_scale_factors_1(mpeg3audio_t *audio, + int *scf, + struct gr_info_s *gr_info, + int ch, + int gr) +{ + static unsigned char slen[2][16] = + {{0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4}, + {0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3}}; + int numbits; + int num0 = slen[0][gr_info->scalefac_compress]; + int num1 = slen[1][gr_info->scalefac_compress]; + + if (gr_info->block_type == 2) + { + int i = 18; + numbits = (num0 + num1) * 18; + + if (gr_info->mixed_block_flag) + { + for(i = 8; i; i--) + *scf++ = mpeg3bits_getbits(audio->astream, num0); + i = 9; +/* num0 * 17 + num1 * 18 */ + numbits -= num0; + } + + for( ; i; i--) + *scf++ = mpeg3bits_getbits(audio->astream, num0); + for(i = 18; i; i--) + *scf++ = mpeg3bits_getbits(audio->astream, num1); +/* short[13][0..2] = 0 */ + *scf++ = 0; + *scf++ = 0; + *scf++ = 0; + } + else + { + int i; + int scfsi = gr_info->scfsi; + + if(scfsi < 0) + { +/* scfsi < 0 => granule == 0 */ + for(i = 11; i; i--) + { + *scf++ = mpeg3bits_getbits(audio->astream, num0); + } + for(i = 10; i; i--) + *scf++ = mpeg3bits_getbits(audio->astream, num1); + numbits = (num0 + num1) * 10 + num0; + *scf++ = 0; + } + else + { + numbits = 0; + if(!(scfsi & 0x8)) + { + for(i = 0; i < 6; i++) + { + *scf++ = mpeg3bits_getbits(audio->astream, num0); + } + numbits += num0 * 6; + } + else + { + scf += 6; + } + + if(!(scfsi & 0x4)) + { + for(i = 0; i < 5; i++) + *scf++ = mpeg3bits_getbits(audio->astream, num0); + numbits += num0 * 5; + } + else + { + scf += 5; + } + + if(!(scfsi & 0x2)) + { + for(i = 0; i < 5; i++) + *scf++ = mpeg3bits_getbits(audio->astream, num1); + numbits += num1 * 5; + } + else + { + scf += 5; + } + + if(!(scfsi & 0x1)) + { + for(i = 0; i < 5; i++) + *scf++ = mpeg3bits_getbits(audio->astream, num1); + numbits += num1 * 5; + } + else + { + scf += 5; + } + *scf++ = 0; /* no l[21] in original sources */ + } + } + return numbits; +} + +int mpeg3audio_III_get_scale_factors_2(mpeg3audio_t *audio, + int *scf, + struct gr_info_s *gr_info, + int i_stereo) +{ + unsigned char *pnt; + int i, j, n = 0, numbits = 0; + unsigned int slen; + static unsigned char stab[3][6][4] = + {{{ 6, 5, 5,5 }, { 6, 5, 7,3 }, { 11,10,0,0}, + { 7, 7, 7,0 }, { 6, 6, 6,3 }, { 8, 8,5,0}}, + {{ 9, 9, 9,9 }, { 9, 9,12,6 }, { 18,18,0,0}, + {12,12,12,0 }, {12, 9, 9,6 }, { 15,12,9,0}}, + {{ 6, 9, 9,9 }, { 6, 9,12,6 }, { 15,18,0,0}, + { 6,15,12,0 }, { 6,12, 9,6 }, { 6,18,9,0}}}; + +/* i_stereo AND second channel -> do_layer3() checks this */ + if(i_stereo) + slen = mpeg3_i_slen2[gr_info->scalefac_compress >> 1]; + else + slen = mpeg3_n_slen2[gr_info->scalefac_compress]; + + gr_info->preflag = (slen >> 15) & 0x1; + + n = 0; + if(gr_info->block_type == 2 ) + { + n++; + if(gr_info->mixed_block_flag) + n++; + } + + pnt = stab[n][(slen >> 12) & 0x7]; + + for(i = 0; i < 4; i++) + { + int num = slen & 0x7; + slen >>= 3; + if(num) + { + for(j = 0; j < (int)(pnt[i]); j++) + *scf++ = mpeg3bits_getbits(audio->astream, num); + numbits += pnt[i] * num; + } + else + { + for(j = 0; j < (int)(pnt[i]); j++) + *scf++ = 0; + } + } + + n = (n << 1) + 1; + for(i = 0; i < n; i++) + *scf++ = 0; + + return numbits; +} + +static int pretab1[22] = {0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2,0}; +static int pretab2[22] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; + +/* + * Dequantize samples (includes huffman decoding) + * + * 24 is enough because tab13 has max. a 19 bit huffvector + */ + +#define BITSHIFT ((sizeof(long) - 1) * 8) +#define REFRESH_MASK \ + while(num < BITSHIFT) \ + { \ + mask |= mpeg3bits_getbits(audio->astream, 8) << (BITSHIFT - num); \ + num += 8; \ + part2remain -= 8; \ + } + +int mpeg3audio_III_dequantize_sample(mpeg3audio_t *audio, + mpeg3_real_t xr[SBLIMIT][SSLIMIT], + int *scf, + struct gr_info_s *gr_info, + int sfreq, + int part2bits) +{ + int shift = 1 + gr_info->scalefac_scale; + mpeg3_real_t *xrpnt = (mpeg3_real_t*)xr; + int l[3],l3; + int part2remain = gr_info->part2_3_length - part2bits; + int *me; + int num = mpeg3bits_getbitoffset(audio->astream); + long mask = mpeg3bits_getbits(audio->astream, num); +//printf("III_dequantize_sample 1 %08x %d\n", mask, num); + mask = mask << (BITSHIFT + 8 - num); + part2remain -= num; + + { + int bv = gr_info->big_values; + int region1 = gr_info->region1start; + int region2 = gr_info->region2start; + + l3 = ((576 >> 1) - bv) >> 1; + +/* + * we may lose the 'odd' bit here !! + * check this later again + */ + + if(bv <= region1) + { + l[0] = bv; + l[1] = 0; + l[2] = 0; + } + else + { + l[0] = region1; + if(bv <= region2) + { + l[1] = bv - l[0]; l[2] = 0; + } + else + { + l[1] = region2 - l[0]; + l[2] = bv - region2; + } + } + } + + if(gr_info->block_type == 2) + { +/* + * decoding with short or mixed mode BandIndex table + */ + int i, max[4]; + int step = 0, lwin = 3, cb = 0; + register mpeg3_real_t v = 0.0; + register int *m, mc; + + if(gr_info->mixed_block_flag) + { + max[3] = -1; + max[0] = max[1] = max[2] = 2; + m = mpeg3_map[sfreq][0]; + me = mpeg3_mapend[sfreq][0]; + } + else + { + max[0] = max[1] = max[2] = max[3] = -1; +/* max[3] not floatly needed in this case */ + m = mpeg3_map[sfreq][1]; + me = mpeg3_mapend[sfreq][1]; + } + + mc = 0; + for(i = 0; i < 2; i++) + { + int lp = l[i]; + struct newhuff *h = mpeg3_ht + gr_info->table_select[i]; + for( ; lp; lp--, mc--) + { + register int x,y; + if(!mc) + { + mc = *m++; + xrpnt = ((mpeg3_real_t*)xr) + (*m++); + lwin = *m++; + cb = *m++; + if(lwin == 3) + { + v = gr_info->pow2gain[(*scf++) << shift]; + step = 1; + } + else + { + v = gr_info->full_gain[lwin][(*scf++) << shift]; + step = 3; + } + } + + { + register short *val = h->table; + REFRESH_MASK; + while((y = *val++) < 0) + { + if (mask < 0) + val -= y; + num--; + mask <<= 1; + } + x = y >> 4; + y &= 0xf; + } + + if(x == 15 && h->linbits) + { + max[lwin] = cb; + REFRESH_MASK; + x += ((unsigned long)mask) >> (BITSHIFT + 8 - h->linbits); + num -= h->linbits + 1; + mask <<= h->linbits; + if(mask < 0) + *xrpnt = -mpeg3_ispow[x] * v; + else + *xrpnt = mpeg3_ispow[x] * v; + mask <<= 1; + } + else + if(x) + { + max[lwin] = cb; + if(mask < 0) + *xrpnt = -mpeg3_ispow[x] * v; + else + *xrpnt = mpeg3_ispow[x] * v; + num--; + mask <<= 1; + } + else + *xrpnt = 0.0; + + xrpnt += step; + if(y == 15 && h->linbits) + { + max[lwin] = cb; + REFRESH_MASK; + y += ((unsigned long) mask) >> (BITSHIFT + 8 - h->linbits); + num -= h->linbits + 1; + mask <<= h->linbits; + if(mask < 0) + *xrpnt = -mpeg3_ispow[y] * v; + else + *xrpnt = mpeg3_ispow[y] * v; + mask <<= 1; + } + else + if(y) + { + max[lwin] = cb; + if(mask < 0) + *xrpnt = -mpeg3_ispow[y] * v; + else + *xrpnt = mpeg3_ispow[y] * v; + num--; + mask <<= 1; + } + else + *xrpnt = 0.0; + xrpnt += step; + } + } + + for( ;l3 && (part2remain + num > 0); l3--) + { + struct newhuff *h = mpeg3_htc + gr_info->count1table_select; + register short *val = h->table, a; + + REFRESH_MASK; + while((a = *val++) < 0) + { + if (mask < 0) + val -= a; + num--; + mask <<= 1; + } + if(part2remain + num <= 0) + { + num -= part2remain + num; + break; + } + + for(i = 0; i < 4; i++) + { + if(!(i & 1)) + { + if(!mc) + { + mc = *m++; + xrpnt = ((mpeg3_real_t*)xr) + (*m++); + lwin = *m++; + cb = *m++; + if(lwin == 3) + { + v = gr_info->pow2gain[(*scf++) << shift]; + step = 1; + } + else + { + v = gr_info->full_gain[lwin][(*scf++) << shift]; + step = 3; + } + } + mc--; + } + if((a & (0x8 >> i))) + { + max[lwin] = cb; + if(part2remain + num <= 0) + { + break; + } + if(mask < 0) + *xrpnt = -v; + else + *xrpnt = v; + num--; + mask <<= 1; + } + else + *xrpnt = 0.0; + xrpnt += step; + } + } + + if(lwin < 3) + { +/* short band? */ + while(1) + { + for( ;mc > 0; mc--) + { +/* short band -> step=3 */ + *xrpnt = 0.0; + xrpnt += 3; + *xrpnt = 0.0; + xrpnt += 3; + } + if(m >= me) + break; + mc = *m++; + xrpnt = ((mpeg3_real_t*)xr) + *m++; +/* optimize: field will be set to zero at the end of the function */ + if(*m++ == 0) + break; +/* cb */ + m++; + } + } + + gr_info->maxband[0] = max[0] + 1; + gr_info->maxband[1] = max[1] + 1; + gr_info->maxband[2] = max[2] + 1; + gr_info->maxbandl = max[3] + 1; + + { + int rmax = max[0] > max[1] ? max[0] : max[1]; + rmax = (rmax > max[2] ? rmax : max[2]) + 1; + gr_info->maxb = rmax ? mpeg3_shortLimit[sfreq][rmax] : mpeg3_longLimit[sfreq][max[3] + 1]; + } + + } + else + { +/* + * decoding with 'long' BandIndex table (block_type != 2) + */ + int *pretab = gr_info->preflag ? pretab1 : pretab2; + int i, max = -1; + int cb = 0; + int *m = mpeg3_map[sfreq][2]; + register mpeg3_real_t v = 0.0; + int mc = 0; + +/* + * long hash table values + */ + for(i = 0; i < 3; i++) + { + int lp = l[i]; + struct newhuff *h = mpeg3_ht + gr_info->table_select[i]; + + for(; lp; lp--, mc--) + { + int x, y; + + if(!mc) + { + mc = *m++; + cb = *m++; + if(cb == 21) + v = 0.0; + else + v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift]; + } + { + register short *val = h->table; + REFRESH_MASK; + while((y = *val++) < 0) + { + if(mask < 0) + val -= y; + num--; + mask <<= 1; + } + x = y >> 4; + y &= 0xf; + } + + if(x == 15 && h->linbits) + { + max = cb; + REFRESH_MASK; + x += ((unsigned long) mask) >> (BITSHIFT + 8 - h->linbits); + num -= h->linbits + 1; + mask <<= h->linbits; + if(mask < 0) + *xrpnt++ = -mpeg3_ispow[x] * v; + else + *xrpnt++ = mpeg3_ispow[x] * v; + mask <<= 1; + } + else + if(x) + { + max = cb; + if(mask < 0) + *xrpnt++ = -mpeg3_ispow[x] * v; + else + *xrpnt++ = mpeg3_ispow[x] * v; + num--; + mask <<= 1; + } + else + *xrpnt++ = 0.0; + + if(y == 15 && h->linbits) + { + max = cb; + REFRESH_MASK; + y += ((unsigned long) mask) >> (BITSHIFT + 8 - h->linbits); + num -= h->linbits + 1; + mask <<= h->linbits; + if(mask < 0) + *xrpnt++ = -mpeg3_ispow[y] * v; + else + *xrpnt++ = mpeg3_ispow[y] * v; + mask <<= 1; + } + else + if(y) + { + max = cb; + if(mask < 0) + *xrpnt++ = -mpeg3_ispow[y] * v; + else + *xrpnt++ = mpeg3_ispow[y] * v; + num--; + mask <<= 1; + } + else + *xrpnt++ = 0.0; + } + } + +/* + * short (count1table) values + */ + for( ; l3 && (part2remain + num > 0); l3--) + { + struct newhuff *h = mpeg3_htc + gr_info->count1table_select; + register short *val = h->table, a; + + REFRESH_MASK; + while((a = *val++) < 0) + { + if(mask < 0) + val -= a; + num--; + mask <<= 1; + } + if(part2remain + num <= 0) + { + num -= part2remain + num; + break; + } + + for(i = 0; i < 4; i++) + { + if(!(i & 1)) + { + if(!mc) + { + mc = *m++; + cb = *m++; + if(cb == 21) + v = 0.0; + else + v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift]; + } + mc--; + } + if((a & (0x8 >> i))) + { + max = cb; + if(part2remain + num <= 0) + { + break; + } + if(mask < 0) + *xrpnt++ = -v; + else + *xrpnt++ = v; + num--; + mask <<= 1; + } + else + *xrpnt++ = 0.0; + } + } + + gr_info->maxbandl = max + 1; + gr_info->maxb = mpeg3_longLimit[sfreq][gr_info->maxbandl]; + } + + part2remain += num; + +//printf("III_dequantize_sample 2 %d %04x\n", num, mpeg3bits_showbits(audio->astream, 16)); + mpeg3bits_start_reverse(audio->astream); + mpeg3bits_getbits_reverse(audio->astream, num); + mpeg3bits_start_forward(audio->astream); +//printf("III_dequantize_sample 3 %d %04x\n", audio->astream->bit_number, mpeg3bits_showbits(audio->astream, 16)); + num = 0; + + while(xrpnt < &xr[SBLIMIT][0]) + *xrpnt++ = 0.0; + + while(part2remain > 16) + { + mpeg3bits_getbits(audio->astream, 16); /* Dismiss stuffing Bits */ + part2remain -= 16; + } + if(part2remain > 0) + { + mpeg3bits_getbits(audio->astream, part2remain); + } + else + if(part2remain < 0) + { + fprintf(stderr,"mpeg3audio_III_dequantize_sample: Can't rewind stream %d bits!\n", -part2remain); + return 1; /* -> error */ + } + return 0; +} + +int mpeg3audio_III_get_side_info(mpeg3audio_t *audio, + struct mpeg3_III_sideinfo *si, + int channels, + int ms_stereo, + long sfreq, + int single, + int lsf) +{ + int ch, gr; + int powdiff = (single == 3) ? 4 : 0; + static const int tabs[2][5] = { { 2,9,5,3,4 } , { 1,8,1,2,9 } }; + const int *tab = tabs[lsf]; + + si->main_data_begin = mpeg3bits_getbits(audio->astream, tab[1]); + if(channels == 1) + si->private_bits = mpeg3bits_getbits(audio->astream, tab[2]); + else + si->private_bits = mpeg3bits_getbits(audio->astream, tab[3]); + if(!lsf) + { + for(ch = 0; ch < channels; ch++) + { + si->ch[ch].gr[0].scfsi = -1; + si->ch[ch].gr[1].scfsi = mpeg3bits_getbits(audio->astream, 4); + } + } + + for(gr = 0; gr < tab[0]; gr++) + { + for(ch = 0; ch < channels; ch++) + { + register struct gr_info_s *gr_info = &(si->ch[ch].gr[gr]); + + gr_info->part2_3_length = mpeg3bits_getbits(audio->astream, 12); + gr_info->big_values = mpeg3bits_getbits(audio->astream, 9); + if(gr_info->big_values > 288) + { + fprintf(stderr,"mpeg3_III_get_side_info: big_values too large!\n"); + gr_info->big_values = 288; + } + gr_info->pow2gain = mpeg3_gainpow2 + 256 - mpeg3bits_getbits(audio->astream, 8) + powdiff; + if(ms_stereo) + gr_info->pow2gain += 2; + gr_info->scalefac_compress = mpeg3bits_getbits(audio->astream, tab[4]); + + if(mpeg3bits_getbits(audio->astream, 1)) + { +/* window switch flag */ + int i; + gr_info->block_type = mpeg3bits_getbits(audio->astream, 2); + gr_info->mixed_block_flag = mpeg3bits_getbits(audio->astream, 1); + gr_info->table_select[0] = mpeg3bits_getbits(audio->astream, 5); + gr_info->table_select[1] = mpeg3bits_getbits(audio->astream, 5); +/* + * table_select[2] not needed, because there is no region2, + * but to satisfy some verifications tools we set it either. + */ + gr_info->table_select[2] = 0; + for(i = 0; i < 3; i++) + gr_info->full_gain[i] = gr_info->pow2gain + (mpeg3bits_getbits(audio->astream, 3) << 3); + + if(gr_info->block_type == 0) + { + fprintf(stderr,"Blocktype == 0 and window-switching == 1 not allowed.\n"); + return 1; + } + +/* region_count/start parameters are implicit in this case. */ + if(!lsf || gr_info->block_type == 2) + gr_info->region1start = 36 >> 1; + else + { +/* check this again for 2.5 and sfreq=8 */ + if(sfreq == 8) + gr_info->region1start = 108 >> 1; + else + gr_info->region1start = 54 >> 1; + } + gr_info->region2start = 576 >> 1; + } + else + { + int i, r0c, r1c; + for(i = 0; i < 3; i++) + gr_info->table_select[i] = mpeg3bits_getbits(audio->astream, 5); + + r0c = mpeg3bits_getbits(audio->astream, 4); + r1c = mpeg3bits_getbits(audio->astream, 3); + gr_info->region1start = mpeg3_bandInfo[sfreq].longIdx[r0c + 1] >> 1 ; + gr_info->region2start = mpeg3_bandInfo[sfreq].longIdx[r0c + 1 + r1c + 1] >> 1; + gr_info->block_type = 0; + gr_info->mixed_block_flag = 0; + } + if(!lsf) gr_info->preflag = mpeg3bits_getbits(audio->astream, 1); + gr_info->scalefac_scale = mpeg3bits_getbits(audio->astream, 1); + gr_info->count1table_select = mpeg3bits_getbits(audio->astream, 1); + } + } + return 0; +} + +int mpeg3audio_III_hybrid(mpeg3audio_t *audio, + mpeg3_real_t fsIn[SBLIMIT][SSLIMIT], + mpeg3_real_t tsOut[SSLIMIT][SBLIMIT], + int ch, + struct gr_info_s *gr_info) +{ + mpeg3_real_t *tspnt = (mpeg3_real_t *) tsOut; + mpeg3_real_t *rawout1,*rawout2; + int bt, sb = 0; + + + { + int b = audio->mp3_blc[ch]; + rawout1 = audio->mp3_block[b][ch]; + b = -b + 1; + rawout2 = audio->mp3_block[b][ch]; + audio->mp3_blc[ch] = b; + } + + if(gr_info->mixed_block_flag) + { + sb = 2; + mpeg3audio_dct36(fsIn[0], rawout1, rawout2, mpeg3_win[0], tspnt); + mpeg3audio_dct36(fsIn[1], rawout1 + 18, rawout2 + 18, mpeg3_win1[0], tspnt + 1); + rawout1 += 36; + rawout2 += 36; + tspnt += 2; + } + + bt = gr_info->block_type; + if(bt == 2) + { + for( ; sb < gr_info->maxb; sb += 2, tspnt += 2, rawout1 += 36, rawout2 += 36) + { + mpeg3audio_dct12(fsIn[sb] ,rawout1 ,rawout2 ,mpeg3_win[2] ,tspnt); + mpeg3audio_dct12(fsIn[sb + 1], rawout1 + 18, rawout2 + 18, mpeg3_win1[2], tspnt + 1); + } + } + else + { + for( ; sb < gr_info->maxb; sb += 2, tspnt += 2, rawout1 += 36, rawout2 += 36) + { + mpeg3audio_dct36(fsIn[sb], rawout1, rawout2, mpeg3_win[bt], tspnt); + mpeg3audio_dct36(fsIn[sb + 1], rawout1 + 18, rawout2 + 18, mpeg3_win1[bt], tspnt + 1); + } + } + + for( ; sb < SBLIMIT; sb++, tspnt++) + { + int i; + for(i = 0; i < SSLIMIT; i++) + { + tspnt[i * SBLIMIT] = *rawout1++; + *rawout2++ = 0.0; + } + } + return 0; +} + +int mpeg3audio_III_antialias(mpeg3audio_t *audio, + mpeg3_real_t xr[SBLIMIT][SSLIMIT], + struct gr_info_s *gr_info) +{ + int sblim; + + if(gr_info->block_type == 2) + { + if(!gr_info->mixed_block_flag) + return 0; + sblim = 1; + } + else + { + sblim = gr_info->maxb-1; + } + +/* 31 alias-reduction operations between each pair of sub-bands */ +/* with 8 butterflies between each pair */ + + { + int sb; + mpeg3_real_t *xr1 = (mpeg3_real_t*)xr[1]; + + for(sb = sblim; sb; sb--, xr1 += 10) + { + int ss; + mpeg3_real_t *cs, *ca; + mpeg3_real_t *xr2; + cs = mpeg3_aa_cs; + ca = mpeg3_aa_ca; + xr2 = xr1; + + for(ss = 7; ss >= 0; ss--) + { +/* upper and lower butterfly inputs */ + register mpeg3_real_t bu, bd; + bu = *--xr2; + bd = *xr1; + *xr2 = (bu * (*cs) ) - (bd * (*ca) ); + *xr1++ = (bd * (*cs++) ) + (bu * (*ca++) ); + } + } + } + return 0; +} + +/* + * III_stereo: calculate mpeg3_real_t channel values for Joint-I-Stereo-mode + */ +int mpeg3audio_III_i_stereo(mpeg3audio_t *audio, + mpeg3_real_t xr_buf[2][SBLIMIT][SSLIMIT], + int *scalefac, + struct gr_info_s *gr_info, + int sfreq, + int ms_stereo, + int lsf) +{ + mpeg3_real_t (*xr)[SBLIMIT*SSLIMIT] = (mpeg3_real_t (*)[SBLIMIT*SSLIMIT] ) xr_buf; + struct mpeg3_bandInfoStruct *bi = &mpeg3_bandInfo[sfreq]; + const mpeg3_real_t *tab1, *tab2; + + int tab; +/* TODO: optimize as static */ + static const mpeg3_real_t *tabs[3][2][2] = + { + { { mpeg3_tan1_1, mpeg3_tan2_1 } , { mpeg3_tan1_2, mpeg3_tan2_2 } }, + { { mpeg3_pow1_1[0], mpeg3_pow2_1[0] } , { mpeg3_pow1_2[0], mpeg3_pow2_2[0] } } , + { { mpeg3_pow1_1[1], mpeg3_pow2_1[1] } , { mpeg3_pow1_2[1], mpeg3_pow2_2[1] } } + }; + + tab = lsf + (gr_info->scalefac_compress & lsf); + tab1 = tabs[tab][ms_stereo][0]; + tab2 = tabs[tab][ms_stereo][1]; + + if(gr_info->block_type == 2) + { + int lwin,do_l = 0; + if(gr_info->mixed_block_flag) + do_l = 1; + + for(lwin = 0; lwin < 3; lwin++) + { +/* process each window */ +/* get first band with zero values */ +/* sfb is minimal 3 for mixed mode */ + int is_p, sb, idx, sfb = gr_info->maxband[lwin]; + if(sfb > 3) do_l = 0; + + for( ; sfb < 12 ; sfb++) + { +/* scale: 0-15 */ + is_p = scalefac[sfb * 3 + lwin - gr_info->mixed_block_flag]; + if(is_p != 7) + { + mpeg3_real_t t1, t2; + sb = bi->shortDiff[sfb]; + idx = bi->shortIdx[sfb] + lwin; + t1 = tab1[is_p]; + t2 = tab2[is_p]; + for( ; sb > 0; sb--, idx += 3) + { + mpeg3_real_t v = xr[0][idx]; + xr[0][idx] = v * t1; + xr[1][idx] = v * t2; + } + } + } + +/* in the original: copy 10 to 11 , here: copy 11 to 12 +maybe still wrong??? (copy 12 to 13?) */ +/* scale: 0-15 */ + is_p = scalefac[11 * 3 + lwin - gr_info->mixed_block_flag]; + sb = bi->shortDiff[12]; + idx = bi->shortIdx[12] + lwin; + if(is_p != 7) + { + mpeg3_real_t t1, t2; + t1 = tab1[is_p]; + t2 = tab2[is_p]; + for( ; sb > 0; sb--, idx += 3) + { + mpeg3_real_t v = xr[0][idx]; + xr[0][idx] = v * t1; + xr[1][idx] = v * t2; + } + } + } /* end for(lwin; .. ; . ) */ + +/* also check l-part, if ALL bands in the three windows are 'empty' +* and mode = mixed_mode +*/ + if(do_l) + { + int sfb = gr_info->maxbandl; + int idx = bi->longIdx[sfb]; + + for ( ; sfb < 8; sfb++) + { + int sb = bi->longDiff[sfb]; +/* scale: 0-15 */ + int is_p = scalefac[sfb]; + if(is_p != 7) + { + mpeg3_real_t t1, t2; + t1 = tab1[is_p]; + t2 = tab2[is_p]; + for( ; sb > 0; sb--, idx++) + { + mpeg3_real_t v = xr[0][idx]; + xr[0][idx] = v * t1; + xr[1][idx] = v * t2; + } + } + else + idx += sb; + } + } + } + else + { +/* ((gr_info->block_type != 2)) */ + int sfb = gr_info->maxbandl; + int is_p, idx = bi->longIdx[sfb]; + for( ; sfb < 21; sfb++) + { + int sb = bi->longDiff[sfb]; +/* scale: 0-15 */ + is_p = scalefac[sfb]; + if(is_p != 7) + { + mpeg3_real_t t1, t2; + t1 = tab1[is_p]; + t2 = tab2[is_p]; + for( ; sb > 0; sb--, idx++) + { + mpeg3_real_t v = xr[0][idx]; + xr[0][idx] = v * t1; + xr[1][idx] = v * t2; + } + } + else + idx += sb; + } + + is_p = scalefac[20]; + if(is_p != 7) + { +/* copy l-band 20 to l-band 21 */ + int sb; + mpeg3_real_t t1 = tab1[is_p], t2 = tab2[is_p]; + + for(sb = bi->longDiff[21]; sb > 0; sb--, idx++) + { + mpeg3_real_t v = xr[0][idx]; + xr[0][idx] = v * t1; + xr[1][idx] = v * t2; + } + } + } /* ... */ +} + +/* Read just the frame after a seek. */ +int mpeg3audio_read_layer3_frame(mpeg3audio_t *audio) +{ + int result = 0; + + result = mpeg3audio_read_header(audio); + if(!result) + { + audio->bsbufold = audio->bsbuf; + audio->bsbuf = audio->bsspace[audio->bsnum] + 512; + audio->bsnum ^= 1; + result = mpeg3bits_read_buffer(audio->astream, audio->bsbuf, audio->framesize); + } + + return result; +} + +int mpeg3audio_dolayer3(mpeg3audio_t *audio) +{ + int gr, ch, ss; + int scalefacs[2][39]; /* max 39 for short[13][3] mode, mixed: 38, long: 22 */ + struct mpeg3_III_sideinfo sideinfo; + int channels = audio->channels; + int single = audio->single; + int ms_stereo, i_stereo; + int sfreq = audio->sampling_frequency_code; + int stereo1, granules; + int i; + +/* flip/init buffer */ + audio->bsbufold = audio->bsbuf; + audio->bsbuf = audio->bsspace[audio->bsnum] + 512; + audio->bsnum ^= 1; + +/* read main data into memory */ + if(mpeg3bits_read_buffer(audio->astream, audio->bsbuf, audio->framesize)) + return 1; + mpeg3bits_use_ptr(audio->astream, audio->bsbuf); + +/* CRC must be skipped here for proper alignment with the backstep */ + if(audio->error_protection) + mpeg3bits_getbits(audio->astream, 16); + + if(channels == 1) + { +/* stream is mono */ + stereo1 = 1; + single = 0; + } + else + { +/* Stereo */ + stereo1 = 2; + } + + if(audio->mode == MPG_MD_JOINT_STEREO) + { + ms_stereo = (audio->mode_ext & 0x2) >> 1; + i_stereo = audio->mode_ext & 0x1; + } + else + ms_stereo = i_stereo = 0; + + if(audio->lsf) + { + granules = 1; + } + else + { + granules = 2; + } + + if(mpeg3audio_III_get_side_info(audio, &sideinfo, channels, ms_stereo, sfreq, single, audio->lsf)) + return 1; + +/* Step back */ + if(sideinfo.main_data_begin >= 512) + return 1; + + if(sideinfo.main_data_begin) + { + memcpy(audio->bsbuf + audio->ssize - sideinfo.main_data_begin, + audio->bsbufold + audio->prev_framesize - sideinfo.main_data_begin, + sideinfo.main_data_begin); + mpeg3bits_use_ptr(audio->astream, audio->bsbuf + audio->ssize - sideinfo.main_data_begin); + } + + for(gr = 0; gr < granules; gr++) + { + mpeg3_real_t hybridIn [2][SBLIMIT][SSLIMIT]; + mpeg3_real_t hybridOut[2][SSLIMIT][SBLIMIT]; + + { + struct gr_info_s *gr_info = &(sideinfo.ch[0].gr[gr]); + long part2bits; + if(audio->lsf) + part2bits = mpeg3audio_III_get_scale_factors_2(audio, scalefacs[0], gr_info, 0); + else + part2bits = mpeg3audio_III_get_scale_factors_1(audio, scalefacs[0], gr_info, 0, gr); +//printf("dolayer3 4 %04x\n", mpeg3bits_showbits(audio->astream, 16)); + + if(mpeg3audio_III_dequantize_sample(audio, hybridIn[0], scalefacs[0], gr_info, sfreq, part2bits)) + { + mpeg3bits_use_demuxer(audio->astream); + return 1; + } +//printf("dolayer3 5 %04x\n", mpeg3bits_showbits(audio->astream, 16)); + } + + if(channels == 2) + { + struct gr_info_s *gr_info = &(sideinfo.ch[1].gr[gr]); + long part2bits; + if(audio->lsf) + part2bits = mpeg3audio_III_get_scale_factors_2(audio, scalefacs[1], gr_info, i_stereo); + else + part2bits = mpeg3audio_III_get_scale_factors_1(audio, scalefacs[1], gr_info, 1, gr); + + if(mpeg3audio_III_dequantize_sample(audio, hybridIn[1], scalefacs[1], gr_info, sfreq, part2bits)) + { + mpeg3bits_use_demuxer(audio->astream); + return 1; + } + + if(ms_stereo) + { + int i; + int maxb = sideinfo.ch[0].gr[gr].maxb; + if(sideinfo.ch[1].gr[gr].maxb > maxb) + maxb = sideinfo.ch[1].gr[gr].maxb; + for(i = 0; i < SSLIMIT * maxb; i++) + { + mpeg3_real_t tmp0 = ((mpeg3_real_t*)hybridIn[0])[i]; + mpeg3_real_t tmp1 = ((mpeg3_real_t*)hybridIn[1])[i]; + ((mpeg3_real_t*)hybridIn[0])[i] = tmp0 + tmp1; + ((mpeg3_real_t*)hybridIn[1])[i] = tmp0 - tmp1; + } + } + + if(i_stereo) + mpeg3audio_III_i_stereo(audio, hybridIn, scalefacs[1], gr_info, sfreq, ms_stereo, audio->lsf); + + if(ms_stereo || i_stereo || (single == 3)) + { + if(gr_info->maxb > sideinfo.ch[0].gr[gr].maxb) + sideinfo.ch[0].gr[gr].maxb = gr_info->maxb; + else + gr_info->maxb = sideinfo.ch[0].gr[gr].maxb; + } + + switch(single) + { + case 3: + { + register int i; + register mpeg3_real_t *in0 = (mpeg3_real_t*)hybridIn[0], *in1 = (mpeg3_real_t*)hybridIn[1]; +/* *0.5 done by pow-scale */ + for(i = 0; i < SSLIMIT * gr_info->maxb; i++, in0++) + *in0 = (*in0 + *in1++); + } + break; + case 1: + { + register int i; + register mpeg3_real_t *in0 = (mpeg3_real_t*)hybridIn[0], *in1 = (mpeg3_real_t*)hybridIn[1]; + for(i = 0; i < SSLIMIT * gr_info->maxb; i++) + *in0++ = *in1++; + } + break; + } + } + + for(ch = 0; ch < stereo1; ch++) + { + struct gr_info_s *gr_info = &(sideinfo.ch[ch].gr[gr]); + mpeg3audio_III_antialias(audio, hybridIn[ch], gr_info); + mpeg3audio_III_hybrid(audio, hybridIn[ch], hybridOut[ch], ch, gr_info); + } + + for(ss = 0; ss < SSLIMIT; ss++) + { + if(single >= 0) + { + mpeg3audio_synth_mono(audio, hybridOut[0][ss], audio->pcm_sample, &(audio->pcm_point)); + } + else + { + int p1 = audio->pcm_point; + mpeg3audio_synth_stereo(audio, hybridOut[0][ss], 0, audio->pcm_sample, &p1); + mpeg3audio_synth_stereo(audio, hybridOut[1][ss], 1, audio->pcm_sample, &(audio->pcm_point)); + } + + if(audio->pcm_point / audio->channels >= audio->pcm_allocated - MPEG3AUDIO_PADDING * audio->channels) + { +/* Need more room */ + mpeg3audio_replace_buffer(audio, audio->pcm_allocated + MPEG3AUDIO_PADDING * audio->channels); + } + } + } + + mpeg3bits_use_demuxer(audio->astream); + return 0; +} diff --git a/core/multimedia/opieplayer/libmpeg3/audio/mantissa.c b/core/multimedia/opieplayer/libmpeg3/audio/mantissa.c new file mode 100644 index 0000000..05fe251 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/mantissa.c @@ -0,0 +1,387 @@ +/* + * + * mantissa.c Copyright (C) Aaron Holtzman - May 1999 + * + * + * This file is part of libmpeg3 + * + * libmpeg3 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * libmpeg3 is distributed in the hope that 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 GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include "mpeg3audio.h" +#include "../libmpeg3.h" +#include "../mpeg3protos.h" + + +/* Lookup tables of 0.16 two's complement quantization values */ +static short mpeg3_q_1[3] = +{ + (-2 << 15) / 3, + 0, + (2 << 15) / 3 +}; + +static short mpeg3_q_2[5] = +{ + (-4 << 15) / 5, + ((-2 << 15) / 5) << 1, + 0, + (2 << 15) / 5, + ((4 << 15) / 5) << 1 +}; + +static short mpeg3_q_3[7] = +{ + (-6 << 15) / 7, + (-4 << 15) / 7, + (-2 << 15) / 7, + 0, + (2 << 15) / 7, + (4 << 15) / 7, + (6 << 15) / 7 +}; + +static short mpeg3_q_4[11] = +{ + (-10 << 15) / 11, + (-8 << 15) / 11, + (-6 << 15) / 11, + (-4 << 15) / 11, + (-2 << 15) / 11, + 0, + ( 2 << 15) / 11, + ( 4 << 15) / 11, + ( 6 << 15) / 11, + ( 8 << 15) / 11, + (10 << 15) / 11 +}; + +static short mpeg3_q_5[15] = +{ + (-14 << 15) / 15, + (-12 << 15) / 15, + (-10 << 15) / 15, + (-8 << 15) / 15, + (-6 << 15) / 15, + (-4 << 15) / 15, + (-2 << 15) / 15, + 0, + ( 2 << 15) / 15, + ( 4 << 15) / 15, + ( 6 << 15) / 15, + ( 8 << 15) / 15, + (10 << 15) / 15, + (12 << 15) / 15, + (14 << 15) / 15 +}; + +static short mpeg3_qnttztab[16] = {0, 0, 0, 3, 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16}; + + +/* */ +/* Scale factors for tofloat */ +/* */ + +static const unsigned MPEG3_INT32 mpeg3_scale_factors[25] = +{ + 0x38000000, /*2 ^ -(0 + 15) */ + 0x37800000, /*2 ^ -(1 + 15) */ + 0x37000000, /*2 ^ -(2 + 15) */ + 0x36800000, /*2 ^ -(3 + 15) */ + 0x36000000, /*2 ^ -(4 + 15) */ + 0x35800000, /*2 ^ -(5 + 15) */ + 0x35000000, /*2 ^ -(6 + 15) */ + 0x34800000, /*2 ^ -(7 + 15) */ + 0x34000000, /*2 ^ -(8 + 15) */ + 0x33800000, /*2 ^ -(9 + 15) */ + 0x33000000, /*2 ^ -(10 + 15) */ + 0x32800000, /*2 ^ -(11 + 15) */ + 0x32000000, /*2 ^ -(12 + 15) */ + 0x31800000, /*2 ^ -(13 + 15) */ + 0x31000000, /*2 ^ -(14 + 15) */ + 0x30800000, /*2 ^ -(15 + 15) */ + 0x30000000, /*2 ^ -(16 + 15) */ + 0x2f800000, /*2 ^ -(17 + 15) */ + 0x2f000000, /*2 ^ -(18 + 15) */ + 0x2e800000, /*2 ^ -(19 + 15) */ + 0x2e000000, /*2 ^ -(20 + 15) */ + 0x2d800000, /*2 ^ -(21 + 15) */ + 0x2d000000, /*2 ^ -(22 + 15) */ + 0x2c800000, /*2 ^ -(23 + 15) */ + 0x2c000000 /*2 ^ -(24 + 15) */ +}; + +static MPEG3_FLOAT32 *mpeg3_scale_factor = (MPEG3_FLOAT32*)mpeg3_scale_factors; + +static inline mpeg3_real_t mpeg3audio_ac3_tofloat(unsigned short exponent, int mantissa) +{ + mpeg3_real_t x; + x = mantissa * mpeg3_scale_factor[exponent]; + return x; +} + +static inline void mpeg3audio_ac3_mantissa_reset(mpeg3_ac3_mantissa_t *mantissa) +{ + mantissa->m_1[2] = mantissa->m_1[1] = mantissa->m_1[0] = 0; + mantissa->m_2[2] = mantissa->m_2[1] = mantissa->m_2[0] = 0; + mantissa->m_4[1] = mantissa->m_4[0] = 0; +/* Force new groups to be loaded */ + mantissa->m_1_pointer = mantissa->m_2_pointer = mantissa->m_4_pointer = 3; +} + +/* + * Generate eight bits of pseudo-entropy using a 16 bit linear + * feedback shift register (LFSR). The primitive polynomial used + * is 1 + x^4 + x^14 + x^16. + * + * The distribution is uniform, over the range [-0.707,0.707] + * + */ +inline unsigned int mpeg3audio_ac3_dither_gen(mpeg3audio_t *audio) +{ + int i; + unsigned int state; + +/* explicitly bring the state into a local var as gcc > 3.0? */ +/* doesn't know how to optimize out the stores */ + state = audio->ac3_lfsr_state; + +/* Generate eight pseudo random bits */ + for(i = 0; i < 8; i++) + { + state <<= 1; + + if(state & 0x10000) + state ^= 0xa011; + } + + audio->ac3_lfsr_state = state; + return (((((int)state << 8) >> 8) * (int)(0.707106f * 256.0f)) >> 16); +} + + +/* Fetch an unpacked, left justified, and properly biased/dithered mantissa value */ +static inline unsigned short mpeg3audio_ac3_mantissa_get(mpeg3audio_t *audio, + unsigned short bap, + unsigned short dithflag) +{ + unsigned short mantissa; + unsigned int group_code; + mpeg3_ac3_mantissa_t *mantissa_struct = &(audio->ac3_mantissa); + +/* If the bap is 0-5 then we have special cases to take care of */ + switch(bap) + { + case 0: + if(dithflag) + mantissa = mpeg3audio_ac3_dither_gen(audio); + else + mantissa = 0; + break; + + case 1: + if(mantissa_struct->m_1_pointer > 2) + { + group_code = mpeg3bits_getbits(audio->astream, 5); + + if(group_code > 26) + { +/* FIXME do proper block error handling */ + fprintf(stderr, "mpeg3audio_ac3_mantissa_get: Invalid mantissa 1 %d\n", group_code); + return 0; + } + + mantissa_struct->m_1[0] = group_code / 9; + mantissa_struct->m_1[1] = (group_code % 9) / 3; + mantissa_struct->m_1[2] = (group_code % 9) % 3; + mantissa_struct->m_1_pointer = 0; + } + mantissa = mantissa_struct->m_1[mantissa_struct->m_1_pointer++]; + mantissa = mpeg3_q_1[mantissa]; + break; + + case 2: + if(mantissa_struct->m_2_pointer > 2) + { + group_code = mpeg3bits_getbits(audio->astream, 7); + + if(group_code > 124) + { + fprintf(stderr, "mpeg3audio_ac3_mantissa_get: Invalid mantissa 2 %d\n", group_code); + return 0; + } + + mantissa_struct->m_2[0] = group_code / 25; + mantissa_struct->m_2[1] = (group_code % 25) / 5; + mantissa_struct->m_2[2] = (group_code % 25) % 5; + mantissa_struct->m_2_pointer = 0; + } + mantissa = mantissa_struct->m_2[mantissa_struct->m_2_pointer++]; + mantissa = mpeg3_q_2[mantissa]; + break; + + case 3: + mantissa = mpeg3bits_getbits(audio->astream, 3); + + if(mantissa > 6) + { + fprintf(stderr, "mpeg3audio_ac3_mantissa_get: Invalid mantissa 3 %d\n", mantissa); + return 0; + } + + mantissa = mpeg3_q_3[mantissa]; + break; + + case 4: + if(mantissa_struct->m_4_pointer > 1) + { + group_code = mpeg3bits_getbits(audio->astream, 7); + + if(group_code > 120) + { + fprintf(stderr, "mpeg3audio_ac3_mantissa_get: Invalid mantissa 4 %d\n", group_code); + return 0; + } + + mantissa_struct->m_4[0] = group_code / 11; + mantissa_struct->m_4[1] = group_code % 11; + mantissa_struct->m_4_pointer = 0; + } + mantissa = mantissa_struct->m_4[mantissa_struct->m_4_pointer++]; + mantissa = mpeg3_q_4[mantissa]; + break; + + case 5: + mantissa = mpeg3bits_getbits(audio->astream, 4); + + if(mantissa > 14) + { +/* FIXME do proper block error handling */ + fprintf(stderr, "mpeg3audio_ac3_mantissa_get: Invalid mantissa 5 %d\n", mantissa); + return 0; + } + + mantissa = mpeg3_q_5[mantissa]; + break; + + default: + mantissa = mpeg3bits_getbits(audio->astream, mpeg3_qnttztab[bap]); + mantissa <<= 16 - mpeg3_qnttztab[bap]; + } + return mantissa; +} + +void mpeg3audio_ac3_uncouple_channel(mpeg3audio_t *audio, + mpeg3_real_t samples[], + mpeg3_ac3bsi_t *bsi, + mpeg3_ac3audblk_t *audblk, + unsigned int ch) +{ + unsigned int bnd = 0; + unsigned int sub_bnd = 0; + unsigned int i, j; + MPEG3_FLOAT32 cpl_coord = 1.0; + unsigned int cpl_exp_tmp; + unsigned int cpl_mant_tmp; + short mantissa; + + for(i = audblk->cplstrtmant; i < audblk->cplendmant; ) + { + if(!audblk->cplbndstrc[sub_bnd++]) + { + cpl_exp_tmp = audblk->cplcoexp[ch][bnd] + 3 * audblk->mstrcplco[ch]; + if(audblk->cplcoexp[ch][bnd] == 15) + cpl_mant_tmp = (audblk->cplcomant[ch][bnd]) << 11; + else + cpl_mant_tmp = ((0x10) | audblk->cplcomant[ch][bnd]) << 10; + + cpl_coord = mpeg3audio_ac3_tofloat(cpl_exp_tmp, cpl_mant_tmp) * 8.0f; + +/*Invert the phase for the right channel if necessary */ + if(bsi->acmod == 0x2 && audblk->phsflginu && ch == 1 && audblk->phsflg[bnd]) + cpl_coord *= -1; + + bnd++; + } + + for(j = 0; j < 12; j++) + { +/* Get new dither values for each channel if necessary, so */ +/* the channels are uncorrelated */ + if(audblk->dithflag[ch] && audblk->cpl_bap[i] == 0) + mantissa = mpeg3audio_ac3_dither_gen(audio); + else + mantissa = audblk->cplmant[i]; + + samples[i] = cpl_coord * mpeg3audio_ac3_tofloat(audblk->cpl_exp[i], mantissa);; + + i++; + } + } + return; +} + +int mpeg3audio_ac3_coeff_unpack(mpeg3audio_t *audio, + mpeg3_ac3bsi_t *bsi, + mpeg3_ac3audblk_t *audblk, + mpeg3ac3_stream_samples_t samples) +{ + int i, j; + int done_cpl = 0; + short mantissa; + + mpeg3audio_ac3_mantissa_reset(&(audio->ac3_mantissa)); + + for(i = 0; i < bsi->nfchans && !mpeg3bits_error(audio->astream); i++) + { + for(j = 0; j < audblk->endmant[i] && !mpeg3bits_error(audio->astream); j++) + { + mantissa = mpeg3audio_ac3_mantissa_get(audio, audblk->fbw_bap[i][j], audblk->dithflag[i]); + samples[i][j] = mpeg3audio_ac3_tofloat(audblk->fbw_exp[i][j], mantissa); + } + + if(audblk->cplinu && audblk->chincpl[i] && !(done_cpl) && !mpeg3bits_error(audio->astream)) + { +/* ncplmant is equal to 12 * ncplsubnd */ +/* Don't dither coupling channel until channel separation so that + * interchannel noise is uncorrelated */ + for(j = audblk->cplstrtmant; + j < audblk->cplendmant && !mpeg3bits_error(audio->astream); + j++) + { + audblk->cplmant[j] = mpeg3audio_ac3_mantissa_get(audio, audblk->cpl_bap[j], 0); + } + done_cpl = 1; + } + } + +/* Uncouple the channel */ + if(audblk->cplinu) + { + if(audblk->chincpl[i]) + mpeg3audio_ac3_uncouple_channel(audio, samples[i], bsi, audblk, i); + } + + if(bsi->lfeon && !mpeg3bits_error(audio->astream)) + { +/* There are always 7 mantissas for lfe, no dither for lfe */ + for(j = 0; j < 7 && !mpeg3bits_error(audio->astream); j++) + mantissa = mpeg3audio_ac3_mantissa_get(audio, audblk->lfe_bap[j], 0); + samples[5][j] = mpeg3audio_ac3_tofloat(audblk->lfe_exp[j], mantissa); + } + + return mpeg3bits_error(audio->astream); +} diff --git a/core/multimedia/opieplayer/libmpeg3/audio/mpeg3audio.c b/core/multimedia/opieplayer/libmpeg3/audio/mpeg3audio.c new file mode 100644 index 0000000..e2d3912 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/mpeg3audio.c @@ -0,0 +1,536 @@ +#include "../libmpeg3.h" +#include "../mpeg3protos.h" +#include "mpeg3audio.h" +#include "tables.h" + +#include <math.h> +#include <stdlib.h> + +mpeg3audio_t* mpeg3audio_allocate_struct(mpeg3_t *file, mpeg3_atrack_t *track) +{ + mpeg3audio_t *audio = (mpeg3audio_t*)calloc(1, sizeof(mpeg3audio_t)); + audio->file = file; + audio->track = track; + audio->astream = mpeg3bits_new_stream(file, track->demuxer); + audio->outscale = 1; + audio->bsbuf = audio->bsspace[1]; + audio->init = 1; + audio->bo = 1; + audio->channels = 1; + return audio; +} + + +int mpeg3audio_delete_struct(mpeg3audio_t *audio) +{ + mpeg3bits_delete_stream(audio->astream); + if(audio->pcm_sample) free(audio->pcm_sample); + free(audio); + return 0; +} + +int mpeg3audio_replace_buffer(mpeg3audio_t *audio, long new_allocation) +{ + long i; + + audio->pcm_sample = (mpeg3_real_t*)realloc( audio->pcm_sample, sizeof(mpeg3_real_t) * new_allocation * audio->channels ); + audio->pcm_allocated = new_allocation; +/* + // Isn't this exactly the same as what the ANSI C function call realloc does, + // or did I miss C Programming 101 ? + + if(!audio->pcm_sample) + { + audio->pcm_sample = (mpeg3_real_t*)malloc(sizeof(mpeg3_real_t) * new_allocation * audio->channels); + audio->pcm_allocated = new_allocation; + } + else + { + mpeg3_real_t *new_samples = (mpeg3_real_t*)malloc(sizeof(mpeg3_real_t) * new_allocation * audio->channels); + for(i = 0; i < audio->pcm_allocated * audio->channels; i++) + { + new_samples[i] = audio->pcm_sample[i]; + } + free(audio->pcm_sample); + audio->pcm_sample = new_samples; + audio->pcm_allocated = new_allocation; + } +*/ + return 0; +} + +int mpeg3audio_read_frame(mpeg3audio_t *audio) +{ + int result = 0; + result = mpeg3audio_read_header(audio); + + if(!result) + { + switch(audio->format) + { + case AUDIO_AC3: + result = mpeg3audio_do_ac3(audio); + break; + + case AUDIO_MPEG: + switch(audio->layer) + { + case 1: + break; + + case 2: + result = mpeg3audio_dolayer2(audio); + break; + + case 3: + result = mpeg3audio_dolayer3(audio); + break; + + default: + result = 1; + break; + } + break; + + case AUDIO_PCM: + result = mpeg3audio_do_pcm(audio); + break; + } + } + + if(!result) + { +/* Byte align the stream */ + mpeg3bits_byte_align(audio->astream); + } + return result; +} + +/* Get the length but also initialize the frame sizes. */ +int mpeg3audio_get_length(mpeg3audio_t *audio, mpeg3_atrack_t *track) +{ + long result = 0; + long framesize1 = 0, total1 = 0; + long framesize2 = 0, total2 = 0; + long total_framesize = 0, total_frames = 0; + long byte_limit = 131072; /* Total bytes to gather information from */ + long total_bytes = 0; + long major_framesize; /* Bigger framesize + header */ + long minor_framesize; /* Smaller framesize + header */ + long major_total; + long minor_total; + mpeg3_t *file = audio->file; + +/* Get the frame sizes */ + mpeg3bits_seek_start(audio->astream); + audio->pcm_point = 0; + result = mpeg3audio_read_frame(audio); /* Stores the framesize */ + audio->samples_per_frame = audio->pcm_point / audio->channels; + + switch(audio->format) + { + case AUDIO_AC3: + audio->avg_framesize = audio->framesize; + break; + + case AUDIO_MPEG: + framesize1 = audio->framesize; + total_bytes += audio->framesize; + total1 = 1; + + while(!result && total_bytes < byte_limit) + { + audio->pcm_point = 0; + result = mpeg3audio_read_frame(audio); + total_bytes += audio->framesize; + if(audio->framesize != framesize1) + { + framesize2 = audio->framesize; + total2 = 1; + break; + } + else + { + total1++; + } + } + + while(!result && total_bytes < byte_limit) + { + audio->pcm_point = 0; + result = mpeg3audio_read_frame(audio); + total_bytes += audio->framesize; + if(audio->framesize != framesize2) + { + break; + } + else + { + total2++; + } + } + + audio->pcm_point = 0; + result = mpeg3audio_read_frame(audio); + if(audio->framesize != framesize1 && audio->framesize != framesize2) + { +/* Variable bit rate. Get the average frame size. */ + while(!result && total_bytes < byte_limit) + { + audio->pcm_point = 0; + result = mpeg3audio_read_frame(audio); + total_bytes += audio->framesize; + if(!result) + { + total_framesize += audio->framesize; + total_frames++; + } + } + audio->avg_framesize = 4 + (total_framesize + framesize1 + framesize2) / (total_frames + total1 + total2); + } + else + { + major_framesize = framesize2 > framesize1 ? framesize2 : framesize1; + major_total = framesize2 > framesize1 ? total2 : total1; + minor_framesize = framesize2 > framesize1 ? framesize1 : framesize2; + minor_total = framesize2 > framesize1 ? total1 : total2; +/* Add the headers to the framesizes */ + audio->avg_framesize = 4 + (major_framesize * major_total + minor_framesize * minor_total) / (major_total + minor_total); + } + break; + + case AUDIO_PCM: + break; + } + +/* Estimate the total samples */ + if(file->is_audio_stream) + { +/* From the raw file */ + result = (long)((float)mpeg3demuxer_total_bytes(audio->astream->demuxer) / audio->avg_framesize * audio->samples_per_frame); + } + else + { +/* Gross approximation from a multiplexed file. */ + result = (long)(mpeg3demux_length(audio->astream->demuxer) * track->sample_rate); +/* result = (long)((mpeg3_real_t)mpeg3_video_frames(file, 0) / mpeg3_frame_rate(file, 0) * track->sample_rate); */ +/* We would scan the multiplexed packets here for the right timecode if only */ +/* they had meaningful timecode. */ + } + + audio->pcm_point = 0; + mpeg3bits_seek_start(audio->astream); + mpeg3audio_reset_synths(audio); + return result; +} + +int mpeg3audio_seek(mpeg3audio_t *audio, long position) +{ + int result = 0; + mpeg3_t *file = audio->file; + mpeg3_atrack_t *track = audio->track; + long frame_number; + long byte_position; + double time_position; + +/* Sample seek wasn't requested */ + if(audio->sample_seek < 0) + { + audio->pcm_position = position; + audio->pcm_size = 0; + return 0; + } + +/* Can't slide buffer. Seek instead. */ + if(!file->is_audio_stream) + { +/* Seek in a multiplexed stream using the multiplexer. */ + time_position = (double)position / track->sample_rate; + result |= mpeg3bits_seek_time(audio->astream, time_position); + audio->pcm_position = (long)mpeg3bits_packet_time(audio->astream) * track->sample_rate; +/*printf("wanted %f got %f\n", time_position, mpeg3bits_packet_time(audio->astream)); */ + } + else + { +/* Seek in an elemental stream. This algorithm achieves sample accuracy on fixed bitrates. */ +/* Forget about variable bitrates or program streams. */ + frame_number = position / audio->samples_per_frame; + byte_position = (long)(audio->avg_framesize * frame_number); + audio->pcm_position = frame_number * audio->samples_per_frame; + + if(byte_position < audio->avg_framesize * 2) + { + result |= mpeg3bits_seek_start(audio->astream); + audio->pcm_position = 0; + } + else + { + result |= mpeg3bits_seek_byte(audio->astream, byte_position); + } + } + +/* Arm the backstep buffer for layer 3 if not at the beginning already. */ + if(byte_position >= audio->avg_framesize * 2 && audio->layer == 3 && !result) + { + result |= mpeg3audio_prev_header(audio); + result |= mpeg3audio_read_layer3_frame(audio); + } + +/* Reset the tables. */ + mpeg3audio_reset_synths(audio); + audio->pcm_size = 0; + audio->pcm_point = 0; + return result; +} + +/* ================================================================ */ +/* ENTRY POINTS */ +/* ================================================================ */ + + + + +mpeg3audio_t* mpeg3audio_new(mpeg3_t *file, mpeg3_atrack_t *track, int format) +{ + mpeg3audio_t *audio = mpeg3audio_allocate_struct(file, track); + int result = 0; + +/* Init tables */ + mpeg3audio_new_decode_tables(audio); + audio->percentage_seek = -1; + audio->sample_seek = -1; + audio->format = format; + +/* Determine the format of the stream */ + if(format == AUDIO_UNKNOWN) + { + if(((mpeg3bits_showbits(audio->astream, 32) & 0xffff0000) >> 16) == MPEG3_AC3_START_CODE) + audio->format = AUDIO_AC3; + else + audio->format = AUDIO_MPEG; + } + +/* get channel count */ + result = mpeg3audio_read_header(audio); + +/* Set up the sample buffer */ + mpeg3audio_replace_buffer(audio, 262144); + +/* Copy information to the mpeg struct */ + if(!result) + { + track->channels = audio->channels; + + switch(audio->format) + { + case AUDIO_AC3: + track->sample_rate = mpeg3_ac3_samplerates[audio->sampling_frequency_code]; + break; + + case AUDIO_MPEG: + track->sample_rate = mpeg3_freqs[audio->sampling_frequency_code]; + break; + + case AUDIO_PCM: + track->sample_rate = 48000; + break; + } + + track->total_samples = mpeg3audio_get_length(audio, track); + result |= mpeg3bits_seek_start(audio->astream); + } + else + { + mpeg3audio_delete_struct(audio); + audio = 0; + } + + return audio; +} + +int mpeg3audio_delete(mpeg3audio_t *audio) +{ + mpeg3audio_delete_struct(audio); + return 0; +} + +int mpeg3audio_seek_percentage(mpeg3audio_t *audio, double percentage) +{ + audio->percentage_seek = percentage; + return 0; +} + +int mpeg3audio_seek_sample(mpeg3audio_t *audio, long sample) +{ + audio->sample_seek = sample; + return 0; +} + +/* Read raw frames for concatenation purposes */ +int mpeg3audio_read_raw(mpeg3audio_t *audio, unsigned char *output, long *size, long max_size) +{ + int result = 0; + int i; + *size = 0; + + switch(audio->format) + { + case AUDIO_AC3: +/* Just write the AC3 stream */ + if(mpeg3bits_read_buffer(audio->astream, output, audio->framesize)) + return 1; + *size = audio->framesize; + break; + + case AUDIO_MPEG: +/* Fix the mpeg stream */ + result = mpeg3audio_read_header(audio); + if(!result) + { + if(max_size < 4) return 1; + *output++ = (audio->newhead & 0xff000000) >> 24; + *output++ = (audio->newhead & 0xff0000) >> 16; + *output++ = (audio->newhead & 0xff00) >> 8; + *output++ = (audio->newhead & 0xff); + *size += 4; + + if(max_size < 4 + audio->framesize) return 1; + if(mpeg3bits_read_buffer(audio->astream, output, audio->framesize)) + return 1; + + *size += audio->framesize; + } + break; + + case AUDIO_PCM: + if(mpeg3bits_read_buffer(audio->astream, output, audio->framesize)) + return 1; + *size = audio->framesize; + break; + } + return result; +} + +/* Channel is 0 to channels - 1 */ +int mpeg3audio_decode_audio(mpeg3audio_t *audio, + mpeg3_real_t *output_f, + short *output_i, int sampleSpacing, + int channel, + long start_position, + long len) +{ + long allocation_needed = len + MPEG3AUDIO_PADDING; + long i, j, result = 0; + mpeg3_t *file = audio->file; + mpeg3_atrack_t *atrack = audio->track; + long attempts; + +/* Create new buffer */ + if(audio->pcm_allocated < allocation_needed) + { + mpeg3audio_replace_buffer(audio, allocation_needed); + } + +/* There was a percentage seek */ + if(audio->percentage_seek >= 0) + { + mpeg3bits_seek_percentage(audio->astream, audio->percentage_seek); +/* Force the pcm buffer to be reread. */ + audio->pcm_position = start_position; + audio->pcm_size = 0; + audio->percentage_seek = -1; + } + else + { +/* Entire output is in buffer so don't do anything. */ + if(start_position >= audio->pcm_position && start_position < audio->pcm_position + audio->pcm_size && + start_position + len <= audio->pcm_size) + { + ; + } + else +/* Output starts in buffer but ends later so slide it back. */ + if(start_position <= audio->pcm_position + audio->pcm_size && + start_position >= audio->pcm_position) + { + for(i = 0, j = (start_position - audio->pcm_position) * audio->channels; + j < audio->pcm_size * audio->channels; + i++, j++) + { + audio->pcm_sample[i] = audio->pcm_sample[j]; + } + + audio->pcm_point = i; + audio->pcm_size -= start_position - audio->pcm_position; + audio->pcm_position = start_position; + } + else + { +/* Output is outside buffer completely. */ + result = mpeg3audio_seek(audio, start_position); + audio->sample_seek = -1; +/* Check sanity */ + if(start_position < audio->pcm_position) audio->pcm_position = start_position; + } + audio->sample_seek = -1; + } + +/* Read packets until the buffer is full. */ + if(!result) + { + attempts = 0; + result = 1; + while(attempts < 6 && + !mpeg3bits_eof(audio->astream) && + audio->pcm_size + audio->pcm_position < start_position + len) + { + result = mpeg3audio_read_frame(audio); + if(result) attempts++; + audio->pcm_size = audio->pcm_point / audio->channels; + } + } + + + +/* Copy the buffer to the output */ + if(output_f) + { + for(i = 0, j = (start_position - audio->pcm_position) * audio->channels + channel; + i < len && j < audio->pcm_size * audio->channels; + i++, j += audio->channels) + { + output_f[i] = audio->pcm_sample[j]; + } + for( ; i < len; i++) + { + output_f[i] = 0; + } + } + else + if(output_i) + { + int sample; + for(i = 0, j = (start_position - audio->pcm_position) * audio->channels + channel; + i < (len*(sampleSpacing+1)) && j < audio->pcm_size * audio->channels; + i++, j += audio->channels) + { + sample = (int)(audio->pcm_sample[j] * 32767); + if(sample > 32767) sample = 32767; + else + if(sample < -32768) sample = -32768; + + output_i[i] = sample; + i += sampleSpacing; + } + for( ; i < (len*(sampleSpacing+1)); i++) + { + output_i[i] = 0; + i += sampleSpacing; + } + } + + if(audio->pcm_point > 0) + return 0; + else + return result; +} diff --git a/core/multimedia/opieplayer/libmpeg3/audio/mpeg3audio.h b/core/multimedia/opieplayer/libmpeg3/audio/mpeg3audio.h new file mode 100644 index 0000000..2117be7 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/mpeg3audio.h @@ -0,0 +1,144 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef MPEG3AUDIO_H +#define MPEG3AUDIO_H + +#include "ac3.h" +#include "../bitstream.h" +typedef struct mpeg3_atrack_rec mpeg3_atrack_t; + +#define MAXFRAMESIZE 1792 +#define HDRCMPMASK 0xfffffd00 +#define SBLIMIT 32 +#define SSLIMIT 18 +#define SCALE_BLOCK 12 +#define MPEG3AUDIO_PADDING 1024 + +/* Values for mode */ +#define MPG_MD_STEREO 0 +#define MPG_MD_JOINT_STEREO 1 +#define MPG_MD_DUAL_CHANNEL 2 +#define MPG_MD_MONO 3 + +/* IMDCT variables */ +typedef struct +{ + mpeg3_real_t real; + mpeg3_real_t imag; +} mpeg3_complex_t; + +#define AC3_N 512 + +struct al_table +{ + short bits; + short d; +}; + +typedef struct +{ + struct mpeg3_rec* file; + mpeg3_atrack_t* track; + mpeg3_bits_t *astream; + +/* In order of importance */ + int format; /* format of audio */ + int layer; /* layer if mpeg */ + int channels; + long outscale; + long framenum; + long prev_framesize; + long framesize; /* For mp3 current framesize without header. For AC3 current framesize with header. */ + int avg_framesize; /* Includes the 4 byte header */ + mpeg3_real_t *pcm_sample; /* Interlaced output from synthesizer in floats */ + int pcm_point; /* Float offset in pcm_sample to write to */ + long pcm_position; /* Sample start of pcm_samples in file */ + long pcm_size; /* Number of pcm samples in the buffer */ + long pcm_allocated; /* Allocated number of samples in pcm_samples */ + int sample_seek; + double percentage_seek; + unsigned long oldhead; + unsigned long newhead; + unsigned long firsthead; + int bsnum; + int lsf; + int mpeg35; + int sampling_frequency_code; + int bitrate_index; + int bitrate; + int samples_per_frame; + int padding; + int extension; + int mode; + int mode_ext; + int copyright; + int original; + int emphasis; + int error_protection; + +/* Back step buffers for mp3 */ + unsigned char bsspace[2][MAXFRAMESIZE + 512]; /* MAXFRAMESIZE */ + unsigned char *bsbuf, *bsbufold; + long ssize; + int init; + int single; + struct al_table *alloc; + int II_sblimit; + int jsbound; + int bo; /* Static variable in synthesizer */ + +/* MP3 Static arrays here */ + mpeg3_real_t synth_stereo_buffs[2][2][0x110]; + mpeg3_real_t synth_mono_buff[64]; + unsigned int layer2_scfsi_buf[64]; + + mpeg3_real_t mp3_block[2][2][SBLIMIT * SSLIMIT]; + int mp3_blc[2]; + +/* AC3 specific stuff. AC3 also shares objects with MPEG */ + unsigned int ac3_framesize_code; + mpeg3_ac3bsi_t ac3_bsi; + mpeg3_ac3audblk_t ac3_audblk; + mpeg3_ac3_bitallocation_t ac3_bit_allocation; + mpeg3_ac3_mantissa_t ac3_mantissa; + mpeg3_complex_t ac3_imdct_buf[AC3_N / 4]; + +/* Delay buffer for DCT interleaving */ + mpeg3_real_t ac3_delay[6][AC3_N / 2]; +/* Twiddle factor LUT */ + mpeg3_complex_t *ac3_w[7]; +#if !defined(USE_FIXED_POINT) || defined(PRINT_FIXED_POINT_TABLES) + /* Just for allocated memory */ + mpeg3_complex_t ac3_w_1[1]; + mpeg3_complex_t ac3_w_2[2]; + mpeg3_complex_t ac3_w_4[4]; + mpeg3_complex_t ac3_w_8[8]; + mpeg3_complex_t ac3_w_16[16]; + mpeg3_complex_t ac3_w_32[32]; + mpeg3_complex_t ac3_w_64[64]; +#endif + int ac3_lfsr_state; + unsigned char ac3_buffer[MAX_AC3_FRAMESIZE]; + mpeg3ac3_stream_samples_t ac3_samples; +} mpeg3audio_t; + + + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/audio/mpeg3real.h b/core/multimedia/opieplayer/libmpeg3/audio/mpeg3real.h new file mode 100644 index 0000000..cdcac3d --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/mpeg3real.h @@ -0,0 +1,232 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef MPEG3REAL_H +#define MPEG3REAL_H + +#ifdef USE_FIXED_POINT + +#include <limits.h> +#include <stdio.h> + +#ifndef LONGLONG +#define LONGLONG long long +#endif + +//#define SC (1<<16) +#define SC (1<<15) + +class mpeg3_real_t { + long v; +public: + mpeg3_real_t() { } // Uninitialized, just like a float + mpeg3_real_t(double d) { v=long(d*SC); } + mpeg3_real_t(float f) { v=long(f*SC); } + mpeg3_real_t(int i) { v=long(i*SC); } + long fixedPoint() const { return v; } + operator float() const { return ((float)v)/SC; } + operator int() const { return (int)(v/SC); } + mpeg3_real_t operator+() const; + mpeg3_real_t operator-() const; + mpeg3_real_t& operator= (const mpeg3_real_t&); + mpeg3_real_t& operator+= (const mpeg3_real_t&); + mpeg3_real_t& operator-= (const mpeg3_real_t&); + mpeg3_real_t& operator*= (const mpeg3_real_t&); + mpeg3_real_t& operator/= (const mpeg3_real_t&); + friend mpeg3_real_t operator+ (const mpeg3_real_t&, const mpeg3_real_t&); + friend mpeg3_real_t operator- (const mpeg3_real_t&, const mpeg3_real_t&); + friend mpeg3_real_t operator* (const mpeg3_real_t&, const mpeg3_real_t&); + friend mpeg3_real_t operator/ (const mpeg3_real_t&, const mpeg3_real_t&); + friend mpeg3_real_t operator+ (const mpeg3_real_t&, const float&); + friend mpeg3_real_t operator- (const mpeg3_real_t&, const float&); + friend mpeg3_real_t operator* (const mpeg3_real_t&, const float&); + friend mpeg3_real_t operator/ (const mpeg3_real_t&, const float&); + friend mpeg3_real_t operator+ (const float&, const mpeg3_real_t&); + friend mpeg3_real_t operator- (const float&, const mpeg3_real_t&); + friend mpeg3_real_t operator* (const float&, const mpeg3_real_t&); + friend mpeg3_real_t operator/ (const float&, const mpeg3_real_t&); + friend mpeg3_real_t operator+ (const mpeg3_real_t&, const int&); + friend mpeg3_real_t operator- (const mpeg3_real_t&, const int&); + friend mpeg3_real_t operator* (const mpeg3_real_t&, const int&); + friend mpeg3_real_t operator/ (const mpeg3_real_t&, const int&); + friend mpeg3_real_t operator+ (const int&, const mpeg3_real_t&); + friend mpeg3_real_t operator- (const int&, const mpeg3_real_t&); + friend mpeg3_real_t operator* (const int&, const mpeg3_real_t&); + friend mpeg3_real_t operator/ (const int&, const mpeg3_real_t&); +}; + +inline mpeg3_real_t mpeg3_real_t::operator+() const +{ + return *this; +} + +inline mpeg3_real_t mpeg3_real_t::operator-() const +{ + mpeg3_real_t r; + r.v=-v; + return r; +} + +inline mpeg3_real_t& mpeg3_real_t::operator= (const mpeg3_real_t& o) +{ + v=o.v; + return *this; +} + +inline mpeg3_real_t& mpeg3_real_t::operator+= (const mpeg3_real_t& o) +{ + v += o.v; + return *this; +} + +inline mpeg3_real_t& mpeg3_real_t::operator-= (const mpeg3_real_t& o) +{ + v -= o.v; + return *this; +} + +inline mpeg3_real_t& mpeg3_real_t::operator*= (const mpeg3_real_t& o) +{ + *this = *this * o; + return *this; +} + +inline mpeg3_real_t& mpeg3_real_t::operator/= (const mpeg3_real_t& o) +{ + *this = *this / o; + return *this; +} + + +inline mpeg3_real_t operator+ (const mpeg3_real_t&a, const mpeg3_real_t&b) +{ + mpeg3_real_t r; + r.v=a.v+b.v; + return r; +} + +inline mpeg3_real_t operator- (const mpeg3_real_t&a, const mpeg3_real_t&b) +{ + mpeg3_real_t r; + r.v=a.v-b.v; + return r; +} + +inline mpeg3_real_t operator* (const mpeg3_real_t&a, const mpeg3_real_t&b) +{ + mpeg3_real_t r; + r.v = (LONGLONG)a.v * b.v / SC; + return r; +} + +inline mpeg3_real_t operator/ (const mpeg3_real_t&a, const mpeg3_real_t&b) +{ + mpeg3_real_t r; + r.v = (LONGLONG)a.v * SC / b.v; + return r; +} + +inline mpeg3_real_t operator+ (const mpeg3_real_t&a, const float&b) +{ + return a+mpeg3_real_t(b); +} + +inline mpeg3_real_t operator- (const mpeg3_real_t&a, const float&b) +{ + return a-mpeg3_real_t(b); +} + +inline mpeg3_real_t operator* (const mpeg3_real_t&a, const float&b) +{ + return a*mpeg3_real_t(b); +} + +inline mpeg3_real_t operator/ (const mpeg3_real_t&a, const float&b) +{ + return a/mpeg3_real_t(b); +} + + +inline mpeg3_real_t operator+ (const float&a, const mpeg3_real_t&b) +{ + return mpeg3_real_t(a)+b; +} + +inline mpeg3_real_t operator- (const float&a, const mpeg3_real_t&b) +{ + return mpeg3_real_t(a)-b; +} + +inline mpeg3_real_t operator* (const float&a, const mpeg3_real_t&b) +{ + return mpeg3_real_t(a)*b; +} + +inline mpeg3_real_t operator/ (const float&a, const mpeg3_real_t&b) +{ + return mpeg3_real_t(a)/b; +} + + +inline mpeg3_real_t operator+ (const mpeg3_real_t&a, const int&b) +{ + return a+mpeg3_real_t(b); +} + +inline mpeg3_real_t operator- (const mpeg3_real_t&a, const int&b) +{ + return a-mpeg3_real_t(b); +} + +inline mpeg3_real_t operator* (const mpeg3_real_t&a, const int&b) +{ + return a*mpeg3_real_t(b); +} + +inline mpeg3_real_t operator/ (const mpeg3_real_t&a, const int&b) +{ + return a/mpeg3_real_t(b); +} + + +inline mpeg3_real_t operator+ (const int&a, const mpeg3_real_t&b) +{ + return mpeg3_real_t(a)+b; +} + +inline mpeg3_real_t operator- (const int&a, const mpeg3_real_t&b) +{ + return mpeg3_real_t(a)-b; +} + +inline mpeg3_real_t operator* (const int&a, const mpeg3_real_t&b) +{ + return mpeg3_real_t(a)*b; +} + +inline mpeg3_real_t operator/ (const int&a, const mpeg3_real_t&b) +{ + return mpeg3_real_t(a)/b; +} + +#else +typedef float mpeg3_real_t; +#endif + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/audio/pcm.c b/core/multimedia/opieplayer/libmpeg3/audio/pcm.c new file mode 100644 index 0000000..8fa0d25 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/pcm.c @@ -0,0 +1,51 @@ +#include "mpeg3audio.h" +#include "../libmpeg3.h" +#include "../mpeg3protos.h" + +int mpeg3audio_read_pcm_header(mpeg3audio_t *audio) +{ + unsigned int code; + + code = mpeg3bits_getbits(audio->astream, 16); + while(!mpeg3bits_eof(audio->astream) && code != MPEG3_PCM_START_CODE) + { + code <<= 8; + code &= 0xffff; + code |= mpeg3bits_getbits(audio->astream, 8); + } + + audio->avg_framesize = audio->framesize = 0x7db; + audio->channels = 2; + + return mpeg3bits_eof(audio->astream); +} + +int mpeg3audio_do_pcm(mpeg3audio_t *audio) +{ + int i, j, k; + MPEG3_INT16 sample; + int frame_samples = (audio->framesize - 3) / audio->channels / 2; + + if(mpeg3bits_read_buffer(audio->astream, audio->ac3_buffer, frame_samples * audio->channels * 2)) + return 1; + +/* Need more room */ + if(audio->pcm_point / audio->channels >= audio->pcm_allocated - MPEG3AUDIO_PADDING * audio->channels) + { + mpeg3audio_replace_buffer(audio, audio->pcm_allocated + MPEG3AUDIO_PADDING * audio->channels); + } + + k = 0; + for(i = 0; i < frame_samples; i++) + { + for(j = 0; j < audio->channels; j++) + { + sample = ((MPEG3_INT16)(audio->ac3_buffer[k++])) << 8; + sample |= audio->ac3_buffer[k++]; + audio->pcm_sample[audio->pcm_point + i * audio->channels + j] = + (mpeg3_real_t)sample / 32767; + } + } + audio->pcm_point += frame_samples * audio->channels; + return 0; +} diff --git a/core/multimedia/opieplayer/libmpeg3/audio/synthesizers.c b/core/multimedia/opieplayer/libmpeg3/audio/synthesizers.c new file mode 100644 index 0000000..71a74b3 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/synthesizers.c @@ -0,0 +1,174 @@ +#include "mpeg3audio.h" +#include "../libmpeg3.h" +#include "../mpeg3protos.h" +#include "tables.h" + +#define WRITE_SAMPLE(samples, sum) \ +{ \ + (*samples) = (sum); \ +} + +int mpeg3audio_synth_stereo(mpeg3audio_t *audio, mpeg3_real_t *bandPtr, int channel, mpeg3_real_t *out, int *pnt) +{ + const int step = 2; + mpeg3_real_t *samples = out + *pnt; + register mpeg3_real_t sum; + mpeg3_real_t *b0, (*buf)[0x110]; + int bo1; + + if(!channel) + { + audio->bo--; + audio->bo &= 0xf; + buf = audio->synth_stereo_buffs[0]; + } + else + { + samples++; + buf = audio->synth_stereo_buffs[1]; + } + + if(audio->bo & 0x1) + { + b0 = buf[0]; + bo1 = audio->bo; + mpeg3audio_dct64(buf[1] + ((audio->bo + 1) & 0xf), buf[0] + audio->bo, bandPtr); + } + else + { + b0 = buf[1]; + bo1 = audio->bo + 1; + mpeg3audio_dct64(buf[0] + audio->bo, buf[1] + audio->bo + 1, bandPtr); + } + +/*printf("%f %f %f\n", buf[0][0], buf[1][0], bandPtr[0]); */ + + { + register int j; + mpeg3_real_t *window = mpeg3_decwin + 16 - bo1; + + for(j = 16; j; j--, b0 += 0x10, window += 0x20, samples += step) + { + sum = window[0x0] * b0[0x0]; + sum -= window[0x1] * b0[0x1]; + sum += window[0x2] * b0[0x2]; + sum -= window[0x3] * b0[0x3]; + sum += window[0x4] * b0[0x4]; + sum -= window[0x5] * b0[0x5]; + sum += window[0x6] * b0[0x6]; + sum -= window[0x7] * b0[0x7]; + sum += window[0x8] * b0[0x8]; + sum -= window[0x9] * b0[0x9]; + sum += window[0xA] * b0[0xA]; + sum -= window[0xB] * b0[0xB]; + sum += window[0xC] * b0[0xC]; + sum -= window[0xD] * b0[0xD]; + sum += window[0xE] * b0[0xE]; + sum -= window[0xF] * b0[0xF]; + + WRITE_SAMPLE(samples, sum); + } + + sum = window[0x0] * b0[0x0]; + sum += window[0x2] * b0[0x2]; + sum += window[0x4] * b0[0x4]; + sum += window[0x6] * b0[0x6]; + sum += window[0x8] * b0[0x8]; + sum += window[0xA] * b0[0xA]; + sum += window[0xC] * b0[0xC]; + sum += window[0xE] * b0[0xE]; + WRITE_SAMPLE(samples, sum); + b0 -= 0x10; + window -= 0x20; + samples += step; + window += bo1 << 1; + + for(j = 15; j; j--, b0 -= 0x10, window -= 0x20, samples += step) + { + sum = -window[-0x1] * b0[0x0]; + sum -= window[-0x2] * b0[0x1]; + sum -= window[-0x3] * b0[0x2]; + sum -= window[-0x4] * b0[0x3]; + sum -= window[-0x5] * b0[0x4]; + sum -= window[-0x6] * b0[0x5]; + sum -= window[-0x7] * b0[0x6]; + sum -= window[-0x8] * b0[0x7]; + sum -= window[-0x9] * b0[0x8]; + sum -= window[-0xA] * b0[0x9]; + sum -= window[-0xB] * b0[0xA]; + sum -= window[-0xC] * b0[0xB]; + sum -= window[-0xD] * b0[0xC]; + sum -= window[-0xE] * b0[0xD]; + sum -= window[-0xF] * b0[0xE]; + sum -= window[-0x0] * b0[0xF]; + + WRITE_SAMPLE(samples, sum); + } + } + *pnt += 64; + + return 0; +} + +int mpeg3audio_synth_mono(mpeg3audio_t *audio, mpeg3_real_t *bandPtr, mpeg3_real_t *samples, int *pnt) +{ + mpeg3_real_t *samples_tmp = audio->synth_mono_buff; + mpeg3_real_t *tmp1 = samples_tmp; + int i, ret; + int pnt1 = 0; + + ret = mpeg3audio_synth_stereo(audio, bandPtr, 0, samples_tmp, &pnt1); + samples += *pnt; + + for(i = 0; i < 32; i++) + { + *samples = *tmp1; + samples++; + tmp1 += 2; + } + *pnt += 32; + + return ret; +} + + +/* Call this after every seek to reset the buffers */ +int mpeg3audio_reset_synths(mpeg3audio_t *audio) +{ + int i, j, k; + for(i = 0; i < 2; i++) + { + for(j = 0; j < 2; j++) + { + for(k = 0; k < 0x110; k++) + { + audio->synth_stereo_buffs[i][j][k] = 0; + } + } + } + for(i = 0; i < 64; i++) + { + audio->synth_mono_buff[i] = 0; + audio->layer2_scfsi_buf[i] = 0; + } + for(i = 0; i < 2; i++) + { + for(j = 0; j < 2; j++) + { + for(k = 0; k < SBLIMIT * SSLIMIT; k++) + { + audio->mp3_block[i][j][k] = 0; + } + } + } + audio->mp3_blc[0] = 0; + audio->mp3_blc[1] = 0; + for(i = 0; i < audio->channels; i++) + { + for(j = 0; j < AC3_N / 2; j++) + { + audio->ac3_delay[i][j] = 0; + } + } + return 0; +} diff --git a/core/multimedia/opieplayer/libmpeg3/audio/tables.c b/core/multimedia/opieplayer/libmpeg3/audio/tables.c new file mode 100644 index 0000000..aeab335 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/tables.c @@ -0,0 +1,554 @@ +#include "mpeg3audio.h" +#include "../libmpeg3.h" +#include "../mpeg3protos.h" +#include "tables.h" + +#include <math.h> + +/* Bitrate indexes */ +int mpeg3_tabsel_123[2][3][16] = { + { {0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,}, + {0,32,48,56, 64, 80, 96,112,128,160,192,224,256,320,384,}, + {0,32,40,48, 56, 64, 80, 96,112,128,160,192,224,256,320,} }, + + { {0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,}, + {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,}, + {0,8,16,24,32,40,48,56,64,80,96,112,128,144,160,} } +}; + +long mpeg3_freqs[9] = { 44100, 48000, 32000, 22050, 24000, 16000 , 11025 , 12000 , 8000 }; + +#ifdef USE_3DNOW +mpeg3_real_t mpeg3_decwin[2 * (512 + 32)]; +mpeg3_real_t mpeg3_cos64[32], mpeg3_cos32[16], mpeg3_cos16[8], mpeg3_cos8[4], mpeg3_cos4[2]; +#else +mpeg3_real_t mpeg3_decwin[512 + 32]; +mpeg3_real_t mpeg3_cos64[16], mpeg3_cos32[8], mpeg3_cos16[4], mpeg3_cos8[2], mpeg3_cos4[1]; +#endif + +mpeg3_real_t *mpeg3_pnts[] = { mpeg3_cos64, mpeg3_cos32, mpeg3_cos16, mpeg3_cos8, mpeg3_cos4 }; + +int mpeg3_grp_3tab[32 * 3] = { 0, }; /* used: 27 */ +int mpeg3_grp_5tab[128 * 3] = { 0, }; /* used: 125 */ +int mpeg3_grp_9tab[1024 * 3] = { 0, }; /* used: 729 */ + +REAL_MATRIX(mpeg3_muls, [27], [64]); /* also used by layer 1 */ +REAL_MATRIX(mpeg3_gainpow2, [256 + 118 + 4], ); +REAL_MATRIX(mpeg3_ispow, [8207], ); +REAL_MATRIX(mpeg3_aa_ca, [8], ); +REAL_MATRIX(mpeg3_aa_cs, [8], ); +REAL_MATRIX(mpeg3_win, [4], [36]); +REAL_MATRIX(mpeg3_win1, [4], [36]); +REAL_MATRIX(mpeg3_COS1, [12], [6]); +REAL_MATRIX(mpeg3_COS9, [9], ); +REAL_MATRIX(mpeg3_tfcos36, [9], ); +REAL_MATRIX(mpeg3_tfcos12, [3], ); +REAL_MATRIX(mpeg3_cos9, [3], ); +REAL_MATRIX(mpeg3_cos18, [3], ); +REAL_MATRIX(mpeg3_tan1_1, [16], ); +REAL_MATRIX(mpeg3_tan2_1, [16], ); +REAL_MATRIX(mpeg3_tan1_2, [16], ); +REAL_MATRIX(mpeg3_tan2_2, [16], ); +REAL_MATRIX(mpeg3_pow1_1, [2], [16]); +REAL_MATRIX(mpeg3_pow2_1, [2], [16]); +REAL_MATRIX(mpeg3_pow1_2, [2], [16]); +REAL_MATRIX(mpeg3_pow2_2, [2], [16]); + +mpeg3_real_t mpeg3_COS6_1, mpeg3_COS6_2; + +#ifdef PRINT_FIXED_POINT_TABLES +static void print_table(const char* var, mpeg3_real_t* data, int count) +{ + int i; + printf("#ifdef USE_DATA_TABLES\n"); + printf("static long %s_data[] = {",var); + for(i = 0; i < count; i++) { + printf("%c0x%08x,", i%8?' ':'\n', data[i].fixedPoint()); + } + printf("};\n"); + printf("#endif\n"); +} +#endif + +#ifdef PRINT_FIXED_POINT_TABLES +# define DO_TABLE(T) print_table(#T, T, sizeof(T)/sizeof(mpeg3_real_t)) +# define DO_TABLE2(T,DIM) print_table(#T, (mpeg3_real_t*)T, sizeof(T)/sizeof(mpeg3_real_t)) +#elif USE_FIXED_POINT +# define DO_TABLE(T) T = (mpeg3_real_t*)T##_data + // multidimensional +# define DO_TABLE2(T,DIM) T = (mpeg3_real_t(*)DIM)T##_data +#else +# define DO_TABLE(T) +# define DO_TABLE2(T,DIM) +#endif + +#if defined(USE_FIXED_POINT) && !defined(PRINT_FIXED_POINT_TABLES) +#define USE_DATA_TABLES +#include "fptables.h" +#endif + +long mpeg3_intwinbase[] = { + 0, -1, -1, -1, -1, -1, -1, -2, -2, -2, + -2, -3, -3, -4, -4, -5, -5, -6, -7, -7, + -8, -9, -10, -11, -13, -14, -16, -17, -19, -21, + -24, -26, -29, -31, -35, -38, -41, -45, -49, -53, + -58, -63, -68, -73, -79, -85, -91, -97, -104, -111, + -117, -125, -132, -139, -147, -154, -161, -169, -176, -183, + -190, -196, -202, -208, -213, -218, -222, -225, -227, -228, + -228, -227, -224, -221, -215, -208, -200, -189, -177, -163, + -146, -127, -106, -83, -57, -29, 2, 36, 72, 111, + 153, 197, 244, 294, 347, 401, 459, 519, 581, 645, + 711, 779, 848, 919, 991, 1064, 1137, 1210, 1283, 1356, + 1428, 1498, 1567, 1634, 1698, 1759, 1817, 1870, 1919, 1962, + 2001, 2032, 2057, 2075, 2085, 2087, 2080, 2063, 2037, 2000, + 1952, 1893, 1822, 1739, 1644, 1535, 1414, 1280, 1131, 970, + 794, 605, 402, 185, -45, -288, -545, -814, -1095, -1388, + -1692, -2006, -2330, -2663, -3004, -3351, -3705, -4063, -4425, -4788, + -5153, -5517, -5879, -6237, -6589, -6935, -7271, -7597, -7910, -8209, + -8491, -8755, -8998, -9219, -9416, -9585, -9727, -9838, -9916, -9959, + -9966, -9935, -9863, -9750, -9592, -9389, -9139, -8840, -8492, -8092, + -7640, -7134, -6574, -5959, -5288, -4561, -3776, -2935, -2037, -1082, + -70, 998, 2122, 3300, 4533, 5818, 7154, 8540, 9975, 11455, + 12980, 14548, 16155, 17799, 19478, 21189, 22929, 24694, 26482, 28289, + 30112, 31947, 33791, 35640, 37489, 39336, 41176, 43006, 44821, 46617, + 48390, 50137, 51853, 53534, 55178, 56778, 58333, 59838, 61289, 62684, + 64019, 65290, 66494, 67629, 68692, 69679, 70590, 71420, 72169, 72835, + 73415, 73908, 74313, 74630, 74856, 74992, 75038 }; + +int mpeg3_longLimit[9][23]; +int mpeg3_shortLimit[9][14]; + +struct mpeg3_bandInfoStruct mpeg3_bandInfo[9] = +{ + +/* MPEG 1.0 */ + { {0,4,8,12,16,20,24,30,36,44,52,62,74, 90,110,134,162,196,238,288,342,418,576}, + {4,4,4,4,4,4,6,6,8, 8,10,12,16,20,24,28,34,42,50,54, 76,158}, + {0,4*3,8*3,12*3,16*3,22*3,30*3,40*3,52*3,66*3, 84*3,106*3,136*3,192*3}, + {4,4,4,4,6,8,10,12,14,18,22,30,56} } , + + { {0,4,8,12,16,20,24,30,36,42,50,60,72, 88,106,128,156,190,230,276,330,384,576}, + {4,4,4,4,4,4,6,6,6, 8,10,12,16,18,22,28,34,40,46,54, 54,192}, + {0,4*3,8*3,12*3,16*3,22*3,28*3,38*3,50*3,64*3, 80*3,100*3,126*3,192*3}, + {4,4,4,4,6,6,10,12,14,16,20,26,66} } , + + { {0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576} , + {4,4,4,4,4,4,6,6,8,10,12,16,20,24,30,38,46,56,68,84,102, 26} , + {0,4*3,8*3,12*3,16*3,22*3,30*3,42*3,58*3,78*3,104*3,138*3,180*3,192*3} , + {4,4,4,4,6,8,12,16,20,26,34,42,12} } , + +/* MPEG 2.0 */ + { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, + {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 } , + {0,4*3,8*3,12*3,18*3,24*3,32*3,42*3,56*3,74*3,100*3,132*3,174*3,192*3} , + {4,4,4,6,6,8,10,14,18,26,32,42,18 } } , + + { {0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,330,394,464,540,576}, + {6,6,6,6,6,6,8,10,12,14,16,18,22,26,32,38,46,52,64,70,76,36 } , + {0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,136*3,180*3,192*3} , + {4,4,4,6,8,10,12,14,18,24,32,44,12 } } , + + { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576}, + {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 }, + {0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,134*3,174*3,192*3}, + {4,4,4,6,8,10,12,14,18,24,30,40,18 } } , +/* MPEG 2.5 */ + { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} , + {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54}, + {0,12,24,36,54,78,108,144,186,240,312,402,522,576}, + {4,4,4,6,8,10,12,14,18,24,30,40,18} }, + { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} , + {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54}, + {0,12,24,36,54,78,108,144,186,240,312,402,522,576}, + {4,4,4,6,8,10,12,14,18,24,30,40,18} }, + { {0,12,24,36,48,60,72,88,108,132,160,192,232,280,336,400,476,566,568,570,572,574,576}, + {12,12,12,12,12,12,16,20,24,28,32,40,48,56,64,76,90,2,2,2,2,2}, + {0, 24, 48, 72,108,156,216,288,372,480,486,492,498,576}, + {8,8,8,12,16,20,24,28,36,2,2,2,26} } , +}; + +int mpeg3_mapbuf0[9][152]; +int mpeg3_mapbuf1[9][156]; +int mpeg3_mapbuf2[9][44]; +int *mpeg3_map[9][3]; +int *mpeg3_mapend[9][3]; + +unsigned int mpeg3_n_slen2[512]; /* MPEG 2.0 slen for 'normal' mode */ +unsigned int mpeg3_i_slen2[256]; /* MPEG 2.0 slen for intensity stereo */ + +int mpeg3audio_init_layer3(mpeg3audio_t *audio); + +int mpeg3audio_init_layer2(mpeg3audio_t *audio) +{ + static double mulmul[27] = + { + 0.0 , -2.0/3.0 , 2.0/3.0 , + 2.0/7.0 , 2.0/15.0 , 2.0/31.0, 2.0/63.0 , 2.0/127.0 , 2.0/255.0 , + 2.0/511.0 , 2.0/1023.0 , 2.0/2047.0 , 2.0/4095.0 , 2.0/8191.0 , + 2.0/16383.0 , 2.0/32767.0 , 2.0/65535.0 , + -4.0/5.0 , -2.0/5.0 , 2.0/5.0, 4.0/5.0 , + -8.0/9.0 , -4.0/9.0 , -2.0/9.0 , 2.0/9.0 , 4.0/9.0 , 8.0/9.0 + }; + static int base[3][9] = + { + { 1 , 0, 2 , } , + { 17, 18, 0 , 19, 20 , } , + { 21, 1, 22, 23, 0, 24, 25, 2, 26 } + }; + static int tablen[3] = { 3, 5, 9 }; + static int *itable, *tables[3] = {mpeg3_grp_3tab, mpeg3_grp_5tab, mpeg3_grp_9tab}; + int i, j, k, l, len; + mpeg3_real_t *table; + + for(i = 0; i < 3; i++) + { + itable = tables[i]; + len = tablen[i]; + for(j = 0; j < len; j++) + for(k = 0; k < len; k++) + for(l = 0; l < len; l++) + { + *itable++ = base[i][l]; + *itable++ = base[i][k]; + *itable++ = base[i][j]; + } + } + +#if !defined(USE_FIXED_POINT) || defined(PRINT_FIXED_POINT_TABLES) +#if defined(PRINT_FIXED_POINT_TABLES) + //mpeg3audio_init_layer3(audio); // we depend on mpeg3_muls table +#endif + for(k = 0; k < 27; k++) + { + double m = mulmul[k]; + table = mpeg3_muls[k]; + for(j = 3, i = 0; i < 63; i++, j--) + *table++ = m * pow(2.0, (double)j / 3.0); + *table++ = 0.0; + } +#endif + DO_TABLE2(mpeg3_muls,[64]); + return 0; +} + +int mpeg3audio_init_layer3(mpeg3audio_t *audio) +{ + int i, j, k, l; + int down_sample_sblimit = 32; + + audio->mp3_block[0][0][0] = 0; + audio->mp3_blc[0] = 0; + audio->mp3_blc[1] = 0; + +#if !defined(USE_FIXED_POINT) || defined(PRINT_FIXED_POINT_TABLES) + for(i = -256; i < 118 + 4; i++) + mpeg3_gainpow2[i + 256] = pow((double)2.0, -0.25 * (double)(i + 210)); + + for(i = 0; i < 8207; i++) + mpeg3_ispow[i] = pow((double)i, (double)4.0 / 3.0); + + for(i = 0; i < 8; i++) + { + static double Ci[8] = {-0.6,-0.535,-0.33,-0.185,-0.095,-0.041,-0.0142,-0.0037}; + double sq = sqrt(1.0+Ci[i]*Ci[i]); + mpeg3_aa_cs[i] = 1.0/sq; + mpeg3_aa_ca[i] = Ci[i]/sq; + } + + for(i = 0; i < 18; i++) + { + mpeg3_win[0][i] = mpeg3_win[1][i] = 0.5 * sin( M_PI / 72.0 * (double)(2 * (i + 0) + 1) ) / cos (M_PI * (double)(2 * (i + 0) + 19) / 72.0); + mpeg3_win[0][i+18] = mpeg3_win[3][i+18] = 0.5 * sin( M_PI / 72.0 * (double)(2 * (i + 18) + 1) ) / cos (M_PI * (double)(2 * (i + 18) + 19) / 72.0); + } + for(i = 0; i < 6; i++) + { + mpeg3_win[1][i + 18] = 0.5 / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 ); + mpeg3_win[3][i + 12] = 0.5 / cos ( M_PI * (double) (2*(i+12)+19) / 72.0 ); + mpeg3_win[1][i + 24] = 0.5 * sin( M_PI / 24.0 * (double)(2 * i + 13) ) / cos (M_PI * (double)(2 * (i + 24)+ 19) / 72.0 ); + mpeg3_win[1][i + 30] = mpeg3_win[3][i] = 0.0; + mpeg3_win[3][i + 6 ] = 0.5 * sin( M_PI / 24.0 * (double)(2 * i + 1) ) / cos (M_PI * (double)(2 * (i + 6 )+ 19) / 72.0 ); + } + + for(i = 0; i < 9; i++) + mpeg3_COS9[i] = cos(M_PI / 18.0 * (double)i); + + for(i = 0; i < 9; i++) + mpeg3_tfcos36[i] = 0.5 / cos (M_PI * (double) (i*2+1) / 36.0); + for(i = 0; i < 3; i++) + mpeg3_tfcos12[i] = 0.5 / cos (M_PI * (double) (i*2+1) / 12.0); + + mpeg3_cos9[0] = cos(1.0 * M_PI / 9.0); + mpeg3_cos9[1] = cos(5.0 * M_PI / 9.0); + mpeg3_cos9[2] = cos(7.0 * M_PI / 9.0); + mpeg3_cos18[0] = cos(1.0 * M_PI / 18.0); + mpeg3_cos18[1] = cos(11.0 * M_PI / 18.0); + mpeg3_cos18[2] = cos(13.0 * M_PI / 18.0); + + for(i = 0; i < 12; i++) + { + mpeg3_win[2][i] = 0.5 * sin(M_PI / 24.0 * (double) (2 * i + 1)) / cos(M_PI * (double)(2 * i + 7) / 24.0); + for(j = 0; j < 6; j++) + mpeg3_COS1[i][j] = cos(M_PI / 24.0 * (double) ((2 * i + 7) * (2 * j + 1))); + } + + for(j = 0; j < 4; j++) + { + static int len[4] = {36, 36, 12, 36}; + for(i = 0; i < len[j]; i += 2) + mpeg3_win1[j][i] = + mpeg3_win[j][i]; + for(i = 1; i < len[j]; i += 2) + mpeg3_win1[j][i] = - mpeg3_win[j][i]; + } + + for(i = 0; i < 16; i++) + { + double t = tan( (double) i * M_PI / 12.0 ); + mpeg3_tan1_1[i] = t / (1.0 + t); + mpeg3_tan2_1[i] = 1.0 / (1.0 + t); + mpeg3_tan1_2[i] = M_SQRT2 * t / (1.0 + t); + mpeg3_tan2_2[i] = M_SQRT2 / (1.0 + t); + + for(j = 0; j < 2; j++) + { + double base = pow(2.0, -0.25 * (j + 1.0)); + double p1 = 1.0,p2 = 1.0; + if(i > 0) + { + if( i & 1 ) + p1 = pow(base, (i + 1.0) * 0.5); + else + p2 = pow(base, i * 0.5); + } + mpeg3_pow1_1[j][i] = p1; + mpeg3_pow2_1[j][i] = p2; + mpeg3_pow1_2[j][i] = M_SQRT2 * p1; + mpeg3_pow2_2[j][i] = M_SQRT2 * p2; + } + } + +#endif + + DO_TABLE(mpeg3_gainpow2); + DO_TABLE(mpeg3_ispow); + DO_TABLE(mpeg3_aa_cs); + DO_TABLE(mpeg3_aa_ca); + DO_TABLE2(mpeg3_win,[36]); + DO_TABLE(mpeg3_COS9); + DO_TABLE(mpeg3_tfcos36); + DO_TABLE(mpeg3_tfcos12); + DO_TABLE(mpeg3_cos9); + DO_TABLE(mpeg3_cos18); + DO_TABLE2(mpeg3_COS1,[6]); + DO_TABLE2(mpeg3_win1,[36]); + DO_TABLE(mpeg3_tan1_1); + DO_TABLE(mpeg3_tan2_1); + DO_TABLE(mpeg3_tan1_2); + DO_TABLE(mpeg3_tan2_2); + DO_TABLE2(mpeg3_pow1_1,[16]); + DO_TABLE2(mpeg3_pow2_1,[16]); + DO_TABLE2(mpeg3_pow1_2,[16]); + DO_TABLE2(mpeg3_pow2_2,[16]); + + mpeg3_COS6_1 = cos( M_PI / 6.0 * (double) 1); + mpeg3_COS6_2 = cos( M_PI / 6.0 * (double) 2); + + for(j = 0; j < 9; j++) + { + struct mpeg3_bandInfoStruct *bi = &mpeg3_bandInfo[j]; + int *mp; + int cb,lwin; + int *bdf; + + mp = mpeg3_map[j][0] = mpeg3_mapbuf0[j]; + bdf = bi->longDiff; + for(i = 0, cb = 0; cb < 8; cb++, i += *bdf++) + { + *mp++ = (*bdf) >> 1; + *mp++ = i; + *mp++ = 3; + *mp++ = cb; + } + bdf = bi->shortDiff + 3; + for(cb = 3; cb < 13; cb++) + { + int l = (*bdf++) >> 1; + for(lwin = 0; lwin < 3; lwin++) + { + *mp++ = l; + *mp++ = i + lwin; + *mp++ = lwin; + *mp++ = cb; + } + i += 6 * l; + } + mpeg3_mapend[j][0] = mp; + + mp = mpeg3_map[j][1] = mpeg3_mapbuf1[j]; + bdf = bi->shortDiff+0; + for(i = 0,cb = 0; cb < 13; cb++) + { + int l = (*bdf++) >> 1; + for(lwin = 0; lwin < 3; lwin++) + { + *mp++ = l; + *mp++ = i + lwin; + *mp++ = lwin; + *mp++ = cb; + } + i += 6 * l; + } + mpeg3_mapend[j][1] = mp; + + mp = mpeg3_map[j][2] = mpeg3_mapbuf2[j]; + bdf = bi->longDiff; + for(cb = 0; cb < 22 ; cb++) + { + *mp++ = (*bdf++) >> 1; + *mp++ = cb; + } + mpeg3_mapend[j][2] = mp; + } + + for(j = 0; j < 9; j++) + { + for(i = 0; i < 23; i++) + { + mpeg3_longLimit[j][i] = (mpeg3_bandInfo[j].longIdx[i] - 1 + 8) / 18 + 1; + if(mpeg3_longLimit[j][i] > (down_sample_sblimit)) + mpeg3_longLimit[j][i] = down_sample_sblimit; + } + for(i = 0; i < 14; i++) + { + mpeg3_shortLimit[j][i] = (mpeg3_bandInfo[j].shortIdx[i] - 1) / 18 + 1; + if(mpeg3_shortLimit[j][i] > (down_sample_sblimit) ) + mpeg3_shortLimit[j][i] = down_sample_sblimit; + } + } + + for(i = 0; i < 5; i++) + { + for(j = 0; j < 6; j++) + { + for(k = 0; k < 6; k++) + { + int n = k + j * 6 + i * 36; + mpeg3_i_slen2[n] = i | (j << 3) | (k << 6) | (3 << 12); + } + } + } + for(i = 0; i < 4; i++) + { + for(j = 0; j < 4; j++) + { + for(k = 0; k < 4; k++) + { + int n = k + j * 4 + i * 16; + mpeg3_i_slen2[n+180] = i | (j << 3) | (k << 6) | (4 << 12); + } + } + } + for(i = 0; i < 4; i++) + { + for(j = 0; j < 3; j++) + { + int n = j + i * 3; + mpeg3_i_slen2[n + 244] = i | (j << 3) | (5 << 12); + mpeg3_n_slen2[n + 500] = i | (j << 3) | (2 << 12) | (1 << 15); + } + } + + for(i = 0; i < 5; i++) + { + for(j = 0; j < 5; j++) + { + for(k = 0; k < 4; k++) + { + for(l = 0; l < 4; l++) + { + int n = l + k * 4 + j * 16 + i * 80; + mpeg3_n_slen2[n] = i | (j << 3) | ( k << 6) | (l << 9) | (0 << 12); + } + } + } + } + for(i = 0; i < 5; i++) + { + for(j = 0; j < 5; j++) + { + for(k = 0; k < 4; k++) + { + int n = k + j * 4 + i * 20; + mpeg3_n_slen2[n + 400] = i | (j << 3) | (k << 6) | (1 << 12); + } + } + } + + return 0; +} + +int mpeg3audio_new_decode_tables(mpeg3audio_t *audio) +{ + int i, j, k, kr, divv; + mpeg3_real_t *costab; + int idx; + long scaleval = audio->outscale; + + + for(i = 0; i < 5; i++) + { + kr = 0x10 >> i; + divv = 0x40 >> i; + costab = mpeg3_pnts[i]; + for(k = 0; k < kr; k++) + costab[k] = 1.0 / (2.0 * cos(M_PI * ((double)k * 2.0 + 1.0) / (double)divv)); + +#ifdef USE_3DNOW + for(k = 0; k < kr; k++) + costab[k + kr] = -costab[k]; +#endif + + } + + idx = 0; + scaleval = -scaleval; + for(i = 0, j = 0; i < 256; i++, j++,idx += 32) + { + if(idx < 512 + 16) + mpeg3_decwin[idx+16] = mpeg3_decwin[idx] = (double)mpeg3_intwinbase[j] / 65536.0 * (double)scaleval; + + if(i % 32 == 31) + idx -= 1023; + if(i % 64 == 63) + scaleval = -scaleval; + } + + for( ; i < 512; i++, j--, idx += 32) + { + if(idx < 512 + 16) + mpeg3_decwin[idx + 16] = mpeg3_decwin[idx] = (double)mpeg3_intwinbase[j] / 65536.0 * (double)scaleval; + + if(i % 32 == 31) + idx -= 1023; + if(i % 64 == 63) + scaleval = -scaleval; + } + +#ifdef USE_3DNOW + if(!param.down_sample) + { + for(i = 0; i < 512 + 32; i++) + { + mpeg3_decwin[512 + 31 - i] *= 65536.0; /* allows faster clipping in 3dnow code */ + mpeg3_decwin[512 + 32 + i] = mpeg3_decwin[512 + 31 - i]; + } + } +#endif + +/* Initialize AC3 */ + audio->ac3_lfsr_state = 1; + mpeg3audio_imdct_init(audio); +/* Initialize MPEG */ + mpeg3audio_init_layer2(audio); /* inits also shared tables with layer1 */ + mpeg3audio_init_layer3(audio); + return 0; +} diff --git a/core/multimedia/opieplayer/libmpeg3/audio/tables.h b/core/multimedia/opieplayer/libmpeg3/audio/tables.h new file mode 100644 index 0000000..7b14de1 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/tables.h @@ -0,0 +1,88 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef TABLES_H +#define TABLES_H + +extern int mpeg3_tabsel_123[2][3][16]; + +extern long mpeg3_freqs[9]; + +struct mpeg3_bandInfoStruct +{ + int longIdx[23]; + int longDiff[22]; + int shortIdx[14]; + int shortDiff[13]; +}; + + +extern mpeg3_real_t mpeg3_decwin[512 + 32]; +extern mpeg3_real_t mpeg3_cos64[16], mpeg3_cos32[8], mpeg3_cos16[4], mpeg3_cos8[2], mpeg3_cos4[1]; + +extern mpeg3_real_t *mpeg3_pnts[5]; + +extern int mpeg3_grp_3tab[32 * 3]; /* used: 27 */ +extern int mpeg3_grp_5tab[128 * 3]; /* used: 125 */ +extern int mpeg3_grp_9tab[1024 * 3]; /* used: 729 */ +extern long mpeg3_intwinbase[257]; +extern mpeg3_real_t mpeg3_COS6_1, mpeg3_COS6_2; + +#if defined(USE_FIXED_POINT) && !defined(PRINT_FIXED_POINT_TABLES) +# define REAL_MATRIX(var,dim1,dimn) mpeg3_real_t (*var)dimn +#else +# define REAL_MATRIX(var,dim1,dimn) mpeg3_real_t var dim1 dimn +#endif +extern REAL_MATRIX(mpeg3_muls, [27], [64]); /* also used by layer 1 */ +extern REAL_MATRIX(mpeg3_gainpow2, [256 + 118 + 4], ); +extern REAL_MATRIX(mpeg3_ispow, [8207], ); +extern REAL_MATRIX(mpeg3_aa_ca, [8], ); +extern REAL_MATRIX(mpeg3_aa_cs, [8], ); +extern REAL_MATRIX(mpeg3_win, [4], [36]); +extern REAL_MATRIX(mpeg3_win1, [4], [36]); +extern REAL_MATRIX(mpeg3_COS1, [12], [6]); +extern REAL_MATRIX(mpeg3_COS9, [9], ); +extern REAL_MATRIX(mpeg3_tfcos36, [9], ); +extern REAL_MATRIX(mpeg3_tfcos12, [3], ); +extern REAL_MATRIX(mpeg3_cos9, [3], ); +extern REAL_MATRIX(mpeg3_cos18, [3], ); +extern REAL_MATRIX(mpeg3_tan1_1, [16], ); +extern REAL_MATRIX(mpeg3_tan2_1, [16], ); +extern REAL_MATRIX(mpeg3_tan1_2, [16], ); +extern REAL_MATRIX(mpeg3_tan2_2, [16], ); +extern REAL_MATRIX(mpeg3_pow1_1, [2], [16]); +extern REAL_MATRIX(mpeg3_pow2_1, [2], [16]); +extern REAL_MATRIX(mpeg3_pow1_2, [2], [16]); +extern REAL_MATRIX(mpeg3_pow2_2, [2], [16]); + +extern int mpeg3_longLimit[9][23]; +extern int mpeg3_shortLimit[9][14]; + +extern struct mpeg3_bandInfoStruct mpeg3_bandInfo[9]; + +extern int mpeg3_mapbuf0[9][152]; +extern int mpeg3_mapbuf1[9][156]; +extern int mpeg3_mapbuf2[9][44]; +extern int *mpeg3_map[9][3]; +extern int *mpeg3_mapend[9][3]; + +extern unsigned int mpeg3_n_slen2[512]; /* MPEG 2.0 slen for 'normal' mode */ +extern unsigned int mpeg3_i_slen2[256]; /* MPEG 2.0 slen for intensity stereo */ + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/audio/uncouple.c b/core/multimedia/opieplayer/libmpeg3/audio/uncouple.c new file mode 100644 index 0000000..d87a078 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/audio/uncouple.c @@ -0,0 +1,135 @@ +/* + * + * uncouple.c Copyright (C) Aaron Holtzman - May 1999 + * + * This file is part of libmpeg3 + * + * libmpeg3 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * libmpeg3 is distributed in the hope that 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 GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#include "../bitstream.h" +#include "mpeg3audio.h" + +static unsigned char mpeg3_first_bit_lut[256] = +{ + 0, 8, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 +}; + +/* Converts an unsigned exponent in the range of 0-24 and a 16 bit mantissa + * to an IEEE single precision floating point value */ +static inline void mpeg3audio_ac3_convert_to_float(unsigned short exp, + unsigned short mantissa, + unsigned MPEG3_INT32 *dest) +{ + int num; + short exponent; + int i; + +/* If the mantissa is zero we can simply return zero */ + if(mantissa == 0) + { + *dest = 0; + return; + } + +/* Exponent is offset by 127 in IEEE format minus the shift to + * align the mantissa to 1.f (subtracted in the final result) */ + exponent = 127 - exp; + +/* Take care of the one asymmetric negative number */ + if(mantissa == 0x8000) + mantissa++; + +/* Extract the sign bit, invert the mantissa if it's negative, and + shift out the sign bit */ + if(mantissa & 0x8000) + { + mantissa *= -1; + num = 0x80000000 + (exponent << 23); + } + else + { + mantissa *= 1; + num = exponent << 23; + } + +/* Find the index of the most significant one bit */ + i = mpeg3_first_bit_lut[mantissa >> 8]; + + if(i == 0) + i = mpeg3_first_bit_lut[mantissa & 0xff] + 8; + + *dest = num - (i << 23) + (mantissa << (7 + i)); + return; +} + + +int mpeg3audio_ac3_uncouple(mpeg3audio_t *audio, + mpeg3_ac3bsi_t *bsi, + mpeg3_ac3audblk_t *audblk, + mpeg3_stream_coeffs_t *coeffs) +{ + int i, j; + + for(i = 0; i < bsi->nfchans; i++) + { + for(j = 0; j < audblk->endmant[i]; j++) + mpeg3audio_ac3_convert_to_float(audblk->fbw_exp[i][j], + audblk->chmant[i][j], + (unsigned MPEG3_INT32*)&coeffs->fbw[i][j]); + } + + if(audblk->cplinu) + { + for(i = 0; i < bsi->nfchans; i++) + { + if(audblk->chincpl[i]) + { + mpeg3audio_ac3_uncouple_channel(audio, + coeffs, + audblk, + i); + } + } + + } + + if(bsi->lfeon) + { +/* There are always 7 mantissas for lfe */ + for(j = 0; j < 7 ; j++) + mpeg3audio_ac3_convert_to_float(audblk->lfe_exp[j], + audblk->lfemant[j], + (unsigned MPEG3_INT32*)&coeffs->lfe[j]); + + } + return 0; +} diff --git a/core/multimedia/opieplayer/libmpeg3/bitstream.c b/core/multimedia/opieplayer/libmpeg3/bitstream.c new file mode 100644 index 0000000..b4f46e3 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/bitstream.c @@ -0,0 +1,167 @@ +#include "mpeg3private.h" +#include "mpeg3protos.h" + +#include <stdlib.h> + +mpeg3_bits_t* mpeg3bits_new_stream(mpeg3_t *file, mpeg3_demuxer_t *demuxer) +{ + mpeg3_bits_t *stream = (mpeg3_bits_t*)malloc(sizeof(mpeg3_bits_t)); + stream->bfr = 0; + stream->bfr_size = 0; + stream->bit_number = 0; + stream->file = file; + stream->demuxer = demuxer; + stream->input_ptr = 0; + return stream; +} + +int mpeg3bits_delete_stream(mpeg3_bits_t* stream) +{ + free(stream); + return 0; +} + + +/* Fill a buffer. Only works if bit_number is on an 8 bit boundary */ +int mpeg3bits_read_buffer(mpeg3_bits_t* stream, unsigned char *buffer, int bytes) +{ + int result, i = 0; + while(stream->bit_number > 0) + { + stream->bit_number -= 8; + mpeg3demux_read_prev_char(stream->demuxer); + } + + stream->bit_number = 0; + stream->bfr_size = 0; + stream->bfr = 0; + result = mpeg3demux_read_data(stream->demuxer, buffer, bytes); + return result; +} + +/* For mp3 decompression use a pointer in a buffer for getbits. */ +int mpeg3bits_use_ptr(mpeg3_bits_t* stream, unsigned char *buffer) +{ + stream->bfr_size = stream->bit_number = 0; + stream->bfr = 0; + stream->input_ptr = buffer; + return 0; +} + +/* Go back to using the demuxer for getbits in mp3. */ +int mpeg3bits_use_demuxer(mpeg3_bits_t* stream) +{ + if(stream->input_ptr) + { + stream->bfr_size = stream->bit_number = 0; + stream->input_ptr = 0; + stream->bfr = 0; + } + + return 0; +} + +/* Reconfigure for reverse operation */ +/* Default is forward operation */ +void mpeg3bits_start_reverse(mpeg3_bits_t* stream) +{ + int i; + for(i = 0; i < stream->bfr_size; i += 8) + if(stream->input_ptr) + stream->input_ptr--; + else + mpeg3demux_read_prev_char(stream->demuxer); +} + +/* Reconfigure for forward operation */ +void mpeg3bits_start_forward(mpeg3_bits_t* stream) +{ + int i; + for(i = 0; i < stream->bfr_size; i += 8) + if(stream->input_ptr) + stream->input_ptr++; + else + mpeg3demux_read_char(stream->demuxer); +} + +/* Erase the buffer with the next 4 bytes in the file. */ +int mpeg3bits_refill(mpeg3_bits_t* stream) +{ + stream->bit_number = 32; + stream->bfr_size = 32; + + if(stream->input_ptr) + { + stream->bfr = (unsigned int)(*stream->input_ptr++) << 24; + stream->bfr |= (unsigned int)(*stream->input_ptr++) << 16; + stream->bfr |= (unsigned int)(*stream->input_ptr++) << 8; + stream->bfr |= *stream->input_ptr++; + } + else + { + stream->bfr = mpeg3demux_read_char(stream->demuxer) << 24; + stream->bfr |= mpeg3demux_read_char(stream->demuxer) << 16; + stream->bfr |= mpeg3demux_read_char(stream->demuxer) << 8; + stream->bfr |= mpeg3demux_read_char(stream->demuxer); + } + return mpeg3demux_eof(stream->demuxer); +} + +/* Erase the buffer with the previous 4 bytes in the file. */ +int mpeg3bits_refill_backwards(mpeg3_bits_t* stream) +{ + stream->bit_number = 0; + stream->bfr_size = 32; + stream->bfr = mpeg3demux_read_prev_char(stream->demuxer); + stream->bfr |= (unsigned int)mpeg3demux_read_prev_char(stream->demuxer) << 8; + stream->bfr |= (unsigned int)mpeg3demux_read_prev_char(stream->demuxer) << 16; + stream->bfr |= (unsigned int)mpeg3demux_read_prev_char(stream->demuxer) << 24; + return mpeg3demux_eof(stream->demuxer); +} + +int mpeg3bits_byte_align(mpeg3_bits_t *stream) +{ + stream->bit_number = (stream->bit_number + 7) & 0xf8; + return 0; +} + +int mpeg3bits_seek_end(mpeg3_bits_t* stream) +{ + stream->bfr_size = stream->bit_number = 0; + return mpeg3demux_seek_byte(stream->demuxer, mpeg3demuxer_total_bytes(stream->demuxer)); +} + +int mpeg3bits_seek_start(mpeg3_bits_t* stream) +{ + stream->bfr_size = stream->bit_number = 0; + return mpeg3demux_seek_byte(stream->demuxer, 0); +} + +int mpeg3bits_seek_time(mpeg3_bits_t* stream, double time_position) +{ + stream->bfr_size = stream->bit_number = 0; + return mpeg3demux_seek_time(stream->demuxer, time_position); +} + +int mpeg3bits_seek_byte(mpeg3_bits_t* stream, long position) +{ + stream->bfr_size = stream->bit_number = 0; + return mpeg3demux_seek_byte(stream->demuxer, position); +} + +int mpeg3bits_seek_percentage(mpeg3_bits_t* stream, double percentage) +{ + stream->bfr_size = stream->bit_number = 0; + return mpeg3demux_seek_percentage(stream->demuxer, percentage); +} + +int mpeg3bits_tell(mpeg3_bits_t* stream) +{ + return mpeg3demux_tell(stream->demuxer); +} + +int mpeg3bits_getbitoffset(mpeg3_bits_t *stream) +{ + return stream->bit_number & 7; +} + diff --git a/core/multimedia/opieplayer/libmpeg3/bitstream.h b/core/multimedia/opieplayer/libmpeg3/bitstream.h new file mode 100644 index 0000000..2f6dcf9 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/bitstream.h @@ -0,0 +1,207 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef BITSTREAM_H +#define BITSTREAM_H + +#include "mpeg3demux.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +// next bit in forward direction +// next bit in reverse direction | +// v v +// | | | | | | | | | | | | | | | | | | | | | | | | | | |1|1|1|1|1|1| */ +// ^ ^ +// | bit_number = 1 +// bfr_size = 6 + +typedef struct +{ + unsigned MPEG3_INT32 bfr; /* bfr = buffer for bits */ + int bit_number; /* position of pointer in bfr */ + int bfr_size; /* number of bits in bfr. Should always be a multiple of 8 */ + struct mpeg3_rec *file; /* Mpeg2 file */ + mpeg3_demuxer_t *demuxer; /* Mpeg2 demuxer */ +/* If the input ptr is true, data is read from it instead of the demuxer. */ + unsigned char *input_ptr; +} mpeg3_bits_t; + +LIBMPEG_EXPORT unsigned int mpeg3demux_read_char_packet(mpeg3_demuxer_t *demuxer); +LIBMPEG_EXPORT unsigned int mpeg3demux_read_prev_char_packet(mpeg3_demuxer_t *demuxer); + +/* ======================================================================== */ +/* Entry Points */ +/* ======================================================================== */ + +#define mpeg3bits_tell_percentage(stream) mpeg3demux_tell_percentage((stream)->demuxer) + +#define mpeg3bits_packet_time(stream) mpeg3demux_current_time((stream)->demuxer) + +#define mpeg3bits_time_offset(stream) mepg2demux_time_offset((stream)->demuxer) + +#define mpeg3bits_error(stream) mpeg3demux_error((stream)->demuxer) + +#define mpeg3bits_eof(stream) mpeg3demux_eof((stream)->demuxer) + +#define mpeg3bits_bof(stream) mpeg3demux_bof((stream)->demuxer) + +/* Read bytes backward from the file until the reverse_bits is full. */ +static inline void mpeg3bits_fill_reverse_bits(mpeg3_bits_t* stream, int bits) +{ +// Right justify + while(stream->bit_number > 7) + { + stream->bfr >>= 8; + stream->bfr_size -= 8; + stream->bit_number -= 8; + } + +// Insert bytes before bfr_size + while(stream->bfr_size - stream->bit_number < bits) + { + if(stream->input_ptr) + stream->bfr |= (unsigned int)(*--stream->input_ptr) << stream->bfr_size; + else + stream->bfr |= (unsigned int)mpeg3demux_read_prev_char(stream->demuxer) << stream->bfr_size; + stream->bfr_size += 8; + } +} + +/* Read bytes forward from the file until the forward_bits is full. */ +extern inline void mpeg3bits_fill_bits(mpeg3_bits_t* stream, int bits) +{ + while(stream->bit_number < bits) + { + stream->bfr <<= 8; + if(stream->input_ptr) + { + stream->bfr |= *stream->input_ptr++; + } + else + { + stream->bfr |= mpeg3demux_read_char(stream->demuxer); + } + stream->bit_number += 8; + stream->bfr_size += 8; + if(stream->bfr_size > 32) stream->bfr_size = 32; + } +} + +/* Return 8 bits, advancing the file position. */ +extern inline unsigned int mpeg3bits_getbyte_noptr(mpeg3_bits_t* stream) +{ + if(stream->bit_number < 8) + { + stream->bfr <<= 8; + if(stream->input_ptr) + stream->bfr |= *stream->input_ptr++; + else + stream->bfr |= mpeg3demux_read_char(stream->demuxer); + + stream->bfr_size += 8; + if(stream->bfr_size > 32) stream->bfr_size = 32; + + return (stream->bfr >> stream->bit_number) & 0xff; + } + return (stream->bfr >> (stream->bit_number -= 8)) & 0xff; +} + +extern inline unsigned int mpeg3bits_getbit_noptr(mpeg3_bits_t* stream) +{ + if(!stream->bit_number) + { + stream->bfr <<= 8; + stream->bfr |= mpeg3demux_read_char(stream->demuxer); + + stream->bfr_size += 8; + if(stream->bfr_size > 32) stream->bfr_size = 32; + + stream->bit_number = 7; + + return (stream->bfr >> 7) & 0x1; + } + return (stream->bfr >> (--stream->bit_number)) & (0x1); +} + +/* Return n number of bits, advancing the file position. */ +/* Use in place of flushbits */ +extern inline unsigned int mpeg3bits_getbits(mpeg3_bits_t* stream, int bits) +{ + if(bits <= 0) return 0; + mpeg3bits_fill_bits(stream, bits); + return (stream->bfr >> (stream->bit_number -= bits)) & (0xffffffff >> (32 - bits)); +} + +extern inline unsigned int mpeg3bits_showbits24_noptr(mpeg3_bits_t* stream) +{ + while(stream->bit_number < 24) + { + stream->bfr <<= 8; + stream->bfr |= mpeg3demux_read_char(stream->demuxer); + stream->bit_number += 8; + stream->bfr_size += 8; + if(stream->bfr_size > 32) stream->bfr_size = 32; + } + return (stream->bfr >> (stream->bit_number - 24)) & 0xffffff; +} + +extern inline unsigned int mpeg3bits_showbits32_noptr(mpeg3_bits_t* stream) +{ + while(stream->bit_number < 32) + { + stream->bfr <<= 8; + stream->bfr |= mpeg3demux_read_char(stream->demuxer); + stream->bit_number += 8; + stream->bfr_size += 8; + if(stream->bfr_size > 32) stream->bfr_size = 32; + } + return stream->bfr; +} + +extern inline unsigned int mpeg3bits_showbits(mpeg3_bits_t* stream, int bits) +{ + mpeg3bits_fill_bits(stream, bits); + return (stream->bfr >> (stream->bit_number - bits)) & (0xffffffff >> (32 - bits)); +} + +extern inline unsigned int mpeg3bits_getbits_reverse(mpeg3_bits_t* stream, int bits) +{ + unsigned int result; + mpeg3bits_fill_reverse_bits(stream, bits); + result = (stream->bfr >> stream->bit_number) & (0xffffffff >> (32 - bits)); + stream->bit_number += bits; + return result; +} + +extern inline unsigned int mpeg3bits_showbits_reverse(mpeg3_bits_t* stream, int bits) +{ + unsigned int result; + mpeg3bits_fill_reverse_bits(stream, bits); + result = (stream->bfr >> stream->bit_number) & (0xffffffff >> (32 - bits)); + return result; +} + +#if defined(__cplusplus) +} +#endif + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/c_flags b/core/multimedia/opieplayer/libmpeg3/c_flags new file mode 100755 index 0000000..0c8a75d --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/c_flags @@ -0,0 +1,4 @@ +case "$1" in + *.c) echo $CFLAGS_lessopt +;; *) echo $CFLAGS +esac diff --git a/core/multimedia/opieplayer/libmpeg3/configure b/core/multimedia/opieplayer/libmpeg3/configure new file mode 100755 index 0000000..e75af76 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/configure @@ -0,0 +1,102 @@ +#!/bin/sh + +USE_MMX=1 +USE_CSS=1 +LESS_OPT= +PLATFORM_CFLAGS="-malign-loops=2 -malign-jumps=2 -malign-functions=2 -march=i486" +DEBUG= +OPTIMIZE=-O2 +OPTIMIZE_less=-O +DEFINES= +CC=gcc + +for ac_option +do +case "$ac_option" in + --fixed-point) + CC=g++ + DEFINES="$DEFINES -DUSE_FIXED_POINT" + ;; + + --lessopt) + LESS_OPT=1 + ;; + + --no-mmx) + USE_MMX=0 + ;; + + --no-css) + USE_CSS=0 + ;; + + --debug) + DEBUG=-g + ;; + + --gcc-prefix=*) + CROSS=${ac_option#--gcc-prefix=} + PLATFORM_CFLAGS="" + ;; + -h | --help | -help) + cat << EOF +Options: + --no-mmx Compile libmpeg3 with no MMX support. + --no-css Compile libmpeg3 with no CSS support. + --fixed-point Compile libmpeg3 to use integers instead of floats. + --debug Compile libmpeg3 with debug support. +EOF + exit 0 + ;; + + *) + ;; +esac +done + + +echo "Configuring libmpeg3" + +cat > global_config << EOF +# DO NOT EDIT. EDIT ./configure INSTEAD AND RERUN IT. +EOF + + +if test -z "$CFLAGS"; then + CF="$DEFINES $DEBUG -funroll-loops -fomit-frame-pointer $PLATFORM_CFLAGS" + echo >> global_config "CFLAGS = $CF $OPTIMIZE" + if test -z "$LESS_OPT"; then + echo >> global_config "CFLAGS_lessopt = $CF $OPTIMIZE_less" + else + echo >> global_config "CFLAGS_lessopt = $CF $OPTIMIZE_less" + fi +fi + +cat >> global_config << EOF +CC = ${CROSS}$CC +AR = ${CROSS}ar +NASM = nasm +EOF + +if [ ${USE_CSS} = 1 ]; then +cat >> global_config << EOF +CFLAGS += -DHAVE_CSS +EOF +fi + +if [ ${USE_MMX} = 1 ]; then +cat >> global_config << EOF +CFLAGS += -DHAVE_MMX +MMXOBJS = \ + video/mmxidct.o \ + video/reconmmx.o +MMXOBJS2 = \ + mmxidct.o \ + reconmmx.o +EOF +fi + + + + +echo "done" diff --git a/core/multimedia/opieplayer/libmpeg3/docs/index.html b/core/multimedia/opieplayer/libmpeg3/docs/index.html new file mode 100644 index 0000000..2d79978 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/docs/index.html @@ -0,0 +1,306 @@ +<TITLE>LibMPEG3</TITLE> + +<CENTER> +<FONT FACE=HELVETICA SIZE=+4><B>Using LibMPEG3 to make your own MPEG applications</B></FONT><P> + +<TABLE> +<TR> +<TD> +<CODE> +Author: Adam Williams broadcast@earthling.net<BR> +Homepage: heroinewarrior.com<BR> +</CODE> +</TD> +</TR> +</TABLE> +</CENTER> + +<P> + + +LibMPEG3 decodes the many many derivatives of MPEG standards into +uncompressed data suitable for editing and playback.<P> + +libmpeg3 currently decodes:<P> + +<BLOCKQUOTE>MPEG-2 video<BR> +MPEG-1 video<BR> +mp3 audio<BR> +mp2 audio<BR> +ac3 audio<BR> +MPEG-2 system streams<BR> +MPEG-1 system streams +</BLOCKQUOTE><P> + +The video output can be in many different color models and frame +sizes. The audio output can be in twos compliment or floating +point.<P> + + + + + + + + + +<FONT FACE=HELVETICA SIZE=+4><B>STEP 1: Verifying file compatibility</B></FONT><P> + +Programs using libmpeg3 must <CODE>#include "libmpeg3.h"</CODE>.<P> + +Call <CODE>mpeg3_check_sig</CODE> to verify if the file can be read by +libmpeg3. This returns a 1 if it is compatible and 0 if it isn't.<P> + + + + + + + + + + + +<FONT FACE=HELVETICA SIZE=+4><B>STEP 2: Open the file</B></FONT><P> + +You need an <CODE>mpeg3_t*</CODE> file descriptor:<P> +<CODE> +mpeg3_t* file; +</CODE> +<P> + +Then you need to open the file:<P> + +<CODE>file = mpeg3_open(char *path);</CODE><P> + +<CODE>mpeg3_open</CODE> returns a NULL if the file couldn't be opened +for some reason. Be sure to check this. Everything you do with +libmpeg3 requires passing the <CODE>file</CODE> pointer.<P> + + + + + + + + + + + + + + +<FONT FACE=HELVETICA SIZE=+4><B>STEP 3: How many CPUs do you want to use?</B></FONT><P> + +Call <CODE>mpeg3_set_cpus(mpeg3_t *file, int cpus)</CODE> to set how +many CPUs should be devoted to video decompression. LibMPEG3 can use +any number. If you don't call this right after opening the file, the +CPU number defaults to 1.<P> + + + + + + + +<FONT FACE=HELVETICA SIZE=+4><B>STEP 4: Get some information about the file.</B></FONT><P> + +There are a number of queries for the audio components of the stream:<P> + +<CODE><PRE> +int mpeg3_has_audio(mpeg3_t *file); +int mpeg3_total_astreams(mpeg3_t *file); // Number of multiplexed audio streams +int mpeg3_audio_channels(mpeg3_t *file, int stream); +int mpeg3_sample_rate(mpeg3_t *file, int stream); +long mpeg3_audio_samples(mpeg3_t *file, int stream); // Total length +</PRE></CODE> + +The audio is presented as a number of <B>streams</B> starting at 0 and +including <CODE>mpeg3_total_astreams</CODE> - 1. Each stream contains a +certain number of <B>channels</B> starting at 0 and including +<CODE>mpeg3_audio_channels</CODE> - 1. + +The methodology is first determine if the file has audio, then get +the number of streams in the file, then for each stream get the number +of channels, sample rate, and length.<P> + +There are also queries for the video components:<P> + +<CODE><PRE> +int mpeg3_has_video(mpeg3_t *file); +int mpeg3_total_vstreams(mpeg3_t *file); // Number of multiplexed video streams +int mpeg3_video_width(mpeg3_t *file, int stream); +int mpeg3_video_height(mpeg3_t *file, int stream); +float mpeg3_frame_rate(mpeg3_t *file, int stream); // Frames/sec +long mpeg3_video_frames(mpeg3_t *file, int stream); // Total length +</PRE></CODE> + +The video behavior is the same as with audio, except that video has no +subdivision under <B>streams</B>. Frame rate is a floating point +number of frames per second.<P> + + + + + + + +<FONT FACE=HELVETICA SIZE=+4><B>STEP 5: Seeking to a point in the file</B></FONT><P> + +Each audio stream and each video stream has a position in the file +independant of each other stream. A variety of methods are available +for specifying the position of a stream: percentage, frame, sample. +Which method you use depends on whether you're seeking audio or video +and whether you're seeking all tracks to a percentage of the file.<P> + +The preferred seeking method if you're writing a player is:<P> + +<CODE><PRE> +int mpeg3_seek_percentage(mpeg3_t *file, double percentage); +double mpeg3_tell_percentage(mpeg3_t *file); +</PRE></CODE> + +This seeks all tracks to a percentage of the file length. The +percentage is from 0 to 1.<P> + +The alternative is absolute seeking. The audio seeking is handled +by:<P> + +<CODE><PRE> +int mpeg3_set_sample(mpeg3_t *file, long sample, int stream); // Seek +long mpeg3_get_sample(mpeg3_t *file, int stream); // Tell current position +</PRE></CODE> + +and the video seeking is handled by:<P> + +<CODE><PRE> +int mpeg3_set_frame(mpeg3_t *file, long frame, int stream); // Seek +long mpeg3_get_frame(mpeg3_t *file, int stream); // Tell current position +</PRE></CODE> + + +You can either perform percentage seeking or absolute seeking but not +both on the same file handle. Once you perform either method, the file +becomes configured for that method.<P> + +If you're in percentage seeking mode and you want the current time +stamp in the file you can't use mpeg3_tell_percentage because you don't +know how many seconds the total length is. The +<CODE>mpeg3_audio_samples</CODE> and <CODE>mpeg3_video_frames</CODE> +commands don't work in percentage seeking. Instead use + +<CODE><PRE> +double mpeg3_get_time(mpeg3_t *file); +</PRE></CODE> + +which gives you the last timecode read in seconds. The MPEG standard +specifies timecodes being placed in the streams.<P> + + + + + + + + + + + +<FONT FACE=HELVETICA SIZE=+4><B>STEP 6: Read the data</B></FONT><P> + +To read <B>audio</B> data use:<P> + +<CODE><PRE> +int mpeg3_read_audio(mpeg3_t *file, + float *output_f, // Pointer to pre-allocated buffer of floats + short *output_i, // Pointer to pre-allocated buffer if int16's + int channel, // Channel to decode + long samples, // Number of samples to decode + int stream); // Stream containing the channel +</PRE></CODE> + +This decodes a buffer of sequential floats or int16's for a single +channel, depending on which *output... parameter has a nonzero +argument. To get a floating point buffer pass a pre-allocated buffer +to <CODE>output_f</CODE> and NULL to <CODE>output_i</CODE>. To get an +int16 buffer pass NULL to <CODE>output_f</CODE> and a pre-allocated +buffer to <CODE>output_i</CODE>.<P> + +After reading an audio buffer, the current position in the one stream +is advanced. How then, do you read more than one channel of audio +data? Use + +<CODE><PRE> +mpeg3_reread_audio(mpeg3_t *file, + float *output_f, /* Pointer to pre-allocated buffer of floats */ + short *output_i, /* Pointer to pre-allocated buffer of int16's */ + int channel, /* Channel to decode */ + long samples, /* Number of samples to decode */ + int stream); +</PRE></CODE> + +to read each remaining channel after the first channel.<P> + +To read <B>video</B> data there are two methods. RGB frames or YUV +frames. To get an RGB frame use:<BR> + +<CODE><PRE> +int mpeg3_read_frame(mpeg3_t *file, + unsigned char **output_rows, // Array of pointers to the start of each output row + int in_x, // Location in input frame to take picture + int in_y, + int in_w, + int in_h, + int out_w, // Dimensions of output_rows + int out_h, + int color_model, // One of the color model #defines given above. + int stream); +</PRE></CODE> + +The video decoding works like a camcorder taking copy of a movie +screen. The decoder "sees" a region of the movie screen defined by +<CODE>in_x, in_y, in_w, in_h</CODE> and transfers it to the frame +buffer defined by <CODE>**output_rows</CODE>. The input values must be +within the boundaries given by <CODE>mpeg3_video_width</CODE> and +<CODE>mpeg3_video_height</CODE>. The size of the frame buffer is +defined by <CODE>out_w, out_h</CODE>. Although the input dimensions +are constrained, the frame buffer can be any size.<P> + +<CODE>color_model</CODE> defines which RGB color model the picture +should be decoded to and the possible values are given in +<B>libmpeg3.h</B>. The frame buffer pointed to by +<CODE>output_rows</CODE> must have enough memory allocated to store the +color model you select.<P> + +<B>You must allocate 4 extra bytes in the last output_row.</B> This is +scratch area for the MMX routines.<P> + +<CODE>mpeg3_read_frame</CODE> advances the position in the one stream by 1 frame.<P> + +The alternative is YUV frames:<BR> + +<CODE><PRE> +int mpeg3_read_yuvframe(mpeg3_t *file, + char *y_output, + char *u_output, + char *v_output, + int in_x, + int in_y, + int in_w, + int in_h, + int stream); +</PRE></CODE> + +The behavior of in_x, in_y, in_w, in_h is identical to mpeg3_read_frame +except here you have no control over the output frame size. <B>You +must allocate in_w * in_h for the y_output, and in_w * in_h / 4 for the +chroma outputs.</B><P> + + + + + +<FONT FACE=HELVETICA SIZE=+4><B>STEP 7: Close the file</B></FONT><P> + +Be sure to close the file with <CODE>mpeg3_close(mpeg3_t *file)</CODE> +when you're done with it. diff --git a/core/multimedia/opieplayer/libmpeg3/dump.c b/core/multimedia/opieplayer/libmpeg3/dump.c new file mode 100644 index 0000000..7158712 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/dump.c @@ -0,0 +1,79 @@ +#include "libmpeg3.h" +#include <stdlib.h> + +#define BUFSIZE 4096 + +int main(int argc, char *argv[]) +{ + mpeg3_t *file; + int i, result = 0; + unsigned char *output, **output_rows; + float *audio_output_f; + short *audio_output_i; + long total_samples = 0; + + if(argc < 2) + { + printf("Need an MPEG stream.\n"); + exit(1); + } + + file = mpeg3_open(argv[1]); + if(file) + { + fprintf(stderr, "MMX supported %d\n", file->have_mmx); + fprintf(stderr, "Audio streams: %d\n", mpeg3_total_astreams(file)); + for(i = 0; i < mpeg3_total_astreams(file); i++) + { + fprintf(stderr, " Stream %d: channels %d sample rate %d total samples %ld\n", + i, + mpeg3_audio_channels(file, i), + mpeg3_sample_rate(file, i), + mpeg3_audio_samples(file, i)); + } + fprintf(stderr, "Video streams: %d\n", mpeg3_total_vstreams(file)); + for(i = 0; i < mpeg3_total_vstreams(file); i++) + { + fprintf(stderr, " Stream %d: width %d height %d frame rate %0.3f total frames %ld\n", + i, + mpeg3_video_width(file, i), + mpeg3_video_height(file, i), + mpeg3_frame_rate(file, i), + mpeg3_video_frames(file, i)); + } +fprintf(stderr,"S"); + + mpeg3_set_cpus(file, 1); +fprintf(stderr,"s"); +/* audio_output_f = malloc(BUFSIZE * sizeof(float)); */ + audio_output_i = (short*)malloc(BUFSIZE * 2 * sizeof(short)); +fprintf(stderr,"x"); +/* mpeg3_set_sample(file, 11229518, 0); */ + /*result = mpeg3_read_audio(file, audio_output_f, 0, 0, BUFSIZE, 0);*/ + for (i=0; i<100; i++) { +fprintf(stderr,"c"); + result = mpeg3_read_audio(file, 0, audio_output_i, 0, BUFSIZE, 0); +fprintf(stderr,"read\n"); + } + //fwrite(audio_output_i, BUFSIZE, 1, stdout); + + output = (unsigned char*)malloc(mpeg3_video_width(file, 0) * mpeg3_video_height(file, 0) * 3 + 4); + output_rows = (unsigned char**)malloc(sizeof(unsigned char*) * mpeg3_video_height(file, 0)); + for(i = 0; i < mpeg3_video_height(file, 0); i++) + output_rows[i] = &output[i * mpeg3_video_width(file, 0) * 3]; +// mpeg3_set_frame(file, 1000, 0); + result = mpeg3_read_frame(file, + output_rows, + 0, + 0, + mpeg3_video_width(file, 0), + mpeg3_video_height(file, 0), + mpeg3_video_width(file, 0), + mpeg3_video_height(file, 0), + MPEG3_RGB888, + 0); + + mpeg3_close(file); + } + return 0; +} diff --git a/core/multimedia/opieplayer/libmpeg3/libmpeg3.c b/core/multimedia/opieplayer/libmpeg3/libmpeg3.c new file mode 100644 index 0000000..c0fc570 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/libmpeg3.c @@ -0,0 +1,672 @@ +#include "libmpeg3.h" +#include "mpeg3protos.h" + +#include <stdlib.h> +#include <string.h> + +#define MAX(a, b) ((a) > (b) ? (a) : (b)) + +mpeg3_t* mpeg3_new(char *path) +{ + int i; + mpeg3_t *file = (mpeg3_t*)calloc(1, sizeof(mpeg3_t)); + file->cpus = 1; + file->fs = mpeg3_new_fs(path); + file->have_mmx = mpeg3_mmx_test(); + file->demuxer = mpeg3_new_demuxer(file, 0, 0, -1); + return file; +} + +int mpeg3_delete(mpeg3_t *file) +{ + int i; + + for(i = 0; i < file->total_vstreams; i++) + mpeg3_delete_vtrack(file, file->vtrack[i]); + + for(i = 0; i < file->total_astreams; i++) + mpeg3_delete_atrack(file, file->atrack[i]); + + mpeg3_delete_fs(file->fs); + mpeg3_delete_demuxer(file->demuxer); + free(file); +} + +int mpeg3_check_sig(char *path) +{ + mpeg3_fs_t *fs; + unsigned int bits; + char *ext; + int result = 0; + + fs = mpeg3_new_fs(path); + if(mpeg3io_open_file(fs)) + { +/* File not found */ + return 0; + } + + bits = mpeg3io_read_int32(fs); +/* Test header */ + if(bits == MPEG3_TOC_PREFIX || bits == MPEG3_TOC_PREFIXLOWER) + { + result = 1; + } + else + if((((bits >> 24) & 0xff) == MPEG3_SYNC_BYTE) || + (bits == MPEG3_PACK_START_CODE) || + ((bits & 0xfff00000) == 0xfff00000) || + (bits == MPEG3_SEQUENCE_START_CODE) || + (bits == MPEG3_PICTURE_START_CODE) || + (((bits & 0xffff0000) >> 16) == MPEG3_AC3_START_CODE) || + ((bits >> 8) == MPEG3_ID3_PREFIX) || + (bits == MPEG3_RIFF_CODE)) + { + result = 1; + + ext = strrchr(path, '.'); + if(ext) + { +/* Test file extension. */ + if(strncasecmp(ext, ".mp2", 4) && + strncasecmp(ext, ".mp3", 4) && + strncasecmp(ext, ".m1v", 4) && + strncasecmp(ext, ".m2v", 4) && + strncasecmp(ext, ".m2s", 4) && + strncasecmp(ext, ".mpg", 4) && + strncasecmp(ext, ".vob", 4) && + strncasecmp(ext, ".mpeg", 4) && + strncasecmp(ext, ".ac3", 4)) + result = 0; + } + } + + mpeg3io_close_file(fs); + mpeg3_delete_fs(fs); + return result; +} + +mpeg3_t* mpeg3_open_copy(char *path, mpeg3_t *old_file) +{ + mpeg3_t *file = 0; + unsigned int bits; + int i, done; + +/* Initialize the file structure */ + file = mpeg3_new(path); + +/* Need to perform authentication before reading a single byte. */ + if(mpeg3io_open_file(file->fs)) + { + mpeg3_delete(file); + return 0; + } + +/* =============================== Create the title objects ========================= */ + bits = mpeg3io_read_int32(file->fs); + + if(bits == MPEG3_TOC_PREFIX || bits == MPEG3_TOC_PREFIXLOWER) /* TOCV */ + { +/* Table of contents for another file */ + if(mpeg3_read_toc(file)) + { + mpeg3_delete(file); + return 0; + } + mpeg3io_close_file(file->fs); + } + else + if(((bits >> 24) & 0xff) == MPEG3_SYNC_BYTE) + { +/* Transport stream */ + file->packet_size = MPEG3_TS_PACKET_SIZE; + file->is_transport_stream = 1; + } + else + if(bits == MPEG3_PACK_START_CODE) + { +/* Program stream */ + file->packet_size = MPEG3_DVD_PACKET_SIZE; + file->is_program_stream = 1; + } + else + if((bits & 0xfff00000) == 0xfff00000 || + ((bits >> 8) == MPEG3_ID3_PREFIX) || + (bits == MPEG3_RIFF_CODE)) + { +/* MPEG Audio only */ + file->packet_size = MPEG3_DVD_PACKET_SIZE; + file->has_audio = 1; + file->is_audio_stream = 1; + } + else + if(bits == MPEG3_SEQUENCE_START_CODE || + bits == MPEG3_PICTURE_START_CODE) + { +/* Video only */ + file->packet_size = MPEG3_DVD_PACKET_SIZE; + file->is_video_stream = 1; + } + else + if(((bits & 0xffff0000) >> 16) == MPEG3_AC3_START_CODE) + { +/* AC3 Audio only */ + file->packet_size = MPEG3_DVD_PACKET_SIZE; + file->has_audio = 1; + file->is_audio_stream = 1; + } + else + { +/* file->packet_size = MPEG3_DVD_PACKET_SIZE; */ +/* file->is_audio_stream = 1; */ + mpeg3_delete(file); + fprintf(stderr, "mpeg3_open: not an MPEG 2 stream\n"); + return 0; + } + +/* Create title */ +/* Copy timecodes from an old demuxer */ + if(old_file && mpeg3_get_demuxer(old_file)) + { + mpeg3demux_copy_titles(file->demuxer, mpeg3_get_demuxer(old_file)); + } + else +/* Start from scratch */ + if(!file->demuxer->total_titles) + { + mpeg3demux_create_title(file->demuxer, 0, 0); + } + +/* =============================== Get title information ========================= */ + if(file->is_transport_stream || file->is_program_stream) + { +/* Create video tracks */ +/* Video must be created before audio because audio uses the video timecode */ +/* to get its length. */ + for(i = 0; i < MPEG3_MAX_STREAMS; i++) + { + if(file->demuxer->vstream_table[i]) + { + file->vtrack[file->total_vstreams] = mpeg3_new_vtrack(file, i, file->demuxer); + if(file->vtrack[file->total_vstreams]) file->total_vstreams++; + } + } + +/* Create audio tracks */ + for(i = 0; i < MPEG3_MAX_STREAMS; i++) + { + if(file->demuxer->astream_table[i]) + { + file->atrack[file->total_astreams] = mpeg3_new_atrack(file, + i, + file->demuxer->astream_table[i], + file->demuxer); + if(file->atrack[file->total_astreams]) file->total_astreams++; + } + } + } + else + if(file->is_video_stream) + { +/* Create video tracks */ + file->vtrack[0] = mpeg3_new_vtrack(file, -1, file->demuxer); + if(file->vtrack[0]) file->total_vstreams++; + } + else + if(file->is_audio_stream) + { +/* Create audio tracks */ + file->atrack[0] = mpeg3_new_atrack(file, -1, AUDIO_UNKNOWN, file->demuxer); + if(file->atrack[0]) file->total_astreams++; + } + + if(file->total_vstreams) file->has_video = 1; + if(file->total_astreams) file->has_audio = 1; + + mpeg3io_close_file(file->fs); + return file; +} + +mpeg3_t* mpeg3_open(char *path) +{ + return mpeg3_open_copy(path, 0); +} + +int mpeg3_close(mpeg3_t *file) +{ +/* File is closed in the same procedure it is opened in. */ + mpeg3_delete(file); + return 0; +} + +int mpeg3_set_cpus(mpeg3_t *file, int cpus) +{ + int i; + file->cpus = cpus; + for(i = 0; i < file->total_vstreams; i++) + mpeg3video_set_cpus(file->vtrack[i]->video, cpus); + return 0; +} + +int mpeg3_set_mmx(mpeg3_t *file, int use_mmx) +{ + int i; + file->have_mmx = use_mmx; + for(i = 0; i < file->total_vstreams; i++) + mpeg3video_set_mmx(file->vtrack[i]->video, use_mmx); + return 0; +} + +int mpeg3_generate_toc(FILE *output, char *path, int timecode_search, int print_streams) +{ + mpeg3_t *file = mpeg3_open(path); + mpeg3_demuxer_t *demuxer; + int i; + + if(file) + { + fprintf(output, "TOCVERSION 2\n" + "PATH: %s\n", path); + demuxer = mpeg3_new_demuxer(file, 0, 0, -1); + mpeg3demux_create_title(demuxer, timecode_search, output); +/* Just print the first title's streams */ + if(print_streams) mpeg3demux_print_streams(demuxer, output); + + fprintf(output, "SIZE: %ld\n", demuxer->titles[demuxer->current_title]->total_bytes); + fprintf(output, "PACKETSIZE: %ld\n", demuxer->packet_size); + + mpeg3demux_print_timecodes(demuxer->titles[demuxer->current_title], output); + + mpeg3_delete_demuxer(demuxer); + mpeg3_close(file); + return 0; + } + return 1; +} + +int mpeg3_read_toc(mpeg3_t *file) +{ + char string[MPEG3_STRLEN]; + int number1; + +/* Test version number */ + file->is_program_stream = 1; + mpeg3io_seek(file->fs, 0); + fscanf(file->fs->fd, "%s %d", string, &number1); + if(number1 > 2 || number1 < 2) return 1; + +/* Read titles */ + mpeg3demux_read_titles(file->demuxer); + return 0; +} + +int mpeg3_has_audio(mpeg3_t *file) +{ + return file->has_audio; +} + +int mpeg3_total_astreams(mpeg3_t *file) +{ + return file->total_astreams; +} + +int mpeg3_audio_channels(mpeg3_t *file, + int stream) +{ + if(file->has_audio) + return file->atrack[stream]->channels; + return -1; +} + +int mpeg3_sample_rate(mpeg3_t *file, + int stream) +{ + if(file->has_audio) + return file->atrack[stream]->sample_rate; + return -1; +} + +long mpeg3_get_sample(mpeg3_t *file, + int stream) +{ + if(file->has_audio) + return file->atrack[stream]->current_position; + return -1; +} + +int mpeg3_set_sample(mpeg3_t *file, + long sample, + int stream) +{ + if(file->has_audio) + { + file->atrack[stream]->current_position = sample; + mpeg3audio_seek_sample(file->atrack[stream]->audio, sample); + return 0; + } + return -1; +} + +long mpeg3_audio_samples(mpeg3_t *file, + int stream) +{ + if(file->has_audio) + return file->atrack[stream]->total_samples; + return -1; +} + +int mpeg3_has_video(mpeg3_t *file) +{ + return file->has_video; +} + +int mpeg3_total_vstreams(mpeg3_t *file) +{ + return file->total_vstreams; +} + +int mpeg3_video_width(mpeg3_t *file, + int stream) +{ + if(file->has_video) + return file->vtrack[stream]->width; + return -1; +} + +int mpeg3_video_height(mpeg3_t *file, + int stream) +{ + if(file->has_video) + return file->vtrack[stream]->height; + return -1; +} + +float mpeg3_frame_rate(mpeg3_t *file, + int stream) +{ + if(file->has_video) + return file->vtrack[stream]->frame_rate; + return -1; +} + +long mpeg3_video_frames(mpeg3_t *file, + int stream) +{ + if(file->has_video) + return file->vtrack[stream]->total_frames; + return -1; +} + +long mpeg3_get_frame(mpeg3_t *file, + int stream) +{ + if(file->has_video) + return file->vtrack[stream]->current_position; + return -1; +} + +int mpeg3_set_frame(mpeg3_t *file, + long frame, + int stream) +{ + if(file->has_video) + { + file->vtrack[stream]->current_position = frame; + mpeg3video_seek_frame(file->vtrack[stream]->video, frame); + return 0; + } + return -1; +} + +int mpeg3_seek_percentage(mpeg3_t *file, double percentage) +{ + int i; + for(i = 0; i < file->total_astreams; i++) + { + mpeg3audio_seek_percentage(file->atrack[i]->audio, percentage); + } + + for(i = 0; i < file->total_vstreams; i++) + { + mpeg3video_seek_percentage(file->vtrack[i]->video, percentage); + } + return 0; +} + +int mpeg3_previous_frame(mpeg3_t *file, int stream) +{ + file->last_type_read = 2; + file->last_stream_read = stream; + + if(file->has_video) + return mpeg3video_previous_frame(file->vtrack[stream]->video); +} + +double mpeg3_tell_percentage(mpeg3_t *file) +{ + double percent = 0; + if(file->last_type_read == 1) + { + percent = mpeg3demux_tell_percentage(file->atrack[file->last_stream_read]->demuxer); + } + + if(file->last_type_read == 2) + { + percent = mpeg3demux_tell_percentage(file->vtrack[file->last_stream_read]->demuxer); + } + return percent; +} + +double mpeg3_get_time(mpeg3_t *file) +{ + double atime = 0, vtime = 0; + + if(file->is_transport_stream || file->is_program_stream) + { +/* Timecode only available in transport stream */ + if(file->last_type_read == 1) + { + atime = mpeg3demux_get_time(file->atrack[file->last_stream_read]->demuxer); + } + else + if(file->last_type_read == 2) + { + vtime = mpeg3demux_get_time(file->vtrack[file->last_stream_read]->demuxer); + } + } + else + { +/* Use percentage and total time */ + if(file->has_audio) + { + atime = mpeg3demux_tell_percentage(file->atrack[0]->demuxer) * + mpeg3_audio_samples(file, 0) / mpeg3_sample_rate(file, 0); + } + + if(file->has_video) + { + vtime = mpeg3demux_tell_percentage(file->vtrack[0]->demuxer) * + mpeg3_video_frames(file, 0) / mpeg3_frame_rate(file, 0); + } + } + + return MAX(atime, vtime); +} + +int mpeg3_end_of_audio(mpeg3_t *file, int stream) +{ + int result = 0; + result = mpeg3demux_eof(file->atrack[stream]->demuxer); + return result; +} + +int mpeg3_end_of_video(mpeg3_t *file, int stream) +{ + int result = 0; + result = mpeg3demux_eof(file->vtrack[stream]->demuxer); + return result; +} + + +int mpeg3_read_frame(mpeg3_t *file, + unsigned char **output_rows, + int in_x, + int in_y, + int in_w, + int in_h, + int out_w, + int out_h, + int color_model, + int stream) +{ + int result = -1; + + if(file->has_video) + { + result = mpeg3video_read_frame(file->vtrack[stream]->video, + file->vtrack[stream]->current_position, + output_rows, + in_x, + in_y, + in_w, + in_h, + out_w, + out_h, + color_model); + file->last_type_read = 2; + file->last_stream_read = stream; + file->vtrack[stream]->current_position++; + } + return result; +} + +int mpeg3_drop_frames(mpeg3_t *file, long frames, int stream) +{ + int result = -1; + + if(file->has_video) + { + result = mpeg3video_drop_frames(file->vtrack[stream]->video, + frames); + if(frames > 0) file->vtrack[stream]->current_position += frames; + file->last_type_read = 2; + file->last_stream_read = stream; + } + return result; +} + +int mpeg3_read_yuvframe(mpeg3_t *file, + char *y_output, + char *u_output, + char *v_output, + int in_x, + int in_y, + int in_w, + int in_h, + int stream) +{ + int result = -1; + +//printf("mpeg3_read_yuvframe 1 %d %d\n", mpeg3demux_tell(file->vtrack[stream]->demuxer), mpeg3demuxer_total_bytes(file->vtrack[stream]->demuxer)); + if(file->has_video) + { + result = mpeg3video_read_yuvframe(file->vtrack[stream]->video, + file->vtrack[stream]->current_position, + y_output, + u_output, + v_output, + in_x, + in_y, + in_w, + in_h); + file->last_type_read = 2; + file->last_stream_read = stream; + file->vtrack[stream]->current_position++; + } +//printf("mpeg3_read_yuvframe 2 %d %d\n", mpeg3demux_tell(file->vtrack[stream]->demuxer), mpeg3demuxer_total_bytes(file->vtrack[stream]->demuxer)); + return result; +} + + +int mpeg3_read_audio(mpeg3_t *file, + mpeg3_real_t *output_f, + short *output_i, int sampleSpacing, + int channel, + long samples, + int stream) +{ + int result = -1; + +//printf("mpeg3_read_audio 1 %d %d\n", mpeg3demux_tell(file->atrack[stream]->demuxer), mpeg3demuxer_total_bytes(file->atrack[stream]->demuxer)); + if(file->has_audio) + { + result = mpeg3audio_decode_audio(file->atrack[stream]->audio, + output_f, + output_i, sampleSpacing, + channel, + file->atrack[stream]->current_position, + samples); + file->last_type_read = 1; + file->last_stream_read = stream; + file->atrack[stream]->current_position += samples; + } +//printf("mpeg3_read_audio 2 %d %d\n", mpeg3demux_tell(file->atrack[stream]->demuxer), mpeg3demuxer_total_bytes(file->atrack[stream]->demuxer)); + + return result; +} + +int mpeg3_reread_audio(mpeg3_t *file, + mpeg3_real_t *output_f, + short *output_i, int sampleSpacing, + int channel, + long samples, + int stream) +{ + if(file->has_audio) + { + mpeg3_set_sample(file, + file->atrack[stream]->current_position - samples, + stream); + file->last_type_read = 1; + file->last_stream_read = stream; + return mpeg3_read_audio(file, + output_f, + output_i, sampleSpacing, + channel, + samples, + stream); + } + return -1; +} + +int mpeg3_read_audio_chunk(mpeg3_t *file, + unsigned char *output, + long *size, + long max_size, + int stream) +{ + int result = 0; + if(file->has_audio) + { + result = mpeg3audio_read_raw(file->atrack[stream]->audio, output, size, max_size); + file->last_type_read = 1; + file->last_stream_read = stream; + } + return result; +} + +int mpeg3_read_video_chunk(mpeg3_t *file, + unsigned char *output, + long *size, + long max_size, + int stream) +{ + int result = 0; + if(file->has_video) + { + result = mpeg3video_read_raw(file->vtrack[stream]->video, output, size, max_size); + file->last_type_read = 2; + file->last_stream_read = stream; + } + return result; +} diff --git a/core/multimedia/opieplayer/libmpeg3/libmpeg3.h b/core/multimedia/opieplayer/libmpeg3/libmpeg3.h new file mode 100644 index 0000000..f4eced4 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/libmpeg3.h @@ -0,0 +1,175 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef LIBMPEG3_H +#define LIBMPEG3_H + +#include "mpeg3private.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +/* Supported color models for mpeg3_read_frame */ +#define MPEG3_RGB565 2 +#define MPEG3_BGR888 0 +#define MPEG3_BGRA8888 1 +#define MPEG3_RGB888 3 +#define MPEG3_RGBA8888 4 +#define MPEG3_RGBA16161616 5 + +/* Color models for the 601 to RGB conversion */ +/* 601 not implemented for scalar code */ +#define MPEG3_601_RGB565 11 +#define MPEG3_601_BGR888 7 +#define MPEG3_601_BGRA8888 8 +#define MPEG3_601_RGB888 9 +#define MPEG3_601_RGBA8888 10 + +/* Check for file compatibility. Return 1 if compatible. */ +LIBMPEG_EXPORT int mpeg3_check_sig(char *path); + +/* Open the MPEG3 stream. */ +LIBMPEG_EXPORT mpeg3_t* mpeg3_open(char *path); + +/* Open the MPEG3 stream and copy the tables from an already open stream. */ +/* Eliminates the initial timecode search. */ +LIBMPEG_EXPORT mpeg3_t* mpeg3_open_copy(char *path, mpeg3_t *old_file); +LIBMPEG_EXPORT int mpeg3_close(mpeg3_t *file); + +/* Performance */ +LIBMPEG_EXPORT int mpeg3_set_cpus(mpeg3_t *file, int cpus); +LIBMPEG_EXPORT int mpeg3_set_mmx(mpeg3_t *file, int use_mmx); + +/* Query the MPEG3 stream about audio. */ +LIBMPEG_EXPORT int mpeg3_has_audio(mpeg3_t *file); +LIBMPEG_EXPORT int mpeg3_total_astreams(mpeg3_t *file); /* Number of multiplexed audio streams */ +LIBMPEG_EXPORT int mpeg3_audio_channels(mpeg3_t *file, int stream); +LIBMPEG_EXPORT int mpeg3_sample_rate(mpeg3_t *file, int stream); + +/* Total length obtained from the timecode. */ +/* For DVD files, this is unreliable. */ +LIBMPEG_EXPORT long mpeg3_audio_samples(mpeg3_t *file, int stream); +LIBMPEG_EXPORT int mpeg3_set_sample(mpeg3_t *file, long sample, int stream); /* Seek to a sample */ +LIBMPEG_EXPORT long mpeg3_get_sample(mpeg3_t *file, int stream); /* Tell current position */ + +/* Read a PCM buffer of audio from 1 channel and advance the position. */ +/* Return a 1 if error. */ +/* Stream defines the number of the multiplexed stream to read. */ +LIBMPEG_EXPORT int mpeg3_read_audio(mpeg3_t *file, + mpeg3_real_t *output_f, /* Pointer to pre-allocated buffer of floats */ + short *output_i, /* Pointer to pre-allocated buffer of int16's */ + int sampleSpacing, // how many bytes to skip over inbetween samples + int channel, /* Channel to decode */ + long samples, /* Number of samples to decode */ + int stream); /* Stream containing the channel */ + +/* Reread the last PCM buffer from a different channel and advance the position */ +LIBMPEG_EXPORT int mpeg3_reread_audio(mpeg3_t *file, + mpeg3_real_t *output_f, /* Pointer to pre-allocated buffer of floats */ + short *output_i, /* Pointer to pre-allocated buffer of int16's */ + int sampleSpacing, // how many bytes to skip over inbetween samples + int channel, /* Channel to decode */ + long samples, /* Number of samples to decode */ + int stream); /* Stream containing the channel */ + +/* Read the next compressed audio chunk. Store the size in size and return a */ +/* 1 if error. */ +/* Stream defines the number of the multiplexed stream to read. */ +LIBMPEG_EXPORT int mpeg3_read_audio_chunk(mpeg3_t *file, + unsigned char *output, + long *size, + long max_size, + int stream); + +/* Query the stream about video. */ +LIBMPEG_EXPORT int mpeg3_has_video(mpeg3_t *file); +LIBMPEG_EXPORT int mpeg3_total_vstreams(mpeg3_t *file); /* Number of multiplexed video streams */ +LIBMPEG_EXPORT int mpeg3_video_width(mpeg3_t *file, int stream); +LIBMPEG_EXPORT int mpeg3_video_height(mpeg3_t *file, int stream); +LIBMPEG_EXPORT float mpeg3_frame_rate(mpeg3_t *file, int stream); /* Frames/sec */ + +/* Total length. */ +/* For DVD files, this is 1 indicating only percentage seeking is available. */ +LIBMPEG_EXPORT long mpeg3_video_frames(mpeg3_t *file, int stream); +LIBMPEG_EXPORT int mpeg3_set_frame(mpeg3_t *file, long frame, int stream); /* Seek to a frame */ +LIBMPEG_EXPORT int mpeg3_skip_frames(); +LIBMPEG_EXPORT long mpeg3_get_frame(mpeg3_t *file, int stream); /* Tell current position */ + +/* Seek all the tracks based on a percentage of the total bytes in the */ +/* file or the total */ +/* time in a toc if one exists. Percentage is a 0 to 1 double. */ +/* This eliminates the need for tocs and 64 bit longs but doesn't */ +/* give frame accuracy. */ +LIBMPEG_EXPORT int mpeg3_seek_percentage(mpeg3_t *file, double percentage); +LIBMPEG_EXPORT double mpeg3_tell_percentage(mpeg3_t *file); +LIBMPEG_EXPORT int mpeg3_previous_frame(mpeg3_t *file, int stream); +LIBMPEG_EXPORT int mpeg3_end_of_audio(mpeg3_t *file, int stream); +LIBMPEG_EXPORT int mpeg3_end_of_video(mpeg3_t *file, int stream); + +/* Give the seconds time in the last packet read */ +LIBMPEG_EXPORT double mpeg3_get_time(mpeg3_t *file); + +/* Read a frame. The dimensions of the input area and output frame must be supplied. */ +/* The frame is taken from the input area and scaled to fit the output frame in 1 step. */ +/* Stream defines the number of the multiplexed stream to read. */ +/* The last row of **output_rows must contain 4 extra bytes for scratch work. */ +LIBMPEG_EXPORT int mpeg3_read_frame(mpeg3_t *file, + unsigned char **output_rows, /* Array of pointers to the start of each output row */ + int in_x, /* Location in input frame to take picture */ + int in_y, + int in_w, + int in_h, + int out_w, /* Dimensions of output_rows */ + int out_h, + int color_model, /* One of the color model #defines */ + int stream); + +/* Read a YUV frame. The 3 planes are copied into the y, u, and v buffers provided. */ +/* The input is cropped to the dimensions given but not scaled. */ +LIBMPEG_EXPORT int mpeg3_read_yuvframe(mpeg3_t *file, + char *y_output, + char *u_output, + char *v_output, + int in_x, + int in_y, + int in_w, + int in_h, + int stream); + +LIBMPEG_EXPORT int mpeg3_drop_frames(mpeg3_t *file, long frames, int stream); + +/* Read the next compressed frame including headers. */ +/* Store the size in size and return a 1 if error. */ +/* Stream defines the number of the multiplexed stream to read. */ +LIBMPEG_EXPORT int mpeg3_read_video_chunk(mpeg3_t *file, + unsigned char *output, + long *size, + long max_size, + int stream); + +/* Master control */ +LIBMPEG_EXPORT int mpeg3_total_programs(); +LIBMPEG_EXPORT int mpeg3_set_program(int program); + +#if defined(__cplusplus) +} +#endif + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/libmpeg3.pro b/core/multimedia/opieplayer/libmpeg3/libmpeg3.pro new file mode 100644 index 0000000..e2c35d3 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/libmpeg3.pro @@ -0,0 +1,42 @@ +TEMPLATE = lib +CONFIG += qt warn_on release +HEADERS = libmpeg3plugin.h libmpeg3pluginimpl.h +SOURCES = libmpeg3plugin.cpp libmpeg3pluginimpl.cpp \ + bitstream.c \ + libmpeg3.c \ + mpeg3atrack.c \ + mpeg3css.c \ + mpeg3demux.c \ + mpeg3io.c \ + mpeg3title.c \ + mpeg3vtrack.c \ + audio/ac3.c \ + audio/bit_allocation.c \ + audio/dct.c \ + audio/exponents.c \ + audio/header.c \ + audio/layer2.c \ + audio/layer3.c \ + audio/mantissa.c \ + audio/mpeg3audio.c \ + audio/pcm.c \ + audio/synthesizers.c \ + audio/tables.c \ + video/getpicture.c \ + video/headers.c \ + video/idct.c \ + video/macroblocks.c \ + video/mmxtest.c \ + video/motion.c \ + video/mpeg3video.c \ + video/output.c \ + video/reconstruct.c \ + video/seek.c \ + video/slice.c \ + video/vlc.c +TARGET = mpeg3plugin +DESTDIR = ../../plugins/codecs +INCLUDEPATH += $(QPEDIR)/include .. +DEPENDPATH += ../$(QPEDIR)/include .. +LIBS += -lqpe -lpthread -lm +VERSION = 1.0.0 diff --git a/core/multimedia/opieplayer/libmpeg3/libmpeg3plugin.cpp b/core/multimedia/opieplayer/libmpeg3/libmpeg3plugin.cpp new file mode 100644 index 0000000..044cb4a --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/libmpeg3plugin.cpp @@ -0,0 +1,105 @@ +/********************************************************************** +** Copyright (C) 2001 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#include "libmpeg3plugin.h" + +/* +bool LibMpeg3Plugin::audioReadSamples( short *output, int channel, long samples, int stream ) { + return file ? mpeg3_read_audio( file, 0, output, 0, channel, samples, stream ) == 1 : FALSE; +} + + +bool LibMpeg3Plugin::audioReReadSamples( short *output, int channel, long samples, int stream ) { + return file ? mpeg3_reread_audio( file, 0, output, 0, channel, samples, stream ) == 1 : FALSE; +} + + +bool LibMpeg3Plugin::audioReadMonoSamples( short *output, long samples, long& samplesRead, int stream ) { + samplesRead = samples; + return file ? mpeg3_read_audio( file, 0, output, 0, 0, samples, stream ) == 1 : FALSE; +} + + +bool LibMpeg3Plugin::audioReadStereoSamples( short *output, long samples, long& samplesRead, int stream ) { + bool err = FALSE; + if ( file ) { +#if 1 + err = mpeg3_read_audio ( file, 0, output, 1, 0, samples, stream ) == 1; + if ( err == FALSE ) { + err = mpeg3_reread_audio( file, 0, output + 1, 1, 1, samples, stream ) == 1; +#else + short left[samples]; + short right[samples]; + err = mpeg3_read_audio ( file, 0, left, 0, samples, stream ) == 1; + if ( !err ) + err = mpeg3_reread_audio( file, 0, right, 1, samples, stream ) == 1; + for ( int j = 0; j < samples; j++ ) { + output[j*2+0] = left[j]; + output[j*2+1] = right[j]; +#endif + } + } + samplesRead = samples; + return err; +} +*/ + +bool LibMpeg3Plugin::audioReadSamples( short *output, int channels, long samples, long& samplesRead, int stream ) { + samplesRead = samples; + switch ( channels ) { + case 1: + return file ? mpeg3_read_audio( file, 0, output, 0, 0, samples, stream ) == 1 : FALSE; + case 2: + if ( ( file ) && ( mpeg3_read_audio( file, 0, output, 1, 0, samples, stream ) != 1 ) && + ( mpeg3_reread_audio( file, 0, output + 1, 1, 1, samples, stream ) != 1 ) ) + return TRUE; + return FALSE; + } + return FALSE; +} + +bool LibMpeg3Plugin::videoReadFrame( unsigned char **output_rows, int in_x, int in_y, int in_w, int in_h, ColorFormat color_model, int stream ) { + int format = MPEG3_RGB565; + switch ( color_model ) { + case RGB565: format = MPEG3_RGB565; break; + case BGR565: /*format = MPEG3_BGR565;*/ break; + case RGBA8888: format = MPEG3_RGBA8888; break; + case BGRA8888: format = MPEG3_BGRA8888; break; + } + return file ? mpeg3_read_frame( file, output_rows, in_x, in_y, in_w, in_h, in_w, in_h, format, stream ) == 1 : FALSE; +} + + +bool LibMpeg3Plugin::videoReadScaledFrame( unsigned char **output_rows, int in_x, int in_y, int in_w, int in_h, int out_w, int out_h, ColorFormat color_model, int stream ) { + int format = MPEG3_RGB565; + switch ( color_model ) { + case RGB565: format = MPEG3_RGB565; break; + case BGR565: /*format = MPEG3_BGR565;*/ break; + case RGBA8888: format = MPEG3_RGBA8888; break; + case BGRA8888: format = MPEG3_BGRA8888; break; + } + return file ? mpeg3_read_frame( file, output_rows, in_x, in_y, in_w, in_h, out_w, out_h, format, stream ) == 1 : FALSE; +} + + +bool LibMpeg3Plugin::videoReadYUVFrame( char *y_output, char *u_output, char *v_output, int in_x, int in_y, int in_w, int in_h, int stream ) { + return file ? mpeg3_read_yuvframe( file, y_output, u_output, v_output, in_x, in_y, in_w, in_h, stream ) == 1 : FALSE; +} + + diff --git a/core/multimedia/opieplayer/libmpeg3/libmpeg3plugin.h b/core/multimedia/opieplayer/libmpeg3/libmpeg3plugin.h new file mode 100644 index 0000000..0a06264 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/libmpeg3plugin.h @@ -0,0 +1,113 @@ +/********************************************************************** +** Copyright (C) 2001 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef LIBMPEG3_PLUGIN_H +#define LIBMPEG3_PLUGIN_H + + +#include <qstring.h> +#include <qapplication.h> +#include "libmpeg3.h" +#include "mpeg3protos.h" +#include "mediaplayerplugininterface.h" + + +class LibMpeg3Plugin : public MediaPlayerDecoder { + +public: + LibMpeg3Plugin() { file = NULL; } + ~LibMpeg3Plugin() { close(); } + + const char *pluginName() { return "LibMpeg3Plugin"; } + const char *pluginComment() { return "This is the libmpeg3 library writen by ... which has been modified by trolltech to use fixed point maths"; } + double pluginVersion() { return 1.0; } + + bool isFileSupported( const QString& fileName ) { return mpeg3_check_sig( (char *)fileName.latin1() ) == 1; } + bool open( const QString& fileName ) { file = mpeg3_open( (char *)fileName.latin1() ); return file != NULL; } + bool close() { if ( file ) { int r = mpeg3_close( file ); file = NULL; return r == 1; } return FALSE; } + bool isOpen() { return file != NULL; } + const QString &fileInfo() { return strInfo = QString( "" ); } + + // If decoder doesn't support audio then return 0 here + int audioStreams() { return file ? mpeg3_total_astreams( file ) : 0; } + int audioChannels( int stream ) { return file ? mpeg3_audio_channels( file, stream ) : 0; } + int audioFrequency( int stream ) { return file ? mpeg3_sample_rate( file, stream ) : 0; } + int audioSamples( int stream ) { return file ? mpeg3_audio_samples( file, stream ) : 0; } + bool audioSetSample( long sample, int stream ) { return file ? mpeg3_set_sample( file, sample, stream) == 1 : FALSE; } + long audioGetSample( int stream ) { return file ? mpeg3_get_sample( file, stream ) : 0; } +// bool audioReadMonoSamples( short *output, long samples, long& samplesRead, int stream ); +// bool audioReadStereoSamples( short *output, long samples, long& samplesRead, int stream ); + bool audioReadSamples( short *output, int channels, long samples, long& samplesRead, int stream ); +// bool audioReadSamples( short *output, int channel, long samples, int stream ); +// bool audioReReadSamples( short *output, int channel, long samples, int stream ); + + // If decoder doesn't support video then return 0 here + int videoStreams() { return file ? mpeg3_total_vstreams( file ) : 0; } + int videoWidth( int stream ) { return file ? mpeg3_video_width( file, stream ) : 0; } + int videoHeight( int stream ) { return file ? mpeg3_video_height( file, stream ) : 0; } + double videoFrameRate( int stream ) { return file ? mpeg3_frame_rate( file, stream ) : 0.0; } + int videoFrames( int stream ) +{ return file ? mpeg3_video_frames( file, stream ) : 0; } +/* +{ + if ( file ) { + int frames = mpeg3_video_frames( file, stream ); + if ( frames == 1 ) { + int res = mpeg3_seek_percentage( file, 0.99 ); + printf("res: %i\n", res ); + mpeg3video_seek( file->vtrack[stream]->video ); + frames = mpeg3_get_frame( file, stream ); + mpeg3_seek_percentage( file, 0.0 ); + } + return frames; + } + return 0; +} +*/ + bool videoSetFrame( long frame, int stream ) { return file ? mpeg3_set_frame( file, frame, stream) == 1 : FALSE; } + long videoGetFrame( int stream ) { return file ? mpeg3_get_frame( file, stream ) : 0; } + bool videoReadFrame( unsigned char **output_rows, int in_x, int in_y, int in_w, int in_h, ColorFormat color_model, int stream ); + bool videoReadScaledFrame( unsigned char **output_rows, int in_x, int in_y, int in_w, int in_h, int out_w, int out_h, ColorFormat color_model, int stream ); + bool videoReadYUVFrame( char *y_output, char *u_output, char *v_output, int in_x, int in_y, int in_w, int in_h, int stream ); + + // Profiling + double getTime() { return file ? mpeg3_get_time( file ) : 0.0; } + + // Ignore if these aren't supported + bool setSMP( int cpus ) { return file ? mpeg3_set_cpus( file, cpus ) == 1 : FALSE; } + bool setMMX( bool useMMX ) { return file ? mpeg3_set_mmx( file, useMMX ) == 1 : FALSE; } + + // Capabilities + bool supportsAudio() { return TRUE; } + bool supportsVideo() { return TRUE; } + bool supportsYUV() { return TRUE; } + bool supportsMMX() { return TRUE; } + bool supportsSMP() { return TRUE; } + bool supportsStereo() { return TRUE; } + bool supportsScaling() { return TRUE; } + +private: + mpeg3_t *file; + QString strInfo; + +}; + + +#endif + diff --git a/core/multimedia/opieplayer/libmpeg3/libmpeg3pluginimpl.cpp b/core/multimedia/opieplayer/libmpeg3/libmpeg3pluginimpl.cpp new file mode 100644 index 0000000..e7216af --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/libmpeg3pluginimpl.cpp @@ -0,0 +1,70 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#include "libmpeg3plugin.h" +#include "libmpeg3pluginimpl.h" + + +LibMpeg3PluginImpl::LibMpeg3PluginImpl() + : libmpeg3plugin(0), ref(0) +{ +} + + +LibMpeg3PluginImpl::~LibMpeg3PluginImpl() +{ + if ( libmpeg3plugin ) + delete libmpeg3plugin; +} + + +MediaPlayerDecoder *LibMpeg3PluginImpl::decoder() +{ + if ( !libmpeg3plugin ) + libmpeg3plugin = new LibMpeg3Plugin; + return libmpeg3plugin; +} + + +MediaPlayerEncoder *LibMpeg3PluginImpl::encoder() +{ + return NULL; +} + + +#ifndef QT_NO_COMPONENT + + +QRESULT LibMpeg3PluginImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) +{ + *iface = 0; + if ( ( uuid == IID_QUnknown ) || ( uuid == IID_MediaPlayerPlugin ) ) + *iface = this, (*iface)->addRef(); + return QS_OK; +} + + +Q_EXPORT_INTERFACE() +{ + Q_CREATE_INSTANCE( LibMpeg3PluginImpl ) +} + + +#endif + diff --git a/core/multimedia/opieplayer/libmpeg3/libmpeg3pluginimpl.h b/core/multimedia/opieplayer/libmpeg3/libmpeg3pluginimpl.h new file mode 100644 index 0000000..29ec6ba --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/libmpeg3pluginimpl.h @@ -0,0 +1,53 @@ +/********************************************************************** +** Copyright (C) 2001 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef LIBMPEG3_PLUGIN_IMPL_H +#define LIBMPEG3_PLUGIN_IMPL_H + + +#include "../mediaplayerplugininterface.h" + + +class LibMpeg3Plugin; + + +class LibMpeg3PluginImpl : public MediaPlayerPluginInterface +{ +public: + LibMpeg3PluginImpl(); + virtual ~LibMpeg3PluginImpl(); + +#ifndef QT_NO_COMPONENT + + QRESULT queryInterface( const QUuid&, QUnknownInterface** ); + Q_REFCOUNT + +#endif + + virtual MediaPlayerDecoder *decoder(); + virtual MediaPlayerEncoder *encoder(); + +private: + LibMpeg3Plugin *libmpeg3plugin; + ulong ref; +}; + + +#endif + diff --git a/core/multimedia/opieplayer/libmpeg3/make_package b/core/multimedia/opieplayer/libmpeg3/make_package new file mode 100755 index 0000000..4be86da --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/make_package @@ -0,0 +1,10 @@ +#!/bin/sh + +VERSION=1.2.1 + +rm -r /tmp/libmpeg3-$VERSION +mkdir -p /tmp/libmpeg3-$VERSION +make clean +cp -rd * /tmp/libmpeg3-$VERSION +cd /tmp +tar zcf libmpeg3-$VERSION.tar.gz libmpeg3-$VERSION diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3atrack.c b/core/multimedia/opieplayer/libmpeg3/mpeg3atrack.c new file mode 100644 index 0000000..e1a900b --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/mpeg3atrack.c @@ -0,0 +1,36 @@ +#include "libmpeg3.h" +#include "mpeg3protos.h" + +#include <stdlib.h> + +mpeg3_atrack_t* mpeg3_new_atrack(mpeg3_t *file, int stream_id, int format, mpeg3_demuxer_t *demuxer) +{ + mpeg3_atrack_t *new_atrack; + + new_atrack = (mpeg3_atrack_t*)calloc(1, sizeof(mpeg3_atrack_t)); + new_atrack->channels = 0; + new_atrack->sample_rate = 0; + new_atrack->total_samples = 0; + new_atrack->current_position = 0; + new_atrack->demuxer = mpeg3_new_demuxer(file, 1, 0, stream_id); + if(demuxer) mpeg3demux_copy_titles(new_atrack->demuxer, demuxer); + new_atrack->audio = mpeg3audio_new(file, new_atrack, format); + + if(!new_atrack->audio) + { +/* Failed */ + mpeg3_delete_atrack(file, new_atrack); + new_atrack = 0; + } + return new_atrack; +} + +int mpeg3_delete_atrack(mpeg3_t *file, mpeg3_atrack_t *atrack) +{ + if(atrack->audio) + mpeg3audio_delete(atrack->audio); + if(atrack->demuxer) + mpeg3_delete_demuxer(atrack->demuxer); + free(atrack); +} + diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3atrack.h b/core/multimedia/opieplayer/libmpeg3/mpeg3atrack.h new file mode 100644 index 0000000..9d70640 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/mpeg3atrack.h @@ -0,0 +1,36 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef MPEG3ATRACK_H +#define MPEG3ATRACK_H + +#include "mpeg3demux.h" +#include "audio/mpeg3audio.h" + +struct mpeg3_atrack_rec +{ + int channels; + int sample_rate; + mpeg3_demuxer_t *demuxer; + mpeg3audio_t *audio; + long current_position; + long total_samples; +}; + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3cat.c b/core/multimedia/opieplayer/libmpeg3/mpeg3cat.c new file mode 100644 index 0000000..20f7660 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/mpeg3cat.c @@ -0,0 +1,225 @@ +/* Concatenate elementary streams */ + +#include "libmpeg3.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define MPEG3_SEQUENCE_START_CODE 0x000001b3 +#define BUFFER_SIZE 1000000 + +int main(int argc, char *argv[]) +{ + char inpath[1024]; + mpeg3_t *in; + int current_file, current_output_file = 0, i; + unsigned int bits; + unsigned char *buffer; + long output_size; + int result = 0; + long total_frames = 0; + int do_audio = 0, do_video = 0; + int stream = 0; + + if(argc < 2) + { + fprintf(stderr, "Concatenate elementary streams or demultiplex a program stream.\n" + "Usage: mpeg3cat -[av0123456789] <infile> [infile...] > <outfile>\n\n" + "Example: Concatenate 2 video files: mpeg3cat xena1.m2v xena2.m2v > xena.m2v\n" + " Extract audio stream 0: mpeg3cat -a0 xena.vob > war_cry.ac3\n"); + exit(1); + } + + for(i = 1; i < argc; i++) + { + if(argv[i][0] == '-') + { + if(argv[i][1] != 'a' && argv[i][1] != 'v') + { + fprintf(stderr, "invalid option %s\n", argv[i]); + } + else + { + if(argv[i][1] == 'a') do_audio = 1; + else + if(argv[i][1] == 'v') do_video = 1; + + if(argv[i][2] != 0) + { + stream = argv[i][2] - 48; + } + } + } + } + + buffer = (unsigned char*)malloc(BUFFER_SIZE); + + for(current_file = 1; current_file < argc; current_file++) + { + if(argv[current_file][0] == '-') continue; + + strcpy(inpath, argv[current_file]); + if(!(in = mpeg3_open(inpath))) + { + fprintf(stderr, "Skipping %s\n", inpath); + continue; + } + + if((mpeg3_has_audio(in) && in->is_audio_stream) || + (do_audio && !in->is_audio_stream && !in->is_video_stream)) + { + do_audio = 1; +/* Add audio stream to end */ + while(!mpeg3_read_audio_chunk(in, buffer, + &output_size, + BUFFER_SIZE, + stream)) + { + result = !fwrite(buffer, output_size, 1, stdout); + if(result) + { + perror("fwrite audio chunk"); + break; + } + } + } + else + if((mpeg3_has_video(in) && in->is_video_stream) || + (do_video && !in->is_video_stream && !in->is_audio_stream)) + { +/* Add video stream to end */ + int hour, minute, second, frame; + long gop_frame; + unsigned long code; + float carry; + int i, offset; + + do_video = 1; + while(!mpeg3_read_video_chunk(in, + buffer, + &output_size, + BUFFER_SIZE, + stream) && + output_size >= 4) + { + code = (unsigned long)buffer[output_size - 4] << 24; + code |= (unsigned long)buffer[output_size - 3] << 16; + code |= (unsigned long)buffer[output_size - 2] << 8; + code |= (unsigned long)buffer[output_size - 1]; + +/* Got a frame at the end of this buffer. */ + if(code == MPEG3_PICTURE_START_CODE) + { + total_frames++; + } + else + if(code == MPEG3_SEQUENCE_END_CODE) + { +/* Got a sequence end code at the end of this buffer. */ + output_size -= 4; + } + + code = (unsigned long)buffer[0] << 24; + code |= (unsigned long)buffer[1] << 16; + code |= (unsigned long)buffer[2] << 8; + code |= buffer[3]; + + i = 0; + offset = 0; + if(code == MPEG3_SEQUENCE_START_CODE && current_output_file > 0) + { +/* Skip the sequence start code */ + i += 4; + while(i < output_size && + code != MPEG3_GOP_START_CODE) + { + code <<= 8; + code |= buffer[i++]; + } + i -= 4; + offset = i; + } + +/* Search for GOP header to fix */ + code = (unsigned long)buffer[i++] << 24; + code |= (unsigned long)buffer[i++] << 16; + code |= (unsigned long)buffer[i++] << 8; + code |= buffer[i++]; + while(i < output_size && + code != MPEG3_GOP_START_CODE) + { + code <<= 8; + code |= buffer[i++]; + } + + if(code == MPEG3_GOP_START_CODE) + { +/* Get the time code */ + code = (unsigned long)buffer[i] << 24; + code |= (unsigned long)buffer[i + 1] << 16; + code |= (unsigned long)buffer[i + 2] << 8; + code |= (unsigned long)buffer[i + 3]; + + hour = code >> 26 & 0x1f; + minute = code >> 20 & 0x3f; + second = code >> 13 & 0x3f; + frame = code >> 7 & 0x3f; + + gop_frame = (long)(hour * 3600 * mpeg3_frame_rate(in, stream) + + minute * 60 * mpeg3_frame_rate(in, stream) + + second * mpeg3_frame_rate(in, stream) + + frame); +/* fprintf(stderr, "old: %02d:%02d:%02d:%02d ", hour, minute, second, frame); */ +/* Write a new time code */ + hour = (long)((float)(total_frames - 1) / mpeg3_frame_rate(in, stream) / 3600); + carry = hour * 3600 * mpeg3_frame_rate(in, stream); + minute = (long)((float)(total_frames - 1 - carry) / mpeg3_frame_rate(in, stream) / 60); + carry += minute * 60 * mpeg3_frame_rate(in, stream); + second = (long)((float)(total_frames - 1 - carry) / mpeg3_frame_rate(in, stream)); + carry += second * mpeg3_frame_rate(in, stream); + frame = (int)(total_frames - 1 - carry); + + buffer[i] = ((code >> 24) & 0x80) | (hour << 2) | (minute >> 4); + buffer[i + 1] = ((code >> 16) & 0x08) | ((minute & 0xf) << 4) | (second >> 3); + buffer[i + 2] = ((second & 0x7) << 5) | (frame >> 1); + buffer[i + 3] = (code & 0x7f) | ((frame & 0x1) << 7); +/* fprintf(stderr, "new: %02d:%02d:%02d:%02d\n", hour, minute, second, frame); */ + } + +/* Write the frame */ + result = !fwrite(buffer + offset, output_size - offset, 1, stdout); + if(result) + { + perror("fwrite video chunk"); + break; + } + } + } + else + { + fprintf(stderr, "Unsupported stream type.\n"); + mpeg3_close(in); + in = 0; + continue; + } + + mpeg3_close(in); + in = 0; + current_output_file++; + } + +/* Terminate output */ + if(current_output_file > 0 && do_video) + { +/*fprintf(stderr, "\n"); */ +/* Write new end of sequence */ + buffer[0] = MPEG3_SEQUENCE_END_CODE >> 24; + buffer[1] = (MPEG3_SEQUENCE_END_CODE >> 16) & 0xff; + buffer[2] = (MPEG3_SEQUENCE_END_CODE >> 8) & 0xff; + buffer[3] = MPEG3_SEQUENCE_END_CODE & 0xff; + result = !fwrite(buffer, 4, 1, stdout); + } + + exit(0); +} diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3css.c b/core/multimedia/opieplayer/libmpeg3/mpeg3css.c new file mode 100644 index 0000000..7f9ad8c --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/mpeg3css.c @@ -0,0 +1,32 @@ +#include "mpeg3css.h" +#include "mpeg3private.h" + +extern "C" { + +int mpeg3_init_css(mpeg3_t *file, mpeg3_css_t *css) +{ + return 0; +} + +int mpeg3_get_keys(mpeg3_css_t *css, char *path) +{ + return 1; +} + +int mpeg3_decrypt_packet(mpeg3_css_t *css, unsigned char *sector) +{ + return 1; +} + +mpeg3_css_t* mpeg3_new_css() +{ + return 0; +} + +int mpeg3_delete_css(mpeg3_css_t *css) +{ + return 0; +} + +}; + diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3css.h b/core/multimedia/opieplayer/libmpeg3/mpeg3css.h new file mode 100644 index 0000000..1272574 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/mpeg3css.h @@ -0,0 +1,29 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef MPEG3CSS_H +#define MPEG3CSS_H + +/* Stubs for deCSS which can't be distributed legally */ + +typedef struct +{ +} mpeg3_css_t; + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3css_fake.c b/core/multimedia/opieplayer/libmpeg3/mpeg3css_fake.c new file mode 100644 index 0000000..0901195 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/mpeg3css_fake.c @@ -0,0 +1,19 @@ +/* Stubs for deCSS which can't be distributed in source form */ + +#include "mpeg3css.h" +#include "mpeg3private.h" + +int mpeg3_init_css(mpeg3_t *file, mpeg3_css_t *css) +{ + return 0; +} + +int mpeg3_get_keys(mpeg3_css_t *css, char *path) +{ + return 1; +} + +int mpeg3_decrypt_packet(mpeg3_css_t *css, unsigned char *sector) +{ + return 1; +} diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3css_fake.h b/core/multimedia/opieplayer/libmpeg3/mpeg3css_fake.h new file mode 100644 index 0000000..1272574 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/mpeg3css_fake.h @@ -0,0 +1,29 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef MPEG3CSS_H +#define MPEG3CSS_H + +/* Stubs for deCSS which can't be distributed legally */ + +typedef struct +{ +} mpeg3_css_t; + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3demux.c b/core/multimedia/opieplayer/libmpeg3/mpeg3demux.c new file mode 100644 index 0000000..cccc820 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/mpeg3demux.c @@ -0,0 +1,1849 @@ +#include "libmpeg3.h" +#include "mpeg3io.h" +#include "mpeg3protos.h" + +#include <math.h> +#include <stdlib.h> +#include <string.h> + +#define ABS(x) ((x) >= 0 ? (x) : -(x)) + +/* Don't advance pointer */ +static inline unsigned char mpeg3packet_next_char(mpeg3_demuxer_t *demuxer) +{ + return demuxer->raw_data[demuxer->raw_offset]; +} + +unsigned char mpeg3packet_read_char(mpeg3_demuxer_t *demuxer) +{ + unsigned char result = demuxer->raw_data[demuxer->raw_offset++]; + return result; +} + +static inline unsigned int mpeg3packet_read_int16(mpeg3_demuxer_t *demuxer) +{ + unsigned int a, b, result; + a = demuxer->raw_data[demuxer->raw_offset++]; + b = demuxer->raw_data[demuxer->raw_offset++]; + result = (a << 8) | b; + + return result; +} + +static inline unsigned int mpeg3packet_next_int24(mpeg3_demuxer_t *demuxer) +{ + unsigned int a, b, c, result; + a = demuxer->raw_data[demuxer->raw_offset]; + b = demuxer->raw_data[demuxer->raw_offset + 1]; + c = demuxer->raw_data[demuxer->raw_offset + 2]; + result = (a << 16) | (b << 8) | c; + + return result; +} + +static inline unsigned int mpeg3packet_read_int24(mpeg3_demuxer_t *demuxer) +{ + unsigned int a, b, c, result; + a = demuxer->raw_data[demuxer->raw_offset++]; + b = demuxer->raw_data[demuxer->raw_offset++]; + c = demuxer->raw_data[demuxer->raw_offset++]; + result = (a << 16) | (b << 8) | c; + + return result; +} + +static inline unsigned int mpeg3packet_read_int32(mpeg3_demuxer_t *demuxer) +{ + unsigned int a, b, c, d, result; + a = demuxer->raw_data[demuxer->raw_offset++]; + b = demuxer->raw_data[demuxer->raw_offset++]; + c = demuxer->raw_data[demuxer->raw_offset++]; + d = demuxer->raw_data[demuxer->raw_offset++]; + result = (a << 24) | (b << 16) | (c << 8) | d; + + return result; +} + +static inline unsigned int mpeg3packet_skip(mpeg3_demuxer_t *demuxer, long length) +{ + demuxer->raw_offset += length; + return 0; +} + +int mpeg3_get_adaptation_field(mpeg3_demuxer_t *demuxer) +{ + long length; + int pcr_flag; + + demuxer->adaptation_fields++; +/* get adaptation field length */ + length = mpeg3packet_read_char(demuxer); +/* get first byte */ + pcr_flag = (mpeg3packet_read_char(demuxer) >> 4) & 1; + + if(pcr_flag) + { + unsigned long clk_ref_base = mpeg3packet_read_int32(demuxer); + unsigned int clk_ref_ext = mpeg3packet_read_int16(demuxer); + + if (clk_ref_base > 0x7fffffff) + { /* correct for invalid numbers */ + clk_ref_base = 0; /* ie. longer than 32 bits when multiplied by 2 */ + clk_ref_ext = 0; /* multiplied by 2 corresponds to shift left 1 (<<=1) */ + } + else + { + clk_ref_base <<= 1; /* Create space for bit */ + clk_ref_base |= (clk_ref_ext >> 15); /* Take bit */ + clk_ref_ext &= 0x01ff; /* Only lower 9 bits */ + } + demuxer->time = clk_ref_base + clk_ref_ext / 300; + if(length) mpeg3packet_skip(demuxer, length - 7); + } + else + mpeg3packet_skip(demuxer, length - 1); + + return 0; +} + +int mpeg3_get_program_association_table(mpeg3_demuxer_t *demuxer) +{ + demuxer->program_association_tables++; + demuxer->table_id = mpeg3packet_read_char(demuxer); + demuxer->section_length = mpeg3packet_read_int16(demuxer) & 0xfff; + demuxer->transport_stream_id = mpeg3packet_read_int16(demuxer); + mpeg3packet_skip(demuxer, demuxer->raw_size - demuxer->raw_offset); + return 0; +} + +int mpeg3packet_get_data_buffer(mpeg3_demuxer_t *demuxer) +{ + while(demuxer->raw_offset < demuxer->raw_size && demuxer->data_size < demuxer->data_allocated) + { + demuxer->data_buffer[demuxer->data_size++] = demuxer->raw_data[demuxer->raw_offset++]; + } + return 0; +} + +int mpeg3_get_pes_packet_header(mpeg3_demuxer_t *demuxer, unsigned long *pts, unsigned long *dts) +{ + unsigned int pes_header_bytes = 0; + unsigned int pts_dts_flags; + int pes_header_data_length; + +/* drop first 8 bits */ + mpeg3packet_read_char(demuxer); + pts_dts_flags = (mpeg3packet_read_char(demuxer) >> 6) & 0x3; + pes_header_data_length = mpeg3packet_read_char(demuxer); + +/* Get Presentation Time stamps and Decoding Time Stamps */ + if(pts_dts_flags == 2) + { + *pts = (mpeg3packet_read_char(demuxer) >> 1) & 7; /* Only low 4 bits (7==1111) */ + *pts <<= 15; + *pts |= (mpeg3packet_read_int16(demuxer) >> 1); + *pts <<= 15; + *pts |= (mpeg3packet_read_int16(demuxer) >> 1); + pes_header_bytes += 5; + } + else if(pts_dts_flags == 3) + { + *pts = (mpeg3packet_read_char(demuxer) >> 1) & 7; /* Only low 4 bits (7==1111) */ + *pts <<= 15; + *pts |= (mpeg3packet_read_int16(demuxer) >> 1); + *pts <<= 15; + *pts |= (mpeg3packet_read_int16(demuxer) >> 1); + *dts = (mpeg3packet_read_char(demuxer) >> 1) & 7; /* Only low 4 bits (7==1111) */ + *dts <<= 15; + *dts |= (mpeg3packet_read_int16(demuxer) >> 1); + *dts <<= 15; + *dts |= (mpeg3packet_read_int16(demuxer) >> 1); + pes_header_bytes += 10; + } +/* extract other stuff here! */ + + mpeg3packet_skip(demuxer, pes_header_data_length - pes_header_bytes); + return 0; +} + +int get_unknown_data(mpeg3_demuxer_t *demuxer) +{ + mpeg3packet_skip(demuxer, demuxer->raw_size - demuxer->raw_offset); + return 0; +} + +int mpeg3_get_pes_packet_data(mpeg3_demuxer_t *demuxer, unsigned int stream_id) +{ + unsigned long pts = 0, dts = 0; + + if((stream_id >> 4) == 12 || (stream_id >> 4) == 13) + { +/* Just pick the first available stream if no ID is set */ + if(demuxer->astream == -1) + demuxer->astream = (stream_id & 0x0f); + + if((stream_id & 0x0f) == demuxer->astream && demuxer->do_audio) + { + mpeg3_get_pes_packet_header(demuxer, &pts, &dts); + demuxer->pes_audio_time = pts; + demuxer->audio_pid = demuxer->pid; + return mpeg3packet_get_data_buffer(demuxer); + } + } + else + if((stream_id >> 4)==14) + { +/* Just pick the first available stream if no ID is set */ + if(demuxer->vstream == -1) + demuxer->vstream = (stream_id & 0x0f); + + if((stream_id & 0x0f) == demuxer->vstream && demuxer->do_video) + { + mpeg3_get_pes_packet_header(demuxer, &pts, &dts); + demuxer->pes_video_time = pts; + demuxer->video_pid = demuxer->pid; + return mpeg3packet_get_data_buffer(demuxer); + } + } + else + { + return get_unknown_data(demuxer); + } + + mpeg3packet_skip(demuxer, demuxer->raw_size - demuxer->raw_offset); + + return 0; +} + +int mpeg3_get_pes_packet(mpeg3_demuxer_t *demuxer) +{ + unsigned int stream_id; + + demuxer->pes_packets++; + stream_id = mpeg3packet_read_char(demuxer); +/* Skip startcode */ + mpeg3packet_read_int24(demuxer); +/* Skip pes packet length */ + mpeg3packet_read_int16(demuxer); + + if(stream_id != MPEG3_PRIVATE_STREAM_2 && stream_id != MPEG3_PADDING_STREAM) + { + return mpeg3_get_pes_packet_data(demuxer, stream_id); + } + else + if(stream_id == MPEG3_PRIVATE_STREAM_2) + { +/* Dump private data! */ + fprintf(stderr, "stream_id == MPEG3_PRIVATE_STREAM_2\n"); + mpeg3packet_skip(demuxer, demuxer->raw_size - demuxer->raw_offset); + return 0; + } + else + if(stream_id == MPEG3_PADDING_STREAM) + { + mpeg3packet_skip(demuxer, demuxer->raw_size - demuxer->raw_offset); + return 0; + } + else + { + fprintf(stderr, "unknown stream_id in pes packet"); + return 1; + } + return 0; +} + +int mpeg3_get_payload(mpeg3_demuxer_t *demuxer) +{ + if(demuxer->payload_unit_start_indicator) + { + if(demuxer->pid==0) mpeg3_get_program_association_table(demuxer); + else + if(mpeg3packet_next_int24(demuxer) == MPEG3_PACKET_START_CODE_PREFIX) mpeg3_get_pes_packet(demuxer); + else + mpeg3packet_skip(demuxer, demuxer->raw_size - demuxer->raw_offset); + } + else + { + if(demuxer->pid == demuxer->audio_pid && demuxer->do_audio) + { + mpeg3packet_get_data_buffer(demuxer); + } + else + if(demuxer->pid == demuxer->video_pid && demuxer->do_video) + { + mpeg3packet_get_data_buffer(demuxer); + } + else + mpeg3packet_skip(demuxer, demuxer->raw_size - demuxer->raw_offset); + } + return 0; +} + +/* Read a transport packet */ +int mpeg3_read_transport(mpeg3_demuxer_t *demuxer) +{ + mpeg3_title_t *title = demuxer->titles[demuxer->current_title]; + int result = mpeg3io_read_data(demuxer->raw_data, demuxer->packet_size, title->fs); + unsigned int bits; + int table_entry; + + demuxer->raw_size = demuxer->packet_size; + demuxer->raw_offset = 0; + if(result) + { + perror("mpeg3_read_transport"); + return 1; + } + +/* Sync byte */ + if(mpeg3packet_read_char(demuxer) != MPEG3_SYNC_BYTE) + { + fprintf(stderr, "mpeg3packet_read_char(demuxer) != MPEG3_SYNC_BYTE\n"); + return 1; + } + +/* bits = mpeg3packet_read_int24(demuxer) & 0x0000ffff; */ +/* demuxer->transport_error_indicator = bits >> 15; */ +/* demuxer->payload_unit_start_indicator = (bits >> 14) & 1; */ +/* demuxer->pid = bits & 0x00001fff; */ +/* demuxer->transport_scrambling_control = (mpeg3packet_next_char(demuxer) >> 6) & 0x3; */ +/* demuxer->adaptation_field_control = (mpeg3packet_next_char(demuxer) >> 4) & 0x3; */ +/* demuxer->continuity_counter = (mpeg3packet_read_char(demuxer) & 0xf); */ + + bits = mpeg3packet_read_int24(demuxer) & 0x00ffffff; + demuxer->transport_error_indicator = (bits >> 23) & 0x1; + demuxer->payload_unit_start_indicator = (bits >> 22) & 0x1; + demuxer->pid = (bits >> 8) & 0x00001fff; + demuxer->transport_scrambling_control = (bits >> 6) & 0x3; + demuxer->adaptation_field_control = (bits >> 4) & 0x3; + demuxer->continuity_counter = bits & 0xf; + + if(demuxer->transport_error_indicator) + { + fprintf(stderr, "demuxer->transport_error_indicator\n"); + return 1; + } + + if (demuxer->pid == 0x1fff) + { + demuxer->is_padding = 1; /* padding; just go to next */ + return 0; + } + else + { + demuxer->is_padding = 0; + } + +/* Get pid */ + for(table_entry = 0, result = 0; table_entry < demuxer->total_pids; table_entry++) + { + if(demuxer->pid == demuxer->pid_table[table_entry]) + { + result = 1; + break; + } + } + +/* Not in pid table */ + if(!result) + { + demuxer->pid_table[table_entry] = demuxer->pid; + demuxer->continuity_counters[table_entry] = demuxer->continuity_counter; /* init */ + demuxer->total_pids++; + } + result = 0; + +/* Check counters */ + if(demuxer->pid != MPEG3_PROGRAM_ASSOCIATION_TABLE && + demuxer->pid != MPEG3_CONDITIONAL_ACCESS_TABLE && + (demuxer->adaptation_field_control == 1 || demuxer->adaptation_field_control == 3)) + { + if(demuxer->continuity_counters[table_entry] != demuxer->continuity_counter) + { + fprintf(stderr, "demuxer->continuity_counters[table_entry] != demuxer->continuity_counter\n"); +/* Reset it */ + demuxer->continuity_counters[table_entry] = demuxer->continuity_counter; + } + if(++(demuxer->continuity_counters[table_entry]) > 15) demuxer->continuity_counters[table_entry] = 0; + } + + if(demuxer->adaptation_field_control == 2 || demuxer->adaptation_field_control == 3) + result = mpeg3_get_adaptation_field(demuxer); + + if(demuxer->adaptation_field_control == 1 || demuxer->adaptation_field_control == 3) + result = mpeg3_get_payload(demuxer); + + return result; +} + +int mpeg3_get_system_header(mpeg3_demuxer_t *demuxer) +{ + int length = mpeg3packet_read_int16(demuxer); + mpeg3packet_skip(demuxer, length); + return 0; +} + +unsigned long mpeg3_get_timestamp(mpeg3_demuxer_t *demuxer) +{ + unsigned long timestamp; +/* Only low 4 bits (7==1111) */ + timestamp = (mpeg3packet_read_char(demuxer) >> 1) & 7; + timestamp <<= 15; + timestamp |= (mpeg3packet_read_int16(demuxer) >> 1); + timestamp <<= 15; + timestamp |= (mpeg3packet_read_int16(demuxer) >> 1); + return timestamp; +} + +int mpeg3_get_pack_header(mpeg3_demuxer_t *demuxer, unsigned int *header) +{ + unsigned long i, j; + unsigned long clock_ref, clock_ref_ext; + +/* Get the time code */ + if((mpeg3packet_next_char(demuxer) >> 4) == 2) + { +/* MPEG-1 */ + demuxer->time = (double)mpeg3_get_timestamp(demuxer) / 90000; +/* Skip 3 bytes */ + mpeg3packet_read_int24(demuxer); + } + else + if(mpeg3packet_next_char(demuxer) & 0x40) + { + i = mpeg3packet_read_int32(demuxer); + j = mpeg3packet_read_int16(demuxer); + if(i & 0x40000000 || (i >> 28) == 2) + { + clock_ref = ((i & 0x31000000) << 3); + clock_ref |= ((i & 0x03fff800) << 4); + clock_ref |= ((i & 0x000003ff) << 5); + clock_ref |= ((j & 0xf800) >> 11); + clock_ref_ext = (j >> 1) & 0x1ff; + + demuxer->time = (double)(clock_ref + clock_ref_ext / 300) / 90000; +/* Skip 3 bytes */ + mpeg3packet_read_int24(demuxer); + i = mpeg3packet_read_char(demuxer) & 0x7; + +/* stuffing */ + mpeg3packet_skip(demuxer, i); + } + } + else + { + mpeg3packet_skip(demuxer, 2); + } + + *header = mpeg3packet_read_int32(demuxer); + if(*header == MPEG3_SYSTEM_START_CODE) + { + mpeg3_get_system_header(demuxer); + *header = mpeg3packet_read_int32(demuxer); + } + return 0; +} + +/* Program packet reading core */ +int mpeg3_get_ps_pes_packet(mpeg3_demuxer_t *demuxer, unsigned int *header) +{ + unsigned long pts = 0, dts = 0; + int stream_id; + int pes_packet_length; + int pes_packet_start; + int i; + mpeg3_t *file = demuxer->file; + + stream_id = *header & 0xff; + pes_packet_length = mpeg3packet_read_int16(demuxer); + pes_packet_start = demuxer->raw_offset; + + if(stream_id != MPEG3_PRIVATE_STREAM_2 && + stream_id != MPEG3_PADDING_STREAM) + { + if((mpeg3packet_next_char(demuxer) >> 6) == 0x02) + { +/* Get MPEG-2 packet */ + int pes_header_bytes = 0; + int scrambling = (mpeg3packet_read_char(demuxer) >> 4) & 0x3; + int pts_dts_flags = (mpeg3packet_read_char(demuxer) >> 6) & 0x3; + int pes_header_data_length = mpeg3packet_read_char(demuxer); + + if(scrambling && (demuxer->do_audio || demuxer->do_video)) + { +/* Decrypt it */ + if(mpeg3_decrypt_packet(demuxer->titles[demuxer->current_title]->fs->css, + demuxer->raw_data)) + { + fprintf(stderr, "mpeg3_get_ps_pes_packet: Decryption not available\n"); + return 1; + } + } + +/* Get Presentation and Decoding Time Stamps */ + if(pts_dts_flags == 2) + { + pts = (mpeg3packet_read_char(demuxer) >> 1) & 7; /* Only low 4 bits (7==1111) */ + pts <<= 15; + pts |= (mpeg3packet_read_int16(demuxer) >> 1); + pts <<= 15; + pts |= (mpeg3packet_read_int16(demuxer) >> 1); + pes_header_bytes += 5; + } + else + if(pts_dts_flags == 3) + { + pts = (mpeg3packet_read_char(demuxer) >> 1) & 7; /* Only low 4 bits (7==1111) */ + pts <<= 15; + pts |= (mpeg3packet_read_int16(demuxer) >> 1); + pts <<= 15; + pts |= (mpeg3packet_read_int16(demuxer) >> 1); + dts = (mpeg3packet_read_char(demuxer) >> 1) & 7; /* Only low 4 bits (7==1111) */ + dts <<= 15; + dts |= (mpeg3packet_read_int16(demuxer) >> 1); + dts <<= 15; + dts |= (mpeg3packet_read_int16(demuxer) >> 1); + pes_header_bytes += 10; + } + +/* Skip unknown */ + mpeg3packet_skip(demuxer, pes_header_data_length - pes_header_bytes); + } + else + { + int pts_dts_flags; +/* Get MPEG-1 packet */ + while(mpeg3packet_next_char(demuxer) == 0xff) + { + mpeg3packet_read_char(demuxer); + } + +/* Skip STD buffer scale */ + if((mpeg3packet_next_char(demuxer) & 0x40) == 0x40) + { + mpeg3packet_skip(demuxer, 2); + } + +/* Decide which timestamps are available */ + pts_dts_flags = mpeg3packet_next_char(demuxer); + + if(pts_dts_flags >= 0x30) + { +/* Get the presentation and decoding time stamp */ + pts = mpeg3_get_timestamp(demuxer); + dts = mpeg3_get_timestamp(demuxer); + } + else + if(pts_dts_flags >= 0x20) + { +/* Get just the presentation time stamp */ + pts = mpeg3_get_timestamp(demuxer); + } + else + if(pts_dts_flags == 0x0f) + { +/* End of timestamps */ + mpeg3packet_read_char(demuxer); + } + else + { + return 1; /* Error */ + } + } + +/* Now extract the payload. */ + if((stream_id >> 4) == 0xc || (stream_id >> 4) == 0xd) + { +/* Audio data */ +/* Take first stream ID if -1 */ + pes_packet_length -= demuxer->raw_offset - pes_packet_start; + if(!demuxer->do_audio && !demuxer->do_video) + demuxer->astream_table[stream_id & 0x0f] = AUDIO_MPEG; + else + if(demuxer->astream == -1) + demuxer->astream = stream_id & 0x0f; + + if((stream_id & 0x0f) == demuxer->astream && demuxer->do_audio) + { + if(pts) demuxer->pes_audio_time = pts; + + memcpy(&demuxer->data_buffer[demuxer->data_size], + &demuxer->raw_data[demuxer->raw_offset], + pes_packet_length); + demuxer->data_size += pes_packet_length; + demuxer->raw_offset += pes_packet_length; + } + else + { + mpeg3packet_skip(demuxer, pes_packet_length); + } + } + else + if((stream_id >> 4) == 0xe) + { +/* Video data */ +/* Take first stream ID if -1 */ + if(!demuxer->do_audio && !demuxer->do_video) + demuxer->vstream_table[stream_id & 0x0f] = 1; + else + if(demuxer->vstream == -1) + demuxer->vstream = stream_id & 0x0f; + + pes_packet_length -= demuxer->raw_offset - pes_packet_start; + if((stream_id & 0x0f) == demuxer->vstream && demuxer->do_video) + { + if(pts) demuxer->pes_video_time = pts; + + memcpy(&demuxer->data_buffer[demuxer->data_size], + &demuxer->raw_data[demuxer->raw_offset], + pes_packet_length); + demuxer->data_size += pes_packet_length; + demuxer->raw_offset += pes_packet_length; + } + else + { + mpeg3packet_skip(demuxer, pes_packet_length); + } + } + else + if(stream_id == 0xbd && demuxer->raw_data[demuxer->raw_offset] != 0xff) + { +/* DVD audio data */ +/* Get the audio format */ + int format; + if((demuxer->raw_data[demuxer->raw_offset] & 0xf0) == 0xa0) + format = AUDIO_PCM; + else + format = AUDIO_AC3; + + stream_id = demuxer->raw_data[demuxer->raw_offset] - 0x80; + +/* Take first stream ID if not building TOC. */ + if(!demuxer->do_audio && !demuxer->do_video) + demuxer->astream_table[stream_id] = format; + else + if(demuxer->astream == -1) + demuxer->astream = stream_id; + + if(stream_id == demuxer->astream && demuxer->do_audio) + { + demuxer->aformat = format; + if(pts) demuxer->pes_audio_time = pts; + mpeg3packet_read_int32(demuxer); + pes_packet_length -= demuxer->raw_offset - pes_packet_start; + + memcpy(&demuxer->data_buffer[demuxer->data_size], + &demuxer->raw_data[demuxer->raw_offset], + pes_packet_length); + demuxer->data_size += pes_packet_length; + demuxer->raw_offset += pes_packet_length; + } + else + { + pes_packet_length -= demuxer->raw_offset - pes_packet_start; + mpeg3packet_skip(demuxer, pes_packet_length); + } + } + else + if(stream_id == 0xbc || 1) + { + pes_packet_length -= demuxer->raw_offset - pes_packet_start; + mpeg3packet_skip(demuxer, pes_packet_length); + } + } + else + if(stream_id == MPEG3_PRIVATE_STREAM_2 || stream_id == MPEG3_PADDING_STREAM) + { + pes_packet_length -= demuxer->raw_offset - pes_packet_start; + mpeg3packet_skip(demuxer, pes_packet_length); + } + + while(demuxer->raw_offset + 4 < demuxer->raw_size) + { + *header = mpeg3packet_read_int32(demuxer); + if((*header >> 8) != MPEG3_PACKET_START_CODE_PREFIX) + demuxer->raw_offset -= 3; + else + break; + } + + return 0; +} + +int mpeg3_read_program(mpeg3_demuxer_t *demuxer) +{ + int result = 0, count = 0; + mpeg3_t *file = demuxer->file; + mpeg3_title_t *title = demuxer->titles[demuxer->current_title]; + unsigned int header; + demuxer->raw_size = demuxer->packet_size; + demuxer->raw_offset = 0; + demuxer->data_size = 0; + +/* Search backward for it. */ + header = mpeg3io_read_int32(title->fs); + result = mpeg3io_eof(title->fs); + + if(!result) result = mpeg3io_seek_relative(title->fs, -4); + +// Search backwards for header + while(header != MPEG3_PACK_START_CODE && !result && count < demuxer->packet_size) + { + result = mpeg3io_seek_relative(title->fs, -1); + if(!result) + { + header >>= 8; + header |= mpeg3io_read_char(title->fs) << 24; + result = mpeg3io_seek_relative(title->fs, -1); + } + count++; + } + + if(result) + { +// couldn't find MPEG3_PACK_START_CODE + return 1; + } + + result = mpeg3io_read_data(demuxer->raw_data, demuxer->packet_size, title->fs); + + if(result) + { + perror("mpeg3_read_program"); + return 1; + } + + header = mpeg3packet_read_int32(demuxer); + while(demuxer->raw_offset + 4 < demuxer->raw_size && !result) + { + if(header == MPEG3_PACK_START_CODE) + { + result = mpeg3_get_pack_header(demuxer, &header); + } + else + if((header >> 8) == MPEG3_PACKET_START_CODE_PREFIX) + { + result = mpeg3_get_ps_pes_packet(demuxer, &header); + } + } + return result; +} + +double mpeg3_lookup_time_offset(mpeg3_demuxer_t *demuxer, long byte) +{ + int i; + mpeg3_title_t *title = demuxer->titles[demuxer->current_title]; + + if(!title->timecode_table_size) return 0; + + for(i = title->timecode_table_size - 1; + i >= 0 && title->timecode_table[i].start_byte > byte; + i--) + ; + if(i < 0) i = 0; + return title->timecode_table[i].absolute_start_time - title->timecode_table[i].start_time; +} + +int mpeg3_advance_timecode(mpeg3_demuxer_t *demuxer, int reverse) +{ + mpeg3_title_t *title = demuxer->titles[demuxer->current_title]; + int result = 0; + int do_seek = 0; + +/* Skip timecode advancing when constructing timecode table */ + if(!title->timecode_table || + !title->timecode_table_size || + demuxer->generating_timecode) return 0; + + if(!reverse) + { +/* Get inside the current timecode */ + if(mpeg3io_tell(title->fs) < title->timecode_table[demuxer->current_timecode].start_byte) + { + mpeg3io_seek(title->fs, title->timecode_table[demuxer->current_timecode].start_byte); + } + +/* Get the next timecode */ + while(!result && + (mpeg3io_tell(title->fs) >= title->timecode_table[demuxer->current_timecode].end_byte || + demuxer->current_program != title->timecode_table[demuxer->current_timecode].program)) + { + +/* + * printf("mpeg3_advance_timecode %d %d %d %d\n", mpeg3io_tell(title->fs), title->timecode_table[demuxer->current_timecode].end_byte, + * demuxer->current_program, title->timecode_table[demuxer->current_timecode].program); + */ + + demuxer->current_timecode++; + if(demuxer->current_timecode >= title->timecode_table_size) + { + demuxer->current_timecode = 0; + if(demuxer->current_title + 1 < demuxer->total_titles) + { + mpeg3demux_open_title(demuxer, demuxer->current_title + 1); + do_seek = 1; + } + else + { + mpeg3io_seek(title->fs, mpeg3io_total_bytes(title->fs)); + result = 1; + } + } + title = demuxer->titles[demuxer->current_title]; + } + + if(!result && do_seek) + { + mpeg3io_seek(title->fs, title->timecode_table[demuxer->current_timecode].start_byte); + } + } + else + { +/* Get the previous timecode */ + while(!result && + (mpeg3io_tell(title->fs) < title->timecode_table[demuxer->current_timecode].start_byte || + demuxer->current_program != title->timecode_table[demuxer->current_timecode].program)) + { +/* + * if(demuxer->do_audio) printf("mpeg3_reverse_timecode %d %d %d %d\n", mpeg3io_tell(title->fs), title->timecode_table[demuxer->current_timecode].end_byte, + * demuxer->current_program, title->timecode_table[demuxer->current_timecode].program); + */ + demuxer->current_timecode--; + if(demuxer->current_timecode < 0) + { + if(demuxer->current_title > 0) + { + mpeg3demux_open_title(demuxer, demuxer->current_title - 1); + title = demuxer->titles[demuxer->current_title]; + demuxer->current_timecode = title->timecode_table_size - 1; + do_seek = 1; + } + else + { + mpeg3io_seek(title->fs, 0); + demuxer->current_timecode = 0; + result = 1; + } + } + } + + if(!result && do_seek) + mpeg3io_seek(title->fs, title->timecode_table[demuxer->current_timecode].start_byte); + } + + return result; +} + +/* Read packet in the forward direction */ +int mpeg3_read_next_packet(mpeg3_demuxer_t *demuxer) +{ + int result = 0; + long current_position; + mpeg3_t *file = demuxer->file; + mpeg3_title_t *title = demuxer->titles[demuxer->current_title]; + demuxer->data_size = 0; + demuxer->data_position = 0; + +/* Flip the file descriptor back to the end of the packet for forward */ +/* reading. */ + if(demuxer->reverse) + { + result = mpeg3io_seek_relative(title->fs, demuxer->packet_size); + demuxer->reverse = 0; + } + +/* Read packets until the output buffer is full */ + if(!result) + { + do + { + result = mpeg3_advance_timecode(demuxer, 0); + + if(!result) + { + demuxer->time_offset = mpeg3_lookup_time_offset(demuxer, mpeg3io_tell(title->fs)); + + if(file->is_transport_stream) + { + result = mpeg3_read_transport(demuxer); + } + else + if(file->is_program_stream) + { + result = mpeg3_read_program(demuxer); + } + else + { +/* Read elementary stream. */ + result = mpeg3io_read_data(demuxer->data_buffer, demuxer->packet_size, title->fs); + if(!result) demuxer->data_size = demuxer->packet_size; + } + } + }while(!result && demuxer->data_size == 0 && (demuxer->do_audio || demuxer->do_video)); + } + + return result; +} + +/* Read the packet right before the packet we're currently on. */ +int mpeg3_read_prev_packet(mpeg3_demuxer_t *demuxer) +{ + int result = 0; + mpeg3_t *file = demuxer->file; + long current_position; + mpeg3_title_t *title = demuxer->titles[demuxer->current_title]; + + demuxer->data_size = 0; + demuxer->data_position = 0; + + do + { +/* Rewind to the start of the packet to be read. */ + result = mpeg3io_seek_relative(title->fs, -demuxer->packet_size); + + if(!result) result = mpeg3_advance_timecode(demuxer, 1); + if(!result) demuxer->time_offset = mpeg3_lookup_time_offset(demuxer, mpeg3io_tell(title->fs)); + + if(file->is_transport_stream && !result) + { + result = mpeg3_read_transport(demuxer); + if(!mpeg3io_bof(title->fs)) + /* if(!result) */result = mpeg3io_seek_relative(title->fs, -demuxer->packet_size); + } + else + if(file->is_program_stream && !result) + { + + result = mpeg3_read_program(demuxer); + if(!mpeg3io_bof(title->fs)) + /* if(!result) */result = mpeg3io_seek_relative(title->fs, -demuxer->packet_size); + } + else + if(!result) + { +/* Elementary stream */ +/* Read the packet forwards and seek back to the start */ + result = mpeg3io_read_data(demuxer->data_buffer, demuxer->packet_size, title->fs); + if(!result) + { + demuxer->data_size = demuxer->packet_size; + result = mpeg3io_seek_relative(title->fs, -demuxer->packet_size); + } + } + }while(!result && demuxer->data_size == 0 && (demuxer->do_audio || demuxer->do_video)); + +/* Remember that the file descriptor is at the beginning of the packet just read. */ + demuxer->reverse = 1; + demuxer->error_flag = result; + return result; +} + + +/* Used for audio */ +int mpeg3demux_read_data(mpeg3_demuxer_t *demuxer, + unsigned char *output, + long size) +{ + long i; + int result = 0; + mpeg3_t *file = demuxer->file; + demuxer->error_flag = 0; + + if(demuxer->data_position >= 0) + { +/* Read forwards */ + for(i = 0; i < size && !result; ) + { + int fragment_size = size - i; + if(fragment_size > demuxer->data_size - demuxer->data_position) + fragment_size = demuxer->data_size - demuxer->data_position; + memcpy(output + i, demuxer->data_buffer + demuxer->data_position, fragment_size); + demuxer->data_position += fragment_size; + i += fragment_size; + + if(i < size) + { + result = mpeg3_read_next_packet(demuxer); + } + } + } + else + { +/* Read backwards a full packet. */ +/* Only good for reading less than the size of a full packet, but */ +/* this routine should only be used for searching for previous markers. */ + long current_position = demuxer->data_position; + result = mpeg3_read_prev_packet(demuxer); + if(!result) demuxer->data_position = demuxer->data_size + current_position; + memcpy(output, demuxer->data_buffer + demuxer->data_position, size); + demuxer->data_position += size; + } + + demuxer->error_flag = result; + return result; +} + +unsigned int mpeg3demux_read_char_packet(mpeg3_demuxer_t *demuxer) +{ + demuxer->error_flag = 0; + if(demuxer->data_position >= demuxer->data_size) + demuxer->error_flag = mpeg3_read_next_packet(demuxer); + demuxer->next_char = demuxer->data_buffer[demuxer->data_position++]; + return demuxer->next_char; +} + +unsigned int mpeg3demux_read_prev_char_packet(mpeg3_demuxer_t *demuxer) +{ + demuxer->error_flag = 0; + demuxer->data_position--; + if(demuxer->data_position < 0) + { + demuxer->error_flag = mpeg3_read_prev_packet(demuxer); + if(!demuxer->error_flag) demuxer->data_position = demuxer->data_size - 1; + } + demuxer->next_char = demuxer->data_buffer[demuxer->data_position]; + return demuxer->next_char; +} + +mpeg3demux_timecode_t* mpeg3_append_timecode(mpeg3_demuxer_t *demuxer, + mpeg3_title_t *title, + long prev_byte, + double prev_time, + long next_byte, + double next_time, + int dont_store) +{ + mpeg3demux_timecode_t *new_table; + mpeg3demux_timecode_t *new_timecode, *old_timecode; + long i; + + if(!title->timecode_table || + title->timecode_table_allocation <= title->timecode_table_size) + { + if(title->timecode_table_allocation == 0) + title->timecode_table_allocation = 1; + else + title->timecode_table_allocation *= 2; + + new_table = (mpeg3demux_timecode_t*)calloc(1, sizeof(mpeg3demux_timecode_t) * title->timecode_table_allocation); + if(title->timecode_table) + { + for(i = 0; i < title->timecode_table_size; i++) + { + new_table[i] = title->timecode_table[i]; + } + + free(title->timecode_table); + } + title->timecode_table = new_table; + } + + if(!dont_store) + { + new_timecode = &title->timecode_table[title->timecode_table_size]; + new_timecode->start_byte = next_byte; + new_timecode->start_time = next_time; + new_timecode->absolute_start_time = 0; + + if(title->timecode_table_size > 0) + { + old_timecode = &title->timecode_table[title->timecode_table_size - 1]; + old_timecode->end_byte = prev_byte; + old_timecode->end_time = prev_time; + new_timecode->absolute_start_time = + prev_time - + old_timecode->start_time + + old_timecode->absolute_start_time; + new_timecode->absolute_end_time = next_time; + } + } + + title->timecode_table_size++; + return new_timecode; +} + +mpeg3demux_timecode_t* mpeg3demux_next_timecode(mpeg3_demuxer_t *demuxer, + int *current_title, + int *current_timecode, + int current_program) +{ + int done = 0; + while(!done) + { +/* Increase timecode number */ + if(*current_timecode < demuxer->titles[*current_title]->timecode_table_size - 1) + { + (*current_timecode)++; + if(demuxer->titles[*current_title]->timecode_table[*current_timecode].program == current_program) + return &(demuxer->titles[*current_title]->timecode_table[*current_timecode]); + } + else +/* Increase title number */ + if(*current_title < demuxer->total_titles - 1) + { + (*current_title)++; + (*current_timecode) = 0; + if(demuxer->titles[*current_title]->timecode_table[*current_timecode].program == current_program) + return &(demuxer->titles[*current_title]->timecode_table[*current_timecode]); + } + else +/* End of disk */ + done = 1; + } + return 0; +} + +mpeg3demux_timecode_t* mpeg3demux_prev_timecode(mpeg3_demuxer_t *demuxer, + int *current_title, + int *current_timecode, + int current_program) +{ + int done = 0; + while(!done) + { +/* Increase timecode number */ + if(*current_timecode > 0) + { + (*current_timecode)--; + if(demuxer->titles[*current_title]->timecode_table[*current_timecode].program == current_program) + return &(demuxer->titles[*current_title]->timecode_table[*current_timecode]); + } + else +/* Increase title number */ + if(*current_title > 0) + { + (*current_title)--; + (*current_timecode) = demuxer->titles[*current_title]->timecode_table_size - 1; + if(demuxer->titles[*current_title]->timecode_table[*current_timecode].program == current_program) + return &(demuxer->titles[*current_title]->timecode_table[*current_timecode]); + } + else +/* End of disk */ + done = 1; + + } + return 0; +} + +int mpeg3demux_open_title(mpeg3_demuxer_t *demuxer, int title_number) +{ + mpeg3_title_t *title; + + if(title_number < demuxer->total_titles) + { + if(demuxer->current_title >= 0) + { + mpeg3io_close_file(demuxer->titles[demuxer->current_title]->fs); + demuxer->current_title = -1; + } + + title = demuxer->titles[title_number]; + if(mpeg3io_open_file(title->fs)) + { + demuxer->error_flag = 1; + perror("mpeg3demux_open_title"); + } + else + { + demuxer->current_title = title_number; + } + } + + demuxer->current_timecode = 0; + + return demuxer->error_flag; +} + +/* Assign program numbers to interleaved programs */ +int mpeg3demux_assign_programs(mpeg3_demuxer_t *demuxer) +{ + int current_program = 0; + int current_title = 0, previous_title; + int current_timecode = 0, previous_timecode; + double current_time, current_length; + int done = 0; + int interleaved = 0; + mpeg3demux_timecode_t *timecode1, *timecode2; + double program_times[MPEG3_MAX_STREAMS]; + int total_programs = 1; + int i, j; + int program_exists, last_program_assigned = 0; + int total_timecodes; + mpeg3_title_t **titles = demuxer->titles; + + for(i = 0, total_timecodes = 0; i < demuxer->total_titles; i++) + total_timecodes += demuxer->titles[i]->timecode_table_size; + +// if(total_timecodes < 3) return 0; + +/* + * // Assign programs based on length of contiguous timecode + * timecode1 = demuxer->titles[current_title]->timecode_table; + * while(!done) + * { + * if(!timecode1) done = 1; + * else + * if(timecode1->end_time - timecode1->start_time < MPEG3_PROGRAM_THRESHOLD) + * { + * // Got interleaved section + * interleaved = 1; + * program_times[0] = timecode1->end_time; + * + * while(interleaved && !done) + * { + * timecode2 = mpeg3demux_next_timecode(demuxer, + * ¤t_title, + * ¤t_timecode, + * 0); + * + * if(!timecode2) done = 1; + * else + * { + * // Another segment of interleaved data + * if(timecode2->end_time - timecode2->start_time < MPEG3_PROGRAM_THRESHOLD) + * { + * // Search program times for where the previous instance of the program left off + * for(program_exists = 0, i = 0; + * i < total_programs && !program_exists; + * i++) + * { + * // Got a previous instance of the program + * if(program_times[i] + 0.5 > timecode2->start_time && + * program_times[i] - 0.5 < timecode2->start_time) + * { + * program_times[i] = timecode2->end_time; + * timecode2->program = i; + * program_exists = 1; + * + * // Programs must always start at 0 for an interleaved section + * if(i < last_program_assigned && i != 0) + * { + * // Shift programs in the interleaved section down until they start at 0 + * for(j = 0; j < total_programs - 1; j++) + * program_times[j] = program_times[j + 1]; + * + * for(previous_title = current_title, previous_timecode = current_timecode; + * titles[previous_title]->timecode_table[previous_timecode].program > 0 && + * (previous_title >= 0 || previous_timecode >= 0); ) + * { + * titles[previous_title]->timecode_table[previous_timecode].program--; + * previous_timecode--; + * if(previous_timecode < 0 && previous_title > 0) + * { + * previous_title--; + * previous_timecode = titles[previous_title]->timecode_table_size - 1; + * } + * } + * } + * } + * } + * + * // Didn't get one + * if(!program_exists) + * { + * program_times[total_programs] = timecode2->end_time; + * timecode2->program = total_programs++; + * } + * last_program_assigned = timecode2->program; + * } + * // No more interleaved section + * else + * { + * interleaved = 0; + * // Restart program table from the beginning + * total_programs = 1; + * last_program_assigned = 0; + * timecode1 = mpeg3demux_next_timecode(demuxer, + * ¤t_title, + * ¤t_timecode, + * 0); + * } + * } + * } + * } + * else + * // Get next timecode + * timecode1 = mpeg3demux_next_timecode(demuxer, + * ¤t_title, + * ¤t_timecode, + * 0); + * } + * + * demuxer->total_programs = total_programs; + */ + +/* Assign absolute timecodes in each program. */ + for(current_program = 0; + current_program < total_programs; + current_program++) + { + current_time = 0; + current_title = 0; + current_timecode = -1; + while(timecode1 = mpeg3demux_next_timecode(demuxer, + ¤t_title, + ¤t_timecode, + current_program)) + { + timecode1->absolute_start_time = current_time; + current_time += timecode1->end_time - timecode1->start_time; + timecode1->absolute_end_time = current_time; + } + } +//for(i = 0; i < demuxer->total_titles; i++) mpeg3_dump_title(demuxer->titles[i]); + demuxer->current_program = 0; + return 0; +} + +/* ==================================================================== */ +/* Entry points */ +/* ==================================================================== */ + +mpeg3_demuxer_t* mpeg3_new_demuxer(mpeg3_t *file, int do_audio, int do_video, int stream_id) +{ + mpeg3_demuxer_t *demuxer = (mpeg3_demuxer_t*)calloc(1, sizeof(mpeg3_demuxer_t)); + int i; + +/* The demuxer will change the default packet size for its own use. */ + demuxer->file = file; + demuxer->packet_size = file->packet_size; + demuxer->do_audio = do_audio; + demuxer->do_video = do_video; + +/* Allocate buffer + padding */ + demuxer->raw_data = (unsigned char*)calloc(1, MPEG3_MAX_PACKSIZE); + demuxer->data_buffer = (unsigned char*)calloc(1, MPEG3_MAX_PACKSIZE); + demuxer->data_allocated = MPEG3_MAX_PACKSIZE; +/* System specific variables */ + demuxer->audio_pid = stream_id; + demuxer->video_pid = stream_id; + demuxer->astream = stream_id; + demuxer->vstream = stream_id; + demuxer->current_title = -1; + return demuxer; +} + +int mpeg3_delete_demuxer(mpeg3_demuxer_t *demuxer) +{ + int i; + + if(demuxer->current_title >= 0) + { + mpeg3io_close_file(demuxer->titles[demuxer->current_title]->fs); + } + + for(i = 0; i < demuxer->total_titles; i++) + { + mpeg3_delete_title(demuxer->titles[i]); + } + + if(demuxer->data_buffer) free(demuxer->data_buffer); + free(demuxer->raw_data); + free(demuxer); +} + +/* Create a title. */ +/* Build a table of timecodes contained in the program stream. */ +/* If toc is 0 just read the first and last timecode. */ +int mpeg3demux_create_title(mpeg3_demuxer_t *demuxer, int timecode_search, FILE *toc) +{ + int result = 0, done = 0, counter_start, counter; + mpeg3_t *file = demuxer->file; + long next_byte, prev_byte; + double next_time, prev_time, absolute_time; + long i; + mpeg3_title_t *title; + unsigned long test_header = 0; + mpeg3demux_timecode_t *timecode = 0; + + demuxer->error_flag = 0; + demuxer->generating_timecode = 1; + +/* Create a single title */ + if(!demuxer->total_titles) + { + demuxer->titles[0] = mpeg3_new_title(file, file->fs->path); + demuxer->total_titles = 1; + mpeg3demux_open_title(demuxer, 0); + } + title = demuxer->titles[0]; + title->total_bytes = mpeg3io_total_bytes(title->fs); + + +/* Get the packet size from the file */ + if(file->is_program_stream) + { + mpeg3io_seek(title->fs, 4); + for(i = 0; i < MPEG3_MAX_PACKSIZE && + test_header != MPEG3_PACK_START_CODE; i++) + { + test_header <<= 8; + test_header |= mpeg3io_read_char(title->fs); + } + if(i < MPEG3_MAX_PACKSIZE) demuxer->packet_size = i; + mpeg3io_seek(title->fs, 0); + } + else + demuxer->packet_size = file->packet_size; + +/* Get timecodes for the title */ + if(file->is_transport_stream || file->is_program_stream) + { + mpeg3io_seek(title->fs, 0); + while(!done && !result && !mpeg3io_eof(title->fs)) + { + next_byte = mpeg3io_tell(title->fs); + result = mpeg3_read_next_packet(demuxer); + + if(!result) + { + next_time = demuxer->time; +//printf("%f %f\n", next_time, prev_time); + if(next_time < prev_time || + next_time - prev_time > MPEG3_CONTIGUOUS_THRESHOLD || + !title->timecode_table_size) + { +/* Discontinuous */ + timecode = mpeg3_append_timecode(demuxer, + title, + prev_byte, + prev_time, + next_byte, + next_time, + 0); +/* + * printf("timecode: %ld %ld %f %f\n", + * timecode->start_byte, + * timecode->end_byte, + * timecode->start_time, + * timecode->end_time); + */ + + counter_start = (int)next_time; + } + prev_time = next_time; + prev_byte = next_byte; + counter = (int)next_time; + } + +/* Just get the first bytes if not building a toc to get the stream ID's. */ + if(next_byte > 0x100000 && + (!timecode_search || !toc)) done = 1; + } + +/* Get the last timecode */ + if(!toc || !timecode_search) + { + result = mpeg3io_seek(title->fs, title->total_bytes); + if(!result) result = mpeg3_read_prev_packet(demuxer); + } + + if(title->timecode_table && timecode) + { + timecode->end_byte = title->total_bytes; +// timecode->end_byte = mpeg3io_tell(title->fs)/* + demuxer->packet_size */; + timecode->end_time = demuxer->time; + timecode->absolute_end_time = timecode->end_time - timecode->start_time; + } + } + + mpeg3io_seek(title->fs, 0); + demuxer->generating_timecode = 0; + return 0; +} + +int mpeg3demux_print_timecodes(mpeg3_title_t *title, FILE *output) +{ + mpeg3demux_timecode_t *timecode; + int i; + + if(title->timecode_table) + { + for(i = 0; i < title->timecode_table_size; i++) + { + timecode = &title->timecode_table[i]; + + fprintf(output, "REGION: %ld %ld %f %f\n", + timecode->start_byte, + timecode->end_byte, + timecode->start_time, + timecode->end_time); + } + } + return 0; +} + +/* Read the title information from a toc */ +int mpeg3demux_read_titles(mpeg3_demuxer_t *demuxer) +{ + char string1[MPEG3_STRLEN], string2[MPEG3_STRLEN]; + long start_byte, end_byte; + float start_time, end_time; + mpeg3_title_t *title = 0; + mpeg3_t *file = demuxer->file; + +// Eventually use IFO file to generate titles + while(!feof(file->fs->fd)) + { + fscanf(file->fs->fd, "%s %s %ld %f %f %f", + string1, + string2, + &end_byte, + &start_time, + &end_time); + + if(!strncasecmp(string1, "PATH:", 5)) + { + title = demuxer->titles[demuxer->total_titles++] = mpeg3_new_title(file, string2); + + if(demuxer->current_title < 0) + mpeg3demux_open_title(demuxer, 0); + } + else + if(title) + { + start_byte = atol(string2); + if(!strcasecmp(string1, "REGION:")) + { + mpeg3_append_timecode(demuxer, + title, + 0, + 0, + 0, + 0, + 1); + title->timecode_table[title->timecode_table_size - 1].start_byte = start_byte; + title->timecode_table[title->timecode_table_size - 1].end_byte = end_byte; + title->timecode_table[title->timecode_table_size - 1].start_time = start_time; + title->timecode_table[title->timecode_table_size - 1].end_time = end_time; + } + else + if(!strcasecmp(string1, "ASTREAM:")) + demuxer->astream_table[start_byte] = end_byte; + else + if(!strcasecmp(string1, "VSTREAM:")) + demuxer->vstream_table[start_byte] = end_byte; + else + if(!strcasecmp(string1, "SIZE:")) + title->total_bytes = start_byte; + else + if(!strcasecmp(string1, "PACKETSIZE:")) + demuxer->packet_size = start_byte; + } + } + + mpeg3demux_assign_programs(demuxer); + return 0; +} + +int mpeg3demux_copy_titles(mpeg3_demuxer_t *dst, mpeg3_demuxer_t *src) +{ + long i; + mpeg3_t *file = dst->file; + mpeg3_title_t *dst_title, *src_title; + + dst->packet_size = src->packet_size; + dst->total_titles = src->total_titles; + dst->total_programs = src->total_programs; + for(i = 0; i < MPEG3_MAX_STREAMS; i++) + { + dst->astream_table[i] = src->astream_table[i]; + dst->vstream_table[i] = src->vstream_table[i]; + } + for(i = 0; i < src->total_titles; i++) + { + src_title = src->titles[i]; + dst_title = dst->titles[i] = mpeg3_new_title(file, src->titles[i]->fs->path); + mpeg3_copy_title(dst_title, src_title); + } + + mpeg3demux_open_title(dst, src->current_title); + return 0; +} + +int mpeg3demux_print_streams(mpeg3_demuxer_t *demuxer, FILE *toc) +{ + int i; +/* Print the stream information */ + for(i = 0; i < MPEG3_MAX_STREAMS; i++) + { + if(demuxer->astream_table[i]) + fprintf(toc, "ASTREAM: %d %d\n", i, demuxer->astream_table[i]); + + if(demuxer->vstream_table[i]) + fprintf(toc, "VSTREAM: %d %d\n", i, demuxer->vstream_table[i]); + } + return 0; +} + +/* Need a timecode table to do this */ +double mpeg3demux_length(mpeg3_demuxer_t *demuxer) +{ + mpeg3_title_t *title; + int i, j; + double length; + + for(i = demuxer->total_titles - 1; i >= 0; i--) + { + title = demuxer->titles[i]; + for(j = title->timecode_table_size - 1; j >= 0; j--) + { + if(title->timecode_table[j].program == demuxer->current_program) + { + return title->timecode_table[j].end_time - + title->timecode_table[j].start_time + + title->timecode_table[j].absolute_start_time; + } + } + } + + return 1; +} + +int mpeg3demux_eof(mpeg3_demuxer_t *demuxer) +{ + if(demuxer->current_title >= 0) + { + if(mpeg3io_eof(demuxer->titles[demuxer->current_title]->fs) && + demuxer->current_title >= demuxer->total_titles - 1) + return 1; + } + + return 0; +} + +int mpeg3demux_bof(mpeg3_demuxer_t *demuxer) +{ + if(demuxer->current_title >= 0) + { + if(mpeg3io_bof(demuxer->titles[demuxer->current_title]->fs) && + demuxer->current_title <= 0) + return 1; + } + return 0; +} + + +/* For elemental streams seek to a byte */ +int mpeg3demux_seek_byte(mpeg3_demuxer_t *demuxer, long byte) +{ + long current_position; + mpeg3_t *file = demuxer->file; + mpeg3_title_t *title = demuxer->titles[demuxer->current_title]; + + demuxer->data_position = 0; + demuxer->data_size = 0; + + demuxer->error_flag = mpeg3io_seek(title->fs, byte); + + if(!demuxer->error_flag && (file->is_transport_stream || file->is_program_stream)) + { +/* Get on a packet boundary only for system streams. */ + current_position = mpeg3io_tell(title->fs); + if(byte % demuxer->packet_size) + { + demuxer->error_flag |= mpeg3io_seek(title->fs, current_position - (current_position % demuxer->packet_size)); + } + } + return demuxer->error_flag; +} + +/* For programs streams and toc seek to a time */ +int mpeg3demux_seek_time(mpeg3_demuxer_t *demuxer, double new_time) +{ + int i, j, done = 0, result = 0; + double byte_offset, new_byte_offset; + double guess = 0, minimum = 65535; + mpeg3_title_t *title; + mpeg3demux_timecode_t *timecode; + + demuxer->error_flag = 0; + + i = 0; + j = 0; + title = demuxer->titles[i]; + timecode = &title->timecode_table[j]; + +/* Get the title and timecode of the new position */ + while(!demuxer->error_flag && + !(timecode->absolute_start_time <= new_time && + timecode->absolute_end_time > new_time && + timecode->program == demuxer->current_program)) + { +/* Next timecode */ + j++; + if(j >= title->timecode_table_size) + { + i++; + j = 0; + if(i >= demuxer->total_titles) + { + demuxer->error_flag = 1; + return 1; + } + else + { + mpeg3demux_open_title(demuxer, i); + } + } + + title = demuxer->titles[i]; + timecode = &title->timecode_table[j]; + } + +/* Guess the new byte position */ + demuxer->current_timecode = j; + + byte_offset = ((new_time - timecode->absolute_start_time) / + (timecode->absolute_end_time - timecode->absolute_start_time) * + (timecode->end_byte - timecode->start_byte) + + timecode->start_byte); +//printf("mpeg3demux_seek_time %f %f\n", new_time, byte_offset); + + while(!done && !result && byte_offset >= 0) + { + result = mpeg3demux_seek_byte(demuxer, (long)byte_offset); +//printf("seek_time 0 byte %.0f want %f result %d\n", byte_offset, new_time, result); + + if(!result) + { + result = mpeg3_read_next_packet(demuxer); +// printf("seek_time 1 guess %f want %f\n", guess, new_time); + guess = demuxer->time + demuxer->time_offset; + + if(fabs(new_time - guess) >= fabs(minimum)) done = 1; + else + { + minimum = guess - new_time; + new_byte_offset = byte_offset + ((new_time - guess) / + (timecode->end_time - timecode->start_time) * + (timecode->end_byte - timecode->start_byte)); + if(labs((long)new_byte_offset - (long)byte_offset) < demuxer->packet_size) done = 1; + byte_offset = new_byte_offset; + } + } + } + +/* Get one packet before the packet just read */ + if(!result && byte_offset > demuxer->packet_size && minimum > 0) + { + mpeg3_read_prev_packet(demuxer); + mpeg3_read_prev_packet(demuxer); + } +//printf("seek_time %d %d %d\n", demuxer->current_title, demuxer->current_timecode, mpeg3demux_tell(demuxer)); + demuxer->error_flag = result; + return result; +} + +int mpeg3demux_seek_percentage(mpeg3_demuxer_t *demuxer, double percentage) +{ + double total_bytes = 0; + double absolute_position; + long relative_position; + int i, new_title; + mpeg3_title_t *title; + + demuxer->error_flag = 0; + +/* Get the absolute byte position; */ + for(i = 0; i < demuxer->total_titles; i++) + total_bytes += demuxer->titles[i]->total_bytes; + + absolute_position = percentage * total_bytes; + +/* Get the title the byte is inside */ + for(new_title = 0, total_bytes = 0; new_title < demuxer->total_titles; new_title++) + { + total_bytes += demuxer->titles[new_title]->total_bytes; + if(absolute_position < total_bytes) break; + } + + if(new_title >= demuxer->total_titles) + { + new_title = demuxer->total_titles - 1; + } + +/* Got a title */ + title = demuxer->titles[new_title]; + total_bytes -= title->total_bytes; + relative_position = (long)(absolute_position - total_bytes); + +/* Get the timecode the byte is inside */ + for(demuxer->current_timecode = 0; + demuxer->current_timecode < title->timecode_table_size; + demuxer->current_timecode++) + { + if(title->timecode_table[demuxer->current_timecode].start_byte <= relative_position && + title->timecode_table[demuxer->current_timecode].end_byte > relative_position) + { + break; + } + } + + if(demuxer->current_timecode >= title->timecode_table_size) + demuxer->current_timecode = title->timecode_table_size - 1; + +/* Get the nearest timecode in the same program */ + while(demuxer->current_timecode < title->timecode_table_size - 1 && + title->timecode_table[demuxer->current_timecode].program != demuxer->current_program) + { + demuxer->current_timecode++; + } + +/* Open the new title and seek to the correct byte */ + if(new_title != demuxer->current_title) + { + demuxer->error_flag = mpeg3demux_open_title(demuxer, new_title); + } + + if(!demuxer->error_flag) + demuxer->error_flag = mpeg3io_seek(title->fs, relative_position); + + return demuxer->error_flag; +} + +double mpeg3demux_tell_percentage(mpeg3_demuxer_t *demuxer) +{ + double total_bytes = 0; + double position = 0; + int i; + + demuxer->error_flag = 0; + position = mpeg3io_tell(demuxer->titles[demuxer->current_title]->fs); + for(i = 0; i < demuxer->total_titles; i++) + { + if(i == demuxer->current_title) + { + position += total_bytes; + } + total_bytes += demuxer->titles[i]->total_bytes; + } + return position / total_bytes; +} + +double mpeg3demux_get_time(mpeg3_demuxer_t *demuxer) +{ + return demuxer->time; +} + +long mpeg3demux_tell(mpeg3_demuxer_t *demuxer) +{ + return mpeg3io_tell(demuxer->titles[demuxer->current_title]->fs); +} + +long mpeg3demuxer_total_bytes(mpeg3_demuxer_t *demuxer) +{ + mpeg3_title_t *title = demuxer->titles[demuxer->current_title]; + return title->total_bytes; +} + +mpeg3_demuxer_t* mpeg3_get_demuxer(mpeg3_t *file) +{ + if(file->is_program_stream || file->is_transport_stream) + { + if(file->has_audio) return file->atrack[0]->demuxer; + else + if(file->has_video) return file->vtrack[0]->demuxer; + } + return 0; +} diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3demux.h b/core/multimedia/opieplayer/libmpeg3/mpeg3demux.h new file mode 100644 index 0000000..9dfd182 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/mpeg3demux.h @@ -0,0 +1,118 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef MPEG3DEMUX_H +#define MPEG3DEMUX_H + +#include "mpeg3title.h" +#include <stdio.h> + +typedef struct +{ + struct mpeg3_rec* file; +/* Data consisting of the multiplexed packet */ + unsigned char *raw_data; + long raw_offset; + int raw_size; + long packet_size; +/* Only one is on depending on which track owns the demultiplexer. */ + int do_audio; + int do_video; +/* Data consisting of the elementary stream */ + unsigned char *data_buffer; + long data_size; + long data_position; + long data_allocated; +/* Remember when the file descriptor is at the beginning of the packet just read. */ + int reverse; +/* Set to 1 when eof or attempt to read before beginning */ + int error_flag; +/* Temp variables for returning */ + unsigned char next_char; +/* Correction factor for time discontinuity */ + double time_offset; + int generating_timecode; + +/* Titles */ + mpeg3_title_t *titles[MPEG3_MAX_STREAMS]; + int total_titles; + int current_title; + +/* Tables of every stream ID encountered */ + int astream_table[MPEG3_MAX_STREAMS]; /* macro of audio format if audio */ + int vstream_table[MPEG3_MAX_STREAMS]; /* 1 if video */ + +/* Programs */ + int total_programs; + int current_program; + +/* Timecode in the current title */ + int current_timecode; + +/* Byte position in the current title */ + long current_byte; + + int transport_error_indicator; + int payload_unit_start_indicator; + int pid; + int transport_scrambling_control; + int adaptation_field_control; + int continuity_counter; + int is_padding; + int pid_table[MPEG3_PIDMAX]; + int continuity_counters[MPEG3_PIDMAX]; + int total_pids; + int adaptation_fields; + double time; /* Time in seconds */ + int audio_pid; + int video_pid; + int astream; /* Video stream ID being decoded. -1 = select first ID in stream */ + int vstream; /* Audio stream ID being decoded. -1 = select first ID in stream */ + int aformat; /* format of the audio derived from multiplexing codes */ + long program_association_tables; + int table_id; + int section_length; + int transport_stream_id; + long pes_packets; + double pes_audio_time; /* Presentation Time stamps */ + double pes_video_time; /* Presentation Time stamps */ +} mpeg3_demuxer_t; + +/* ========================================================================= */ +/* Entry points */ +/* ========================================================================= */ + +#define mpeg3demux_error(demuxer) (((mpeg3_demuxer_t *)(demuxer))->error_flag) + +#define mpeg3demux_time_offset(demuxer) (((mpeg3_demuxer_t *)(demuxer))->time_offset) + +#define mpeg3demux_current_time(demuxer) (((mpeg3_demuxer_t *)(demuxer))->time + ((mpeg3_demuxer_t *)(demuxer))->time_offset) + +#define mpeg3demux_read_char(demuxer) \ + ((((mpeg3_demuxer_t *)(demuxer))->data_position < ((mpeg3_demuxer_t *)(demuxer))->data_size) ? \ + ((mpeg3_demuxer_t *)(demuxer))->data_buffer[((mpeg3_demuxer_t *)(demuxer))->data_position++] : \ + mpeg3demux_read_char_packet(demuxer)) + +#define mpeg3demux_read_prev_char(demuxer) \ + ((((mpeg3_demuxer_t *)(demuxer))->data_position != 0) ? \ + ((mpeg3_demuxer_t *)(demuxer))->data_buffer[((mpeg3_demuxer_t *)(demuxer))->data_position--] : \ + mpeg3demux_read_prev_char_packet(demuxer)) + + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3io.c b/core/multimedia/opieplayer/libmpeg3/mpeg3io.c new file mode 100644 index 0000000..c5807a7 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/mpeg3io.c @@ -0,0 +1,127 @@ +#include "mpeg3private.h" +#include "mpeg3protos.h" + +#ifndef _WIN32 +#include <mntent.h> +#else + +#endif +#include <sys/stat.h> +#include <stdlib.h> +#include <string.h> + +mpeg3_fs_t* mpeg3_new_fs(char *path) +{ + mpeg3_fs_t *fs = (mpeg3_fs_t*)calloc(1, sizeof(mpeg3_fs_t)); + fs->css = mpeg3_new_css(); + strcpy(fs->path, path); + return fs; +} + +int mpeg3_delete_fs(mpeg3_fs_t *fs) +{ + mpeg3_delete_css(fs->css); + free(fs); + return 0; +} + +int mpeg3_copy_fs(mpeg3_fs_t *dst, mpeg3_fs_t *src) +{ + strcpy(dst->path, src->path); + dst->current_byte = 0; + return 0; +} + +long mpeg3io_get_total_bytes(mpeg3_fs_t *fs) +{ +/* + * struct stat st; + * if(stat(fs->path, &st) < 0) return 0; + * return (long)st.st_size; + */ + + fseek(fs->fd, 0, SEEK_END); + fs->total_bytes = ftell(fs->fd); + fseek(fs->fd, 0, SEEK_SET); + return fs->total_bytes; +} + +int mpeg3io_open_file(mpeg3_fs_t *fs) +{ +/* Need to perform authentication before reading a single byte. */ + mpeg3_get_keys(fs->css, fs->path); + + if(!(fs->fd = fopen(fs->path, "rb"))) + { + perror("mpeg3io_open_file"); + return 1; + } + + fs->total_bytes = mpeg3io_get_total_bytes(fs); + + if(!fs->total_bytes) + { + fclose(fs->fd); + return 1; + } + fs->current_byte = 0; + return 0; +} + +int mpeg3io_close_file(mpeg3_fs_t *fs) +{ + if(fs->fd) fclose(fs->fd); + fs->fd = 0; + return 0; +} + +int mpeg3io_read_data(unsigned char *buffer, long bytes, mpeg3_fs_t *fs) +{ + int result = 0; +//printf("read %d bytes\n",bytes); + result = !fread(buffer, 1, bytes, fs->fd); + fs->current_byte += bytes; + return (result && bytes); +} + +int mpeg3io_device(char *path, char *device) +{ + struct stat file_st, device_st; + struct mntent *mnt; + FILE *fp; + + if(stat(path, &file_st) < 0) + { + perror("mpeg3io_device"); + return 1; + } + +#ifndef _WIN32 + fp = setmntent(MOUNTED, "r"); + while(fp && (mnt = getmntent(fp))) + { + if(stat(mnt->mnt_fsname, &device_st) < 0) continue; + if(device_st.st_rdev == file_st.st_dev) + { + strncpy(device, mnt->mnt_fsname, MPEG3_STRLEN); + break; + } + } + endmntent(fp); +#endif + + return 0; +} + +int mpeg3io_seek(mpeg3_fs_t *fs, long byte) +{ + fs->current_byte = byte; + return fseek(fs->fd, byte, SEEK_SET); +} + +int mpeg3io_seek_relative(mpeg3_fs_t *fs, long bytes) +{ + fs->current_byte += bytes; + return fseek(fs->fd, fs->current_byte, SEEK_SET); +} + diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3io.h b/core/multimedia/opieplayer/libmpeg3/mpeg3io.h new file mode 100644 index 0000000..092e411 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/mpeg3io.h @@ -0,0 +1,74 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef MPEG3IO_H +#define MPEG3IO_H + + +#include <stdio.h> +#include "mpeg3css.h" +#include "mpeg3private.inc" + +/* Filesystem structure */ + +typedef struct +{ + FILE *fd; + mpeg3_css_t *css; /* Encryption object */ + char path[MPEG3_STRLEN]; +/* Hypothetical position of file pointer */ + long current_byte; + long total_bytes; +} mpeg3_fs_t; + +#define mpeg3io_tell(fs) (((mpeg3_fs_t *)(fs))->current_byte) + +// End of file +#define mpeg3io_eof(fs) (((mpeg3_fs_t *)(fs))->current_byte >= ((mpeg3_fs_t *)(fs))->total_bytes) + +// Beginning of file +#define mpeg3io_bof(fs) (((mpeg3_fs_t *)(fs))->current_byte < 0) + + +#define mpeg3io_total_bytes(fs) (((mpeg3_fs_t *)(fs))->total_bytes) + +extern inline unsigned int mpeg3io_read_int32(mpeg3_fs_t *fs) +{ + int a, b, c, d; + unsigned int result; +/* Do not fread. This breaks byte ordering. */ + a = (unsigned char)fgetc(fs->fd); + b = (unsigned char)fgetc(fs->fd); + c = (unsigned char)fgetc(fs->fd); + d = (unsigned char)fgetc(fs->fd); + result = ((int)a << 24) | + ((int)b << 16) | + ((int)c << 8) | + ((int)d); + fs->current_byte += 4; + return result; +} + +extern inline unsigned int mpeg3io_read_char(mpeg3_fs_t *fs) +{ + fs->current_byte++; + return fgetc(fs->fd); +} + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3private.h b/core/multimedia/opieplayer/libmpeg3/mpeg3private.h new file mode 100644 index 0000000..f0e11aa --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/mpeg3private.h @@ -0,0 +1,62 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef MPEG3PRIVATE_H +#define MPEG3PRIVATE_H + +#include "mpeg3atrack.h" +#include "mpeg3css.h" +#include "mpeg3io.h" +#include "mpeg3private.inc" +#include "mpeg3title.h" +#include "mpeg3vtrack.h" + +struct mpeg3_rec +{ + mpeg3_fs_t *fs; /* Store entry path here */ + mpeg3_demuxer_t *demuxer; /* Master tables */ + +/* Media specific */ + int has_audio; + int has_video; + int total_astreams; + int total_vstreams; + mpeg3_atrack_t *atrack[MPEG3_MAX_STREAMS]; + mpeg3_vtrack_t *vtrack[MPEG3_MAX_STREAMS]; + +/* Only one of these is set to 1 to specify what kind of stream we have. */ + int is_transport_stream; + int is_program_stream; + int is_audio_stream; /* Elemental stream */ + int is_video_stream; /* Elemental stream */ + long packet_size; +/* Type and stream for getting current percentage */ + int last_type_read; /* 1 - audio 2 - video */ + int last_stream_read; + + int program; /* Number of program to play */ + int cpus; + int have_mmx; +}; + +typedef struct mpeg3_rec mpeg3_t; + + + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3private.inc b/core/multimedia/opieplayer/libmpeg3/mpeg3private.inc new file mode 100644 index 0000000..7e56e7f --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/mpeg3private.inc @@ -0,0 +1,110 @@ +#ifndef LIBMPEG3_INC +#define LIBMPEG3_INC + +#ifdef _WIN32 + +// Disable some compiler warnings that happen a lot but don't matter +#pragma warning( disable : 4003 ) // not enough parameters for macro +#pragma warning( disable : 4305 ) // truncation frm double to float +#pragma warning( disable : 4715 ) // not all control paths return a value +#pragma warning( disable : 4716 ) // must return a value + +#ifdef LIBMPEG_EXPORTS +#define LIBMPEG_EXPORT __declspec( dllexport ) +#else +#define LIBMPEG_EXPORT __declspec( dllimport ) +#endif + +#ifdef ERROR +#undef ERROR +#include <windows.h> +#undef ERROR +#define ERROR (-1) +#else +#include <windows.h> +#undef ERROR +#endif + +#define inline __inline +#define M_PI 3.14159265358979323846 +#define M_SQRT2 1.41421356237309504880 + +#define pthread_mutexattr_t int +#define pthread_mutexattr_init(a) // Nothing +#define pthread_mutex_t CRITICAL_SECTION +#define pthread_mutex_init(a,b) InitializeCriticalSection(a) +#define pthread_mutex_lock(a) EnterCriticalSection(a) +#define pthread_mutex_unlock(a) LeaveCriticalSection(a) +#define pthread_mutex_destroy(a) //DeleteCriticalSection(a) + +#define pthread_attr_t int +#define pthread_attr_init(a) // Nothing +#define pthread_t unsigned long +#define pthread_create(a,b,c,d) *(a) = _beginthread(c,0,d) +//#define pthread_join(a,b) _endthread(b) +//#define pthread_join(a,b) _cwait(NULL,b,NULL) +#define pthread_join(a,b) + +#define strncasecmp(a,b,c) _strnicmp(a,b,c) +#define strcasecmp(a,b) _stricmp(a,b) +#define bzero(a,b) memset(a,0,b) + +#else + +#define LONGLONG long long +#define ULONGLONG unsigned long long + +#endif + +#ifndef LIBMPEG_EXPORT +#define LIBMPEG_EXPORT +#endif + +#define MPEG3_FLOAT32 mpeg3_real_t +#define MPEG3_INT16 short int +#define MPEG3_INT32 int +#define MPEG3_INT64 long + +#define MPEG3_TOC_PREFIX 0x544f4356 +#define MPEG3_TOC_PREFIXLOWER 0x746f6376 +#define MPEG3_ID3_PREFIX 0x494433 +#define MPEG3_RIFF_CODE 0x52494646 +#define MPEG3_PROC_CPUINFO "/proc/cpuinfo" +#define MPEG3_TS_PACKET_SIZE 188 +#define MPEG3_DVD_PACKET_SIZE 0x800 +#define MPEG3_SYNC_BYTE 0x47 +#define MPEG3_PACK_START_CODE 0x000001ba +#define MPEG3_SEQUENCE_START_CODE 0x000001b3 +#define MPEG3_SEQUENCE_END_CODE 0x000001b7 +#define MPEG3_SYSTEM_START_CODE 0x000001bb +#define MPEG3_STRLEN 1024 +#define MPEG3_PIDMAX 20 /* Maximum number of PIDs in one stream */ +#define MPEG3_PROGRAM_ASSOCIATION_TABLE 0x00 +#define MPEG3_CONDITIONAL_ACCESS_TABLE 0x01 +#define MPEG3_PACKET_START_CODE_PREFIX 0x000001 +#define MPEG3_PRIVATE_STREAM_2 0xbf +#define MPEG3_PADDING_STREAM 0xbe +#define MPEG3_GOP_START_CODE 0x000001b8 +#define MPEG3_PICTURE_START_CODE 0x00000100 +#define MPEG3_EXT_START_CODE 0x000001b5 +#define MPEG3_USER_START_CODE 0x000001b2 +#define MPEG3_SLICE_MIN_START 0x00000101 +#define MPEG3_SLICE_MAX_START 0x000001af +#define MPEG3_AC3_START_CODE 0x0b77 +#define MPEG3_PCM_START_CODE 0x0180 +#define MPEG3_MAX_CPUS 256 +#define MPEG3_MAX_STREAMS 256 +#define MPEG3_MAX_PACKSIZE 262144 +#define MPEG3_CONTIGUOUS_THRESHOLD 10 /* Positive difference before declaring timecodes discontinuous */ +#define MPEG3_PROGRAM_THRESHOLD 5 /* Minimum number of seconds before interleaving programs */ +#define MPEG3_SEEK_THRESHOLD 16 /* Number of frames difference before absolute seeking */ + +/* Values for audio format */ +#define AUDIO_UNKNOWN 0 +#define AUDIO_MPEG 1 +#define AUDIO_AC3 2 +#define AUDIO_PCM 3 +#define AUDIO_AAC 4 +#define AUDIO_JESUS 5 + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3protos.h b/core/multimedia/opieplayer/libmpeg3/mpeg3protos.h new file mode 100644 index 0000000..631336b --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/mpeg3protos.h @@ -0,0 +1,278 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef MPEG3PROTOS_H +#define MPEG3PROTOS_H + +#if defined(__cplusplus) +extern "C" { +#endif + +/* CSS */ + +mpeg3_css_t* mpeg3_new_css(); + +/* DEMUX */ + +mpeg3_demuxer_t* mpeg3_new_demuxer(mpeg3_t *file, int do_audio, int do_video, int stream_id); +int mpeg3_delete_demuxer(mpeg3_demuxer_t *demuxer); +int mpeg3demux_read_data(mpeg3_demuxer_t *demuxer, unsigned char *output, long size); +unsigned int mpeg3demux_read_int32(mpeg3_demuxer_t *demuxer); +unsigned int mpeg3demux_read_int24(mpeg3_demuxer_t *demuxer); +unsigned int mpeg3demux_read_int16(mpeg3_demuxer_t *demuxer); +double mpeg3demux_length(mpeg3_demuxer_t *demuxer); +mpeg3_demuxer_t* mpeg3_get_demuxer(mpeg3_t *file); +long mpeg3demux_tell(mpeg3_demuxer_t *demuxer); +double mpeg3demux_tell_percentage(mpeg3_demuxer_t *demuxer); +double mpeg3demux_get_time(mpeg3_demuxer_t *demuxer); +int mpeg3demux_eof(mpeg3_demuxer_t *demuxer); +int mpeg3demux_bof(mpeg3_demuxer_t *demuxer); +int mpeg3demux_copy_titles(mpeg3_demuxer_t *dst, mpeg3_demuxer_t *src); +int mpeg3demux_create_title(mpeg3_demuxer_t *demuxer, int timecode_search, FILE *toc); +long mpeg3demuxer_total_bytes(mpeg3_demuxer_t *demuxer); +int mpeg3demux_seek_byte(mpeg3_demuxer_t *demuxer, long byte); +int mpeg3demux_seek_time(mpeg3_demuxer_t *demuxer, double new_time); +int mpeg3demux_seek_percentage(mpeg3_demuxer_t *demuxer, double percentage); +int mpeg3demux_print_streams(mpeg3_demuxer_t *demuxer, FILE *toc); +int mpeg3demux_print_timecodes(mpeg3_title_t *title, FILE *output); +int mpeg3demux_read_titles(mpeg3_demuxer_t *demuxer); +int mpeg3demux_open_title(mpeg3_demuxer_t *demuxer, int title_number); + +/* TITLE */ + +mpeg3_title_t* mpeg3_new_title(mpeg3_t *file, char *path); +int mpeg3_delete_title(mpeg3_title_t *title); +int mpeg3_copy_title(mpeg3_title_t *dst, mpeg3_title_t *src); + + +/* ATRACK */ + +mpeg3_atrack_t* mpeg3_new_atrack(mpeg3_t *file, int stream_id, int is_ac3, mpeg3_demuxer_t *demuxer); +int mpeg3_delete_atrack(mpeg3_t *file, mpeg3_atrack_t *atrack); + +/* VTRACK */ + +mpeg3_vtrack_t* mpeg3_new_vtrack(mpeg3_t *file, int stream_id, mpeg3_demuxer_t *demuxer); +int mpeg3_delete_vtrack(mpeg3_t *file, mpeg3_vtrack_t *vtrack); + +/* AUDIO */ +mpeg3audio_t* mpeg3audio_new(mpeg3_t *file, mpeg3_atrack_t *track, int is_ac3); +int mpeg3audio_delete(mpeg3audio_t *audio); +int mpeg3audio_seek_sample(mpeg3audio_t *audio, long sample); +int mpeg3audio_seek_percentage(mpeg3audio_t *audio, double percentage); +int mpeg3audio_decode_audio(mpeg3audio_t *audio, + mpeg3_real_t *output_f, + short *output_i, int sampleSpacing, + int channel, + long start_position, + long len); +int mpeg3audio_read_raw(mpeg3audio_t *audio, unsigned char *output, long *size, long max_size); +int mpeg3audio_read_ac3_header(mpeg3audio_t *audio); +int mpeg3audio_read_pcm_header(mpeg3audio_t *audio); +int mpeg3audio_synth_mono(mpeg3audio_t *audio, mpeg3_real_t *bandPtr, mpeg3_real_t *samples, int *pnt); +int mpeg3audio_synth_stereo(mpeg3audio_t *audio, mpeg3_real_t *bandPtr, int channel, mpeg3_real_t *out, int *pnt); +int mpeg3audio_replace_buffer(mpeg3audio_t *audio, long new_allocation); +int mpeg3audio_ac3_exponent_unpack(mpeg3audio_t *audio, + mpeg3_ac3bsi_t *bsi, + mpeg3_ac3audblk_t *audblk); +int mpeg3audio_ac3_bit_allocate(mpeg3audio_t *audio, + unsigned int fscod, + mpeg3_ac3bsi_t *bsi, + mpeg3_ac3audblk_t *audblk); +int mpeg3audio_ac3_coeff_unpack(mpeg3audio_t *audio, + mpeg3_ac3bsi_t *bsi, + mpeg3_ac3audblk_t *audblk, + mpeg3ac3_stream_samples_t samples); +int mpeg3audio_ac3_imdct(mpeg3audio_t *audio, + mpeg3_ac3bsi_t *bsi, + mpeg3_ac3audblk_t *audblk, + mpeg3ac3_stream_samples_t samples); +int mpeg3audio_replace_buffer(mpeg3audio_t *audio, long new_allocation); +int mpeg3audio_dct36(mpeg3_real_t *inbuf, mpeg3_real_t *o1, mpeg3_real_t *o2, mpeg3_real_t *wintab, mpeg3_real_t *tsbuf); +int mpeg3audio_dct12(mpeg3_real_t *in,mpeg3_real_t *rawout1,mpeg3_real_t *rawout2,register mpeg3_real_t *wi,register mpeg3_real_t *ts); +int mpeg3audio_read_header(mpeg3audio_t *audio); +int mpeg3audio_do_ac3(mpeg3audio_t *audio); +int mpeg3audio_dolayer2(mpeg3audio_t *audio); +int mpeg3audio_dolayer3(mpeg3audio_t *audio); +int mpeg3audio_do_pcm(mpeg3audio_t *audio); +int mpeg3audio_dct64(mpeg3_real_t *a, mpeg3_real_t *b, mpeg3_real_t *c); +int mpeg3audio_reset_synths(mpeg3audio_t *audio); +int mpeg3audio_prev_header(mpeg3audio_t *audio); +int mpeg3audio_read_layer3_frame(mpeg3audio_t *audio); +int mpeg3audio_new_decode_tables(mpeg3audio_t *audio); +int mpeg3audio_imdct_init(mpeg3audio_t *audio); + + +/* VIDEO */ +mpeg3video_t* mpeg3video_new(mpeg3_t *file, mpeg3_vtrack_t *track); +int mpeg3video_delete(mpeg3video_t *video); +int mpeg3video_read_frame(mpeg3video_t *video, + long frame_number, + unsigned char **output_rows, + int in_x, + int in_y, + int in_w, + int in_h, + int out_w, + int out_h, + int color_model); +int mpeg3video_set_cpus(mpeg3video_t *video, int cpus); +int mpeg3video_set_mmx(mpeg3video_t *video, int use_mmx); +int mpeg3video_seek(mpeg3video_t *video); +int mpeg3video_seek_frame(mpeg3video_t *video, long frame); +int mpeg3video_seek_percentage(mpeg3video_t *video, double percentage); +int mpeg3video_previous_frame(mpeg3video_t *video); +int mpeg3video_drop_frames(mpeg3video_t *video, long frames); +int mpeg3video_read_yuvframe(mpeg3video_t *video, + long frame_number, + char *y_output, + char *u_output, + char *v_output, + int in_x, + int in_y, + int in_w, + int in_h); +int mpeg3video_read_raw(mpeg3video_t *video, unsigned char *output, long *size, long max_size); +int mpeg3video_display_second_field(mpeg3video_t *video); +int mpeg3video_init_output(); +int mpeg3video_get_header(mpeg3video_t *video, int dont_repeat); +int mpeg3video_getpicture(mpeg3video_t *video, int framenum); +int mpeg3video_match_refframes(mpeg3video_t *video); +int mpeg3video_next_code(mpeg3_bits_t* stream, unsigned int code); +int mpeg3video_prev_code(mpeg3_bits_t* stream, unsigned int code); +int mpeg3video_getgophdr(mpeg3video_t *video); +int mpeg3video_present_frame(mpeg3video_t *video); +int mpeg3video_read_frame_backend(mpeg3video_t *video, int skip_bframes); +int mpeg3video_getslicehdr(mpeg3_slice_t *slice, mpeg3video_t *video); +int mpeg3video_get_macroblock_address(mpeg3_slice_t *slice); +int mpeg3video_macroblock_modes(mpeg3_slice_t *slice, + mpeg3video_t *video, + int *pmb_type, + int *pstwtype, + int *pstwclass, + int *pmotion_type, + int *pmv_count, + int *pmv_format, + int *pdmv, + int *pmvscale, + int *pdct_type); +int mpeg3video_motion_vectors(mpeg3_slice_t *slice, + mpeg3video_t *video, + int PMV[2][2][2], + int dmvector[2], + int mv_field_sel[2][2], + int s, + int mv_count, + int mv_format, + int h_r_size, + int v_r_size, + int dmv, + int mvscale); +void mpeg3video_motion_vector(mpeg3_slice_t *slice, + mpeg3video_t *video, + int *PMV, + int *dmvector, + int h_r_size, + int v_r_size, + int dmv, + int mvscale, + int full_pel_vector); +int mpeg3video_get_cbp(mpeg3_slice_t *slice); +int mpeg3video_clearblock(mpeg3_slice_t *slice, int comp, int size); +int mpeg3video_getmpg2intrablock(mpeg3_slice_t *slice, + mpeg3video_t *video, + int comp, + int dc_dct_pred[]); +int mpeg3video_getintrablock(mpeg3_slice_t *slice, + mpeg3video_t *video, + int comp, + int dc_dct_pred[]); +int mpeg3video_getmpg2interblock(mpeg3_slice_t *slice, + mpeg3video_t *video, + int comp); +int mpeg3video_getinterblock(mpeg3_slice_t *slice, + mpeg3video_t *video, + int comp); +int mpeg3video_reconstruct(mpeg3video_t *video, + int bx, + int by, + int mb_type, + int motion_type, + int PMV[2][2][2], + int mv_field_sel[2][2], + int dmvector[2], + int stwtype); +void mpeg3video_calc_dmv(mpeg3video_t *video, + int DMV[][2], + int *dmvector, + int mvx, + int mvy); + + +/* FILESYSTEM */ + +mpeg3_fs_t* mpeg3_new_fs(char *path); +int mpeg3_delete_fs(mpeg3_fs_t *fs); +int mpeg3io_open_file(mpeg3_fs_t *fs); +int mpeg3io_close_file(mpeg3_fs_t *fs); +int mpeg3io_read_data(unsigned char *buffer, long bytes, mpeg3_fs_t *fs); + +/* BITSTREAM */ +mpeg3_bits_t* mpeg3bits_new_stream(mpeg3_t *file, mpeg3_demuxer_t *demuxer); +unsigned int mpeg3bits_getbits(mpeg3_bits_t* stream, int n); +int mpeg3bits_read_buffer(mpeg3_bits_t* stream, unsigned char *buffer, int bytes); +int mpeg3bits_use_ptr(mpeg3_bits_t* stream, unsigned char *buffer); +int mpeg3bits_use_demuxer(mpeg3_bits_t* stream); +int mpeg3bits_refill(mpeg3_bits_t* stream); +int mpeg3bits_getbitoffset(mpeg3_bits_t *stream); +void mpeg3bits_start_reverse(mpeg3_bits_t* stream); +void mpeg3bits_start_forward(mpeg3_bits_t* stream); +int mpeg3bits_delete_stream(mpeg3_bits_t* stream); +int mpeg3bits_byte_align(mpeg3_bits_t *stream); +int mpeg3bits_seek_start(mpeg3_bits_t* stream); +int mpeg3bits_seek_time(mpeg3_bits_t* stream, double time_position); +int mpeg3bits_seek_byte(mpeg3_bits_t* stream, long position); +int mpeg3bits_seek_percentage(mpeg3_bits_t* stream, double percentage); +unsigned int mpeg3bits_next_startcode(mpeg3_bits_t* stream); +int mpeg3bits_seek_end(mpeg3_bits_t* stream); + +/* MISC */ +int mpeg3_read_toc(mpeg3_t *file); +int mpeg3_generate_toc(FILE *output, char *path, int timecode_search, int print_streams); +int mpeg3_mmx_test(); +int mpeg3io_seek(mpeg3_fs_t *fs, long byte); +int mpeg3io_seek_relative(mpeg3_fs_t *fs, long bytes); +int mpeg3io_device(char *path, char *device); +int mpeg3_decrypt_packet(mpeg3_css_t *css, unsigned char *sector); +int mpeg3_delete_css(mpeg3_css_t *css); +int mpeg3_get_keys(mpeg3_css_t *css, char *path); +int mpeg3_copy_fs(mpeg3_fs_t *dst, mpeg3_fs_t *src); +int mpeg3_min(int x, int y); +int mpeg3_max(int x, int y); +int mpeg3_new_slice_buffer(mpeg3_slice_buffer_t *slice_buffer); +int mpeg3_expand_slice_buffer(mpeg3_slice_buffer_t *slice_buffer); +int mpeg3_delete_slice_decoder(mpeg3_slice_t *slice); +int mpeg3_new_slice_decoder(mpeg3video_t *video, mpeg3_slice_t *slice); +int mpeg3_delete_slice_buffer(mpeg3_slice_buffer_t *slice_buffer); + +#if defined(__cplusplus) +} +#endif + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3title.c b/core/multimedia/opieplayer/libmpeg3/mpeg3title.c new file mode 100644 index 0000000..0c93363 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/mpeg3title.c @@ -0,0 +1,63 @@ +#include "mpeg3private.h" +#include "mpeg3protos.h" +#include "mpeg3title.h" + + +#include <stdlib.h> + + +mpeg3_title_t* mpeg3_new_title(mpeg3_t *file, char *path) +{ + mpeg3_title_t *title = (mpeg3_title_t*)calloc(1, sizeof(mpeg3_title_t)); + title->fs = mpeg3_new_fs(path); + title->file = file; + return title; +} + +int mpeg3_delete_title(mpeg3_title_t *title) +{ + mpeg3_delete_fs(title->fs); + if(title->timecode_table_size) + { + free(title->timecode_table); + } + free(title); + return 0; +} + + +int mpeg3_copy_title(mpeg3_title_t *dst, mpeg3_title_t *src) +{ + int i; + + mpeg3_copy_fs(dst->fs, src->fs); + dst->total_bytes = src->total_bytes; + + if(src->timecode_table_size) + { + dst->timecode_table_allocation = src->timecode_table_allocation; + dst->timecode_table_size = src->timecode_table_size; + dst->timecode_table = (mpeg3demux_timecode_t*)calloc(1, sizeof(mpeg3demux_timecode_t) * dst->timecode_table_allocation); + + for(i = 0; i < dst->timecode_table_size; i++) + { + dst->timecode_table[i] = src->timecode_table[i]; + } + } +} + +int mpeg3_dump_title(mpeg3_title_t *title) +{ + int i; + + for(i = 0; i < title->timecode_table_size; i++) + { + printf("%f: %d - %d %f %f %d\n", + title->timecode_table[i].absolute_start_time, + title->timecode_table[i].start_byte, + title->timecode_table[i].end_byte, + title->timecode_table[i].start_time, + title->timecode_table[i].end_time, + title->timecode_table[i].program); + } +} diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3title.h b/core/multimedia/opieplayer/libmpeg3/mpeg3title.h new file mode 100644 index 0000000..a853217 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/mpeg3title.h @@ -0,0 +1,47 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef MPEG3TITLE_H +#define MPEG3TITLE_H + +#include "mpeg3io.h" + +typedef struct +{ + long start_byte; + double start_time; + double absolute_start_time; + double absolute_end_time; + long end_byte; + double end_time; + int program; +} mpeg3demux_timecode_t; + +typedef struct +{ + struct mpeg3_rec *file; + mpeg3_fs_t *fs; + long total_bytes; /* Total bytes in file. Critical for seeking and length. */ +/* Timecode table */ + mpeg3demux_timecode_t *timecode_table; + long timecode_table_size; /* Number of entries */ + long timecode_table_allocation; /* Number of available slots */ +} mpeg3_title_t; + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3toc.c b/core/multimedia/opieplayer/libmpeg3/mpeg3toc.c new file mode 100644 index 0000000..84b31cb --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/mpeg3toc.c @@ -0,0 +1,81 @@ +#include "libmpeg3.h" +#include "mpeg3protos.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/stat.h> +#include <stdlib.h> + +int main(int argc, char *argv[]) +{ + int i; +/* FILE *output; */ + char new_path[1024], *ext; + struct stat st; + long size; + int timecode_search = 0; + + if(argc < 2) + { + fprintf(stderr, "Create a table of contents for a DVD.\n" + " Usage: mpeg3toc [-t] <filename>...\n" + " -t Perform timecode search.\n" + "\n" + " The filenames should be absolute paths unless you plan\n" + " to always run your movie player from the same directory\n" + " as the filename. Alternatively you can edit the toc by\n" + " hand.\n" + " The timecode search allows XMovie to play the Matrix.\n" + "Example: mpeg3toc /cd2/video_ts/vts_01_*.vob > titanic.toc\n"); + exit(1); + } + + for(i = 1; i < argc; i++) + { + if(!strcmp(argv[i], "-t")) + { + timecode_search = 1; + } + else + { +/* Get just name */ + ext = strrchr(argv[i], '/'); + if(ext) + { + ext++; + strcpy(new_path, ext); + } + else + strcpy(new_path, argv[i]); + + +/* Replace suffix */ + ext = strrchr(new_path, '.'); + if(ext) + { + sprintf(ext, ".toc"); + } + else + strcat(new_path, ".toc"); + +/* fprintf(stderr, "Creating %s\n", new_path); */ + + stat(argv[i], &st); + size = (long)st.st_size; + + if(!size) + { + fprintf(stderr, "%s is 0 length. Skipping\n", new_path); + } + else + { +/* Just want the first title's streams */ + if(mpeg3_generate_toc(stdout, argv[i], timecode_search, i == argc - 1)) + { + fprintf(stderr, "Skipping %s\n", argv[i]); + } + } + } + } +} diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3vtrack.c b/core/multimedia/opieplayer/libmpeg3/mpeg3vtrack.c new file mode 100644 index 0000000..dffe9d0 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/mpeg3vtrack.c @@ -0,0 +1,33 @@ +#include "libmpeg3.h" +#include "mpeg3protos.h" + +#include <stdlib.h> + +mpeg3_vtrack_t* mpeg3_new_vtrack(mpeg3_t *file, int stream_id, mpeg3_demuxer_t *demuxer) +{ + int result = 0; + mpeg3_vtrack_t *new_vtrack; + new_vtrack = (mpeg3_vtrack_t*)calloc(1, sizeof(mpeg3_vtrack_t)); + new_vtrack->demuxer = mpeg3_new_demuxer(file, 0, 1, stream_id); + if(demuxer) mpeg3demux_copy_titles(new_vtrack->demuxer, demuxer); + new_vtrack->current_position = 0; + +/* Get information about the track here. */ + new_vtrack->video = mpeg3video_new(file, new_vtrack); + if(!new_vtrack->video) + { +/* Failed */ + mpeg3_delete_vtrack(file, new_vtrack); + new_vtrack = 0; + } + return new_vtrack; +} + +int mpeg3_delete_vtrack(mpeg3_t *file, mpeg3_vtrack_t *vtrack) +{ + if(vtrack->video) + mpeg3video_delete(vtrack->video); + if(vtrack->demuxer) + mpeg3_delete_demuxer(vtrack->demuxer); + free(vtrack); +} diff --git a/core/multimedia/opieplayer/libmpeg3/mpeg3vtrack.h b/core/multimedia/opieplayer/libmpeg3/mpeg3vtrack.h new file mode 100644 index 0000000..9a3c13d --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/mpeg3vtrack.h @@ -0,0 +1,39 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef MPEG3_VTRACK_H +#define MPEG3_VTRACK_H + +#include "mpeg3demux.h" +#include "video/mpeg3video.h" + +struct mpeg3_vtrack_rec +{ + int width; + int height; + float frame_rate; + mpeg3_demuxer_t *demuxer; + mpeg3video_t *video; + long current_position; /* Number of next frame to be played */ + long total_frames; /* Total frames in the file */ +}; + +typedef struct mpeg3_vtrack_rec mpeg3_vtrack_t; + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/ronin_narrow.toc b/core/multimedia/opieplayer/libmpeg3/ronin_narrow.toc new file mode 100644 index 0000000..07cbbf8 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/ronin_narrow.toc @@ -0,0 +1,26 @@ +TOCVERSION 2 +PATH: /cdrom/video_ts/vts_01_1.vob +ASTREAM: 0 2 +VSTREAM: 0 1 +ASTREAM: 1 2 +ASTREAM: 2 2 +SIZE: 1073709056 +PACKETSIZE: 2048 +REGION: 0 35557376 0.000000 51.643256 +REGION: 35559424 307005440 0.000000 440.561122 +REGION: 307007488 556705792 0.000000 423.698289 +REGION: 556707840 792827904 0.000000 423.877622 +REGION: 792829952 967956480 0.000000 292.754122 +REGION: 967958528 1073709056 0.000000 191.720711 +TOCVERSION 2 +PATH: /cdrom/video_ts/vts_01_2.vob +ASTREAM: 0 2 +VSTREAM: 0 1 +ASTREAM: 1 2 +ASTREAM: 2 2 +SIZE: 1073709056 +PACKETSIZE: 2048 +REGION: 0 268423168 191.722344 632.760000 +REGION: 268425216 539189248 0.000000 448.729167 +REGION: 539191296 823230464 0.000000 374.061122 +REGION: 823232512 1073709056 0.000000 421.215667 diff --git a/core/multimedia/opieplayer/libmpeg3/ronin_wide.toc b/core/multimedia/opieplayer/libmpeg3/ronin_wide.toc new file mode 100644 index 0000000..a638304 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/ronin_wide.toc @@ -0,0 +1,47 @@ +TOCVERSION 2 +PATH: /cdrom/video_ts/vts_01_1.vob +SIZE: 1073709056 +PACKETSIZE: 2048 +REGION: 0 33830912 0.000000 51.643256 +REGION: 33832960 321945600 0.000000 440.561122 +REGION: 321947648 566126592 0.000000 423.698289 +REGION: 566128640 804149248 0.000000 423.877622 +REGION: 804151296 979050496 0.000000 292.754122 +REGION: 979052544 1073709056 0.000000 170.331700 +TOCVERSION 2 +PATH: /cdrom/video_ts/vts_01_2.vob +SIZE: 1073709056 +PACKETSIZE: 2048 +REGION: 0 274845696 170.333322 632.760000 +REGION: 274847744 539138048 0.000000 448.729167 +REGION: 539140096 818880512 0.000000 374.061122 +REGION: 818882560 1073709056 0.000000 431.104722 +TOCVERSION 2 +PATH: /cdrom/video_ts/vts_01_3.vob +SIZE: 1073709056 +PACKETSIZE: 2048 +REGION: 0 3602432 431.122100 437.362056 +REGION: 3604480 316528640 0.000000 508.150422 +REGION: 316530688 562409472 0.000000 446.758722 +REGION: 562411520 728014848 0.000000 317.737689 +REGION: 728016896 943480832 0.000000 401.809556 +REGION: 943482880 1073709056 0.000000 177.871922 +TOCVERSION 2 +PATH: /cdrom/video_ts/vts_01_4.vob +SIZE: 1073709056 +PACKETSIZE: 2048 +REGION: 0 224798720 177.873544 496.357422 +REGION: 224800768 469219328 0.000000 431.833522 +REGION: 469221376 718004224 0.000000 426.048756 +REGION: 718006272 978356224 0.000000 411.668422 +REGION: 978358272 1073709056 0.000000 154.534211 +TOCVERSION 2 +PATH: /cdrom/video_ts/vts_01_5.vob +ASTREAM: 0 2 +VSTREAM: 0 1 +ASTREAM: 1 2 +ASTREAM: 2 2 +SIZE: 78041088 +PACKETSIZE: 2048 +REGION: 0 78028800 154.545878 312.853122 +REGION: 78030848 78041088 0.000000 0.006500 diff --git a/core/multimedia/opieplayer/libmpeg3/timecode.h b/core/multimedia/opieplayer/libmpeg3/timecode.h new file mode 100644 index 0000000..21e51e5 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/timecode.h @@ -0,0 +1,31 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef TIMECODE_H +#define TIMECODE_H + +typedef struct +{ + long hour; + long minute; + long second; + long frame; +} mpeg3_timecode_t; + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/video/Makefile b/core/multimedia/opieplayer/libmpeg3/video/Makefile new file mode 100644 index 0000000..46d8407 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/Makefile @@ -0,0 +1,32 @@ +include ../global_config +export CFLAGS +export CFLAGS_lessopt + +OBJS = \ + getpicture.o \ + headers.o \ + idct.o \ + macroblocks.o \ + mmxtest.o \ + motion.o \ + mpeg3video.o \ + output.o \ + reconstruct.o \ + seek.o \ + slice.o \ + vlc.o + + +all: $(OBJS) $(MMXOBJS2) + +.c.o: + $(CC) -c `./c_flags` -o $@ $< + +.s.o: + $(NASM) -f elf $*.s + +.S.o: + $(CC) -S `./c_flags` $*.S + +clean: + rm -f *.o diff --git a/core/multimedia/opieplayer/libmpeg3/video/c_flags b/core/multimedia/opieplayer/libmpeg3/video/c_flags new file mode 100755 index 0000000..d7943d0 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/c_flags @@ -0,0 +1 @@ +echo $CFLAGS diff --git a/core/multimedia/opieplayer/libmpeg3/video/getpicture.c b/core/multimedia/opieplayer/libmpeg3/video/getpicture.c new file mode 100644 index 0000000..4f67484 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/getpicture.c @@ -0,0 +1,767 @@ +#include "../libmpeg3.h" +#include "../mpeg3protos.h" +#include "mpeg3video.h" +#include "vlc.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +int mpeg3video_get_cbp(mpeg3_slice_t *slice) +{ + int code; + mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer; + + if((code = mpeg3slice_showbits9(slice_buffer)) >= 128) + { + code >>= 4; + mpeg3slice_flushbits(slice_buffer, mpeg3_CBPtab0[code].len); + return mpeg3_CBPtab0[code].val; + } + + if(code >= 8) + { + code >>= 1; + mpeg3slice_flushbits(slice_buffer, mpeg3_CBPtab1[code].len); + return mpeg3_CBPtab1[code].val; + } + + if(code < 1) + { +/* fprintf(stderr,"mpeg3video_get_cbp: invalid coded_block_pattern code\n"); */ + slice->fault = 1; + return 0; + } + + mpeg3slice_flushbits(slice_buffer, mpeg3_CBPtab2[code].len); + return mpeg3_CBPtab2[code].val; +} + + +/* set block to zero */ +int mpeg3video_clearblock(mpeg3_slice_t *slice, int comp, int size) +{ + slice->sparse[comp] = 1; + +/* Compiler error */ +/* + * for(i = 0; i < size; i++) + * { + * bzero(slice->block[comp] + sizeof(short) * 64 * i, sizeof(short) * 64); + * } + */ + + if(size == 6) + { + bzero(slice->block[comp], sizeof(short) * 64 * 6); + } + else + { +printf("mpeg3video_clearblock size = %d\n", size); + memset(slice->block[comp], 0, sizeof(short) * 64 * size); + } + return 0; +} + +static inline int mpeg3video_getdclum(mpeg3_slice_buffer_t *slice_buffer) +{ + int code, size, val; +/* decode length */ + code = mpeg3slice_showbits5(slice_buffer); + + if(code < 31) + { + size = mpeg3_DClumtab0[code].val; + mpeg3slice_flushbits(slice_buffer, mpeg3_DClumtab0[code].len); + } + else + { + code = mpeg3slice_showbits9(slice_buffer) - 0x1f0; + size = mpeg3_DClumtab1[code].val; + mpeg3slice_flushbits(slice_buffer, mpeg3_DClumtab1[code].len); + } + + if(size == 0) val = 0; + else + { + val = mpeg3slice_getbits(slice_buffer, size); + if((val & (1 << (size - 1))) == 0) val -= (1 << size) - 1; + } + + return val; +} + + +int mpeg3video_getdcchrom(mpeg3_slice_buffer_t *slice_buffer) +{ + int code, size, val; + +/* decode length */ + code = mpeg3slice_showbits5(slice_buffer); + + if(code < 31) + { + size = mpeg3_DCchromtab0[code].val; + mpeg3slice_flushbits(slice_buffer, mpeg3_DCchromtab0[code].len); + } + else + { + code = mpeg3slice_showbits(slice_buffer, 10) - 0x3e0; + size = mpeg3_DCchromtab1[code].val; + mpeg3slice_flushbits(slice_buffer, mpeg3_DCchromtab1[code].len); + } + + if(size == 0) val = 0; + else + { + val = mpeg3slice_getbits(slice_buffer, size); + if((val & (1 << (size - 1))) == 0) val -= (1 << size) - 1; + } + + return val; +} + + +/* decode one intra coded MPEG-1 block */ + +int mpeg3video_getintrablock(mpeg3_slice_t *slice, + mpeg3video_t *video, + int comp, + int dc_dct_pred[]) +{ + int val, i, j, sign; + unsigned int code; + mpeg3_DCTtab_t *tab = 0; + short *bp = slice->block[comp]; + mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer; + +/* decode DC coefficients */ + if(comp < 4) + bp[0] = (dc_dct_pred[0] += mpeg3video_getdclum(slice_buffer)) << 3; + else + if(comp == 4) + bp[0] = (dc_dct_pred[1] += mpeg3video_getdcchrom(slice_buffer)) << 3; + else + bp[0] = (dc_dct_pred[2] += mpeg3video_getdcchrom(slice_buffer)) << 3; + +#ifdef HAVE_MMX + if(video->have_mmx) + bp[0] <<= 4; +#endif + + if(slice->fault) return 1; + +/* decode AC coefficients */ + for(i = 1; ; i++) + { + code = mpeg3slice_showbits16(slice_buffer); + if(code >= 16384) + tab = &mpeg3_DCTtabnext[(code >> 12) - 4]; + else + if(code >= 1024) tab = &mpeg3_DCTtab0[(code >> 8) - 4]; + else + if(code >= 512) tab = &mpeg3_DCTtab1[(code >> 6) - 8]; + else + if(code >= 256) tab = &mpeg3_DCTtab2[(code >> 4) - 16]; + else + if(code >= 128) tab = &mpeg3_DCTtab3[(code >> 3) - 16]; + else + if(code >= 64) tab = &mpeg3_DCTtab4[(code >> 2) - 16]; + else + if(code >= 32) tab = &mpeg3_DCTtab5[(code >> 1) - 16]; + else + if(code >= 16) tab = &mpeg3_DCTtab6[code - 16]; + else + { +/* fprintf(stderr, "mpeg3video_getintrablock: invalid Huffman code\n"); */ + slice->fault = 1; + return 1; + } + + mpeg3slice_flushbits(slice_buffer, tab->len); + + if(tab->run == 64) break; /* end_of_block */ + + if(tab->run == 65) + { +/* escape */ + i += mpeg3slice_getbits(slice_buffer, 6); + + if((val = mpeg3slice_getbits(slice_buffer, 8)) == 0) + val = mpeg3slice_getbits(slice_buffer, 8); + else + if(val == 128) + val = mpeg3slice_getbits(slice_buffer, 8) - 256; + else + if(val > 128) + val -= 256; + + if((sign = (val < 0)) != 0) val= -val; + } + else + { + i += tab->run; + val = tab->level; + sign = mpeg3slice_getbit(slice_buffer); + } + + if(i < 64) + j = video->mpeg3_zigzag_scan_table[i]; + else + { + slice->fault = 1; + return 1; + } + + +#ifdef HAVE_MMX + if(video->have_mmx) + { + val = (val * slice->quant_scale * video->intra_quantizer_matrix[j]) << 1; + val = (val - 16) | 16; + } + else +#endif + { + val = (val * slice->quant_scale * video->intra_quantizer_matrix[j]) >> 3; + val = (val - 1) | 1; + } + + bp[j] = sign ? -val : val; + } + + if(j != 0) + { +/* not a sparse matrix ! */ + slice->sparse[comp] = 0; + } + return 0; +} + + +/* decode one non-intra coded MPEG-1 block */ + +int mpeg3video_getinterblock(mpeg3_slice_t *slice, + mpeg3video_t *video, + int comp) +{ + int val, i, j, sign; + unsigned int code; + mpeg3_DCTtab_t *tab; + short *bp = slice->block[comp]; + mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer; + +/* decode AC coefficients */ + for(i = 0; ; i++) + { + code = mpeg3slice_showbits16(slice_buffer); + if(code >= 16384) + { + if(i == 0) + tab = &mpeg3_DCTtabfirst[(code >> 12) - 4]; + else + tab = &mpeg3_DCTtabnext[(code >> 12) - 4]; + } + else + if(code >= 1024) tab = &mpeg3_DCTtab0[(code >> 8) - 4]; + else + if(code >= 512) tab = &mpeg3_DCTtab1[(code >> 6) - 8]; + else + if(code >= 256) tab = &mpeg3_DCTtab2[(code >> 4) - 16]; + else + if(code >= 128) tab = &mpeg3_DCTtab3[(code >> 3) - 16]; + else + if(code >= 64) tab = &mpeg3_DCTtab4[(code >> 2) - 16]; + else + if(code >= 32) tab = &mpeg3_DCTtab5[(code >> 1) - 16]; + else + if(code >= 16) tab = &mpeg3_DCTtab6[code - 16]; + else + { +// invalid Huffman code + slice->fault = 1; + return 1; + } + + mpeg3slice_flushbits(slice_buffer, tab->len); + +/* end of block */ + if(tab->run == 64) + break; + + if(tab->run == 65) + { +/* escape */ + i += mpeg3slice_getbits(slice_buffer, 6); + if((val = mpeg3slice_getbits(slice_buffer, 8)) == 0) + val = mpeg3slice_getbits(slice_buffer, 8); + else + if(val == 128) + val = mpeg3slice_getbits(slice_buffer, 8) - 256; + else + if(val > 128) + val -= 256; + + if((sign = (val < 0)) != 0) val = -val; + } + else + { + i += tab->run; + val = tab->level; + sign = mpeg3slice_getbit(slice_buffer); + } + + j = video->mpeg3_zigzag_scan_table[i]; + +#ifdef HAVE_MMX + if(video->have_mmx) + { + val = (((val << 1)+1) * slice->quant_scale * video->non_intra_quantizer_matrix[j]); + val = (val - 16) | 16; + } + else +#endif + { + val = (((val << 1)+1) * slice->quant_scale * video->non_intra_quantizer_matrix[j]) >> 4; + val = (val - 1) | 1; + } + + bp[j] = sign ? -val : val; + } + + if(j != 0) + { +/* not a sparse matrix ! */ + slice->sparse[comp] = 0; + } + return 0; +} + + +/* decode one intra coded MPEG-2 block */ +int mpeg3video_getmpg2intrablock(mpeg3_slice_t *slice, + mpeg3video_t *video, + int comp, + int dc_dct_pred[]) +{ + int val, i, j, sign, nc; + unsigned int code; + mpeg3_DCTtab_t *tab; + short *bp; + int *qmat; + mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer; + +/* with data partitioning, data always goes to base layer */ + bp = slice->block[comp]; + + qmat = (comp < 4 || video->chroma_format == CHROMA420) + ? video->intra_quantizer_matrix + : video->chroma_intra_quantizer_matrix; + +/* decode DC coefficients */ + if(comp < 4) + val = (dc_dct_pred[0] += mpeg3video_getdclum(slice_buffer)); + else + if((comp & 1) == 0) + val = (dc_dct_pred[1] += mpeg3video_getdcchrom(slice_buffer)); + else + val = (dc_dct_pred[2] += mpeg3video_getdcchrom(slice_buffer)); + + if(slice->fault) return 1; +#ifdef HAVE_MMX + if(video->have_mmx) + bp[0] = val << (7 - video->dc_prec); + else +#endif + bp[0] = val << (3 - video->dc_prec); + + nc = 0; + +/* decode AC coefficients */ + for(i = 1; ; i++) + { + code = mpeg3slice_showbits16(slice_buffer); + + if(code >= 16384 && !video->intravlc) + tab = &mpeg3_DCTtabnext[(code >> 12) - 4]; + else + if(code >= 1024) + { + if(video->intravlc) + tab = &mpeg3_DCTtab0a[(code >> 8) - 4]; + else + tab = &mpeg3_DCTtab0[(code >> 8) - 4]; + } + else + if(code >= 512) + { + if(video->intravlc) + tab = &mpeg3_DCTtab1a[(code >> 6) - 8]; + else + tab = &mpeg3_DCTtab1[(code >> 6) - 8]; + } + else + if(code >= 256) tab = &mpeg3_DCTtab2[(code >> 4) - 16]; + else + if(code >= 128) tab = &mpeg3_DCTtab3[(code >> 3) - 16]; + else + if(code >= 64) tab = &mpeg3_DCTtab4[(code >> 2) - 16]; + else + if(code >= 32) tab = &mpeg3_DCTtab5[(code >> 1) - 16]; + else + if(code >= 16) tab = &mpeg3_DCTtab6[code - 16]; + else + { +/* fprintf(stderr,"mpeg3video_getmpg2intrablock: invalid Huffman code\n"); */ + slice->fault = 1; + return 1; + } + + mpeg3slice_flushbits(slice_buffer, tab->len); + +/* end_of_block */ + if(tab->run == 64) + break; + + if(tab->run == 65) + { +/* escape */ + i += mpeg3slice_getbits(slice_buffer, 6); + + val = mpeg3slice_getbits(slice_buffer, 12); + if((val & 2047) == 0) + { +// invalid signed_level (escape) + slice->fault = 1; + return 1; + } + if((sign = (val >= 2048)) != 0) val = 4096 - val; + } + else + { + i += tab->run; + val = tab->level; + sign = mpeg3slice_getbit(slice_buffer); + } + + j = (video->altscan ? video->mpeg3_alternate_scan_table : video->mpeg3_zigzag_scan_table)[i]; + +#ifdef HAVE_MMX + if(video->have_mmx) + val = (val * slice->quant_scale * qmat[j]); + else +#endif + val = (val * slice->quant_scale * qmat[j]) >> 4; + + bp[j] = sign ? -val : val; + nc++; + } + + if(j != 0) + { +/* not a sparse matrix ! */ + slice->sparse[comp] = 0; + } + return 1; +} + + +/* decode one non-intra coded MPEG-2 block */ + +int mpeg3video_getmpg2interblock(mpeg3_slice_t *slice, + mpeg3video_t *video, + int comp) +{ + int val, i, j, sign, nc; + unsigned int code; + mpeg3_DCTtab_t *tab; + short *bp; + int *qmat; + mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer; + +/* with data partitioning, data always goes to base layer */ + bp = slice->block[comp]; + + qmat = (comp < 4 || video->chroma_format == CHROMA420) + ? video->non_intra_quantizer_matrix + : video->chroma_non_intra_quantizer_matrix; + + nc = 0; + +/* decode AC coefficients */ + for(i = 0; ; i++) + { + code = mpeg3slice_showbits16(slice_buffer); + if(code >= 16384) + { + if(i == 0) tab = &mpeg3_DCTtabfirst[(code >> 12) - 4]; + else tab = &mpeg3_DCTtabnext[(code >> 12) - 4]; + } + else + if(code >= 1024) tab = &mpeg3_DCTtab0[(code >> 8) - 4]; + else + if(code >= 512) tab = &mpeg3_DCTtab1[(code >> 6) - 8]; + else + if(code >= 256) tab = &mpeg3_DCTtab2[(code >> 4) - 16]; + else + if(code >= 128) tab = &mpeg3_DCTtab3[(code >> 3) - 16]; + else + if(code >= 64) tab = &mpeg3_DCTtab4[(code >> 2) - 16]; + else + if(code >= 32) tab = &mpeg3_DCTtab5[(code >> 1) - 16]; + else + if(code >= 16) tab = &mpeg3_DCTtab6[code - 16]; + else + { +// invalid Huffman code + slice->fault = 1; + return 1; + } + + mpeg3slice_flushbits(slice_buffer, tab->len); + +/* end_of_block */ + if(tab->run == 64) + break; + + if(tab->run == 65) + { +/* escape */ + i += mpeg3slice_getbits(slice_buffer, 6); + val = mpeg3slice_getbits(slice_buffer, 12); + if((val & 2047) == 0) + { +/* fprintf(stderr, "mpeg3video_getmpg2interblock: invalid signed_level (escape)\n"); */ + slice->fault = 1; + return 1; + } + if((sign = (val >= 2048)) != 0) val = 4096 - val; + } + else + { + i += tab->run; + val = tab->level; + sign = mpeg3slice_getbit(slice_buffer); + } + + j = (video->altscan ? video->mpeg3_alternate_scan_table : video->mpeg3_zigzag_scan_table)[i]; + +#ifdef HAVE_MMX + if(video->have_mmx) + val = (((val << 1)+1) * slice->quant_scale * qmat[j]) >> 1; + else +#endif + val = (((val << 1)+1) * slice->quant_scale * qmat[j]) >> 5; + + bp[j] = sign ? (-val) : val ; + nc++; + } + + if(j != 0) + { + slice->sparse[comp] = 0; + } + return 0; +} + + +/* decode all macroblocks of the current picture */ +int mpeg3video_get_macroblocks(mpeg3video_t *video, int framenum) +{ + unsigned int code; + mpeg3_slice_buffer_t *slice_buffer; /* Buffer being loaded */ + int i; + int current_buffer; + mpeg3_bits_t *vstream = video->vstream; + +/* Load every slice into a buffer array */ + video->total_slice_buffers = 0; + current_buffer = 0; + while(!mpeg3bits_eof(vstream) && + mpeg3bits_showbits32_noptr(vstream) >= MPEG3_SLICE_MIN_START && + mpeg3bits_showbits32_noptr(vstream) <= MPEG3_SLICE_MAX_START) + { +/* Initialize the buffer */ + if(current_buffer >= video->slice_buffers_initialized) + mpeg3_new_slice_buffer(&(video->slice_buffers[video->slice_buffers_initialized++])); + slice_buffer = &(video->slice_buffers[current_buffer]); + slice_buffer->buffer_size = 0; + slice_buffer->current_position = 0; + slice_buffer->bits_size = 0; + slice_buffer->done = 0; + +/* Read the slice into the buffer including the slice start code */ + do + { +/* Expand buffer */ + if(slice_buffer->buffer_allocation <= slice_buffer->buffer_size) + mpeg3_expand_slice_buffer(slice_buffer); + +/* Load 1 char into buffer */ + slice_buffer->data[slice_buffer->buffer_size++] = mpeg3bits_getbyte_noptr(vstream); + }while(!mpeg3bits_eof(vstream) && + mpeg3bits_showbits24_noptr(vstream) != MPEG3_PACKET_START_CODE_PREFIX); + +/* Pad the buffer to get the last macroblock */ + if(slice_buffer->buffer_allocation <= slice_buffer->buffer_size + 4) + mpeg3_expand_slice_buffer(slice_buffer); + + slice_buffer->data[slice_buffer->buffer_size++] = 0; + slice_buffer->data[slice_buffer->buffer_size++] = 0; + slice_buffer->data[slice_buffer->buffer_size++] = 1; + slice_buffer->data[slice_buffer->buffer_size++] = 0; + slice_buffer->bits_size = 0; + + pthread_mutex_lock(&(slice_buffer->completion_lock)); fflush(stdout); + current_buffer++; + video->total_slice_buffers++; + } + +/* Run the slice decoders */ + if(video->total_slice_buffers > 0) + { + for(i = 0; i < video->total_slice_decoders; i++) + { + if(i == 0 && video->total_slice_decoders > 1) + { + video->slice_decoders[i].current_buffer = 0; + video->slice_decoders[i].buffer_step = 1; + video->slice_decoders[i].last_buffer = (video->total_slice_buffers - 1); + } + else + if(i == 1) + { + video->slice_decoders[i].current_buffer = video->total_slice_buffers - 1; + video->slice_decoders[i].buffer_step = -1; + video->slice_decoders[i].last_buffer = 0; + } + else + { + video->slice_decoders[i].current_buffer = i; + video->slice_decoders[i].buffer_step = 1; + video->slice_decoders[i].last_buffer = video->total_slice_buffers - 1; + } + pthread_mutex_unlock(&(video->slice_decoders[i].input_lock)); + } + } + +/* Wait for the slice decoders to finish */ + if(video->total_slice_buffers > 0) + { + for(i = 0; i < video->total_slice_buffers; i++) + { + pthread_mutex_lock(&(video->slice_buffers[i].completion_lock)); + pthread_mutex_unlock(&(video->slice_buffers[i].completion_lock)); + } + } + return 0; +} + +int mpeg3video_allocate_decoders(mpeg3video_t *video, int decoder_count) +{ + int i; + mpeg3_t *file = video->file; +/* Get the slice decoders */ + if(video->total_slice_decoders != file->cpus) + { + for(i = 0; i < video->total_slice_decoders; i++) + { + mpeg3_delete_slice_decoder(&video->slice_decoders[i]); + } + + for(i = 0; i < file->cpus && i < MPEG3_MAX_CPUS; i++) + { + mpeg3_new_slice_decoder(video, &(video->slice_decoders[i])); + video->slice_decoders[i].thread_number = i; + } + + video->total_slice_decoders = file->cpus; + } + return 0; +} + +/* decode one frame or field picture */ + +int mpeg3video_getpicture(mpeg3video_t *video, int framenum) +{ + int i, result = 0; + mpeg3_t *file = video->file; + + if(video->pict_struct == FRAME_PICTURE && video->secondfield) + { +/* recover from illegal number of field pictures */ + video->secondfield = 0; + } + + if(!video->mpeg2) + { + video->current_repeat = video->repeat_count = 0; + } + + mpeg3video_allocate_decoders(video, file->cpus); + + for(i = 0; i < 3; i++) + { + if(video->pict_type == B_TYPE) + { + video->newframe[i] = video->auxframe[i]; + } + else + { + if(!video->secondfield && !video->current_repeat) + { +/* Swap refframes for I frames */ + unsigned char* tmp = video->oldrefframe[i]; + video->oldrefframe[i] = video->refframe[i]; + video->refframe[i] = tmp; + } + + video->newframe[i] = video->refframe[i]; + } + + if(video->pict_struct == BOTTOM_FIELD) + { +/* Only used if fields are in different pictures */ + video->newframe[i] += (i == 0) ? video->coded_picture_width : video->chrom_width; + } + } + +/* The problem is when a B frame lands on the first repeat and is skipped, */ +/* the second repeat goes for the same bitmap as the skipped repeat, */ +/* so it picks up a frame from 3 frames back. */ +/* The first repeat must consititutively read a B frame if its B frame is going to be */ +/* used in a later repeat. */ + if(!video->current_repeat) + if(!(video->skip_bframes && video->pict_type == B_TYPE) || + (video->repeat_count >= 100 + 100 * video->skip_bframes)) + result = mpeg3video_get_macroblocks(video, framenum); + +/* Set the frame to display */ + video->output_src = 0; + if(framenum > -1 && !result) + { + if(video->pict_struct == FRAME_PICTURE || video->secondfield) + { + if(video->pict_type == B_TYPE) + { + video->output_src = video->auxframe; + } + else + { + video->output_src = video->oldrefframe; + } + } + else + { + mpeg3video_display_second_field(video); + } + } + + if(video->mpeg2) + { + video->current_repeat += 100; + } + + if(video->pict_struct != FRAME_PICTURE) video->secondfield = !video->secondfield; + return result; +} diff --git a/core/multimedia/opieplayer/libmpeg3/video/headers.c b/core/multimedia/opieplayer/libmpeg3/video/headers.c new file mode 100644 index 0000000..5274530 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/headers.c @@ -0,0 +1,492 @@ +#include "../mpeg3demux.h" +#include "../libmpeg3.h" +#include "../mpeg3protos.h" +#include "mpeg3video.h" + +#include <stdio.h> +#include <stdlib.h> + +int mpeg3video_getseqhdr(mpeg3video_t *video) +{ + int i; + mpeg3_t *file = video->file; + + int aspect_ratio, picture_rate, vbv_buffer_size; + int constrained_parameters_flag; + int load_intra_quantizer_matrix, load_non_intra_quantizer_matrix; + + video->horizontal_size = mpeg3bits_getbits(video->vstream, 12); + video->vertical_size = mpeg3bits_getbits(video->vstream, 12); + aspect_ratio = mpeg3bits_getbits(video->vstream, 4); + video->framerate_code = mpeg3bits_getbits(video->vstream, 4); + video->bitrate = mpeg3bits_getbits(video->vstream, 18); + mpeg3bits_getbit_noptr(video->vstream); /* marker bit (=1) */ + vbv_buffer_size = mpeg3bits_getbits(video->vstream, 10); + constrained_parameters_flag = mpeg3bits_getbit_noptr(video->vstream); + video->frame_rate = mpeg3_frame_rate_table[video->framerate_code]; + + load_intra_quantizer_matrix = mpeg3bits_getbit_noptr(video->vstream); + if(load_intra_quantizer_matrix) + { + for(i = 0; i < 64; i++) + video->intra_quantizer_matrix[video->mpeg3_zigzag_scan_table[i]] = mpeg3bits_getbyte_noptr(video->vstream); + } + else + { + for(i = 0; i < 64; i++) + video->intra_quantizer_matrix[i] = mpeg3_default_intra_quantizer_matrix[i]; + } + + load_non_intra_quantizer_matrix = mpeg3bits_getbit_noptr(video->vstream); + if(load_non_intra_quantizer_matrix) + { + for(i = 0; i < 64; i++) + video->non_intra_quantizer_matrix[video->mpeg3_zigzag_scan_table[i]] = mpeg3bits_getbyte_noptr(video->vstream); + } + else + { + for(i = 0; i < 64; i++) + video->non_intra_quantizer_matrix[i] = 16; + } + +/* copy luminance to chrominance matrices */ + for(i = 0; i < 64; i++) + { + video->chroma_intra_quantizer_matrix[i] = video->intra_quantizer_matrix[i]; + video->chroma_non_intra_quantizer_matrix[i] = video->non_intra_quantizer_matrix[i]; + } + + return 0; +} + + +/* decode sequence extension */ + +int mpeg3video_sequence_extension(mpeg3video_t *video) +{ + int prof_lev; + int horizontal_size_extension, vertical_size_extension; + int bit_rate_extension, vbv_buffer_size_extension, low_delay; + int frame_rate_extension_n, frame_rate_extension_d; + int pos = 0; + + video->mpeg2 = 1; + video->scalable_mode = SC_NONE; /* unless overwritten by seq. scal. ext. */ + prof_lev = mpeg3bits_getbyte_noptr(video->vstream); + video->prog_seq = mpeg3bits_getbit_noptr(video->vstream); + video->chroma_format = mpeg3bits_getbits(video->vstream, 2); + horizontal_size_extension = mpeg3bits_getbits(video->vstream, 2); + vertical_size_extension = mpeg3bits_getbits(video->vstream, 2); + bit_rate_extension = mpeg3bits_getbits(video->vstream, 12); + mpeg3bits_getbit_noptr(video->vstream); + vbv_buffer_size_extension = mpeg3bits_getbyte_noptr(video->vstream); + low_delay = mpeg3bits_getbit_noptr(video->vstream); + frame_rate_extension_n = mpeg3bits_getbits(video->vstream, 2); + frame_rate_extension_d = mpeg3bits_getbits(video->vstream, 5); + video->horizontal_size = (horizontal_size_extension << 12) | (video->horizontal_size & 0x0fff); + video->vertical_size = (vertical_size_extension << 12) | (video->vertical_size & 0x0fff); +} + + +/* decode sequence display extension */ + +int mpeg3video_sequence_display_extension(mpeg3video_t *video) +{ + int colour_primaries = 0, transfer_characteristics = 0; + int display_horizontal_size, display_vertical_size; + int pos = 0; + int video_format = mpeg3bits_getbits(video->vstream, 3); + int colour_description = mpeg3bits_getbit_noptr(video->vstream); + + if(colour_description) + { + colour_primaries = mpeg3bits_getbyte_noptr(video->vstream); + transfer_characteristics = mpeg3bits_getbyte_noptr(video->vstream); + video->matrix_coefficients = mpeg3bits_getbyte_noptr(video->vstream); + } + + display_horizontal_size = mpeg3bits_getbits(video->vstream, 14); + mpeg3bits_getbit_noptr(video->vstream); + display_vertical_size = mpeg3bits_getbits(video->vstream, 14); +} + + +/* decode quant matrix entension */ + +int mpeg3video_quant_matrix_extension(mpeg3video_t *video) +{ + int i; + int load_intra_quantiser_matrix, load_non_intra_quantiser_matrix; + int load_chroma_intra_quantiser_matrix; + int load_chroma_non_intra_quantiser_matrix; + int pos = 0; + + if((load_intra_quantiser_matrix = mpeg3bits_getbit_noptr(video->vstream)) != 0) + { + for(i = 0; i < 64; i++) + { + video->chroma_intra_quantizer_matrix[video->mpeg3_zigzag_scan_table[i]] + = video->intra_quantizer_matrix[video->mpeg3_zigzag_scan_table[i]] + = mpeg3bits_getbyte_noptr(video->vstream); + } + } + + if((load_non_intra_quantiser_matrix = mpeg3bits_getbit_noptr(video->vstream)) != 0) + { + for (i = 0; i < 64; i++) + { + video->chroma_non_intra_quantizer_matrix[video->mpeg3_zigzag_scan_table[i]] + = video->non_intra_quantizer_matrix[video->mpeg3_zigzag_scan_table[i]] + = mpeg3bits_getbyte_noptr(video->vstream); + } + } + + if((load_chroma_intra_quantiser_matrix = mpeg3bits_getbit_noptr(video->vstream)) != 0) + { + for(i = 0; i < 64; i++) + video->chroma_intra_quantizer_matrix[video->mpeg3_zigzag_scan_table[i]] = mpeg3bits_getbyte_noptr(video->vstream); + } + + if((load_chroma_non_intra_quantiser_matrix = mpeg3bits_getbit_noptr(video->vstream)) != 0) + { + for(i = 0; i < 64; i++) + video->chroma_non_intra_quantizer_matrix[video->mpeg3_zigzag_scan_table[i]] = mpeg3bits_getbyte_noptr(video->vstream); + } +} + + +/* decode sequence scalable extension */ + +int mpeg3video_sequence_scalable_extension(mpeg3video_t *video) +{ + int layer_id; + + video->scalable_mode = mpeg3bits_getbits(video->vstream, 2) + 1; /* add 1 to make SC_DP != SC_NONE */ + layer_id = mpeg3bits_getbits(video->vstream, 4); + + if(video->scalable_mode == SC_SPAT) + { + video->llw = mpeg3bits_getbits(video->vstream, 14); /* lower_layer_prediction_horizontal_size */ + mpeg3bits_getbit_noptr(video->vstream); + video->llh = mpeg3bits_getbits(video->vstream, 14); /* lower_layer_prediction_vertical_size */ + video->hm = mpeg3bits_getbits(video->vstream, 5); + video->hn = mpeg3bits_getbits(video->vstream, 5); + video->vm = mpeg3bits_getbits(video->vstream, 5); + video->vn = mpeg3bits_getbits(video->vstream, 5); + } + + if(video->scalable_mode == SC_TEMP) + fprintf(stderr, "mpeg3video_sequence_scalable_extension: temporal scalability not implemented\n"); +} + + +/* decode picture display extension */ + +int mpeg3video_picture_display_extension(mpeg3video_t *video) +{ + int n, i; + short frame_centre_horizontal_offset[3]; + short frame_centre_vertical_offset[3]; + + if(video->prog_seq || video->pict_struct != FRAME_PICTURE) + n = 1; + else + n = video->repeatfirst ? 3 : 2; + + for(i = 0; i < n; i++) + { + frame_centre_horizontal_offset[i] = (short)mpeg3bits_getbits(video->vstream, 16); + mpeg3bits_getbit_noptr(video->vstream); + frame_centre_vertical_offset[i] = (short)mpeg3bits_getbits(video->vstream, 16); + mpeg3bits_getbit_noptr(video->vstream); + } +} + + +/* decode picture coding extension */ + +int mpeg3video_picture_coding_extension(mpeg3video_t *video) +{ + int chroma_420_type, composite_display_flag; + int v_axis = 0, field_sequence = 0, sub_carrier = 0, burst_amplitude = 0, sub_carrier_phase = 0; + + video->h_forw_r_size = mpeg3bits_getbits(video->vstream, 4) - 1; + video->v_forw_r_size = mpeg3bits_getbits(video->vstream, 4) - 1; + video->h_back_r_size = mpeg3bits_getbits(video->vstream, 4) - 1; + video->v_back_r_size = mpeg3bits_getbits(video->vstream, 4) - 1; + video->dc_prec = mpeg3bits_getbits(video->vstream, 2); + video->pict_struct = mpeg3bits_getbits(video->vstream, 2); + video->topfirst = mpeg3bits_getbit_noptr(video->vstream); + video->frame_pred_dct = mpeg3bits_getbit_noptr(video->vstream); + video->conceal_mv = mpeg3bits_getbit_noptr(video->vstream); + video->qscale_type = mpeg3bits_getbit_noptr(video->vstream); + video->intravlc = mpeg3bits_getbit_noptr(video->vstream); + video->altscan = mpeg3bits_getbit_noptr(video->vstream); + video->repeatfirst = mpeg3bits_getbit_noptr(video->vstream); + chroma_420_type = mpeg3bits_getbit_noptr(video->vstream); + video->prog_frame = mpeg3bits_getbit_noptr(video->vstream); + + if(video->repeat_count > 100) + video->repeat_count = 0; + video->repeat_count += 100; + + video->current_repeat = 0; + + if(video->prog_seq) + { + if(video->repeatfirst) + { + if(video->topfirst) + video->repeat_count += 200; + else + video->repeat_count += 100; + } + } + else + if(video->prog_frame) + { + if(video->repeatfirst) + { + video->repeat_count += 50; + } + } + +/*printf("mpeg3video_picture_coding_extension %d\n", video->repeat_count); */ + composite_display_flag = mpeg3bits_getbit_noptr(video->vstream); + + if(composite_display_flag) + { + v_axis = mpeg3bits_getbit_noptr(video->vstream); + field_sequence = mpeg3bits_getbits(video->vstream, 3); + sub_carrier = mpeg3bits_getbit_noptr(video->vstream); + burst_amplitude = mpeg3bits_getbits(video->vstream, 7); + sub_carrier_phase = mpeg3bits_getbyte_noptr(video->vstream); + } +} + + +/* decode picture spatial scalable extension */ + +int mpeg3video_picture_spatial_scalable_extension(mpeg3video_t *video) +{ + video->pict_scal = 1; /* use spatial scalability in this picture */ + + video->lltempref = mpeg3bits_getbits(video->vstream, 10); + mpeg3bits_getbit_noptr(video->vstream); + video->llx0 = mpeg3bits_getbits(video->vstream, 15); + if(video->llx0 >= 16384) video->llx0 -= 32768; + mpeg3bits_getbit_noptr(video->vstream); + video->lly0 = mpeg3bits_getbits(video->vstream, 15); + if(video->lly0 >= 16384) video->lly0 -= 32768; + video->stwc_table_index = mpeg3bits_getbits(video->vstream, 2); + video->llprog_frame = mpeg3bits_getbit_noptr(video->vstream); + video->llfieldsel = mpeg3bits_getbit_noptr(video->vstream); +} + + +/* decode picture temporal scalable extension + * + * not implemented + * + */ + +int mpeg3video_picture_temporal_scalable_extension(mpeg3video_t *video) +{ + fprintf(stderr, "mpeg3video_picture_temporal_scalable_extension: temporal scalability not supported\n"); +} + + +/* decode extension and user data */ + +int mpeg3video_ext_user_data(mpeg3video_t *video) +{ + int code = mpeg3bits_next_startcode(video->vstream); + + + while(code == MPEG3_EXT_START_CODE || code == MPEG3_USER_START_CODE && + !mpeg3bits_eof(video->vstream)) + { + mpeg3bits_refill(video->vstream); + + if(code == MPEG3_EXT_START_CODE) + { + int ext_id = mpeg3bits_getbits(video->vstream, 4); + switch(ext_id) + { + case SEQ_ID: + mpeg3video_sequence_extension(video); + break; + case DISP_ID: + mpeg3video_sequence_display_extension(video); + break; + case QUANT_ID: + mpeg3video_quant_matrix_extension(video); + break; + case SEQSCAL_ID: + mpeg3video_sequence_scalable_extension(video); + break; + case PANSCAN_ID: + mpeg3video_picture_display_extension(video); + break; + case CODING_ID: + mpeg3video_picture_coding_extension(video); + break; + case SPATSCAL_ID: + mpeg3video_picture_spatial_scalable_extension(video); + break; + case TEMPSCAL_ID: + mpeg3video_picture_temporal_scalable_extension(video); + break; + default: + fprintf(stderr,"mpeg3video_ext_user_data: reserved extension start code ID %d\n", ext_id); + break; + } + } + code = mpeg3bits_next_startcode(video->vstream); + } +} + + +/* decode group of pictures header */ + +int mpeg3video_getgophdr(mpeg3video_t *video) +{ + int drop_flag, closed_gop, broken_link; + + drop_flag = mpeg3bits_getbit_noptr(video->vstream); + video->gop_timecode.hour = mpeg3bits_getbits(video->vstream, 5); + video->gop_timecode.minute = mpeg3bits_getbits(video->vstream, 6); + mpeg3bits_getbit_noptr(video->vstream); + video->gop_timecode.second = mpeg3bits_getbits(video->vstream, 6); + video->gop_timecode.frame = mpeg3bits_getbits(video->vstream, 6); + closed_gop = mpeg3bits_getbit_noptr(video->vstream); + broken_link = mpeg3bits_getbit_noptr(video->vstream); + +/* + * printf("%d:%d:%d:%d %d %d %d\n", video->gop_timecode.hour, video->gop_timecode.minute, video->gop_timecode.second, video->gop_timecode.frame, + * drop_flag, closed_gop, broken_link); + */ + return mpeg3bits_error(video->vstream); +} + +/* decode picture header */ + +int mpeg3video_getpicturehdr(mpeg3video_t *video) +{ + int temp_ref, vbv_delay; + + video->pict_scal = 0; /* unless overwritten by pict. spat. scal. ext. */ + + temp_ref = mpeg3bits_getbits(video->vstream, 10); + video->pict_type = mpeg3bits_getbits(video->vstream, 3); + vbv_delay = mpeg3bits_getbits(video->vstream, 16); + + if(video->pict_type == P_TYPE || video->pict_type == B_TYPE) + { + video->full_forw = mpeg3bits_getbit_noptr(video->vstream); + video->forw_r_size = mpeg3bits_getbits(video->vstream, 3) - 1; + } + + if(video->pict_type == B_TYPE) + { + video->full_back = mpeg3bits_getbit_noptr(video->vstream); + video->back_r_size = mpeg3bits_getbits(video->vstream, 3) - 1; + } + +/* get extra bit picture */ + while(mpeg3bits_getbit_noptr(video->vstream) && + !mpeg3bits_eof(video->vstream)) mpeg3bits_getbyte_noptr(video->vstream); + return 0; +} + + +int mpeg3video_get_header(mpeg3video_t *video, int dont_repeat) +{ + unsigned int code; + +/* a sequence header should be found before returning from `getheader' the */ +/* first time (this is to set horizontal/vertical size properly) */ + +/* Repeat the frame until it's less than 1 count from repeat_count */ + if(video->repeat_count - video->current_repeat >= 100 && !dont_repeat) + { + return 0; + } + + if(dont_repeat) + { + video->repeat_count = 0; + video->current_repeat = 0; + } + else + video->repeat_count -= video->current_repeat; + + while(1) + { +/* look for startcode */ + code = mpeg3bits_next_startcode(video->vstream); + if(mpeg3bits_eof(video->vstream)) return 1; + if(code != MPEG3_SEQUENCE_END_CODE) mpeg3bits_refill(video->vstream); + + switch(code) + { + case MPEG3_SEQUENCE_START_CODE: + video->found_seqhdr = 1; + mpeg3video_getseqhdr(video); + mpeg3video_ext_user_data(video); + break; + + case MPEG3_GOP_START_CODE: + mpeg3video_getgophdr(video); + mpeg3video_ext_user_data(video); + break; + + case MPEG3_PICTURE_START_CODE: + mpeg3video_getpicturehdr(video); + mpeg3video_ext_user_data(video); + if(video->found_seqhdr) return 0; /* Exit here */ + break; + + case MPEG3_SEQUENCE_END_CODE: +// Continue until the end + mpeg3bits_refill(video->vstream); + break; + + default: + break; + } + } + return 1; /* Shouldn't be reached. */ +} + +int mpeg3video_ext_bit_info(mpeg3_slice_buffer_t *slice_buffer) +{ + while(mpeg3slice_getbit(slice_buffer)) mpeg3slice_getbyte(slice_buffer); + return 0; +} + +/* decode slice header */ +int mpeg3video_getslicehdr(mpeg3_slice_t *slice, mpeg3video_t *video) +{ + int slice_vertical_position_extension, intra_slice; + int qs; + + slice_vertical_position_extension = (video->mpeg2 && video->vertical_size > 2800) ? + mpeg3slice_getbits(slice->slice_buffer, 3) : 0; + + if(video->scalable_mode == SC_DP) slice->pri_brk = mpeg3slice_getbits(slice->slice_buffer, 7); + + qs = mpeg3slice_getbits(slice->slice_buffer, 5); + slice->quant_scale = video->mpeg2 ? (video->qscale_type ? mpeg3_non_linear_mquant_table[qs] : (qs << 1)) : qs; + + if(mpeg3slice_getbit(slice->slice_buffer)) + { + intra_slice = mpeg3slice_getbit(slice->slice_buffer); + mpeg3slice_getbits(slice->slice_buffer, 7); + mpeg3video_ext_bit_info(slice->slice_buffer); + } + else + intra_slice = 0; + + return slice_vertical_position_extension; +} diff --git a/core/multimedia/opieplayer/libmpeg3/video/idct.c b/core/multimedia/opieplayer/libmpeg3/video/idct.c new file mode 100644 index 0000000..c79f90a --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/idct.c @@ -0,0 +1,160 @@ +#include "idct.h" +#include <stdlib.h> + +/**********************************************************/ +/* inverse two dimensional DCT, Chen-Wang algorithm */ +/* (cf. IEEE ASSP-32, pp. 803-816, Aug. 1984) */ +/* 32-bit integer arithmetic (8 bit coefficients) */ +/* 11 mults, 29 adds per DCT */ +/* sE, 18.8.91 */ +/**********************************************************/ +/* coefficients extended to 12 bit for IEEE1180-1990 */ +/* compliance sE, 2.1.94 */ +/**********************************************************/ + +/* this code assumes >> to be a two's-complement arithmetic */ +/* right shift: (-2)>>1 == -1 , (-3)>>1 == -2 */ + +#define W1 2841 /* 2048*sqrt(2)*cos(1*pi/16) */ +#define W2 2676 /* 2048*sqrt(2)*cos(2*pi/16) */ +#define W3 2408 /* 2048*sqrt(2)*cos(3*pi/16) */ +#define W5 1609 /* 2048*sqrt(2)*cos(5*pi/16) */ +#define W6 1108 /* 2048*sqrt(2)*cos(6*pi/16) */ +#define W7 565 /* 2048*sqrt(2)*cos(7*pi/16) */ + +/* row (horizontal) IDCT + * + * 7 pi 1 + * dst[k] = sum c[l] * src[l] * cos( -- * ( k + - ) * l ) + * l=0 8 2 + * + * where: c[0] = 128 + * c[1..7] = 128*sqrt(2) + */ + +int mpeg3video_idctrow(short *blk) +{ + int x0, x1, x2, x3, x4, x5, x6, x7, x8; + + /* shortcut */ + if (!((x1 = blk[4]<<11) | (x2 = blk[6]) | (x3 = blk[2]) | + (x4 = blk[1]) | (x5 = blk[7]) | (x6 = blk[5]) | (x7 = blk[3]))) + { + blk[0]=blk[1]=blk[2]=blk[3]=blk[4]=blk[5]=blk[6]=blk[7]=blk[0]<<3; + return 0; + } + + x0 = (blk[0]<<11) + 128; /* for proper rounding in the fourth stage */ + + /* first stage */ + x8 = W7*(x4+x5); + x4 = x8 + (W1-W7)*x4; + x5 = x8 - (W1+W7)*x5; + x8 = W3*(x6+x7); + x6 = x8 - (W3-W5)*x6; + x7 = x8 - (W3+W5)*x7; + + /* second stage */ + x8 = x0 + x1; + x0 -= x1; + x1 = W6*(x3+x2); + x2 = x1 - (W2+W6)*x2; + x3 = x1 + (W2-W6)*x3; + x1 = x4 + x6; + x4 -= x6; + x6 = x5 + x7; + x5 -= x7; + + /* third stage */ + x7 = x8 + x3; + x8 -= x3; + x3 = x0 + x2; + x0 -= x2; + x2 = (181*(x4+x5)+128)>>8; + x4 = (181*(x4-x5)+128)>>8; + + /* fourth stage */ + blk[0] = (x7+x1)>>8; + blk[1] = (x3+x2)>>8; + blk[2] = (x0+x4)>>8; + blk[3] = (x8+x6)>>8; + blk[4] = (x8-x6)>>8; + blk[5] = (x0-x4)>>8; + blk[6] = (x3-x2)>>8; + blk[7] = (x7-x1)>>8; + + return 1; +} + +/* column (vertical) IDCT + * + * 7 pi 1 + * dst[8*k] = sum c[l] * src[8*l] * cos( -- * ( k + - ) * l ) + * l=0 8 2 + * + * where: c[0] = 1/1024 + * c[1..7] = (1/1024)*sqrt(2) + */ + +int mpeg3video_idctcol(short *blk) +{ + int x0, x1, x2, x3, x4, x5, x6, x7, x8; + + /* shortcut */ + if (!((x1 = (blk[8 * 4]<<8)) | (x2 = blk[8 * 6]) | (x3 = blk[8 * 2]) | + (x4 = blk[8*1]) | (x5 = blk[8 * 7]) | (x6 = blk[8 * 5]) | (x7 = blk[8 * 3]))){ + blk[8*0]=blk[8*1]=blk[8 * 2]=blk[8 * 3]=blk[8 * 4]=blk[8 * 5]=blk[8 * 6]=blk[8 * 7]= + (blk[8*0]+32)>>6; + return 0; + } + + x0 = (blk[8*0]<<8) + 8192; + + /* first stage */ + x8 = W7*(x4+x5) + 4; + x4 = (x8+(W1-W7)*x4)>>3; + x5 = (x8-(W1+W7)*x5)>>3; + x8 = W3*(x6+x7) + 4; + x6 = (x8-(W3-W5)*x6)>>3; + x7 = (x8-(W3+W5)*x7)>>3; + + /* second stage */ + x8 = x0 + x1; + x0 -= x1; + x1 = W6*(x3+x2) + 4; + x2 = (x1-(W2+W6)*x2)>>3; + x3 = (x1+(W2-W6)*x3)>>3; + x1 = x4 + x6; + x4 -= x6; + x6 = x5 + x7; + x5 -= x7; + + /* third stage */ + x7 = x8 + x3; + x8 -= x3; + x3 = x0 + x2; + x0 -= x2; + x2 = (181 * (x4 + x5) + 128) >> 8; + x4 = (181 * (x4 - x5) + 128) >> 8; + + /* fourth stage */ + blk[8 * 0] = (x7 + x1) >> 14; + blk[8 * 1] = (x3 + x2) >> 14; + blk[8 * 2] = (x0 + x4) >> 14; + blk[8 * 3] = (x8 + x6) >> 14; + blk[8 * 4] = (x8 - x6) >> 14; + blk[8 * 5] = (x0 - x4) >> 14; + blk[8 * 6] = (x3 - x2) >> 14; + blk[8 * 7] = (x7 - x1) >> 14; + + return 1; +} + + +/* two dimensional inverse discrete cosine transform */ +void mpeg3video_idct_conversion(short* block) +{ + int i; + for(i = 0; i < 8; i++) mpeg3video_idctrow(block + 8 * i); + for(i = 0; i < 8; i++) mpeg3video_idctcol(block + i); +} diff --git a/core/multimedia/opieplayer/libmpeg3/video/idct.h b/core/multimedia/opieplayer/libmpeg3/video/idct.h new file mode 100644 index 0000000..f0aa1d8 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/idct.h @@ -0,0 +1,24 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef IDCT_H +#define IDCT_H + + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/video/layerdata.h b/core/multimedia/opieplayer/libmpeg3/video/layerdata.h new file mode 100644 index 0000000..3ef0f90 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/layerdata.h @@ -0,0 +1,35 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef LAYERDATA_H +#define LAYERDATA_H + +typedef struct +{ +/* sequence header */ + int intra_quantizer_matrix[64], non_intra_quantizer_matrix[64]; + int chroma_intra_quantizer_matrix[64], chroma_non_intra_quantizer_matrix[64]; + int mpeg2; + int qscale_type, altscan; /* picture coding extension */ + int pict_scal; /* picture spatial scalable extension */ + int scalable_mode; /* sequence scalable extension */ +} mpeg3_layerdata_t; + + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/video/macroblocks.c b/core/multimedia/opieplayer/libmpeg3/video/macroblocks.c new file mode 100644 index 0000000..11e17c1 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/macroblocks.c @@ -0,0 +1,338 @@ +#include "../libmpeg3.h" +#include "../mpeg3protos.h" +#include "mpeg3video.h" +#include "slice.h" +#include "vlc.h" + +#include <stdio.h> + +int mpeg3video_get_macroblock_address(mpeg3_slice_t *slice) +{ + int code, val = 0; + mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer; + + while((code = mpeg3slice_showbits(slice_buffer, 11)) < 24) + { +/* Is not macroblock_stuffing */ + if(code != 15) + { +/* Is macroblock_escape */ + if(code == 8) + { + val += 33; + } + else + { +/* fprintf(stderr, "mpeg3video_get_macroblock_address: invalid macroblock_address_increment code\n"); */ + slice->fault = 1; + return 1; + } + } + + mpeg3slice_flushbits(slice_buffer, 11); + } + + if(code >= 1024) + { + mpeg3slice_flushbit(slice_buffer); + return val + 1; + } + + if(code >= 128) + { + code >>= 6; + mpeg3slice_flushbits(slice_buffer, mpeg3_MBAtab1[code].len); + return val + mpeg3_MBAtab1[code].val; + } + + code -= 24; + mpeg3slice_flushbits(slice_buffer, mpeg3_MBAtab2[code].len); + + return val + mpeg3_MBAtab2[code].val; +} + +/* macroblock_type for pictures with spatial scalability */ + +static inline int mpeg3video_getsp_imb_type(mpeg3_slice_t *slice) +{ +// ### This looks wrong. +// slice_buffer is used without being initialised and slice is not used +// mpeg3_slice_buffer_t *slice_buffer = slice_buffer; +// I think this would make more sense and might be what is intended + mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer; + unsigned int code = mpeg3slice_showbits(slice_buffer, 4); + if(!code) + { +/* fprintf(stderr,"mpeg3video_getsp_imb_type: invalid macroblock_type code\n"); */ + slice->fault = 1; + return 0; + } + + mpeg3slice_flushbits(slice_buffer, mpeg3_spIMBtab[code].len); + return mpeg3_spIMBtab[code].val; +} + +static inline int mpeg3video_getsp_pmb_type(mpeg3_slice_t *slice) +{ + mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer; + int code = mpeg3slice_showbits(slice_buffer, 7); + if(code < 2) + { +/* fprintf(stderr,"mpeg3video_getsp_pmb_type: invalid macroblock_type code\n"); */ + slice->fault = 1; + return 0; + } + + if(code >= 16) + { + code >>= 3; + mpeg3slice_flushbits(slice_buffer, mpeg3_spPMBtab0[code].len); + + return mpeg3_spPMBtab0[code].val; + } + + mpeg3slice_flushbits(slice_buffer, mpeg3_spPMBtab1[code].len); + return mpeg3_spPMBtab1[code].val; +} + +static inline int mpeg3video_getsp_bmb_type(mpeg3_slice_t *slice) +{ + mpeg3_VLCtab_t *p; + mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer; + int code = mpeg3slice_showbits9(slice_buffer); + + if(code >= 64) + p = &mpeg3_spBMBtab0[(code >> 5) - 2]; + else + if(code >= 16) + p = &mpeg3_spBMBtab1[(code >> 2) - 4]; + else + if(code >= 8) + p = &mpeg3_spBMBtab2[code - 8]; + else + { +/* fprintf(stderr,"mpeg3video_getsp_bmb_type: invalid macroblock_type code\n"); */ + slice->fault = 1; + return 0; + } + + mpeg3slice_flushbits(slice_buffer, p->len); + return p->val; +} + +static inline int mpeg3video_get_imb_type(mpeg3_slice_t *slice) +{ + mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer; + if(mpeg3slice_getbit(slice_buffer)) + { + return 1; + } + + if(!mpeg3slice_getbit(slice_buffer)) + { +/* fprintf(stderr,"mpeg3video_get_imb_type: invalid macroblock_type code\n"); */ + slice->fault = 1; + } + + return 17; +} + +static inline int mpeg3video_get_pmb_type(mpeg3_slice_t *slice) +{ + int code; + mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer; + + if((code = mpeg3slice_showbits(slice_buffer, 6)) >= 8) + { + code >>= 3; + mpeg3slice_flushbits(slice_buffer, mpeg3_PMBtab0[code].len); + return mpeg3_PMBtab0[code].val; + } + + if(code == 0) + { +/* fprintf(stderr,"mpeg3video_get_pmb_type: invalid macroblock_type code\n"); */ + slice->fault = 1; + return 0; + } + + mpeg3slice_flushbits(slice_buffer, mpeg3_PMBtab1[code].len); + return mpeg3_PMBtab1[code].val; +} + +static inline int mpeg3video_get_bmb_type(mpeg3_slice_t *slice) +{ + int code; + mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer; + + if((code = mpeg3slice_showbits(slice_buffer, 6)) >= 8) + { + code >>= 2; + mpeg3slice_flushbits(slice_buffer, mpeg3_BMBtab0[code].len); + return mpeg3_BMBtab0[code].val; + } + + if(code == 0) + { +/* fprintf(stderr,"mpeg3video_get_bmb_type: invalid macroblock_type code\n"); */ + slice->fault = 1; + return 0; + } + + mpeg3slice_flushbits(slice_buffer, mpeg3_BMBtab1[code].len); + + return mpeg3_BMBtab1[code].val; +} + +static inline int mpeg3video_get_dmb_type(mpeg3_slice_t *slice) +{ + if(!mpeg3slice_getbit(slice->slice_buffer)) + { +/* fprintf(stderr,"mpeg3video_get_dmb_type: invalid macroblock_type code\n"); */ + slice->fault=1; + } + + return 1; +} + + +static inline int mpeg3video_get_snrmb_type(mpeg3_slice_t *slice) +{ + mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer; + int code = mpeg3slice_showbits(slice_buffer, 3); + + if(code == 0) + { +/* fprintf(stderr,"mpeg3video_get_snrmb_type: invalid macroblock_type code\n"); */ + slice->fault = 1; + return 0; + } + + mpeg3slice_flushbits(slice_buffer, mpeg3_SNRMBtab[code].len); + return mpeg3_SNRMBtab[code].val; +} + +int mpeg3video_get_mb_type(mpeg3_slice_t *slice, mpeg3video_t *video) +{ + if(video->scalable_mode == SC_SNR) + { + return mpeg3video_get_snrmb_type(slice); + } + else + { + switch(video->pict_type) + { + case I_TYPE: return video->pict_scal ? mpeg3video_getsp_imb_type(slice) : mpeg3video_get_imb_type(slice); + case P_TYPE: return video->pict_scal ? mpeg3video_getsp_pmb_type(slice) : mpeg3video_get_pmb_type(slice); + case B_TYPE: return video->pict_scal ? mpeg3video_getsp_bmb_type(slice) : mpeg3video_get_bmb_type(slice); + case D_TYPE: return mpeg3video_get_dmb_type(slice); + default: + /*fprintf(stderr, "mpeg3video_getmbtype: unknown coding type\n"); */ + break; +/* MPEG-1 only, not implemented */ + } + } + + return 0; +} + +int mpeg3video_macroblock_modes(mpeg3_slice_t *slice, + mpeg3video_t *video, + int *pmb_type, + int *pstwtype, + int *pstwclass, + int *pmotion_type, + int *pmv_count, + int *pmv_format, + int *pdmv, + int *pmvscale, + int *pdct_type) +{ + int mb_type; + int stwtype, stwcode, stwclass; + int motion_type = 0, mv_count, mv_format, dmv, mvscale; + int dct_type; + mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer; + static unsigned char stwc_table[3][4] + = { {6,3,7,4}, {2,1,5,4}, {2,5,7,4} }; + static unsigned char stwclass_table[9] + = {0, 1, 2, 1, 1, 2, 3, 3, 4}; + +/* get macroblock_type */ + mb_type = mpeg3video_get_mb_type(slice, video); + + if(slice->fault) return 1; + +/* get spatial_temporal_weight_code */ + if(mb_type & MB_WEIGHT) + { + if(video->stwc_table_index == 0) + stwtype = 4; + else + { + stwcode = mpeg3slice_getbits2(slice_buffer); + stwtype = stwc_table[video->stwc_table_index - 1][stwcode]; + } + } + else + stwtype = (mb_type & MB_CLASS4) ? 8 : 0; + +/* derive spatial_temporal_weight_class (Table 7-18) */ + stwclass = stwclass_table[stwtype]; + +/* get frame/field motion type */ + if(mb_type & (MB_FORWARD | MB_BACKWARD)) + { + if(video->pict_struct == FRAME_PICTURE) + { +/* frame_motion_type */ + motion_type = video->frame_pred_dct ? MC_FRAME : mpeg3slice_getbits2(slice_buffer); + } + else + { +/* field_motion_type */ + motion_type = mpeg3slice_getbits2(slice_buffer); + } + } + else + if((mb_type & MB_INTRA) && video->conceal_mv) + { +/* concealment motion vectors */ + motion_type = (video->pict_struct == FRAME_PICTURE) ? MC_FRAME : MC_FIELD; + } + +/* derive mv_count, mv_format and dmv, (table 6-17, 6-18) */ + if(video->pict_struct == FRAME_PICTURE) + { + mv_count = (motion_type == MC_FIELD && stwclass < 2) ? 2 : 1; + mv_format = (motion_type == MC_FRAME) ? MV_FRAME : MV_FIELD; + } + else + { + mv_count = (motion_type == MC_16X8) ? 2 : 1; + mv_format = MV_FIELD; + } + + dmv = (motion_type == MC_DMV); /* dual prime */ + +/* field mv predictions in frame pictures have to be scaled */ + mvscale = ((mv_format == MV_FIELD) && (video->pict_struct == FRAME_PICTURE)); + +/* get dct_type (frame DCT / field DCT) */ + dct_type = (video->pict_struct == FRAME_PICTURE) && + (!video->frame_pred_dct) && + (mb_type & (MB_PATTERN | MB_INTRA)) ? + mpeg3slice_getbit(slice_buffer) : 0; + +/* return values */ + *pmb_type = mb_type; + *pstwtype = stwtype; + *pstwclass = stwclass; + *pmotion_type = motion_type; + *pmv_count = mv_count; + *pmv_format = mv_format; + *pdmv = dmv; + *pmvscale = mvscale; + *pdct_type = dct_type; + return 0; +} diff --git a/core/multimedia/opieplayer/libmpeg3/video/mmxidct.S b/core/multimedia/opieplayer/libmpeg3/video/mmxidct.S new file mode 100644 index 0000000..9c3bebe --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/mmxidct.S @@ -0,0 +1,675 @@ +/* + * the input data is tranposed and each 16 bit element in the 8x8 matrix + * is left aligned: + * for example in 11...1110000 format + * If the iDCT is of I macroblock then 0.5 needs to be added to the;DC Component + * (element[0][0] of the matrix) + */ + +/* extrn re_matrix */ + +/* constants */ + +.data + .align 16 + .type preSC, @object +preSC: .short 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520 + .short 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270 + .short 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906 + .short 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315 + .short 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520 + .short 12873, 17855, 16819, 15137, 25746, 20228, 13933, 7103 + .short 17734, 24598, 23170, 20853, 17734, 13933, 9597, 4892 + .short 18081, 25080, 23624, 21261, 18081, 14206, 9785, 4988 + .size preSC, 128 + .align 8 + .type x0005000200010001, @object + .size x0005000200010001, 8 +x0005000200010001: + .long 0x00010001, 0x00050002 + .align 8 + .type x0040000000000000, @object + .size x0040000000000000, 8 +x0040000000000000: + .long 0, 0x00400000 + .align 8 + .type x5a825a825a825a82, @object + .size x5a825a825a825a82, 8 +x5a825a825a825a82: + .long 0x5a825a82, 0x5a825a82 + .align 8 + .type x539f539f539f539f, @object + .size x539f539f539f539f, 8 +x539f539f539f539f: + .long 0x539f539f, 0x539f539f + .align 8 + .type x4546454645464546, @object + .size x4546454645464546, 8 +x4546454645464546: + .long 0x45464546, 0x45464546 + .align 8 + .type x61f861f861f861f8, @object + .size x61f861f861f861f8, 8 +x61f861f861f861f8: + .long 0x61f861f8, 0x61f861f8 +/* Static variables */ + .align 8 + .type x0, @object + .size x0, 8 +x0: + .long 0, 0 +/* Procedure */ + + + .align 8 +.text + .align 4 +.globl IDCT_mmx + .type IDCT_mmx, @function +IDCT_mmx: + pushl %ebp + movl %esp, %ebp + pushl %ebx + pushl %ecx + pushl %edx + pushl %esi + pushl %edi + + pushl $0 /* allocate the temp variables */ + pushl $0 + pushl $0 + pushl $0 + pushl $0 + pushl $0 + pushl $0 + pushl $0 + + movl 8(%ebp), %esi /* source matrix */ + leal preSC, %ecx +/* column 0: even part + * use V4, V12, V0, V8 to produce V22..V25 + */ + movq 8*12(%ecx), %mm0 /* maybe the first mul can be done together */ + /* with the dequantization in iHuff module */ + pmulhw 8*12(%esi), %mm0 /* V12 */ + movq 8*4(%ecx), %mm1 + pmulhw 8*4(%esi), %mm1 /* V4 */ + movq (%ecx), %mm3 + psraw $1, %mm0 /* t64=t66 */ + pmulhw (%esi), %mm3 /* V0 */ + movq 8*8(%ecx), %mm5 /* duplicate V4 */ + movq %mm1, %mm2 /* added 11/1/96 */ + pmulhw 8*8(%esi),%mm5 /* V8 */ + psubsw %mm0, %mm1 /* V16 */ + pmulhw x5a825a825a825a82, %mm1 /* 23170 ->V18 */ + paddsw %mm0, %mm2 /* V17 */ + movq %mm2, %mm0 /* duplicate V17 */ + psraw $1, %mm2 /* t75=t82 */ + psraw $2, %mm0 /* t72 */ + movq %mm3, %mm4 /* duplicate V0 */ + paddsw %mm5, %mm3 /* V19 */ + psubsw %mm5, %mm4 /* V20 ;mm5 free */ +/* moved from the block below */ + movq 8*10(%ecx), %mm7 + psraw $1, %mm3 /* t74=t81 */ + movq %mm3, %mm6 /* duplicate t74=t81 */ + psraw $2, %mm4 /* t77=t79 */ + psubsw %mm0, %mm1 /* V21 ; mm0 free */ + paddsw %mm2, %mm3 /* V22 */ + movq %mm1, %mm5 /* duplicate V21 */ + paddsw %mm4, %mm1 /* V23 */ + movq %mm3, 8*4(%esi) /* V22 */ + psubsw %mm5, %mm4 /* V24; mm5 free */ + movq %mm1, 8*12(%esi) /* V23 */ + psubsw %mm2, %mm6 /* V25; mm2 free */ + movq %mm4, (%esi) /* V24 */ +/* keep mm6 alive all along the next block */ + /* movq %mm6, 8*8(%esi) V25 */ +/* column 0: odd part + * use V2, V6, V10, V14 to produce V31, V39, V40, V41 + */ +/* moved above: movq 8*10(%ecx), %mm7 */ + + pmulhw 8*10(%esi), %mm7 /* V10 */ + movq 8*6(%ecx), %mm0 + pmulhw 8*6(%esi), %mm0 /* V6 */ + movq 8*2(%ecx), %mm5 + movq %mm7, %mm3 /* duplicate V10 */ + pmulhw 8*2(%esi), %mm5 /* V2 */ + movq 8*14(%ecx), %mm4 + psubsw %mm0, %mm7 /* V26 */ + pmulhw 8*14(%esi), %mm4 /* V14 */ + paddsw %mm0, %mm3 /* V29 ; free mm0 */ + movq %mm7, %mm1 /* duplicate V26 */ + psraw $1, %mm3 /* t91=t94 */ + pmulhw x539f539f539f539f,%mm7 /* V33 */ + psraw $1, %mm1 /* t96 */ + movq %mm5, %mm0 /* duplicate V2 */ + psraw $2, %mm4 /* t85=t87 */ + paddsw %mm4,%mm5 /* V27 */ + psubsw %mm4, %mm0 /* V28 ; free mm4 */ + movq %mm0, %mm2 /* duplicate V28 */ + psraw $1, %mm5 /* t90=t93 */ + pmulhw x4546454645464546,%mm0 /* V35 */ + psraw $1, %mm2 /* t97 */ + movq %mm5, %mm4 /* duplicate t90=t93 */ + psubsw %mm2, %mm1 /* V32 ; free mm2 */ + pmulhw x61f861f861f861f8,%mm1 /* V36 */ + psllw $1, %mm7 /* t107 */ + paddsw %mm3, %mm5 /* V31 */ + psubsw %mm3, %mm4 /* V30 ; free mm3 */ + pmulhw x5a825a825a825a82,%mm4 /* V34 */ + nop + psubsw %mm1, %mm0 /* V38 */ + psubsw %mm7, %mm1 /* V37 ; free mm7 */ + psllw $1, %mm1 /* t114 */ +/* move from the next block */ + movq %mm6, %mm3 /* duplicate V25 */ +/* move from the next block */ + movq 8*4(%esi), %mm7 /* V22 */ + psllw $1, %mm0 /* t110 */ + psubsw %mm5, %mm0 /* V39 (mm5 needed for next block) */ + psllw $2, %mm4 /* t112 */ +/* moved from the next block */ + movq 8*12(%esi), %mm2 /* V23 */ + psubsw %mm0, %mm4 /* V40 */ + paddsw %mm4, %mm1 /* V41; free mm0 */ +/* moved from the next block */ + psllw $1, %mm2 /* t117=t125 */ +/* column 0: output butterfly */ +/* moved above: + * movq %mm6, %mm3 duplicate V25 + * movq 8*4(%esi), %mm7 V22 + * movq 8*12(%esi), %mm2 V23 + * psllw $1, %mm2 t117=t125 + */ + psubsw %mm1, %mm6 /* tm6 */ + paddsw %mm1, %mm3 /* tm8; free mm1 */ + movq %mm7, %mm1 /* duplicate V22 */ + paddsw %mm5, %mm7 /* tm0 */ + movq %mm3, 8*8(%esi) /* tm8; free mm3 */ + psubsw %mm5, %mm1 /* tm14; free mm5 */ + movq %mm6, 8*6(%esi) /* tm6; free mm6 */ + movq %mm2, %mm3 /* duplicate t117=t125 */ + movq (%esi), %mm6 /* V24 */ + paddsw %mm0, %mm2 /* tm2 */ + movq %mm7, (%esi) /* tm0; free mm7 */ + psubsw %mm0, %mm3 /* tm12; free mm0 */ + movq %mm1, 8*14(%esi) /* tm14; free mm1 */ + psllw $1, %mm6 /* t119=t123 */ + movq %mm2, 8*2(%esi) /* tm2; free mm2 */ + movq %mm6, %mm0 /* duplicate t119=t123 */ + movq %mm3, 8*12(%esi) /* tm12; free mm3 */ + paddsw %mm4, %mm6 /* tm4 */ +/* moved from next block */ + movq 8*5(%ecx), %mm1 + psubsw %mm4, %mm0 /* tm10; free mm4 */ +/* moved from next block */ + pmulhw 8*5(%esi), %mm1 /* V5 */ + movq %mm6, 8*4(%esi) /* tm4; free mm6 */ + movq %mm0, 8*10(%esi) /* tm10; free mm0 */ +/* column 1: even part + * use V5, V13, V1, V9 to produce V56..V59 + */ +/* moved to prev block: + * movq 8*5(%ecx), %mm1 + * pmulhw 8*5(%esi), %mm1 V5 + */ + movq 8*13(%ecx), %mm7 + psllw $1, %mm1 /* t128=t130 */ + pmulhw 8*13(%esi), %mm7 /* V13 */ + movq %mm1, %mm2 /* duplicate t128=t130 */ + movq 8(%ecx), %mm3 + pmulhw 8(%esi), %mm3 /* V1 */ + movq 8*9(%ecx), %mm5 + psubsw %mm7, %mm1 /* V50 */ + pmulhw 8*9(%esi), %mm5 /* V9 */ + paddsw %mm7, %mm2 /* V51 */ + pmulhw x5a825a825a825a82, %mm1 /* 23170 ->V52 */ + movq %mm2, %mm6 /* duplicate V51 */ + psraw $1, %mm2 /* t138=t144 */ + movq %mm3, %mm4 /* duplicate V1 */ + psraw $2, %mm6 /* t136 */ + paddsw %mm5, %mm3 /* V53 */ + psubsw %mm5, %mm4 /* V54 ;mm5 free */ + movq %mm3, %mm7 /* duplicate V53 */ +/* moved from next block */ + movq 8*11(%ecx), %mm0 + psraw $1, %mm4 /* t140=t142 */ + psubsw %mm6, %mm1 /* V55 ; mm6 free */ + paddsw %mm2, %mm3 /* V56 */ + movq %mm4, %mm5 /* duplicate t140=t142 */ + paddsw %mm1, %mm4 /* V57 */ + movq %mm3, 8*5(%esi) /* V56 */ + psubsw %mm1, %mm5 /* V58; mm1 free */ + movq %mm4, 8*13(%esi) /* V57 */ + psubsw %mm2, %mm7 /* V59; mm2 free */ + movq %mm5, 8*9(%esi) /* V58 */ +/* keep mm7 alive all along the next block + * movq %mm7, 8(%esi) V59 + * moved above + * movq 8*11(%ecx), %mm0 + */ + pmulhw 8*11(%esi), %mm0 /* V11 */ + movq 8*7(%ecx), %mm6 + pmulhw 8*7(%esi), %mm6 /* V7 */ + movq 8*15(%ecx), %mm4 + movq %mm0, %mm3 /* duplicate V11 */ + pmulhw 8*15(%esi), %mm4 /* V15 */ + movq 8*3(%ecx), %mm5 + psllw $1, %mm6 /* t146=t152 */ + pmulhw 8*3(%esi), %mm5 /* V3 */ + paddsw %mm6, %mm0 /* V63 */ +/* note that V15 computation has a correction step: + * this is a 'magic' constant that rebiases the results to be closer to the + * expected result. this magic constant can be refined to reduce the error + * even more by doing the correction step in a later stage when the number + * is actually multiplied by 16 + */ + paddw x0005000200010001, %mm4 + psubsw %mm6, %mm3 /* V60 ; free mm6 */ + psraw $1, %mm0 /* t154=t156 */ + movq %mm3, %mm1 /* duplicate V60 */ + pmulhw x539f539f539f539f, %mm1 /* V67 */ + movq %mm5, %mm6 /* duplicate V3 */ + psraw $2, %mm4 /* t148=t150 */ + paddsw %mm4, %mm5 /* V61 */ + psubsw %mm4, %mm6 /* V62 ; free mm4 */ + movq %mm5, %mm4 /* duplicate V61 */ + psllw $1, %mm1 /* t169 */ + paddsw %mm0, %mm5 /* V65 -> result */ + psubsw %mm0, %mm4 /* V64 ; free mm0 */ + pmulhw x5a825a825a825a82, %mm4 /* V68 */ + psraw $1, %mm3 /* t158 */ + psubsw %mm6, %mm3 /* V66 */ + movq %mm5, %mm2 /* duplicate V65 */ + pmulhw x61f861f861f861f8, %mm3 /* V70 */ + psllw $1, %mm6 /* t165 */ + pmulhw x4546454645464546, %mm6 /* V69 */ + psraw $1, %mm2 /* t172 */ +/* moved from next block */ + movq 8*5(%esi), %mm0 /* V56 */ + psllw $1, %mm4 /* t174 */ +/* moved from next block */ + psraw $1, %mm0 /* t177=t188 */ + nop + psubsw %mm3, %mm6 /* V72 */ + psubsw %mm1, %mm3 /* V71 ; free mm1 */ + psubsw %mm2, %mm6 /* V73 ; free mm2 */ +/* moved from next block */ + psraw $1, %mm5 /* t178=t189 */ + psubsw %mm6, %mm4 /* V74 */ +/* moved from next block */ + movq %mm0, %mm1 /* duplicate t177=t188 */ + paddsw %mm4, %mm3 /* V75 */ +/* moved from next block */ + paddsw %mm5, %mm0 /* tm1 */ +/* location + * 5 - V56 + * 13 - V57 + * 9 - V58 + * X - V59, mm7 + * X - V65, mm5 + * X - V73, mm6 + * X - V74, mm4 + * X - V75, mm3 + * free mm0, mm1 & mm2 + * moved above + * movq 8*5(%esi), %mm0 V56 + * psllw $1, %mm0 t177=t188 ! new !! + * psllw $1, %mm5 t178=t189 ! new !! + * movq %mm0, %mm1 duplicate t177=t188 + * paddsw %mm5, %mm0 tm1 + */ + movq 8*13(%esi), %mm2 /* V57 */ + psubsw %mm5, %mm1 /* tm15; free mm5 */ + movq %mm0, 8(%esi) /* tm1; free mm0 */ + psraw $1, %mm7 /* t182=t184 ! new !! */ +/* save the store as used directly in the transpose + * movq %mm1, 120(%esi) tm15; free mm1 + */ + movq %mm7, %mm5 /* duplicate t182=t184 */ + psubsw %mm3, %mm7 /* tm7 */ + paddsw %mm3, %mm5 /* tm9; free mm3 */ + movq 8*9(%esi), %mm0 /* V58 */ + movq %mm2, %mm3 /* duplicate V57 */ + movq %mm7, 8*7(%esi) /* tm7; free mm7 */ + psubsw %mm6, %mm3 /* tm13 */ + paddsw %mm6, %mm2 /* tm3 ; free mm6 */ +/* moved up from the transpose */ + movq %mm3, %mm7 +/* moved up from the transpose */ + punpcklwd %mm1, %mm3 + movq %mm0, %mm6 /* duplicate V58 */ + movq %mm2, 8*3(%esi) /* tm3; free mm2 */ + paddsw %mm4, %mm0 /* tm5 */ + psubsw %mm4, %mm6 /* tm11; free mm4 */ +/* moved up from the transpose */ + punpckhwd %mm1, %mm7 + movq %mm0, 8*5(%esi) /* tm5; free mm0 */ +/* moved up from the transpose */ + movq %mm5, %mm2 +/* transpose - M4 part + * --------- --------- + * | M1 | M2 | | M1'| M3'| + * --------- --> --------- + * | M3 | M4 | | M2'| M4'| + * --------- --------- + * Two alternatives: use full mmword approach so the following code can be + * scheduled before the transpose is done without stores, or use the faster + * half mmword stores (when possible) + */ + movd %mm3, 8*9+4(%esi) /* MS part of tmt9 */ + punpcklwd %mm6, %mm5 + movd %mm7, 8*13+4(%esi) /* MS part of tmt13 */ + punpckhwd %mm6, %mm2 + movd %mm5, 8*9(%esi) /* LS part of tmt9 */ + punpckhdq %mm3, %mm5 /* free mm3 */ + movd %mm2, 8*13(%esi) /* LS part of tmt13 */ + punpckhdq %mm7, %mm2 /* free mm7 */ +/* moved up from the M3 transpose */ + movq 8*8(%esi), %mm0 +/* moved up from the M3 transpose */ + movq 8*10(%esi), %mm1 +/* moved up from the M3 transpose */ + movq %mm0, %mm3 +/* shuffle the rest of the data, and write it with 2 mmword writes */ + movq %mm5, 8*11(%esi) /* tmt11 */ +/* moved up from the M3 transpose */ + punpcklwd %mm1, %mm0 + movq %mm2, 8*15(%esi) /* tmt15 */ +/* moved up from the M3 transpose */ + punpckhwd %mm1, %mm3 +/* transpose - M3 part + * moved up to previous code section + * movq 8*8(%esi), %mm0 + * movq 8*10(%esi), %mm1 + * movq %mm0, %mm3 + * punpcklwd %mm1, %mm0 + * punpckhwd %mm1, %mm3 + */ + movq 8*12(%esi), %mm6 + movq 8*14(%esi), %mm4 + movq %mm6, %mm2 +/* shuffle the data and write the lower parts of the transposed in 4 dwords */ + punpcklwd %mm4, %mm6 + movq %mm0, %mm1 + punpckhdq %mm6, %mm1 + movq %mm3, %mm7 + punpckhwd %mm4, %mm2 /* free mm4 */ + punpckldq %mm6, %mm0 /* free mm6 */ +/* moved from next block */ + movq 8*13(%esi), %mm4 /* tmt13 */ + punpckldq %mm2, %mm3 + punpckhdq %mm2, %mm7 /* free mm2 */ +/* moved from next block */ + movq %mm3, %mm5 /* duplicate tmt5 */ +/* column 1: even part (after transpose) +* moved above +* movq %mm3, %mm5 duplicate tmt5 +* movq 8*13(%esi), %mm4 tmt13 +*/ + psubsw %mm4, %mm3 /* V134 */ + pmulhw x5a825a825a825a82, %mm3 /* 23170 ->V136 */ + movq 8*9(%esi), %mm6 /* tmt9 */ + paddsw %mm4, %mm5 /* V135 ; mm4 free */ + movq %mm0, %mm4 /* duplicate tmt1 */ + paddsw %mm6, %mm0 /* V137 */ + psubsw %mm6, %mm4 /* V138 ; mm6 free */ + psllw $2, %mm3 /* t290 */ + psubsw %mm5, %mm3 /* V139 */ + movq %mm0, %mm6 /* duplicate V137 */ + paddsw %mm5, %mm0 /* V140 */ + movq %mm4, %mm2 /* duplicate V138 */ + paddsw %mm3, %mm2 /* V141 */ + psubsw %mm3, %mm4 /* V142 ; mm3 free */ + movq %mm0, 8*9(%esi) /* V140 */ + psubsw %mm5, %mm6 /* V143 ; mm5 free */ +/* moved from next block */ + movq 8*11(%esi), %mm0 /* tmt11 */ + movq %mm2, 8*13(%esi) /* V141 */ +/* moved from next block */ + movq %mm0, %mm2 /* duplicate tmt11 */ +/* column 1: odd part (after transpose) */ +/* moved up to the prev block + * movq 8*11(%esi), %mm0 tmt11 + * movq %mm0, %mm2 duplicate tmt11 + */ + movq 8*15(%esi), %mm5 /* tmt15 */ + psubsw %mm7, %mm0 /* V144 */ + movq %mm0, %mm3 /* duplicate V144 */ + paddsw %mm7, %mm2 /* V147 ; free mm7 */ + pmulhw x539f539f539f539f, %mm0 /* 21407-> V151 */ + movq %mm1, %mm7 /* duplicate tmt3 */ + paddsw %mm5, %mm7 /* V145 */ + psubsw %mm5, %mm1 /* V146 ; free mm5 */ + psubsw %mm1, %mm3 /* V150 */ + movq %mm7, %mm5 /* duplicate V145 */ + pmulhw x4546454645464546, %mm1 /* 17734-> V153 */ + psubsw %mm2, %mm5 /* V148 */ + pmulhw x61f861f861f861f8, %mm3 /* 25080-> V154 */ + psllw $2, %mm0 /* t311 */ + pmulhw x5a825a825a825a82, %mm5 /* 23170-> V152 */ + paddsw %mm2, %mm7 /* V149 ; free mm2 */ + psllw $1, %mm1 /* t313 */ + nop /* without the nop - freeze here for one clock */ + movq %mm3, %mm2 /* duplicate V154 */ + psubsw %mm0, %mm3 /* V155 ; free mm0 */ + psubsw %mm2, %mm1 /* V156 ; free mm2 */ +/* moved from the next block */ + movq %mm6, %mm2 /* duplicate V143 */ +/* moved from the next block */ + movq 8*13(%esi), %mm0 /* V141 */ + psllw $1, %mm1 /* t315 */ + psubsw %mm7, %mm1 /* V157 (keep V149) */ + psllw $2, %mm5 /* t317 */ + psubsw %mm1, %mm5 /* V158 */ + psllw $1, %mm3 /* t319 */ + paddsw %mm5, %mm3 /* V159 */ +/* column 1: output butterfly (after transform) + * moved to the prev block + * movq %mm6, %mm2 duplicate V143 + * movq 8*13(%esi), %mm0 V141 + */ + psubsw %mm3, %mm2 /* V163 */ + paddsw %mm3, %mm6 /* V164 ; free mm3 */ + movq %mm4, %mm3 /* duplicate V142 */ + psubsw %mm5, %mm4 /* V165 ; free mm5 */ + movq %mm2, (%esp) /* out7 */ + psraw $4, %mm6 + psraw $4, %mm4 + paddsw %mm5, %mm3 /* V162 */ + movq 8*9(%esi), %mm2 /* V140 */ + movq %mm0, %mm5 /* duplicate V141 */ +/* in order not to perculate this line up, + * we read 72(%esi) very near to this location + */ + movq %mm6, 8*9(%esi) /* out9 */ + paddsw %mm1, %mm0 /* V161 */ + movq %mm3, 8(%esp) /* out5 */ + psubsw %mm1, %mm5 /* V166 ; free mm1 */ + movq %mm4, 8*11(%esi) /* out11 */ + psraw $4, %mm5 + movq %mm0, 16(%esp) /* out3 */ + movq %mm2, %mm4 /* duplicate V140 */ + movq %mm5, 8*13(%esi) /* out13 */ + paddsw %mm7, %mm2 /* V160 */ +/* moved from the next block */ + movq 8(%esi), %mm0 + psubsw %mm7, %mm4 /* V167 ; free mm7 */ +/* moved from the next block */ + movq 8*3(%esi), %mm7 + psraw $4, %mm4 + movq %mm2, 24(%esp) /* out1 */ +/* moved from the next block */ + movq %mm0, %mm1 + movq %mm4, 8*15(%esi) /* out15 */ +/* moved from the next block */ + punpcklwd %mm7, %mm0 +/* transpose - M2 parts + * moved up to the prev block + * movq 8(%esi), %mm0 + * movq 8*3(%esi), %mm7 + * movq %mm0, %mm1 + * punpcklwd %mm7, %mm0 + */ + movq 8*5(%esi), %mm5 + punpckhwd %mm7, %mm1 + movq 8*7(%esi), %mm4 + movq %mm5, %mm3 +/* shuffle the data and write the lower parts of the trasposed in 4 dwords */ + movd %mm0, 8*8(%esi) /* LS part of tmt8 */ + punpcklwd %mm4, %mm5 + movd %mm1, 8*12(%esi) /* LS part of tmt12 */ + punpckhwd %mm4, %mm3 + movd %mm5, 8*8+4(%esi) /* MS part of tmt8 */ + punpckhdq %mm5, %mm0 /* tmt10 */ + movd %mm3, 8*12+4(%esi) /* MS part of tmt12 */ + punpckhdq %mm3, %mm1 /* tmt14 */ +/* transpose - M1 parts */ + movq (%esi), %mm7 + movq 8*2(%esi), %mm2 + movq %mm7, %mm6 + movq 8*4(%esi), %mm5 + punpcklwd %mm2, %mm7 + movq 8*6(%esi), %mm4 + punpckhwd %mm2, %mm6 /* free mm2 */ + movq %mm5, %mm3 + punpcklwd %mm4, %mm5 + punpckhwd %mm4, %mm3 /* free mm4 */ + movq %mm7, %mm2 + movq %mm6, %mm4 + punpckldq %mm5, %mm7 /* tmt0 */ + punpckhdq %mm5, %mm2 /* tmt2 ; free mm5 */ +/* shuffle the rest of the data, and write it with 2 mmword writes */ + punpckldq %mm3, %mm6 /* tmt4 */ +/* moved from next block */ + movq %mm2, %mm5 /* duplicate tmt2 */ + punpckhdq %mm3, %mm4 /* tmt6 ; free mm3 */ +/* moved from next block */ + movq %mm0, %mm3 /* duplicate tmt10 */ +/* column 0: odd part (after transpose) + *moved up to prev block + * movq %mm0, %mm3 duplicate tmt10 + * movq %mm2, %mm5 duplicate tmt2 + */ + psubsw %mm4, %mm0 /* V110 */ + paddsw %mm4, %mm3 /* V113 ; free mm4 */ + movq %mm0, %mm4 /* duplicate V110 */ + paddsw %mm1, %mm2 /* V111 */ + pmulhw x539f539f539f539f, %mm0 /* 21407-> V117 */ + psubsw %mm1, %mm5 /* V112 ; free mm1 */ + psubsw %mm5, %mm4 /* V116 */ + movq %mm2, %mm1 /* duplicate V111 */ + pmulhw x4546454645464546, %mm5 /* 17734-> V119 */ + psubsw %mm3, %mm2 /* V114 */ + pmulhw x61f861f861f861f8, %mm4 /* 25080-> V120 */ + paddsw %mm3, %mm1 /* V115 ; free mm3 */ + pmulhw x5a825a825a825a82, %mm2 /* 23170-> V118 */ + psllw $2, %mm0 /* t266 */ + movq %mm1, (%esi) /* save V115 */ + psllw $1, %mm5 /* t268 */ + psubsw %mm4, %mm5 /* V122 */ + psubsw %mm0, %mm4 /* V121 ; free mm0 */ + psllw $1, %mm5 /* t270 */ + psubsw %mm1, %mm5 /* V123 ; free mm1 */ + psllw $2, %mm2 /* t272 */ + psubsw %mm5, %mm2 /* V124 (keep V123) */ + psllw $1, %mm4 /* t274 */ + movq %mm5, 8*2(%esi) /* save V123 ; free mm5 */ + paddsw %mm2, %mm4 /* V125 (keep V124) */ +/* column 0: even part (after transpose) */ + movq 8*12(%esi), %mm0 /* tmt12 */ + movq %mm6, %mm3 /* duplicate tmt4 */ + psubsw %mm0, %mm6 /* V100 */ + paddsw %mm0, %mm3 /* V101 ; free mm0 */ + pmulhw x5a825a825a825a82, %mm6 /* 23170 ->V102 */ + movq %mm7, %mm5 /* duplicate tmt0 */ + movq 8*8(%esi), %mm1 /* tmt8 */ + paddsw %mm1, %mm7 /* V103 */ + psubsw %mm1, %mm5 /* V104 ; free mm1 */ + movq %mm7, %mm0 /* duplicate V103 */ + psllw $2, %mm6 /* t245 */ + paddsw %mm3, %mm7 /* V106 */ + movq %mm5, %mm1 /* duplicate V104 */ + psubsw %mm3, %mm6 /* V105 */ + psubsw %mm3, %mm0 /* V109; free mm3 */ + paddsw %mm6, %mm5 /* V107 */ + psubsw %mm6, %mm1 /* V108 ; free mm6 */ +/* column 0: output butterfly (after transform) */ + movq %mm1, %mm3 /* duplicate V108 */ + paddsw %mm2, %mm1 /* out4 */ + psraw $4, %mm1 + psubsw %mm2, %mm3 /* out10 ; free mm2 */ + psraw $4, %mm3 + movq %mm0, %mm6 /* duplicate V109 */ + movq %mm1, 8*4(%esi) /* out4 ; free mm1 */ + psubsw %mm4, %mm0 /* out6 */ + movq %mm3, 8*10(%esi) /* out10 ; free mm3 */ + psraw $4, %mm0 + paddsw %mm4, %mm6 /* out8 ; free mm4 */ + movq %mm7, %mm1 /* duplicate V106 */ + movq %mm0, 8*6(%esi) /* out6 ; free mm0 */ + psraw $4, %mm6 + movq (%esi), %mm4 /* V115 */ + movq %mm6, 8*8(%esi) /* out8 ; free mm6 */ + movq %mm5, %mm2 /* duplicate V107 */ + movq 8*2(%esi), %mm3 /* V123 */ + paddsw %mm4, %mm7 /* out0 */ +/* moved up from next block */ + movq 16(%esp), %mm0 + psraw $4, %mm7 +/* moved up from next block */ + movq 8(%esp), %mm6 + psubsw %mm4, %mm1 /* out14 ; free mm4 */ + paddsw %mm3, %mm5 /* out2 */ + psraw $4, %mm1 + movq %mm7, (%esi) /* out0 ; free mm7 */ + psraw $4, %mm5 + movq %mm1, 8*14(%esi) /* out14 ; free mm1 */ + psubsw %mm3, %mm2 /* out12 ; free mm3 */ + movq %mm5, 8*2(%esi) /* out2 ; free mm5 */ + psraw $4, %mm2 +/* moved up to the prev block */ + movq (%esp), %mm4 +/* moved up to the prev block */ + psraw $4, %mm0 + movq %mm2, 8*12(%esi) /* out12 ; free mm2 */ +/* moved up to the prev block */ + psraw $4, %mm6 +/* move back the data to its correct place +* moved up to the prev block + * movq 16(%esp), %mm0 + * movq 8(%esp), %mm6 + * movq (%esp), %mm4 + * psraw $4, %mm0 + * psraw $4, %mm6 +*/ + movq 24(%esp), %mm1 + psraw $4, %mm4 + movq %mm0, 8*3(%esi) /* out3 */ + psraw $4, %mm1 + movq %mm6, 8*5(%esi) /* out5 */ + movq %mm4, 8*7(%esi) /* out7 */ + movq %mm1, 8(%esi) /* out1 */ + + popl %edi /* Pop off the temp variables */ + popl %edi + popl %edi + popl %edi + popl %edi + popl %edi + popl %edi + popl %edi + + popl %edi /* Pop off the old variables */ + popl %esi + popl %edx + popl %ecx + popl %ebx + movl %ebp, %esp + popl %ebp + + ret +.Lfe1: + .size IDCT_mmx,.Lfe1-IDCT_mmx diff --git a/core/multimedia/opieplayer/libmpeg3/video/mmxtest.c b/core/multimedia/opieplayer/libmpeg3/video/mmxtest.c new file mode 100644 index 0000000..567f139 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/mmxtest.c @@ -0,0 +1,35 @@ +#include "../libmpeg3.h" +#include "../mpeg3protos.h" + +#include <stdio.h> +#include <string.h> + +int mpeg3_mmx_test() +{ + int result = 0; + FILE *proc; + char string[MPEG3_STRLEN]; + + +#ifdef HAVE_MMX + if(!(proc = fopen(MPEG3_PROC_CPUINFO, "r"))) + { + return 0; + } + + while(!feof(proc)) + { + fgets(string, MPEG3_STRLEN, proc); +/* Got the flags line */ + if(!strncmp(string, "flags", 5)) + { + char *needle; + needle = strstr(string, "mmx"); + if(!needle) return 0; + if(!strncmp(needle, "mmx", 3)) return 1; + } + } +#endif + + return 0; +} diff --git a/core/multimedia/opieplayer/libmpeg3/video/motion.c b/core/multimedia/opieplayer/libmpeg3/video/motion.c new file mode 100644 index 0000000..4d2f681 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/motion.c @@ -0,0 +1,230 @@ +#include "mpeg3video.h" +#include "../libmpeg3.h" +#include "../mpeg3protos.h" +#include "vlc.h" + +#include <stdio.h> + + +/* calculate motion vector component */ + +static inline void mpeg3video_calc_mv(int *pred, int r_size, int motion_code, int motion_r, int full_pel_vector) +{ + int lim = 16 << r_size; + int vec = full_pel_vector ? (*pred >> 1) : (*pred); + + if(motion_code > 0) + { + vec += ((motion_code - 1) << r_size) + motion_r + 1; + if(vec >= lim) vec -= lim + lim; + } + else + if(motion_code < 0) + { + vec -= ((-motion_code - 1) << r_size) + motion_r + 1; + if(vec < -lim) vec += lim + lim; + } + *pred = full_pel_vector ? (vec << 1) : vec; +} + + +/* +int *dmvector, * differential motion vector * +int mvx, int mvy * decoded mv components (always in field format) * +*/ +void mpeg3video_calc_dmv(mpeg3video_t *video, + int DMV[][2], + int *dmvector, + int mvx, + int mvy) +{ + if(video->pict_struct == FRAME_PICTURE) + { + if(video->topfirst) + { +/* vector for prediction of top field from bottom field */ + DMV[0][0] = ((mvx + (mvx>0)) >> 1) + dmvector[0]; + DMV[0][1] = ((mvy + (mvy>0)) >> 1) + dmvector[1] - 1; + +/* vector for prediction of bottom field from top field */ + DMV[1][0] = ((3 * mvx + (mvx > 0)) >> 1) + dmvector[0]; + DMV[1][1] = ((3 * mvy + (mvy > 0)) >> 1) + dmvector[1] + 1; + } + else + { +/* vector for prediction of top field from bottom field */ + DMV[0][0] = ((3 * mvx + (mvx>0)) >> 1) + dmvector[0]; + DMV[0][1] = ((3 * mvy + (mvy>0)) >> 1) + dmvector[1] - 1; + +/* vector for prediction of bottom field from top field */ + DMV[1][0] = ((mvx + (mvx>0)) >> 1) + dmvector[0]; + DMV[1][1] = ((mvy + (mvy>0)) >> 1) + dmvector[1] + 1; + } + } + else + { +/* vector for prediction from field of opposite 'parity' */ + DMV[0][0] = ((mvx + (mvx > 0)) >> 1) + dmvector[0]; + DMV[0][1] = ((mvy + (mvy > 0)) >> 1) + dmvector[1]; + +/* correct for vertical field shift */ + if(video->pict_struct == TOP_FIELD) + DMV[0][1]--; + else + DMV[0][1]++; + } +} + +static inline int mpeg3video_get_mv(mpeg3_slice_t *slice) +{ + int code; + mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer; + + if(mpeg3slice_getbit(slice_buffer)) + { + return 0; + } + + if((code = mpeg3slice_showbits9(slice_buffer)) >= 64) + { + code >>= 6; + mpeg3slice_flushbits(slice_buffer, mpeg3_MVtab0[code].len); + return mpeg3slice_getbit(slice_buffer) ? -mpeg3_MVtab0[code].val : mpeg3_MVtab0[code].val; + } + + if(code >= 24) + { + code >>= 3; + mpeg3slice_flushbits(slice_buffer, mpeg3_MVtab1[code].len); + return mpeg3slice_getbit(slice_buffer) ? -mpeg3_MVtab1[code].val : mpeg3_MVtab1[code].val; + } + + if((code -= 12) < 0) + { +/* fprintf(stdout,"mpeg3video_get_mv: invalid motion_vector code\n"); */ + slice->fault = 1; + return 1; + } + + mpeg3slice_flushbits(slice_buffer, mpeg3_MVtab2[code].len); + return mpeg3slice_getbit(slice_buffer) ? -mpeg3_MVtab2[code].val : mpeg3_MVtab2[code].val; +} + +/* get differential motion vector (for dual prime prediction) */ + +static inline int mpeg3video_get_dmv(mpeg3_slice_t *slice) +{ + mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer; + if(mpeg3slice_getbit(slice_buffer)) + { + return mpeg3slice_getbit(slice_buffer) ? -1 : 1; + } + else + { + return 0; + } +} + + + +/* get and decode motion vector and differential motion vector */ + +void mpeg3video_motion_vector(mpeg3_slice_t *slice, + mpeg3video_t *video, + int *PMV, + int *dmvector, + int h_r_size, + int v_r_size, + int dmv, + int mvscale, + int full_pel_vector) +{ + int motion_r; + int motion_code = mpeg3video_get_mv(slice); + mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer; + + if(slice->fault) return; + motion_r = (h_r_size != 0 && motion_code != 0) ? mpeg3slice_getbits(slice_buffer, h_r_size) : 0; + + mpeg3video_calc_mv(&PMV[0], h_r_size, motion_code, motion_r, full_pel_vector); + + if(dmv) dmvector[0] = mpeg3video_get_dmv(slice); + + motion_code = mpeg3video_get_mv(slice); + if(slice->fault) return; + motion_r = (v_r_size != 0 && motion_code != 0) ? mpeg3slice_getbits(slice_buffer, v_r_size) : 0; + +/* DIV 2 */ + if(mvscale) PMV[1] >>= 1; + + mpeg3video_calc_mv(&PMV[1], v_r_size, motion_code, motion_r, full_pel_vector); + + if(mvscale) PMV[1] <<= 1; + if(dmv) dmvector[1] = mpeg3video_get_dmv(slice); +} + +int mpeg3video_motion_vectors(mpeg3_slice_t *slice, + mpeg3video_t *video, + int PMV[2][2][2], + int dmvector[2], + int mv_field_sel[2][2], + int s, + int mv_count, + int mv_format, + int h_r_size, + int v_r_size, + int dmv, + int mvscale) +{ + int result = 0; + mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer; + if(mv_count == 1) + { + if(mv_format == MV_FIELD && !dmv) + { + mv_field_sel[1][s] = mv_field_sel[0][s] = mpeg3slice_getbit(slice_buffer); + } + + mpeg3video_motion_vector(slice, + video, + PMV[0][s], + dmvector, + h_r_size, + v_r_size, + dmv, + mvscale, + 0); + if(slice->fault) return 1; + +/* update other motion vector predictors */ + PMV[1][s][0] = PMV[0][s][0]; + PMV[1][s][1] = PMV[0][s][1]; + } + else + { + mv_field_sel[0][s] = mpeg3slice_getbit(slice_buffer); + mpeg3video_motion_vector(slice, + video, + PMV[0][s], + dmvector, + h_r_size, + v_r_size, + dmv, + mvscale, + 0); + if(slice->fault) return 1; + + mv_field_sel[1][s] = mpeg3slice_getbit(slice_buffer); + mpeg3video_motion_vector(slice, + video, + PMV[1][s], + dmvector, + h_r_size, + v_r_size, + dmv, + mvscale, + 0); + if(slice->fault) return 1; + } + return 0; +} diff --git a/core/multimedia/opieplayer/libmpeg3/video/mpeg3video.c b/core/multimedia/opieplayer/libmpeg3/video/mpeg3video.c new file mode 100644 index 0000000..a9f113e --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/mpeg3video.c @@ -0,0 +1,597 @@ +#include "../libmpeg3.h" +#include "../mpeg3protos.h" +#include "mpeg3video.h" +#include "mpeg3videoprotos.h" +#include <stdlib.h> + +unsigned char mpeg3_zig_zag_scan_mmx[64] = +{ + 0*8+0 /* 0*/, 1*8+0 /* 1*/, 0*8+1 /* 8*/, 0*8+2 /*16*/, 1*8+1 /* 9*/, 2*8+0 /* 2*/, 3*8+0 /* 3*/, 2*8+1 /*10*/, + 1*8+2 /*17*/, 0*8+3 /*24*/, 0*8+4 /*32*/, 1*8+3 /*25*/, 2*8+2 /*18*/, 3*8+1 /*11*/, 4*8+0 /* 4*/, 5*8+0 /* 5*/, + 4*8+1 /*12*/, 5*8+2 /*19*/, 2*8+3 /*26*/, 1*8+4 /*33*/, 0*8+5 /*40*/, 0*8+6 /*48*/, 1*8+5 /*41*/, 2*8+4 /*34*/, + 3*8+3 /*27*/, 4*8+2 /*20*/, 5*8+1 /*13*/, 6*8+0 /* 6*/, 7*8+0 /* 7*/, 6*8+1 /*14*/, 5*8+2 /*21*/, 4*8+3 /*28*/, + 3*8+4 /*35*/, 2*8+5 /*42*/, 1*8+6 /*49*/, 0*8+7 /*56*/, 1*8+7 /*57*/, 2*8+6 /*50*/, 3*8+5 /*43*/, 4*8+4 /*36*/, + 5*8+3 /*29*/, 6*8+2 /*22*/, 7*8+1 /*15*/, 7*8+2 /*23*/, 6*8+3 /*30*/, 5*8+4 /*37*/, 4*8+5 /*44*/, 3*8+6 /*51*/, + 2*8+7 /*58*/, 3*8+7 /*59*/, 4*8+6 /*52*/, 5*8+5 /*45*/, 6*8+4 /*38*/, 7*8+3 /*31*/, 7*8+4 /*39*/, 6*8+5 /*46*/, + 7*8+6 /*53*/, 4*8+7 /*60*/, 5*8+7 /*61*/, 6*8+6 /*54*/, 7*8+5 /*47*/, 7*8+6 /*55*/, 6*8+7 /*62*/, 7*8+7 /*63*/ +}; + +/* alternate scan */ +unsigned char mpeg3_alternate_scan_mmx[64] = +{ + 0*8+0 /*0 */, 0*8+1 /* 8*/, 0*8+2 /*16*/, 0*8+3 /*24*/, 1*8+0 /* 1*/, 1*8+1 /* 9*/, 2*8+0 /* 2*/, 2*8+1 /*10*/, + 1*8+2 /*17*/, 1*8+3 /*25*/, 0*8+4 /*32*/, 0*8+5 /*40*/, 0*8+6 /*48*/, 0*8+7 /*56*/, 1*8+7 /*57*/, 1*8+6 /*49*/, + 1*8+5 /*41*/, 1*8+4 /*33*/, 2*8+3 /*26*/, 2*8+2 /*18*/, 3*8+0 /* 3*/, 3*8+1 /*11*/, 4*8+0 /* 4*/, 4*8+1 /*12*/, + 3*8+2 /*19*/, 3*8+3 /*27*/, 2*8+4 /*34*/, 2*8+5 /*42*/, 2*8+6 /*50*/, 2*8+7 /*58*/, 3*8+4 /*35*/, 3*8+5 /*43*/, + 3*8+6 /*51*/, 3*8+7 /*59*/, 4*8+2 /*20*/, 4*8+3 /*28*/, 5*8+0 /* 5*/, 5*8+1 /*13*/, 6*8+0 /* 6*/, 6*8+1 /*14*/, + 5*8+2 /*21*/, 5*8+3 /*29*/, 4*8+4 /*36*/, 4*8+5 /*44*/, 4*8+6 /*52*/, 4*8+7 /*60*/, 5*8+4 /*37*/, 5*8+5 /*45*/, + 5*8+6 /*53*/, 5*8+7 /*61*/, 6*8+2 /*22*/, 6*8+3 /*30*/, 7*8+0 /* 7*/, 7*8+1 /*15*/, 7*8+2 /*23*/, 7*8+3 /*31*/, + 6*8+4 /*38*/, 6*8+5 /*46*/, 6*8+6 /*54*/, 6*8+7 /*62*/, 7*8+4 /*39*/, 7*8+5 /*47*/, 7*8+6 /*55*/, 7*8+6 /*63*/ +}; + + + +/* zig-zag scan */ +unsigned char mpeg3_zig_zag_scan_nommx[64] = +{ + 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5, + 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28, + 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51, + 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63 +}; + +/* alternate scan */ +unsigned char mpeg3_alternate_scan_nommx[64] = +{ + 0, 8, 16, 24, 1, 9, 2, 10, 17, 25, 32, 40, 48, 56, 57, 49, + 41, 33, 26, 18, 3, 11, 4, 12, 19, 27, 34, 42, 50, 58, 35, 43, + 51, 59, 20, 28, 5, 13, 6, 14, 21, 29, 36, 44, 52, 60, 37, 45, + 53, 61, 22, 30, 7, 15, 23, 31, 38, 46, 54, 62, 39, 47, 55, 63 +}; + +/* default intra quantization matrix */ +unsigned char mpeg3_default_intra_quantizer_matrix[64] = +{ + 8, 16, 19, 22, 26, 27, 29, 34, + 16, 16, 22, 24, 27, 29, 34, 37, + 19, 22, 26, 27, 29, 34, 34, 38, + 22, 22, 26, 27, 29, 34, 37, 40, + 22, 26, 27, 29, 32, 35, 40, 48, + 26, 27, 29, 32, 35, 40, 48, 58, + 26, 27, 29, 34, 38, 46, 56, 69, + 27, 29, 35, 38, 46, 56, 69, 83 +}; + +unsigned char mpeg3_non_linear_mquant_table[32] = +{ + 0, 1, 2, 3, 4, 5, 6, 7, + 8, 10, 12, 14, 16, 18, 20, 22, + 24, 28, 32, 36, 40, 44, 48, 52, + 56, 64, 72, 80, 88, 96, 104, 112 +}; + +double mpeg3_frame_rate_table[16] = +{ + 0.0, /* Pad */ + 24000.0/1001.0, /* Official frame rates */ + 24.0, + 25.0, + 30000.0/1001.0, + 30.0, + 50.0, + ((60.0*1000.0)/1001.0), + 60.0, + + 1, /* Unofficial economy rates */ + 5, + 10, + 12, + 15, + 0, + 0, +}; + +int mpeg3video_initdecoder(mpeg3video_t *video) +{ + int blk_cnt_tab[3] = {6, 8, 12}; + int cc; + int i; + long size[4], padding[2]; /* Size of Y, U, and V buffers */ + + if(!video->mpeg2) + { +/* force MPEG-1 parameters */ + video->prog_seq = 1; + video->prog_frame = 1; + video->pict_struct = FRAME_PICTURE; + video->frame_pred_dct = 1; + video->chroma_format = CHROMA420; + video->matrix_coefficients = 5; + } + +/* Get dimensions rounded to nearest multiple of coded macroblocks */ + video->mb_width = (video->horizontal_size + 15) / 16; + video->mb_height = (video->mpeg2 && !video->prog_seq) ? + (2 * ((video->vertical_size + 31) / 32)) : + ((video->vertical_size + 15) / 16); + video->coded_picture_width = 16 * video->mb_width; + video->coded_picture_height = 16 * video->mb_height; + video->chrom_width = (video->chroma_format == CHROMA444) ? + video->coded_picture_width : + (video->coded_picture_width >> 1); + video->chrom_height = (video->chroma_format != CHROMA420) ? + video->coded_picture_height : + (video->coded_picture_height >> 1); + video->blk_cnt = blk_cnt_tab[video->chroma_format - 1]; + +/* Get sizes of YUV buffers */ + padding[0] = 16 * video->coded_picture_width; + size[0] = video->coded_picture_width * video->coded_picture_height + padding[0] * 2; + + padding[1] = 16 * video->chrom_width; + size[1] = video->chrom_width * video->chrom_height + 2 * padding[1]; + + size[2] = (video->llw * video->llh); + size[3] = (video->llw * video->llh) / 4; + +/* Allocate contiguous fragments for YUV buffers for hardware YUV decoding */ + video->yuv_buffer[0] = (unsigned char*)calloc(1, (size[0] + padding[0]) + 2 * (size[1] + padding[1])); + video->yuv_buffer[1] = (unsigned char*)calloc(1, (size[0] + padding[0]) + 2 * (size[1] + padding[1])); + video->yuv_buffer[2] = (unsigned char*)calloc(1, (size[0] + padding[0]) + 2 * (size[1] + padding[1])); + + if(video->scalable_mode == SC_SPAT) + { + video->yuv_buffer[3] = (unsigned char*)calloc(1, size[2] + 2 * size[3]); + video->yuv_buffer[4] = (unsigned char*)calloc(1, size[2] + 2 * size[3]); + } + +/* Direct pointers to areas of contiguous fragments in YVU order per Microsoft */ + for(cc = 0; cc < 3; cc++) + { + video->llframe0[cc] = 0; + video->llframe1[cc] = 0; + video->newframe[cc] = 0; + } + + video->refframe[0] = video->yuv_buffer[0]; + video->oldrefframe[0] = video->yuv_buffer[1]; + video->auxframe[0] = video->yuv_buffer[2]; + video->refframe[2] = video->yuv_buffer[0] + size[0] + padding[0]; + video->oldrefframe[2] = video->yuv_buffer[1] + size[0] + padding[0]; + video->auxframe[2] = video->yuv_buffer[2] + size[0] + padding[0]; + video->refframe[1] = video->yuv_buffer[0] + size[0] + padding[0] + size[1] + padding[1]; + video->oldrefframe[1] = video->yuv_buffer[1] + size[0] + padding[0] + size[1] + padding[1]; + video->auxframe[1] = video->yuv_buffer[2] + size[0] + padding[0] + size[1] + padding[1]; + + if(video->scalable_mode == SC_SPAT) + { +/* this assumes lower layer is 4:2:0 */ + video->llframe0[0] = video->yuv_buffer[3] + padding[0] ; + video->llframe1[0] = video->yuv_buffer[4] + padding[0] ; + video->llframe0[2] = video->yuv_buffer[3] + padding[1] + size[2] ; + video->llframe1[2] = video->yuv_buffer[4] + padding[1] + size[2] ; + video->llframe0[1] = video->yuv_buffer[3] + padding[1] + size[2] + size[3]; + video->llframe1[1] = video->yuv_buffer[4] + padding[1] + size[2] + size[3]; + } + +/* Initialize the YUV tables for software YUV decoding */ + video->cr_to_r = (long*)malloc(sizeof(long) * 256); + video->cr_to_g = (long*)malloc(sizeof(long) * 256); + video->cb_to_g = (long*)malloc(sizeof(long) * 256); + video->cb_to_b = (long*)malloc(sizeof(long) * 256); + video->cr_to_r_ptr = video->cr_to_r + 128; + video->cr_to_g_ptr = video->cr_to_g + 128; + video->cb_to_g_ptr = video->cb_to_g + 128; + video->cb_to_b_ptr = video->cb_to_b + 128; + + for(i = -128; i < 128; i++) + { + video->cr_to_r_ptr[i] = (long)( 1.371 * 65536 * i); + video->cr_to_g_ptr[i] = (long)(-0.698 * 65536 * i); + video->cb_to_g_ptr[i] = (long)(-0.336 * 65536 * i); + video->cb_to_b_ptr[i] = (long)( 1.732 * 65536 * i); + } + + return 0; +} + +int mpeg3video_deletedecoder(mpeg3video_t *video) +{ + int i, padding; + + free(video->yuv_buffer[0]); + free(video->yuv_buffer[1]); + free(video->yuv_buffer[2]); + + if(video->llframe0[0]) + { + free(video->yuv_buffer[3]); + free(video->yuv_buffer[4]); + } + + free(video->cr_to_r); + free(video->cr_to_g); + free(video->cb_to_g); + free(video->cb_to_b); + return 0; +} + +void mpeg3video_init_scantables(mpeg3video_t *video) +{ +#ifdef HAVE_MMX + if(video->have_mmx) + { + video->mpeg3_zigzag_scan_table = mpeg3_zig_zag_scan_mmx; + video->mpeg3_alternate_scan_table = mpeg3_alternate_scan_mmx; + } + else +#endif + { + video->mpeg3_zigzag_scan_table = mpeg3_zig_zag_scan_nommx; + video->mpeg3_alternate_scan_table = mpeg3_alternate_scan_nommx; + } +} + +mpeg3video_t* mpeg3video_allocate_struct(mpeg3_t *file, mpeg3_vtrack_t *track) +{ + int i; + mpeg3video_t *video = (mpeg3video_t*)calloc(1, sizeof(mpeg3video_t)); + pthread_mutexattr_t mutex_attr; + + video->file = file; + video->track = track; + video->vstream = mpeg3bits_new_stream(file, track->demuxer); + video->last_number = -1; + +/* First frame is all green */ + video->framenum = -1; + video->have_mmx = file->have_mmx; + + video->percentage_seek = -1; + video->frame_seek = -1; + + mpeg3video_init_scantables(video); + mpeg3video_init_output(); + + pthread_mutexattr_init(&mutex_attr); + pthread_mutex_init(&(video->test_lock), &mutex_attr); + pthread_mutex_init(&(video->slice_lock), &mutex_attr); + return video; +} + +int mpeg3video_delete_struct(mpeg3video_t *video) +{ + int i; + mpeg3bits_delete_stream(video->vstream); + pthread_mutex_destroy(&(video->test_lock)); + pthread_mutex_destroy(&(video->slice_lock)); + if(video->x_table) + { + free(video->x_table); + free(video->y_table); + } + if(video->total_slice_decoders) + { + for(i = 0; i < video->total_slice_decoders; i++) + mpeg3_delete_slice_decoder(&video->slice_decoders[i]); + } + for(i = 0; i < video->slice_buffers_initialized; i++) + mpeg3_delete_slice_buffer(&(video->slice_buffers[i])); + + free(video); +} + + +int mpeg3video_read_frame_backend(mpeg3video_t *video, int skip_bframes) +{ + int result = 0; + + if(mpeg3bits_eof(video->vstream)) result = 1; + + if(!result) result = mpeg3video_get_header(video, 0); + +//printf("frame type %d\n", video->pict_type); +/* skip_bframes is the number of bframes we can skip successfully. */ +/* This is in case a skipped B-frame is repeated and the second repeat happens */ +/* to be a B frame we need. */ + video->skip_bframes = skip_bframes; + + if(!result) + result = mpeg3video_getpicture(video, video->framenum); + +#ifdef HAVE_MMX + if(video->have_mmx) + __asm__ __volatile__ ("emms"); +#endif + + if(!result) + { + video->last_number = video->framenum; + video->framenum++; + } + return result; +} + +int* mpeg3video_get_scaletable(int input_w, int output_w) +{ + int *result = (int*)malloc(sizeof(int) * output_w); + float i; + float scale = (float)input_w / output_w; + for(i = 0; i < output_w; i++) + { + result[(int)i] = (int)(scale * i); + } + return result; +} + +/* Get the first frame read. */ +int mpeg3video_get_firstframe(mpeg3video_t *video) +{ + int result = 0; + if(video->framenum < 0) + { + video->repeat_count = video->current_repeat = 0; + result = mpeg3video_read_frame_backend(video, 0); + mpeg3bits_seek_byte(video->vstream, 0); + mpeg3video_match_refframes(video); + } + return result; +} + + +/* ======================================================================= */ +/* ENTRY POINTS */ +/* ======================================================================= */ + + + +mpeg3video_t* mpeg3video_new(mpeg3_t *file, mpeg3_vtrack_t *track) +{ + mpeg3video_t *video; + int result = 0; + + video = mpeg3video_allocate_struct(file, track); + result = mpeg3video_get_header(video, 1); + + if(!result) + { + int hour, minute, second, frame; + int gop_found; + + mpeg3video_initdecoder(video); + video->decoder_initted = 1; + track->width = video->horizontal_size; + track->height = video->vertical_size; + track->frame_rate = video->frame_rate; + +/* Get the length of the file from an elementary stream */ + if(file->is_video_stream) + { +/* Load the first GOP */ + mpeg3bits_seek_start(video->vstream); + result = mpeg3video_next_code(video->vstream, MPEG3_GOP_START_CODE); + if(!result) mpeg3bits_getbits(video->vstream, 32); + if(!result) result = mpeg3video_getgophdr(video); + + hour = video->gop_timecode.hour; + minute = video->gop_timecode.minute; + second = video->gop_timecode.second; + frame = video->gop_timecode.frame; + video->first_frame = (long)(hour * 3600 * video->frame_rate + + minute * 60 * video->frame_rate + + second * video->frame_rate + + frame); + +/* GOPs always have 16 frames */ + video->frames_per_gop = 16; + +/* Read the last GOP in the file by seeking backward. */ + mpeg3bits_seek_end(video->vstream); + mpeg3bits_start_reverse(video->vstream); + result = mpeg3video_prev_code(video->vstream, MPEG3_GOP_START_CODE); + mpeg3bits_start_forward(video->vstream); + mpeg3bits_getbits(video->vstream, 8); + if(!result) result = mpeg3video_getgophdr(video); + + hour = video->gop_timecode.hour; + minute = video->gop_timecode.minute; + second = video->gop_timecode.second; + frame = video->gop_timecode.frame; + + video->last_frame = (long)(hour * 3600 * video->frame_rate + + minute * 60 * video->frame_rate + + second * video->frame_rate + + frame); + +/* Count number of frames to end */ + while(!result) + { + result = mpeg3video_next_code(video->vstream, MPEG3_PICTURE_START_CODE); + if(!result) + { + mpeg3bits_getbyte_noptr(video->vstream); + video->last_frame++; + } + } + + track->total_frames = video->last_frame - video->first_frame + 1; + mpeg3bits_seek_start(video->vstream); + } + else + { +/* Gross approximation from a multiplexed file. */ + video->first_frame = 0; + track->total_frames = video->last_frame = + (long)(mpeg3demux_length(video->vstream->demuxer) * + video->frame_rate); + video->first_frame = 0; + } + + video->maxframe = track->total_frames; + mpeg3bits_seek_start(video->vstream); + } + else + { + mpeg3video_delete(video); + video = 0; + } + + return video; +} + +int mpeg3video_delete(mpeg3video_t *video) +{ + if(video->decoder_initted) + { + mpeg3video_deletedecoder(video); + } + mpeg3video_delete_struct(video); + return 0; +} + +int mpeg3video_set_cpus(mpeg3video_t *video, int cpus) +{ + return 0; +} + +int mpeg3video_set_mmx(mpeg3video_t *video, int use_mmx) +{ + video->have_mmx = use_mmx; + mpeg3video_init_scantables(video); + return 0; +} + +int mpeg3video_seek_percentage(mpeg3video_t *video, double percentage) +{ + video->percentage_seek = percentage; + return 0; +} + +int mpeg3video_previous_frame(mpeg3video_t *video) +{ + if(mpeg3bits_tell_percentage(video->vstream) <= 0) return 1; + mpeg3bits_start_reverse(video->vstream); + mpeg3video_prev_code(video->vstream, MPEG3_PICTURE_START_CODE); + mpeg3bits_getbits_reverse(video->vstream, 32); + + if(mpeg3bits_bof(video->vstream)) mpeg3bits_seek_percentage(video->vstream, 0); + mpeg3bits_start_forward(video->vstream); + video->repeat_count = 0; + return 0; +} + +int mpeg3video_seek_frame(mpeg3video_t *video, long frame) +{ + video->frame_seek = frame; + return 0; +} + +/* Read all the way up to and including the next picture start code */ +int mpeg3video_read_raw(mpeg3video_t *video, unsigned char *output, long *size, long max_size) +{ + unsigned MPEG3_INT32 code = 0; + mpeg3_bits_t *vstream = video->vstream; + + *size = 0; + while(code != MPEG3_PICTURE_START_CODE && + code != MPEG3_SEQUENCE_END_CODE && + *size < max_size && + !mpeg3bits_eof(vstream)) + { + code <<= 8; + *output = mpeg3bits_getbyte_noptr(vstream); + code |= *output++; + (*size)++; + } + return mpeg3bits_eof(vstream); +} + +int mpeg3video_read_frame(mpeg3video_t *video, + long frame_number, + unsigned char **output_rows, + int in_x, + int in_y, + int in_w, + int in_h, + int out_w, + int out_h, + int color_model) +{ + int result = 0; + + video->want_yvu = 0; + video->output_rows = output_rows; + video->color_model = color_model; + +/* Get scaling tables */ + if(video->out_w != out_w || video->out_h != out_h || + video->in_w != in_w || video->in_h != in_h || + video->in_x != in_x || video->in_y != in_y) + { + if(video->x_table) + { + free(video->x_table); + free(video->y_table); + video->x_table = 0; + video->y_table = 0; + } + } + + video->out_w = out_w; + video->out_h = out_h; + video->in_w = in_w; + video->in_h = in_h; + video->in_x = in_x; + video->in_y = in_y; + + if(!video->x_table) + { + video->x_table = mpeg3video_get_scaletable(video->in_w, video->out_w); + video->y_table = mpeg3video_get_scaletable(video->in_h, video->out_h); + } + + mpeg3video_get_firstframe(video); + + if(!result) result = mpeg3video_seek(video); + + if(!result) result = mpeg3video_read_frame_backend(video, 0); + + if(video->output_src) mpeg3video_present_frame(video); + + video->percentage_seek = -1; + return result; +} + +int mpeg3video_read_yuvframe(mpeg3video_t *video, + long frame_number, + char *y_output, + char *u_output, + char *v_output, + int in_x, + int in_y, + int in_w, + int in_h) +{ + int result = 0; + + video->want_yvu = 1; + video->y_output = y_output; + video->u_output = u_output; + video->v_output = v_output; + video->in_x = in_x; + video->in_y = in_y; + video->in_w = in_w; + video->in_h = in_h; + + mpeg3video_get_firstframe(video); + + if(!result) result = mpeg3video_seek(video); + + if(!result) result = mpeg3video_read_frame_backend(video, 0); + + if(video->output_src) mpeg3video_present_frame(video); + + video->want_yvu = 0; + video->percentage_seek = -1; + return result; +} diff --git a/core/multimedia/opieplayer/libmpeg3/video/mpeg3video.h b/core/multimedia/opieplayer/libmpeg3/video/mpeg3video.h new file mode 100644 index 0000000..2db62b0 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/mpeg3video.h @@ -0,0 +1,180 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef MPEGVIDEO_H +#define MPEGVIDEO_H + +#include "../bitstream.h" +#include "../mpeg3private.inc" +#include "idct.h" +#include "slice.h" +#include "../timecode.h" + +/* zig-zag scan */ +extern unsigned char mpeg3_zig_zag_scan_nommx[64]; +extern unsigned char mpeg3_zig_zag_scan_mmx[64]; + +/* alternate scan */ +extern unsigned char mpeg3_alternate_scan_nommx[64]; +extern unsigned char mpeg3_alternate_scan_mmx[64]; + +/* default intra quantization matrix */ +extern unsigned char mpeg3_default_intra_quantizer_matrix[64]; + +/* Frame rate table must agree with the one in the encoder */ +extern double mpeg3_frame_rate_table[16]; + +/* non-linear quantization coefficient table */ +extern unsigned char mpeg3_non_linear_mquant_table[32]; + +#define CHROMA420 1 /* chroma_format */ +#define CHROMA422 2 +#define CHROMA444 3 + +#define TOP_FIELD 1 /* picture structure */ +#define BOTTOM_FIELD 2 +#define FRAME_PICTURE 3 + +#define SEQ_ID 1 /* extension start code IDs */ +#define DISP_ID 2 +#define QUANT_ID 3 +#define SEQSCAL_ID 5 +#define PANSCAN_ID 7 +#define CODING_ID 8 +#define SPATSCAL_ID 9 +#define TEMPSCAL_ID 10 + +#define ERROR (-1) + +#define SC_NONE 0 /* scalable_mode */ +#define SC_DP 1 +#define SC_SPAT 2 +#define SC_SNR 3 +#define SC_TEMP 4 + +#define I_TYPE 1 /* picture coding type */ +#define P_TYPE 2 +#define B_TYPE 3 +#define D_TYPE 4 + +#define MB_INTRA 1 /* macroblock type */ +#define MB_PATTERN 2 +#define MB_BACKWARD 4 +#define MB_FORWARD 8 +#define MB_QUANT 16 +#define MB_WEIGHT 32 +#define MB_CLASS4 64 + +#define MC_FIELD 1 /* motion_type */ +#define MC_FRAME 2 +#define MC_16X8 2 +#define MC_DMV 3 + +#define MV_FIELD 0 /* mv_format */ +#define MV_FRAME 1 + +#define CLIP(x) ((x) >= 0 ? ((x) < 255 ? (x) : 255) : 0) + +/* Statically allocate as little as possible so a fake video struct */ +/* can be used for reading the GOP headers. */ + +struct mpeg3video_rec +{ + struct mpeg3_rec* file; + struct mpeg3_vtrack_rec* track; + +/* ================================= Seeking variables ========================= */ + mpeg3_bits_t *vstream; + int decoder_initted; + unsigned char **output_rows; /* Output frame buffer supplied by user */ + int in_x, in_y, in_w, in_h, out_w, out_h; /* Output dimensions */ + int *x_table, *y_table; /* Location of every output pixel in the input */ + int color_model; + int want_yvu; /* Want to return a YUV frame */ + char *y_output, *u_output, *v_output; /* Output pointers for a YUV frame */ + + mpeg3_slice_t slice_decoders[MPEG3_MAX_CPUS]; /* One slice decoder for every CPU */ + int total_slice_decoders; /* Total slice decoders in use */ + mpeg3_slice_buffer_t slice_buffers[MPEG3_MAX_CPUS]; /* Buffers for holding the slice data */ + int total_slice_buffers; /* Total buffers in the array to be decompressed */ + int slice_buffers_initialized; /* Total buffers initialized in the array */ + pthread_mutex_t slice_lock; /* Lock slice array while getting the next buffer */ + pthread_mutex_t test_lock; + + int blockreadsize; + long maxframe; /* Max value of frame num to read */ + double percentage_seek; /* Perform a percentage seek before the next frame is read */ + int frame_seek; /* Perform a frame seek before the next frame is read */ + long framenum; /* Number of the next frame to be decoded */ + long last_number; /* Last framenum rendered */ + int found_seqhdr; + long bitrate; + mpeg3_timecode_t gop_timecode; /* Timecode for the last GOP header read. */ + +/* These are only available from elementary streams. */ + long frames_per_gop; /* Frames per GOP after the first GOP. */ + long first_gop_frames; /* Frames in the first GOP. */ + long first_frame; /* Number of first frame stored in timecode */ + long last_frame; /* Last frame in file */ + +/* ================================= Compression variables ===================== */ +/* Malloced frame buffers. 2 refframes are swapped in and out. */ +/* while only 1 auxframe is used. */ + unsigned char *yuv_buffer[5]; /* Make YVU buffers contiguous for all frames */ + unsigned char *oldrefframe[3], *refframe[3], *auxframe[3]; + unsigned char *llframe0[3], *llframe1[3]; + unsigned char *mpeg3_zigzag_scan_table; + unsigned char *mpeg3_alternate_scan_table; +// Source for the next frame presentation + unsigned char **output_src; +/* Pointers to frame buffers. */ + unsigned char *newframe[3]; + int horizontal_size, vertical_size, mb_width, mb_height; + int coded_picture_width, coded_picture_height; + int chroma_format, chrom_width, chrom_height, blk_cnt; + int pict_type; + int forw_r_size, back_r_size, full_forw, full_back; + int prog_seq, prog_frame; + int h_forw_r_size, v_forw_r_size, h_back_r_size, v_back_r_size; + int dc_prec, pict_struct, topfirst, frame_pred_dct, conceal_mv; + int intravlc; + int repeatfirst; + int repeat_count; /* Number of times to repeat the current frame * 100 since floating point is impossible in MMX */ + int current_repeat; /* Number of times the current frame has been repeated * 100 */ + int secondfield; + int skip_bframes; + int stwc_table_index, llw, llh, hm, hn, vm, vn; + int lltempref, llx0, lly0, llprog_frame, llfieldsel; + int matrix_coefficients; + int framerate_code; + float frame_rate; + long *cr_to_r, *cr_to_g, *cb_to_g, *cb_to_b; + long *cr_to_r_ptr, *cr_to_g_ptr, *cb_to_g_ptr, *cb_to_b_ptr; + int have_mmx; + int intra_quantizer_matrix[64], non_intra_quantizer_matrix[64]; + int chroma_intra_quantizer_matrix[64], chroma_non_intra_quantizer_matrix[64]; + int mpeg2; + int qscale_type, altscan; /* picture coding extension */ + int pict_scal; /* picture spatial scalable extension */ + int scalable_mode; /* sequence scalable extension */ +}; + +typedef struct mpeg3video_rec mpeg3video_t; + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/video/mpeg3videoprotos.h b/core/multimedia/opieplayer/libmpeg3/video/mpeg3videoprotos.h new file mode 100644 index 0000000..e48d6cd --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/mpeg3videoprotos.h @@ -0,0 +1,26 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef MPEG3VIDEOPROTOS_H +#define MPEG3VIDEOPROTOS_H + +void mpeg3video_idct_conversion(short* block); +unsigned int mpeg3slice_showbits(mpeg3_slice_buffer_t *slice_buffer, int bits); + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/video/output.c b/core/multimedia/opieplayer/libmpeg3/video/output.c new file mode 100644 index 0000000..919a0ff --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/output.c @@ -0,0 +1,993 @@ +#include "../libmpeg3.h" +#include "../mpeg3protos.h" +#include "mpeg3video.h" +#include <string.h> + +static LONGLONG mpeg3_MMX_0 = 0L; +static unsigned long mpeg3_MMX_10w[] = {0x00100010, 0x00100010}; /*dd 00010 0010h, 000100010h */ +static unsigned long mpeg3_MMX_80w[] = {0x00800080, 0x00800080}; /*dd 00080 0080h, 000800080h */ + +static unsigned long mpeg3_MMX_00FFw[] = {0x00ff00ff, 0x00ff00ff}; /*dd 000FF 00FFh, 000FF00FFh */ + +static unsigned short mpeg3_MMX_Ublucoeff[] = {0x81, 0x81, 0x81, 0x81}; /*dd 00081 0081h, 000810081h */ +static unsigned short mpeg3_MMX_Vredcoeff[] = {0x66, 0x66, 0x66, 0x66}; /*dd 00066 0066h, 000660066h */ + +static unsigned short mpeg3_MMX_Ugrncoeff[] = {0xffe8, 0xffe8, 0xffe8, 0xffe8}; /*dd 0FFE7 FFE7h, 0FFE7FFE7h */ +static unsigned short mpeg3_MMX_Vgrncoeff[] = {0xffcd, 0xffcd, 0xffcd, 0xffcd}; /*dd 0FFCC FFCCh, 0FFCCFFCCh */ + +static unsigned short mpeg3_MMX_Ycoeff[] = {0x4a, 0x4a, 0x4a, 0x4a}; /*dd 0004A 004Ah, 0004A004Ah */ + +static unsigned short mpeg3_MMX_redmask[] = {0xf800, 0xf800, 0xf800, 0xf800}; /*dd 07c00 7c00h, 07c007c00h */ + +static unsigned short mpeg3_MMX_grnmask[] = {0x7e0, 0x7e0, 0x7e0, 0x7e0}; /*dd 003e0 03e0h, 003e003e0h */ + +static unsigned char mpeg3_601_to_rgb[256]; + +/* Algorithm */ +/* r = (int)(*y + 1.371 * (*cr - 128)); */ +/* g = (int)(*y - 0.698 * (*cr - 128) - 0.336 * (*cb - 128)); */ +/* b = (int)(*y + 1.732 * (*cb - 128)); */ + +#ifdef HAVE_MMX +inline void mpeg3video_rgb16_mmx(unsigned char *lum, + unsigned char *cr, + unsigned char *cb, + unsigned char *out, + int rows, + int cols, + int mod) +{ + unsigned short *row1; + int x; + unsigned char *y; + int col1; + + row1 = (unsigned short *)out; + col1 = cols + mod; + mod += cols + mod; + mod *= 2; + y = lum + cols * rows; + x = 0; + + __asm__ __volatile__( + ".align 8\n" + "1:\n" + "movd (%1), %%mm0\n" /* 4 Cb 0 0 0 0 u3 u2 u1 u0 */ + "pxor %%mm7, %%mm7\n" + "movd (%0), %%mm1\n" /* 4 Cr 0 0 0 0 v3 v2 v1 v0 */ + "punpcklbw %%mm7, %%mm0\n" /* 4 W cb 0 u3 0 u2 0 u1 0 u0 */ + "punpcklbw %%mm7, %%mm1\n" /* 4 W cr 0 v3 0 v2 0 v1 0 v0 */ + + "psubw mpeg3_MMX_80w, %%mm0\n" + "psubw mpeg3_MMX_80w, %%mm1\n" + "movq %%mm0, %%mm2\n" /* Cb 0 u3 0 u2 0 u1 0 u0 */ + "movq %%mm1, %%mm3\n" /* Cr */ + "pmullw mpeg3_MMX_Ugrncoeff, %%mm2\n" /* Cb2green 0 R3 0 R2 0 R1 0 R0 */ + "movq (%2), %%mm6\n" /* L1 l7 L6 L5 L4 L3 L2 L1 L0 */ + "pmullw mpeg3_MMX_Ublucoeff, %%mm0\n" /* Cb2blue */ + "pand mpeg3_MMX_00FFw, %%mm6\n" /* L1 00 L6 00 L4 00 L2 00 L0 */ + "pmullw mpeg3_MMX_Vgrncoeff, %%mm3\n" /* Cr2green */ + "movq (%2), %%mm7\n" /* L2 */ + "pmullw mpeg3_MMX_Vredcoeff, %%mm1\n" /* Cr2red */ + "psrlw $8, %%mm7\n" /* L2 00 L7 00 L5 00 L3 00 L1 */ + "pmullw mpeg3_MMX_Ycoeff, %%mm6\n" /* lum1 */ + "paddw %%mm3, %%mm2\n" /* Cb2green + Cr2green == green */ + "pmullw mpeg3_MMX_Ycoeff, %%mm7\n" /* lum2 */ + + "movq %%mm6, %%mm4\n" /* lum1 */ + "paddw %%mm0, %%mm6\n" /* lum1 +blue 00 B6 00 B4 00 B2 00 B0 */ + "movq %%mm4, %%mm5\n" /* lum1 */ + "paddw %%mm1, %%mm4\n" /* lum1 +red 00 R6 00 R4 00 R2 00 R0 */ + "paddw %%mm2, %%mm5\n" /* lum1 +green 00 G6 00 G4 00 G2 00 G0 */ + "psraw $6, %%mm4\n" /* R1 0 .. 64 */ + "movq %%mm7, %%mm3\n" /* lum2 00 L7 00 L5 00 L3 00 L1 */ + "psraw $6, %%mm5\n" /* G1 - .. + */ + "paddw %%mm0, %%mm7\n" /* Lum2 +blue 00 B7 00 B5 00 B3 00 B1 */ + "psraw $6, %%mm6\n" /* B1 0 .. 64 */ + "packuswb %%mm4, %%mm4\n" /* R1 R1 */ + "packuswb %%mm5, %%mm5\n" /* G1 G1 */ + "packuswb %%mm6, %%mm6\n" /* B1 B1 */ + "punpcklbw %%mm4, %%mm4\n" + "punpcklbw %%mm5, %%mm5\n" + + "pand mpeg3_MMX_redmask, %%mm4\n" + "psllw $3, %%mm5\n" /* GREEN 1 */ + "punpcklbw %%mm6, %%mm6\n" + "pand mpeg3_MMX_grnmask, %%mm5\n" + "pand mpeg3_MMX_redmask, %%mm6\n" + "por %%mm5, %%mm4\n" /* */ + "psrlw $11, %%mm6\n" /* BLUE 1 */ + "movq %%mm3, %%mm5\n" /* lum2 */ + "paddw %%mm1, %%mm3\n" /* lum2 +red 00 R7 00 R5 00 R3 00 R1 */ + "paddw %%mm2, %%mm5\n" /* lum2 +green 00 G7 00 G5 00 G3 00 G1 */ + "psraw $6, %%mm3\n" /* R2 */ + "por %%mm6, %%mm4\n" /* MM4 */ + "psraw $6, %%mm5\n" /* G2 */ + "movq (%2, %3), %%mm6\n" /* L3 */ + "psraw $6, %%mm7\n" + "packuswb %%mm3, %%mm3\n" + "packuswb %%mm5, %%mm5\n" + "packuswb %%mm7, %%mm7\n" + "pand mpeg3_MMX_00FFw, %%mm6\n" /* L3 */ + "punpcklbw %%mm3, %%mm3\n" + "punpcklbw %%mm5, %%mm5\n" + "pmullw mpeg3_MMX_Ycoeff, %%mm6\n" /* lum3 */ + "punpcklbw %%mm7, %%mm7\n" + "psllw $3, %%mm5\n" /* GREEN 2 */ + "pand mpeg3_MMX_redmask, %%mm7\n" + "pand mpeg3_MMX_redmask, %%mm3\n" + "psrlw $11, %%mm7\n" /* BLUE 2 */ + "pand mpeg3_MMX_grnmask, %%mm5\n" + "por %%mm7, %%mm3\n" + "movq (%2,%3), %%mm7\n" /* L4 */ + "por %%mm5, %%mm3\n" /* */ + "psrlw $8, %%mm7\n" /* L4 */ + "movq %%mm4, %%mm5\n" + "punpcklwd %%mm3, %%mm4\n" + "pmullw mpeg3_MMX_Ycoeff, %%mm7\n" /* lum4 */ + "punpckhwd %%mm3, %%mm5\n" + + "movq %%mm4, (%4)\n" + "movq %%mm5, 8(%4)\n" + + "movq %%mm6, %%mm4\n" /* Lum3 */ + "paddw %%mm0, %%mm6\n" /* Lum3 +blue */ + + "movq %%mm4, %%mm5\n" /* Lum3 */ + "paddw %%mm1, %%mm4\n" /* Lum3 +red */ + "paddw %%mm2, %%mm5\n" /* Lum3 +green */ + "psraw $6, %%mm4\n" + "movq %%mm7, %%mm3\n" /* Lum4 */ + "psraw $6, %%mm5\n" + "paddw %%mm0, %%mm7\n" /* Lum4 +blue */ + "psraw $6, %%mm6\n" /* Lum3 +blue */ + "movq %%mm3, %%mm0\n" /* Lum4 */ + "packuswb %%mm4, %%mm4\n" + "paddw %%mm1, %%mm3\n" /* Lum4 +red */ + "packuswb %%mm5, %%mm5\n" + "paddw %%mm2, %%mm0\n" /* Lum4 +green */ + "packuswb %%mm6, %%mm6\n" + "punpcklbw %%mm4, %%mm4\n" + "punpcklbw %%mm5, %%mm5\n" + "punpcklbw %%mm6, %%mm6\n" + "psllw $3, %%mm5\n" /* GREEN 3 */ + "pand mpeg3_MMX_redmask, %%mm4\n" + "psraw $6, %%mm3\n" /* psr 6 */ + "psraw $6, %%mm0\n" + "pand mpeg3_MMX_redmask, %%mm6\n" /* BLUE */ + "pand mpeg3_MMX_grnmask, %%mm5\n" + "psrlw $11, %%mm6\n" /* BLUE 3 */ + "por %%mm5, %%mm4\n" + "psraw $6, %%mm7\n" + "por %%mm6, %%mm4\n" + "packuswb %%mm3, %%mm3\n" + "packuswb %%mm0, %%mm0\n" + "packuswb %%mm7, %%mm7\n" + "punpcklbw %%mm3, %%mm3\n" + "punpcklbw %%mm0, %%mm0\n" + "punpcklbw %%mm7, %%mm7\n" + "pand mpeg3_MMX_redmask, %%mm3\n" + "pand mpeg3_MMX_redmask, %%mm7\n" /* BLUE */ + "psllw $3, %%mm0\n" /* GREEN 4 */ + "psrlw $11, %%mm7\n" + "pand mpeg3_MMX_grnmask, %%mm0\n" + "por %%mm7, %%mm3\n" + "addl $8, %6\n" + "por %%mm0, %%mm3\n" + + "movq %%mm4, %%mm5\n" + + "punpcklwd %%mm3, %%mm4\n" + "punpckhwd %%mm3, %%mm5\n" + + "movq %%mm4, (%4,%5,2)\n" + "movq %%mm5, 8(%4,%5,2)\n" + + "addl $8, %2\n" + "addl $4, %0\n" + "addl $4, %1\n" + "cmpl %3, %6\n" + "leal 16(%4), %4\n" + "jl 1b\n" + "addl %3, %2\n" /* lum += cols */ + "addl %7, %4\n" /* row1 += mod */ + "movl $0, %6\n" + "cmpl %8, %2\n" + "jl 1b\n" + : : "r" (cr), + "r" (cb), + "r" (lum), + "r" (cols), + "r" (row1) , + "r" (col1), + "m" (x), + "m" (mod), + "m" (y) + ); +} + +static unsigned LONGLONG mpeg3_MMX_U_80 = 0x0000008000800000LL; +static unsigned LONGLONG mpeg3_MMX_V_80 = 0x0000000000800080LL; +static LONGLONG mpeg3_MMX_U_COEF = 0x00000058ffd30000LL; +static LONGLONG mpeg3_MMX_V_COEF = 0x00000000ffea006fLL; +static LONGLONG mpeg3_MMX_601_Y_COEF = 0x0000004800480048LL; +static LONGLONG mpeg3_MMX_601_Y_DIFF = 0x0000000000000010LL; + +inline void mpeg3_bgra32_mmx(unsigned long y, + unsigned long u, + unsigned long v, + unsigned long *output) +{ +asm(" +/* Output will be 0x00rrggbb with the 00 trailing so this can also be used */ +/* for bgr24. */ + movd (%0), %%mm0; /* Load y 0x00000000000000yy */ + movd (%1), %%mm1; /* Load u 0x00000000000000cr */ + movq %%mm0, %%mm3; /* Copy y to temp */ + psllq $16, %%mm1; /* Shift u 0x0000000000cr0000 */ + movd (%2), %%mm2; /* Load v 0x00000000000000cb */ + psllq $16, %%mm3; /* Shift y */ + movq %%mm1, %%mm4; /* Copy u to temp */ + por %%mm3, %%mm0; /* Overlay new y byte 0x0000000000yy00yy */ + psllq $16, %%mm4; /* Shift u */ + movq %%mm2, %%mm5; /* Copy v to temp */ + psllq $16, %%mm3; /* Shift y */ + por %%mm4, %%mm1; /* Overlay new u byte 0x000000cr00cr0000 */ + psllq $16, %%mm5; /* Shift v */ + por %%mm3, %%mm0; /* Overlay new y byte 0x000000yy00yy00yy */ + por %%mm5, %%mm2; /* Overlay new v byte 0x0000000000cb00cb */ + +/* mm0: 0x000000yy00yy00yy mm1: 0x000000uu00uu0000 mm2: 0x0000000000vv00vv */ + psubw mpeg3_MMX_U_80, %%mm1; /* Subtract 128 from u 0x000000uu00uu0000 */ + pmullw mpeg3_MMX_U_COEF, %%mm1; /* Multiply u coeffs 0x0000uuuuuuuu0000 */ + psllw $6, %%mm0; /* Shift y coeffs 0x0000yyy0yyy0yyy0 */ + psubw mpeg3_MMX_V_80, %%mm2; /* Subtract 128 from v 0x0000000000cb00cb */ + pmullw mpeg3_MMX_V_COEF, %%mm2; /* Multiply v coeffs 0x0000crcrcrcrcrcr */ + +/* mm0: 0x000000yy00yy00yy mm1: 0x0000uuuuuuuu0000 mm2: 0x00000000vvvvvvvv */ + paddsw %%mm1, %%mm0; /* Add u to result */ + paddsw %%mm2, %%mm0; /* Add v to result 0x0000rrrrggggbbbb */ + psraw $6, %%mm0; /* Demote precision */ + packuswb %%mm0, %%mm0; /* Pack into ARGB 0x0000000000rrggbb */ + movd %%mm0, (%3); /* Store output */ + " +: +: "r" (&y), "r" (&u), "r" (&v), "r" (output)); +} + +inline void mpeg3_601_bgra32_mmx(unsigned long y, + unsigned long u, + unsigned long v, + unsigned long *output) +{ +asm(" +/* Output will be 0x00rrggbb with the 00 trailing so this can also be used */ +/* for bgr24. */ + movd (%0), %%mm0; /* Load y 0x00000000000000yy */ + psubsw mpeg3_MMX_601_Y_DIFF, %%mm0; /* Subtract 16 from y */ + movd (%1), %%mm1; /* Load u 0x00000000000000cr */ + movq %%mm0, %%mm3; /* Copy y to temp */ + psllq $16, %%mm1; /* Shift u 0x0000000000cr0000 */ + movd (%2), %%mm2; /* Load v 0x00000000000000cb */ + psllq $16, %%mm3; /* Shift y */ + movq %%mm1, %%mm4; /* Copy u to temp */ + por %%mm3, %%mm0; /* Overlay new y byte 0x0000000000yy00yy */ + psllq $16, %%mm4; /* Shift u */ + movq %%mm2, %%mm5; /* Copy v to temp */ + psllq $16, %%mm3; /* Shift y */ + por %%mm4, %%mm1; /* Overlay new u byte 0x000000cr00cr0000 */ + psllq $16, %%mm5; /* Shift v */ + por %%mm3, %%mm0; /* Overlay new y byte 0x000000yy00yy00yy */ + por %%mm5, %%mm2; /* Overlay new v byte 0x0000000000cb00cb */ + +/* mm0: 0x000000yy00yy00yy mm1: 0x000000uu00uu0000 mm2: 0x0000000000vv00vv */ + pmullw mpeg3_MMX_601_Y_COEF, %%mm0; /* Scale and shift y coeffs */ + psubw mpeg3_MMX_U_80, %%mm1; /* Subtract 128 from u 0x000000uu00uu0000 */ + pmullw mpeg3_MMX_U_COEF, %%mm1; /* Multiply u coeffs 0x0000uuuuuuuu0000 */ + psubw mpeg3_MMX_V_80, %%mm2; /* Subtract 128 from v 0x0000000000cb00cb */ + pmullw mpeg3_MMX_V_COEF, %%mm2; /* Multiply v coeffs 0x0000crcrcrcrcrcr */ + +/* mm0: 0x000000yy00yy00yy mm1: 0x0000uuuuuuuu0000 mm2: 0x00000000vvvvvvvv */ + paddsw %%mm1, %%mm0; /* Add u to result */ + paddsw %%mm2, %%mm0; /* Add v to result 0x0000rrrrggggbbbb */ + psraw $6, %%mm0; /* Demote precision */ + packuswb %%mm0, %%mm0; /* Pack into ARGB 0x0000000000rrggbb */ + movd %%mm0, (%3); /* Store output */ + " +: +: "r" (&y), "r" (&u), "r" (&v), "r" (output)); +} + +static unsigned LONGLONG mpeg3_MMX_U_80_RGB = 0x0000000000800080LL; +static unsigned LONGLONG mpeg3_MMX_V_80_RGB = 0x0000008000800000LL; +static LONGLONG mpeg3_MMX_U_COEF_RGB = 0x00000000ffd30058LL; +static LONGLONG mpeg3_MMX_V_COEF_RGB = 0x0000006fffea0000LL; + +inline void mpeg3_rgba32_mmx(unsigned long y, + unsigned long u, + unsigned long v, + unsigned long *output) +{ +asm(" +/* Output will be 0x00bbggrr with the 00 trailing so this can also be used */ +/* for rgb24. */ + movd (%0), %%mm0; /* Load y 0x00000000000000yy */ + movd (%1), %%mm1; /* Load v 0x00000000000000vv */ + movq %%mm0, %%mm3; /* Copy y to temp */ + psllq $16, %%mm1; /* Shift v 0x0000000000vv0000 */ + movd (%2), %%mm2; /* Load u 0x00000000000000uu */ + psllq $16, %%mm3; /* Shift y */ + movq %%mm1, %%mm4; /* Copy v to temp */ + por %%mm3, %%mm0; /* Overlay new y byte 0x0000000000yy00yy */ + psllq $16, %%mm4; /* Shift v */ + movq %%mm2, %%mm5; /* Copy u to temp */ + psllq $16, %%mm3; /* Shift y */ + por %%mm4, %%mm1; /* Overlay new v byte 0x000000vv00vv0000 */ + psllq $16, %%mm5; /* Shift u */ + por %%mm3, %%mm0; /* Overlay new y byte 0x000000yy00yy00yy */ + por %%mm5, %%mm2; /* Overlay new u byte 0x0000000000uu00uu */ + +/* mm0: 0x000000yy00yy00yy mm1: 0x000000vv00vv0000 mm2: 0x0000000000uu00uu */ + psubw mpeg3_MMX_V_80_RGB, %%mm1; /* Subtract 128 from v 0x000000vv00vv0000 */ + pmullw mpeg3_MMX_V_COEF_RGB, %%mm1; /* Multiply v coeffs 0x0000vvvvvvvv0000 */ + psllw $6, %%mm0; /* Shift y coeffs 0x0000yyy0yyy0yyy0 */ + psubw mpeg3_MMX_U_80_RGB, %%mm2; /* Subtract 128 from u 0x0000000000uu00uu */ + pmullw mpeg3_MMX_U_COEF_RGB, %%mm2; /* Multiply u coeffs 0x0000uuuuuuuuuuuu */ + +/* mm0: 0x000000yy00yy00yy mm1: 0x0000vvvvvvvv0000 mm2: 0x00000000uuuuuuuu */ + paddsw %%mm1, %%mm0; /* Add v to result */ + paddsw %%mm2, %%mm0; /* Add u to result 0x0000bbbbggggrrrr */ + psraw $6, %%mm0; /* Demote precision */ + packuswb %%mm0, %%mm0; /* Pack into RGBA 0x0000000000bbggrr */ + movd %%mm0, (%3); /* Store output */ + " +: +: "r" (&y), "r" (&v), "r" (&u), "r" (output)); +} + +inline void mpeg3_601_rgba32_mmx(unsigned long y, + unsigned long u, + unsigned long v, + unsigned long *output) +{ +asm(" +/* Output will be 0x00bbggrr with the 00 trailing so this can also be used */ +/* for rgb24. */ + movd (%0), %%mm0; /* Load y 0x00000000000000yy */ + psubsw mpeg3_MMX_601_Y_DIFF, %%mm0; /* Subtract 16 from y */ + movd (%1), %%mm1; /* Load v 0x00000000000000vv */ + movq %%mm0, %%mm3; /* Copy y to temp */ + psllq $16, %%mm1; /* Shift v 0x0000000000vv0000 */ + movd (%2), %%mm2; /* Load u 0x00000000000000uu */ + psllq $16, %%mm3; /* Shift y */ + movq %%mm1, %%mm4; /* Copy v to temp */ + por %%mm3, %%mm0; /* Overlay new y byte 0x0000000000yy00yy */ + psllq $16, %%mm4; /* Shift v */ + movq %%mm2, %%mm5; /* Copy u to temp */ + psllq $16, %%mm3; /* Shift y */ + por %%mm4, %%mm1; /* Overlay new v byte 0x000000vv00vv0000 */ + psllq $16, %%mm5; /* Shift u */ + por %%mm3, %%mm0; /* Overlay new y byte 0x000000yy00yy00yy */ + por %%mm5, %%mm2; /* Overlay new u byte 0x0000000000uu00uu */ + +/* mm0: 0x000000yy00yy00yy mm1: 0x000000vv00vv0000 mm2: 0x0000000000uu00uu */ + pmullw mpeg3_MMX_601_Y_COEF, %%mm0; /* Scale y coeffs */ + psubw mpeg3_MMX_V_80_RGB, %%mm1; /* Subtract 128 from v 0x000000vv00vv0000 */ + pmullw mpeg3_MMX_V_COEF_RGB, %%mm1; /* Multiply v coeffs 0x0000vvvvvvvv0000 */ + psubw mpeg3_MMX_U_80_RGB, %%mm2; /* Subtract 128 from u 0x0000000000uu00uu */ + pmullw mpeg3_MMX_U_COEF_RGB, %%mm2; /* Multiply u coeffs 0x0000uuuuuuuuuuuu */ + +/* mm0: 0x000000yy00yy00yy mm1: 0x0000vvvvvvvv0000 mm2: 0x00000000uuuuuuuu */ + paddsw %%mm1, %%mm0; /* Add v to result */ + paddsw %%mm2, %%mm0; /* Add u to result 0x0000bbbbggggrrrr */ + psraw $6, %%mm0; /* Demote precision */ + packuswb %%mm0, %%mm0; /* Pack into RGBA 0x0000000000bbggrr */ + movd %%mm0, (%3); /* Store output */ + " +: +: "r" (&y), "r" (&v), "r" (&u), "r" (output)); +} + +#endif + +#define DITHER_ROW_HEAD \ + for(h = 0; h < video->out_h; h++) \ + { \ + y_in = &src[0][(video->y_table[h] + video->in_y) * video->coded_picture_width] + video->in_x; \ + cb_in = &src[1][((video->y_table[h] + video->in_y) >> 1) * video->chrom_width] + (video->in_x >> 2); \ + cr_in = &src[2][((video->y_table[h] + video->in_y) >> 1) * video->chrom_width] + (video->in_x >> 1); \ + data = output_rows[h]; + +#define DITHER_ROW_TAIL \ + } + +#define DITHER_SCALE_HEAD \ + for(w = 0; w < video->out_w; w++) \ + { \ + uv_subscript = video->x_table[w] / 2; \ + y_l = y_in[video->x_table[w]]; \ + y_l <<= 16; \ + r_l = (y_l + video->cr_to_r[cr_in[uv_subscript]]) >> 16; \ + g_l = (y_l + video->cr_to_g[cr_in[uv_subscript]] + video->cb_to_g[cb_in[uv_subscript]]) >> 16; \ + b_l = (y_l + video->cb_to_b[cb_in[uv_subscript]]) >> 16; + +#define DITHER_SCALE_601_HEAD \ + for(w = 0; w < video->out_w; w++) \ + { \ + uv_subscript = video->x_table[w] / 2; \ + y_l = mpeg3_601_to_rgb[y_in[video->x_table[w]]]; \ + y_l <<= 16; \ + r_l = (y_l + video->cr_to_r[cr_in[uv_subscript]]) >> 16; \ + g_l = (y_l + video->cr_to_g[cr_in[uv_subscript]] + video->cb_to_g[cb_in[uv_subscript]]) >> 16; \ + b_l = (y_l + video->cb_to_b[cb_in[uv_subscript]]) >> 16; + +#define DITHER_SCALE_TAIL \ + } + +#define DITHER_MMX_SCALE_HEAD \ + for(w = 0; w < video->out_w; w++) \ + { \ + uv_subscript = video->x_table[w] / 2; + +#define DITHER_MMX_SCALE_TAIL \ + data += step; \ + } + +#define DITHER_MMX_HEAD \ + for(w = 0; w < video->out_w; w += 2) \ + { + +#define DITHER_MMX_TAIL \ + data += step; \ + cr_in++; \ + cb_in++; \ + } + +#define DITHER_HEAD \ + for(w = 0; w < video->horizontal_size; w++) \ + { \ + y_l = *y_in++; \ + y_l <<= 16; \ + r_l = (y_l + video->cr_to_r[*cr_in]) >> 16; \ + g_l = (y_l + video->cr_to_g[*cr_in] + video->cb_to_g[*cb_in]) >> 16; \ + b_l = (y_l + video->cb_to_b[*cb_in]) >> 16; + +#define DITHER_601_HEAD \ + for(w = 0; w < video->horizontal_size; w++) \ + { \ + y_l = mpeg3_601_to_rgb[*y_in++]; \ + y_l <<= 16; \ + r_l = (y_l + video->cr_to_r[*cr_in]) >> 16; \ + g_l = (y_l + video->cr_to_g[*cr_in] + video->cb_to_g[*cb_in]) >> 16; \ + b_l = (y_l + video->cb_to_b[*cb_in]) >> 16; + +#define DITHER_TAIL \ + if(w & 1) \ + { \ + cr_in++; \ + cb_in++; \ + } \ + } + + +#define STORE_PIXEL_BGR888 \ + *data++ = CLIP(b_l); \ + *data++ = CLIP(g_l); \ + *data++ = CLIP(r_l); + +#define STORE_PIXEL_BGRA8888 \ + *data++ = CLIP(b_l); \ + *data++ = CLIP(g_l); \ + *data++ = CLIP(r_l); \ + *data++ = 0; + +#define STORE_PIXEL_RGB565 \ + *((unsigned short*)data)++ = \ + ((CLIP(r_l) & 0xf8) << 8) | \ + ((CLIP(g_l) & 0xfc) << 3) | \ + ((CLIP(b_l) & 0xf8) >> 3); + +#define STORE_PIXEL_RGB888 \ + *data++ = CLIP(r_l); \ + *data++ = CLIP(g_l); \ + *data++ = CLIP(b_l); + +#define STORE_PIXEL_RGBA8888 \ + *data++ = CLIP(r_l); \ + *data++ = CLIP(g_l); \ + *data++ = CLIP(b_l); \ + *data++ = 0; + +#define STORE_PIXEL_RGBA16161616 \ + *data_s++ = CLIP(r_l); \ + *data_s++ = CLIP(g_l); \ + *data_s++ = CLIP(b_l); \ + *data_s++ = 0; + + + +/* Only good for YUV 4:2:0 */ +int mpeg3video_ditherframe(mpeg3video_t *video, unsigned char **src, unsigned char **output_rows) +{ + int h = 0; + register unsigned char *y_in, *cb_in, *cr_in; + long y_l, r_l, b_l, g_l; + register unsigned char *data; + register int uv_subscript, step, w = -1; + +#ifdef HAVE_MMX +/* =================================== MMX ===================================== */ + if(video->have_mmx && + video->out_w == video->horizontal_size && + video->out_h == video->vertical_size && + video->in_w == video->out_w && + video->in_h == video->out_h && + video->in_x == 0 && + video->in_y == 0 && + (video->color_model == MPEG3_RGB565 || video->color_model == MPEG3_601_RGB565)) + { +/* Unscaled 16 bit */ + mpeg3video_rgb16_mmx(src[0], + src[2], + src[1], + output_rows[0], + video->out_h, + video->out_w, + (output_rows[1] - output_rows[0]) / 2 - video->out_w); + } + else + if(video->have_mmx && + (video->color_model == MPEG3_BGRA8888 || + video->color_model == MPEG3_BGR888 || +/* video->color_model == MPEG3_RGB888 || */ + video->color_model == MPEG3_RGBA8888 || + video->color_model == MPEG3_601_BGR888 || + video->color_model == MPEG3_601_BGRA8888 || + video->color_model == MPEG3_601_RGB888 || + video->color_model == MPEG3_601_RGBA8888)) + { +/* Original MMX */ + if(video->color_model == MPEG3_BGRA8888 || + video->color_model == MPEG3_RGBA8888 || + video->color_model == MPEG3_601_BGRA8888 || + video->color_model == MPEG3_601_RGBA8888) step = 4; + else + if(video->color_model == MPEG3_BGR888 || + video->color_model == MPEG3_RGB888 || + video->color_model == MPEG3_601_BGR888 || + video->color_model == MPEG3_601_RGB888) step = 3; + + DITHER_ROW_HEAD +/* Transfer row with scaling */ + if(video->out_w != video->horizontal_size) + { + switch(video->color_model) + { + case MPEG3_BGRA8888: + case MPEG3_BGR888: + DITHER_MMX_SCALE_HEAD + mpeg3_bgra32_mmx(y_in[video->x_table[w]], + cr_in[uv_subscript], + cb_in[uv_subscript], + (unsigned long*)data); + DITHER_MMX_SCALE_TAIL + break; + + case MPEG3_601_BGRA8888: + case MPEG3_601_BGR888: + DITHER_MMX_SCALE_HEAD + mpeg3_601_bgra32_mmx(y_in[video->x_table[w]], + cr_in[uv_subscript], + cb_in[uv_subscript], + (unsigned long*)data); + DITHER_MMX_SCALE_TAIL + break; + + case MPEG3_RGBA8888: + case MPEG3_RGB888: + DITHER_MMX_SCALE_HEAD + mpeg3_rgba32_mmx(y_in[video->x_table[w]], + cr_in[uv_subscript], + cb_in[uv_subscript], + (unsigned long*)data); + DITHER_MMX_SCALE_TAIL + break; + + case MPEG3_601_RGBA8888: + case MPEG3_601_RGB888: + DITHER_MMX_SCALE_HEAD + mpeg3_601_rgba32_mmx(y_in[video->x_table[w]], + cr_in[uv_subscript], + cb_in[uv_subscript], + (unsigned long*)data); + DITHER_MMX_SCALE_TAIL + break; + } + } + else +/* Transfer row unscaled */ + { + switch(video->color_model) + { +/* MMX byte swap 24 and 32 bit */ + case MPEG3_BGRA8888: + case MPEG3_BGR888: + DITHER_MMX_HEAD + mpeg3_bgra32_mmx(*y_in++, + *cr_in, + *cb_in, + (unsigned long*)data); + data += step; + mpeg3_bgra32_mmx(*y_in++, + *cr_in, + *cb_in, + (unsigned long*)data); + DITHER_MMX_TAIL + break; + +/* MMX 601 byte swap 24 and 32 bit */ + case MPEG3_601_BGRA8888: + case MPEG3_601_BGR888: + DITHER_MMX_HEAD + mpeg3_601_bgra32_mmx(*y_in++, + *cr_in, + *cb_in, + (unsigned long*)data); + data += step; + mpeg3_601_bgra32_mmx(*y_in++, + *cr_in, + *cb_in, + (unsigned long*)data); + DITHER_MMX_TAIL + break; + +/* MMX 24 and 32 bit no byte swap */ + case MPEG3_RGBA8888: + case MPEG3_RGB888: + DITHER_MMX_HEAD + mpeg3_rgba32_mmx(*y_in++, + *cr_in, + *cb_in, + (unsigned long*)data); + data += step; + mpeg3_rgba32_mmx(*y_in++, + *cr_in, + *cb_in, + (unsigned long*)data); + DITHER_MMX_TAIL + break; + +/* MMX 601 24 and 32 bit no byte swap */ + case MPEG3_601_RGBA8888: + case MPEG3_601_RGB888: + DITHER_MMX_HEAD + mpeg3_601_rgba32_mmx(*y_in++, + *cr_in, + *cb_in, + (unsigned long*)data); + data += step; + mpeg3_601_rgba32_mmx(*y_in++, + *cr_in, + *cb_in, + (unsigned long*)data); + DITHER_MMX_TAIL + break; + } + } + DITHER_ROW_TAIL + } + else +#endif +/* ================================== NO MMX ==================================== */ + { + DITHER_ROW_HEAD +/* Transfer row with scaling */ + if(video->out_w != video->horizontal_size) + { + switch(video->color_model) + { + case MPEG3_BGR888: + DITHER_SCALE_HEAD + STORE_PIXEL_BGR888 + DITHER_SCALE_TAIL + break; + case MPEG3_BGRA8888: + DITHER_SCALE_HEAD + STORE_PIXEL_BGRA8888 + DITHER_SCALE_TAIL + break; + case MPEG3_RGB565: + DITHER_SCALE_HEAD + STORE_PIXEL_RGB565 + DITHER_SCALE_TAIL + break; + case MPEG3_RGB888: + DITHER_SCALE_HEAD + STORE_PIXEL_RGB888 + DITHER_SCALE_TAIL + break; + case MPEG3_RGBA8888: + DITHER_SCALE_HEAD + STORE_PIXEL_RGBA8888 + DITHER_SCALE_TAIL + break; + case MPEG3_601_BGR888: + DITHER_SCALE_601_HEAD + STORE_PIXEL_BGR888 + DITHER_SCALE_TAIL + break; + case MPEG3_601_BGRA8888: + DITHER_SCALE_601_HEAD + STORE_PIXEL_BGRA8888 + DITHER_SCALE_TAIL + break; + case MPEG3_601_RGB565: + DITHER_SCALE_601_HEAD + STORE_PIXEL_RGB565 + DITHER_SCALE_TAIL + break; + case MPEG3_601_RGB888: + DITHER_SCALE_601_HEAD + STORE_PIXEL_RGB888 + DITHER_SCALE_TAIL + break; + case MPEG3_601_RGBA8888: + DITHER_SCALE_601_HEAD + STORE_PIXEL_RGBA8888 + DITHER_SCALE_TAIL + break; + case MPEG3_RGBA16161616: + { + register unsigned short *data_s = (unsigned short*)data; + DITHER_SCALE_HEAD + STORE_PIXEL_RGBA16161616 + DITHER_SCALE_TAIL + } + break; + } + } + else + { +/* Transfer row unscaled */ + switch(video->color_model) + { + case MPEG3_BGR888: + DITHER_HEAD + STORE_PIXEL_BGR888 + DITHER_TAIL + break; + case MPEG3_BGRA8888: + DITHER_HEAD + STORE_PIXEL_BGRA8888 + DITHER_TAIL + break; + case MPEG3_RGB565: + DITHER_HEAD + STORE_PIXEL_RGB565 + DITHER_TAIL + break; + case MPEG3_RGB888: + DITHER_HEAD + STORE_PIXEL_RGB888 + DITHER_TAIL + break; + case MPEG3_RGBA8888: + DITHER_HEAD + STORE_PIXEL_RGBA8888 + DITHER_TAIL + break; + case MPEG3_601_BGR888: + DITHER_601_HEAD + STORE_PIXEL_BGR888 + DITHER_TAIL + break; + case MPEG3_601_BGRA8888: + DITHER_601_HEAD + STORE_PIXEL_RGB565 + DITHER_TAIL + break; + case MPEG3_601_RGB565: + DITHER_601_HEAD + STORE_PIXEL_RGB565 + DITHER_TAIL + break; + case MPEG3_601_RGB888: + DITHER_601_HEAD + STORE_PIXEL_RGB888 + DITHER_TAIL + break; + case MPEG3_601_RGBA8888: + DITHER_601_HEAD + STORE_PIXEL_RGBA8888 + DITHER_TAIL + break; + case MPEG3_RGBA16161616: + { + register unsigned short *data_s = (unsigned short*)data; + DITHER_HEAD + STORE_PIXEL_RGBA16161616 + DITHER_TAIL + } + break; + } + } + DITHER_ROW_TAIL + } /* End of non-MMX */ + +#ifdef HAVE_MMX + if(video->have_mmx) + __asm__ __volatile__ ("emms"); +#endif + return 0; +} + +int mpeg3video_ditherframe444(mpeg3video_t *video, unsigned char *src[]) +{ + return 0; +} + +int mpeg3video_dithertop(mpeg3video_t *video, unsigned char *src[]) +{ + return mpeg3video_ditherframe(video, src, video->output_rows); +} + +int mpeg3video_dithertop444(mpeg3video_t *video, unsigned char *src[]) +{ + return 0; +} + +int mpeg3video_ditherbot(mpeg3video_t *video, unsigned char *src[]) +{ + return 0; +} + +int mpeg3video_ditherbot444(mpeg3video_t *video, unsigned char *src[]) +{ + return 0; +} + +void memcpy_fast(unsigned char *output, unsigned char *input, long len) +{ + int i, len2; +/* 8 byte alignment */ +/* + * if(!((long)input & 0x7)) + * { + * len2 = len >> 4; + * for(i = 0; i < len2; ) + * { + * ((MPEG3_INT64*)output)[i] = ((MPEG3_INT64*)input)[i]; + * i++; + * ((MPEG3_INT64*)output)[i] = ((MPEG3_INT64*)input)[i]; + * i++; + * } + * + * for(i *= 16; i < len; i++) + * { + * output[i] = input[i]; + * } + * } + * else + */ + memcpy(output, input, len); +} + +int mpeg3video_init_output() +{ + int i, value; + for(i = 0; i < 256; i++) + { + value = (int)(1.1644 * i - 255 * 0.0627 + 0.5); + if(value < 0) value = 0; + else + if(value > 255) value = 255; + mpeg3_601_to_rgb[i] = value; + } + return 0; +} + +int mpeg3video_present_frame(mpeg3video_t *video) +{ + int i, j, k, l; + unsigned char **src = video->output_src; + +/* Copy YUV buffers */ + if(video->want_yvu) + { + long size[2]; + long offset[2]; + +/* Drop a frame */ + if(!video->y_output) return 0; + +/* Copy a frame */ + if(video->in_x == 0 && + video->in_w >= video->coded_picture_width) + { + size[0] = video->coded_picture_width * video->in_h; + size[1] = video->chrom_width * (int)((float)video->in_h / 2 + 0.5); + offset[0] = video->coded_picture_width * video->in_y; + offset[1] = video->chrom_width * (int)((float)video->in_y / 2 + 0.5); + +/* + * if(video->in_y > 0) + * { + * offset[1] += video->chrom_width / 2; + * size[1] += video->chrom_width / 2; + * } + */ + + memcpy(video->y_output, src[0] + offset[0], size[0]); + memcpy(video->u_output, src[1] + offset[1], size[1]); + memcpy(video->v_output, src[2] + offset[1], size[1]); + } + else + { + for(i = 0, j = video->in_y; i < video->in_h; i++, j++) + { + memcpy(video->y_output + i * video->in_w, + src[0] + j * video->coded_picture_width + video->in_x, + video->in_w); + memcpy(video->u_output + i * video->in_w / 4, + src[1] + j * video->chrom_width / 2 + video->in_x / 4, + video->in_w / 4); + memcpy(video->v_output + i * video->in_w / 4, + src[2] + j * video->chrom_width / 2 + video->in_x / 4, + video->in_w / 4); + } + } + + return 0; + } + +/* Want RGB buffer */ +/* Copy the frame to the output with YUV to RGB conversion */ + if(video->prog_seq) + { + if(video->chroma_format != CHROMA444) + { + mpeg3video_ditherframe(video, src, video->output_rows); + } + else + mpeg3video_ditherframe444(video, src); + } + else + { + if((video->pict_struct == FRAME_PICTURE && video->topfirst) || + video->pict_struct == BOTTOM_FIELD) + { +/* top field first */ + if(video->chroma_format != CHROMA444) + { + mpeg3video_dithertop(video, src); + mpeg3video_ditherbot(video, src); + } + else + { + mpeg3video_dithertop444(video, src); + mpeg3video_ditherbot444(video, src); + } + } + else + { +/* bottom field first */ + if(video->chroma_format != CHROMA444) + { + mpeg3video_ditherbot(video, src); + mpeg3video_dithertop(video, src); + } + else + { + mpeg3video_ditherbot444(video, src); + mpeg3video_dithertop444(video, src); + } + } + } + return 0; +} + +int mpeg3video_display_second_field(mpeg3video_t *video) +{ +/* Not used */ + return 0; +} diff --git a/core/multimedia/opieplayer/libmpeg3/video/reconmmx.s b/core/multimedia/opieplayer/libmpeg3/video/reconmmx.s new file mode 100644 index 0000000..1bb98ef --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/reconmmx.s @@ -0,0 +1,301 @@ +ADD_1: dd 01010101h, 01010101h +MASK_AND: dd 7f7f7f7fh, 7f7f7f7fh +PLUS_384: dd 01800180h, 01800180h +PLUS_128: dd 00800080h, 00800080h + +%assign LocalFrameSize 0 +%assign RegisterStorageSize 16 + +; Arguments: +%assign source LocalFrameSize + RegisterStorageSize + 4 +%assign dest LocalFrameSize + RegisterStorageSize + 8 +%assign lx2 LocalFrameSize + RegisterStorageSize + 12 +%assign h LocalFrameSize + RegisterStorageSize + 16 + +; Locals (on local stack frame) + + +; extern void C rec_mmx ( +; unsigned char *source, +; unsigned char *dest, +; int lx2, +; int h +; +; The local variables are on the stack, +; + +global recva_mmx +global recvac_mmx +global rech_mmx +global rechc_mmx +global add_block_mmx +global set_block_mmx + + + align 16 +rech_mmx: + push esi + push edi + push ecx + push ebx + mov esi, [esp+source] + mov edi, [esp+dest] + mov ecx, [esp+h] + mov ebx, [esp+lx2] + movq mm5, [MASK_AND] + movq mm6, [ADD_1] +.rech1: + movq mm0,[esi] + movq mm1,[esi+1] + movq mm2,[esi+8] + movq mm3,[esi+9] + psrlw mm0,1 + psrlw mm1,1 + psrlw mm2,1 + psrlw mm3,1 + pand mm0,mm5 + pand mm1,mm5 + pand mm2,mm5 + pand mm3,mm5 + paddusb mm0,mm1 + paddusb mm2,mm3 + paddusb mm0,mm6 + paddusb mm2,mm6 + movq [edi],mm0 + add esi,ebx + movq [edi+8],mm2 + add edi,ebx + dec ecx + jnz .rech1 + emms + pop ebx + pop ecx + pop edi + pop esi + ret + + align 16 +rechc_mmx: + push esi + push edi + push ecx + push ebx +; sub esp, LocalFrameSize + mov esi, [esp+source] + mov edi, [esp+dest] + mov ecx, [esp+h] + mov ebx, [esp+lx2] + movq mm5, [MASK_AND] + movq mm6, [ADD_1] +.rechc1: + movq mm0,[esi] + movq mm1,[esi+1] + psrlw mm0,1 + psrlw mm1,1 + pand mm0,mm5 + pand mm1,mm5 + paddusb mm0,mm1 + paddusb mm0,mm6 + movq [edi],mm0 + add edi,ebx + add esi,ebx + dec ecx + jnz .rechc1 + emms +; add esp, LocalFrameSize + pop ebx + pop ecx + pop edi + pop esi + ret + + + +%assign RegisterStorageSize 20 +%assign source LocalFrameSize + RegisterStorageSize + 4 +%assign dest LocalFrameSize + RegisterStorageSize + 8 +%assign lx LocalFrameSize + RegisterStorageSize + 12 +%assign lx2 LocalFrameSize + RegisterStorageSize + 16 +%assign h LocalFrameSize + RegisterStorageSize + 20 + + align 16 +recva_mmx: + push esi + push edi + push ecx + push ebx + push edx + mov esi, [esp+source] + mov edi, [esp+dest] + mov ecx, [esp+h] + mov ebx, [esp+lx2] + mov edx, [esp+lx] + movq mm7, [MASK_AND] + movq mm6, [ADD_1] +.recva1: + movq mm0,[esi] + movq mm1,[esi+edx] + movq mm2,[esi+8] + movq mm3,[esi+edx+8] + movq mm4,[edi] + movq mm5,[edi+8] + psrlw mm0,1 + psrlw mm1,1 + psrlw mm2,1 + psrlw mm3,1 + psrlw mm4,1 + psrlw mm5,1 + pand mm0,mm7 + pand mm1,mm7 + pand mm2,mm7 + pand mm3,mm7 + pand mm4,mm7 + pand mm5,mm7 + paddusb mm0,mm1 + paddusb mm2,mm3 + paddusb mm0,mm6 + paddusb mm2,mm6 + psrlw mm0,1 + psrlw mm2,1 + pand mm0,mm7 + pand mm2,mm7 + paddusb mm4,mm0 + paddusb mm5,mm2 + paddusb mm4,mm6 + paddusb mm5,mm6 + movq [edi],mm4 + movq [edi+8],mm5 + add edi,ebx + add esi,ebx + dec ecx + jnz near .recva1 + emms + pop edx + pop ebx + pop ecx + pop edi + pop esi + ret + + align 16 +recvac_mmx: + push esi + push edi + push ecx + push ebx + push edx + mov esi, [esp+source] + mov edi, [esp+dest] + mov ecx, [esp+h] + mov ebx, [esp+lx2] + mov edx, [esp+lx] + movq mm5, [MASK_AND] + movq mm6, [ADD_1] +.recvac1: + movq mm0,[esi] + movq mm1,[esi+edx] + movq mm4,[edi] + psrlw mm0,1 + psrlw mm1,1 + psrlw mm4,1 + pand mm0,mm5 + pand mm1,mm5 + pand mm4,mm5 + paddusb mm0,mm1 + paddusb mm0,mm6 + psrlw mm0,1 + pand mm0,mm5 + paddusb mm4,mm0 + paddusb mm4,mm6 + movq [edi],mm4 + add edi,ebx + add esi,ebx + dec ecx + jnz .recvac1 + emms + pop edx + pop ebx + pop ecx + pop edi + pop esi + ret + +%assign RegisterStorageSize 20 +%assign rfp LocalFrameSize + RegisterStorageSize + 4 +%assign bp LocalFrameSize + RegisterStorageSize + 8 +%assign iincr LocalFrameSize + RegisterStorageSize + 12 + +; FIXME clipping needs to be done + + align 16 +add_block_mmx: + push esi + push edi + push ecx + push ebx + push edx + mov esi, [esp+bp] + mov edi, [esp+rfp] + mov ebx, [esp+iincr] +; movq mm7, [PLUS_384] + mov ecx,8 + pxor mm2,mm2 ; clear +%rep 8 + movq mm0, [edi] ; get dest + movq mm1,mm0 + punpcklbw mm0,mm2 + punpckhbw mm1,mm2 + paddsw mm0, [esi] + paddsw mm1, [esi+8] +; paddsw mm0, mm7 +; paddsw mm1, mm7 + packuswb mm0,mm1 + movq [edi], mm0 + add edi,ebx + add esi,16 +%endrep + emms + pop edx + pop ebx + pop ecx + pop edi + pop esi + ret + + align 16 +set_block_mmx: + push esi + push edi + push ecx + push ebx + push edx + mov esi, [esp+bp] + mov edi, [esp+rfp] + mov ebx, [esp+iincr] + movq mm7, [PLUS_128] +%rep 4 + movq mm0, [esi] + movq mm1, [esi+8] + paddsw mm0, mm7 + movq mm2, [esi+16] + paddsw mm1, mm7 + movq mm3, [esi+24] + paddsw mm2, mm7 + packuswb mm0, mm1 + paddsw mm3, mm7 + movq [edi], mm0 + packuswb mm2, mm3 + add edi, ebx + add esi, 32 + movq [edi], mm2 + add edi, ebx +%endrep + emms + pop edx + pop ebx + pop ecx + pop edi + pop esi + ret + + diff --git a/core/multimedia/opieplayer/libmpeg3/video/reconstruct.c b/core/multimedia/opieplayer/libmpeg3/video/reconstruct.c new file mode 100644 index 0000000..531f9c0 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/reconstruct.c @@ -0,0 +1,1290 @@ +#include "../libmpeg3.h" +#include "../mpeg3protos.h" +#include "mpeg3video.h" +#include <stdio.h> + +#ifdef HAVE_MMX + +#ifdef HAVE_3Dnow +static inline void recva_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h) +{ + __asm__( + ".align 8\n" + "1:" + "movq (%1), %%mm0\n" /* 8 s */ + "movq 8(%1), %%mm1\n" /* 8 s */ + "movq (%4), %%mm2\n" /* 8 s +lx */ + "movq 8(%4), %%mm3\n" /* 8 s +lx **/ + + "pavgusb %%mm2, %%mm0\n" + "addl %3, %1\n" + "pavgusb %%mm3, %%mm1\n" + + "movq (%2), %%mm2\n" /* 8 d */ + "movq 8(%2), %%mm3\n" /* 8 d */ + "pavgusb %%mm2, %%mm0\n" + "addl %3, %4\n" + "pavgusb %%mm3, %%mm1\n" + + "movq %%mm0, (%2)\n" + "movq %%mm1, 8(%2)\n" + "addl %3, %2\n" + "loop 1b\n" + : + : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx) + ); +} + +static inline void recvac_mmx(unsigned char *s, unsigned char *d, int lx,int lx2, int h) +{ + __asm__( + ".align 8\n" + "1:" + "movq (%1), %%mm0\n" /* 8 s */ + "movq (%4), %%mm2\n" /* 8 s +lx */ + "addl %3, %1\n" + "pavgusb %%mm2, %%mm0\n" + "movq (%2), %%mm3\n" /* 8 d */ + "addl %3, %4\n" + "pavgusb %%mm3, %%mm0\n" + "movq %%mm0, (%2)\n" + "addl %3, %2\n" + "loop 1b\n" + : + : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx) + ); +} + +static inline void rech_mmx(unsigned char *s, unsigned char *d, int lx2, int h) +{ + __asm__ ( + ".align 8\n" + "1:" + "movq (%1), %%mm0\n" /* 8 s */ + "movq 8(%1), %%mm1\n" /* 8 s */ + "movq 1(%1), %%mm2\n" /* 8 s */ + "movq 9(%1), %%mm3\n" /* 8 s */ + + "pavgusb %%mm2, %%mm0\n" + "addl %3, %1\n" + "pavgusb %%mm3, %%mm1\n" + + "movq %%mm0, (%2)\n" + "movq %%mm1, 8(%2)\n" + "addl %3, %2\n" + "loop 1b\n" + : + : "c" (h), "r" (s), "r" (d), "r" (lx2) + ); +} + +static inline void rechc_mmx(unsigned char *s, unsigned char *d, int lx2, int h) +{ + __asm__ ( + ".align 8\n" + "1:" + "movq (%1), %%mm0\n" /* 8 s */ + "movq 1(%1), %%mm2\n" /* 8 s +1 */ + "addl %3, %1\n" + "pavgusb %%mm2, %%mm0\n" + "movq %%mm0, (%2)\n" + "addl %3, %2\n" + "loop 1b\n" + : + : "c" (h), "r" (s), "r" (d), "r" (lx2) + ); +} + +static inline void recha_mmx(unsigned char *s, unsigned char *d,int lx2, int h) +{ + __asm__ ( + ".align 8\n" + "1:" + "movq (%1), %%mm0\n" /* 8 s */ + "movq 8(%1), %%mm1\n" /* 8 s */ + "movq 1(%1), %%mm2\n" /* 8 s */ + "movq 9(%1), %%mm3\n" /* 8 s */ + + "pavgusb %%mm2, %%mm0\n" + "addl %3, %1\n" + "pavgusb %%mm3, %%mm1\n" + + "movq (%2), %%mm2\n" /* 8 d */ + "movq 8(%2), %%mm3\n" /* 8 d */ + "pavgusb %%mm2, %%mm0\n" + "pavgusb %%mm3, %%mm1\n" + + "movq %%mm0, (%2)\n" + "movq %%mm1, 8(%2)\n" + "addl %3, %2\n" + "loop 1b\n" + : + : "c" (h), "r" (s), "r" (d), "r" (lx2) + ); +} + +static inline void rechac_mmx(unsigned char *s,unsigned char *d, int lx2, int h) +{ + __asm__ ( + ".align 8\n" + "1:" + "movq (%1), %%mm0\n" /* 8 s */ + "movq 1(%1), %%mm2\n" /* 8 s */ + + "addl %3, %1\n" + "pavgusb %%mm2, %%mm0\n" + + "movq (%2), %%mm1\n" /* 8 d */ + "pavgusb %%mm1, %%mm0\n" + + "movq %%mm0, (%2)\n" + "addl %3, %2\n" + "loop 1b\n" + : + : "c" (h), "r" (s), "r" (d), "r" (lx2) + ); +} + +static inline void rec4_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h) +{ + __asm__ __volatile__( + "movq (%1), %%mm0\n" /* 8 s */ + "movq 8(%1), %%mm1\n" /* 8 s */ + "movq 1(%1), %%mm2\n" /* 8 s +1*/ + "movq 9(%1), %%mm3\n" /* 8 s +1*/ + ".align 8\n" + "1:" + "movq (%4), %%mm4\n" /* 8 s+lx */ + "pavgusb %%mm2, %%mm0\n" + "movq 8(%4), %%mm5\n" /* 8 s+lx */ + "pavgusb %%mm3, %%mm1\n" + + "movq 1(%4), %%mm6\n" /* 8 s+lx +1*/ + "pavgusb %%mm4, %%mm0\n" + "movq 9(%4), %%mm7\n" /* 8 s+lx +1*/ + "pavgusb %%mm5, %%mm1\n" + + "pavgusb %%mm6, %%mm0\n" + "addl %3, %4\n" + "pavgusb %%mm7, %%mm1\n" + "movq %%mm0, (%2)\n" + "movq %%mm6, %%mm2\n" + "movq %%mm7, %%mm3\n" + "movq %%mm1, 8(%2)\n" + "movq %%mm4, %%mm0\n" + "movq %%mm5, %%mm1\n" + "addl %3, %2\n" + "loop 1b\n" + : + : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx) + ); +} + +static inline void rec4c_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h) +{ + __asm__ __volatile__( + "movq (%1), %%mm0\n" /* 8 s */ + "movq 1(%1), %%mm2\n" /* 8 s +1*/ + ".align 8\n" + "1:" + "movq (%4), %%mm4\n" /* 8 s+lx */ + "pavgusb %%mm2, %%mm0\n" + + "movq 1(%4), %%mm6\n" /* 8 s+lx +1*/ + "pavgusb %%mm4, %%mm0\n" + + "addl %3, %4\n" + "pavgusb %%mm6, %%mm0\n" + "movq %%mm0, (%2)\n" + "movq %%mm6, %%mm2\n" + "movq %%mm4, %%mm0\n" + "addl %3, %2\n" + "loop 1b\n" + : + : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx) + ); +} + +static inline void rec4a_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h) +{ + __asm__ __volatile__( + "movq (%1), %%mm0\n" /* 8 s */ + "movq 8(%1), %%mm1\n" /* 8 s */ + "movq 1(%1), %%mm2\n" /* 8 s +1*/ + "movq 9(%1), %%mm3\n" /* 8 s +1*/ + ".align 8\n" + "1:" + "movq (%4), %%mm4\n" /* 8 s+lx */ + "pavgusb %%mm2, %%mm0\n" + "movq 8(%4), %%mm5\n" /* 8 s+lx */ + "pavgusb %%mm3, %%mm1\n" + + "movq 1(%4), %%mm6\n" /* 8 s+lx +1*/ + "pavgusb %%mm4, %%mm0\n" + "movq 9(%4), %%mm7\n" /* 8 s+lx +1*/ + "pavgusb %%mm5, %%mm1\n" + "movq (%2), %%mm2\n" + "pavgusb %%mm6, %%mm0\n" + "movq 8(%2), %%mm3\n" + + "pavgusb %%mm2, %%mm0\n" + "addl %3, %4\n" + "pavgusb %%mm3, %%mm1\n" + "movq %%mm0, (%2)\n" + + "pavgusb %%mm7, %%mm1\n" + "movq %%mm6, %%mm2\n" + "movq %%mm7, %%mm3\n" + "movq %%mm1, 8(%2)\n" + "movq %%mm4, %%mm0\n" + "movq %%mm5, %%mm1\n" + "addl %3, %2\n" + "loop 1b\n" + : + : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx) + ); +} + +static inline void rec4ac_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h) +{ + __asm__ __volatile__( + "movq (%1), %%mm0\n" /* 8 s */ + "movq 1(%1), %%mm2\n" /* 8 s +1*/ + ".align 8\n" + "1:" + "movq (%4), %%mm4\n" /* 8 s+lx */ + "pavgusb %%mm2, %%mm0\n" + + "movq 1(%4), %%mm6\n" /* 8 s+lx +1*/ + "pavgusb %%mm4, %%mm0\n" + "movq (%2), %%mm1\n" /* 8 d */ + "pavgusb %%mm6, %%mm0\n" + "addl %3, %4\n" + "pavgusb %%mm1, %%mm0\n" + "movq %%mm6, %%mm2\n" + "movq %%mm0, (%2)\n" + "movq %%mm4, %%mm0\n" + "addl %3, %2\n" + "loop 1b\n" + : + : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx) + ); +} + +#else // HAVE_3DNOW + static LONGLONG ADD_1 = 0x0101010101010101LL; + static LONGLONG MASK_AND = 0x7f7f7f7f7f7f7f7fLL; +#endif + +static inline void rec_mmx(unsigned char *s, unsigned char *d, int lx2, int h) +{ + __asm__ __volatile__( + ".align 8\n" + "1:\t" + "movq ( %1 ), %%mm0\n" /* 8 s */ + "movq 8( %1 ), %%mm2\n" /* 16 s */ + "movq %%mm0, ( %2 )\n" + "addl %3, %1\n" + "movq %%mm2, 8( %2 )\n" + "decl %0\n" + "leal (%2, %3), %2\n" + "jnz 1b" + : + : "c" (h), "r" (s), "r" (d), "r" (lx2) + ); +} + + +static inline void recc_mmx(unsigned char *s, unsigned char *d, int lx2, int h) +{ + __asm__ __volatile__( + ".align 8\n" + "1:\t" + "movq ( %1 ), %%mm0\n" + "addl %3, %1\n" + "movq %%mm0, ( %2 )\n" + "decl %0\n" + "leal (%2, %3), %2\n" + "jnz 1b" + : + : "c" (h), "r" (s), "r" (d), "r" (lx2) + ); +} + + +static inline void reca_mmx(unsigned char *s, unsigned char *d, int lx2, int h) +{ +#ifdef HAVE_3Dnow + __asm__ ( + ".align 8\n" + "1:" + "movq (%1), %%mm0\n" /* 8 s */ + "movq (%2), %%mm2\n" /* 8 d */ + "movq 8(%1), %%mm1\n" /* 8 s */ + "movq 8(%2), %%mm3\n" /* 8 d */ + "pavgusb %%mm2, %%mm0\n" + "addl %3, %1\n" + "pavgusb %%mm3, %%mm1\n" + + "movq %%mm0, (%2)\n" + "movq %%mm1, 8(%2)\n" + "addl %3, %2\n" + "loop 1b\n" + : + : "c" (h), "r" (s), "r" (d), "r" (lx2) + ); +#else /* No 3dnow */ + __asm__ ( + "movq MASK_AND, %%mm5\n" + "movq ADD_1, %%mm6\n" + "1:\t" + "movq (%1),%%mm0\n" /* Load 16 pixels from each row */ + "movq (%2),%%mm1\n" + "movq 8(%1),%%mm2\n" + "movq 8(%2),%%mm3\n" + "psrlw $1,%%mm0\n" /* Shift pixels down */ + "psrlw $1,%%mm1\n" + "pand %%mm5,%%mm0\n" /* Zero out significant bit */ + "psrlw $1,%%mm2\n" + "pand %%mm5,%%mm1\n" + "psrlw $1,%%mm3\n" + "pand %%mm5,%%mm2\n" + "paddusb %%mm1,%%mm0\n" /* Add pixels */ + "pand %%mm5,%%mm3\n" + "paddusb %%mm3,%%mm2\n" + "paddusb %%mm6,%%mm0\n" /* Add 1 to results */ + "paddusb %%mm6,%%mm2\n" + "movq %%mm0,(%2)\n" + "addl %3,%1\n" + "movq %%mm2, 8(%2)\n" + "decl %0\n" + "leal (%2, %3), %2\n" + "jnz 1b\n" + : + : "c" (h), "r" (s), "r" (d), "r" (lx2) + ); +#endif +} + + +static inline void recac_mmx(unsigned char *s, unsigned char *d, int lx2, int h) +{ +#ifdef HAVE_3Dnow + __asm__ ( + ".align 8\n" + "1:" + "movq (%1), %%mm0\n" /* 8 s */ + "movq (%2), %%mm2\n" /* 8 d */ + "pavgusb %%mm2, %%mm0\n" + "addl %3, %1\n" + "movq %%mm0, (%2)\n" + "addl %3, %2\n" + "loop 1b\n" + : + : "c" (h), "r" (s), "r" (d), "r" (lx2) + ); +#else /* No 3dnow */ + __asm__ ( + "movq MASK_AND, %%mm5\n" + "movq ADD_1, %%mm6\n" + "1:\t" + "movq (%1),%%mm0\n" + "movq (%2),%%mm1\n" + "psrlw $1,%%mm0\n" + "psrlw $1,%%mm1\n" + "pand %%mm5,%%mm0\n" + "pand %%mm5,%%mm1\n" + "paddusb %%mm1,%%mm0\n" + "paddusb %%mm6,%%mm0\n" + "addl %3,%1\n" + "movq %%mm0,(%2)\n" + "decl %0\n" + "leal (%2, %3), %2\n" + "jnz 1b\n" + : + : "c" (h), "r" (s), "r" (d), "r" (lx2) + ); +#endif +} + + +static inline void recv_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h) +{ +#ifdef HAVE_3Dnow + __asm__( + ".align 8\n" + "1:" + "movq (%1), %%mm0\n" /* 8 s */ + "movq (%4), %%mm2\n" /* 8 s +lx */ + "movq 8(%1), %%mm1\n" /* 8 s */ + "movq 8(%4), %%mm3\n" /* 8 s +lx **/ + + "pavgusb %%mm2, %%mm0\n" + "addl %3, %1\n" + "pavgusb %%mm3, %%mm1\n" + + "movq %%mm0, (%2)\n" + "addl %3, %4\n" + "movq %%mm1, 8(%2)\n" + "addl %3, %2\n" + "loop 1b\n" + : + : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx) + ); +#else + __asm__ ( + "movq MASK_AND, %%mm5\n" + "movq ADD_1, %%mm6\n" + "1:\t" + "movq (%1), %%mm0\n" /* 8 s */ + "movq (%4), %%mm1\n" /* 8 s +lx */ + "movq 8(%1), %%mm2\n" /* 8 s */ + "movq 8(%4), %%mm3\n" /* 8 s +lx **/ + "psrlw $1,%%mm0\n" + "psrlw $1,%%mm1\n" + "pand %%mm5,%%mm0\n" + "psrlw $1,%%mm2\n" + "pand %%mm5,%%mm1\n" + "psrlw $1,%%mm3\n" + "pand %%mm5,%%mm2\n" + "paddusb %%mm1,%%mm0\n" + "pand %%mm5,%%mm3\n" + "paddusb %%mm3,%%mm2\n" + "paddusb %%mm6,%%mm0\n" + "paddusb %%mm6,%%mm2\n" + "movq %%mm0,(%2)\n" + "addl %3,%1\n" + "movq %%mm2, 8(%2)\n" + "addl %3,%4\n" + "decl %0\n" + "leal (%2, %3), %2\n" + "jnz 1b\n" + : + : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx) + ); +#endif +} + + +static inline void recvc_mmx(unsigned char *s, unsigned char *d, int lx, int lx2, int h) +{ +#ifdef HAVE_3Dnow + __asm__( + ".align 8\n" + "1:" + "movq (%1), %%mm0\n" /* 8 s */ + "movq (%4), %%mm2\n" /* 8 s +lx */ + "addl %3, %1\n" + "pavgusb %%mm2, %%mm0\n" + "addl %3, %4\n" + "movq %%mm0, (%2)\n" + "addl %3, %2\n" + "loop 1b\n" + : + : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx) + ); +#else + __asm__ ( + "movq MASK_AND, %%mm5\n" + "movq ADD_1, %%mm6\n" + "1:\t" + "movq (%1), %%mm0\n" /* 8 s */ + "movq (%4), %%mm1\n" /* 8 s +lx */ + "psrlw $1,%%mm0\n" + "psrlw $1,%%mm1\n" + "pand %%mm5,%%mm0\n" + "pand %%mm5,%%mm1\n" + "paddusb %%mm1,%%mm0\n" + "addl %3,%1\n" + "paddusb %%mm6,%%mm0\n" + "addl %3,%4\n" + "movq %%mm0,(%2)\n" + "decl %0\n" + "leal (%2, %3), %2\n" + "jnz 1b\n" + : + : "c" (h), "r" (s), "r" (d), "r" (lx2), "r" (s +lx) + ); +#endif +} + +#endif // HAVE_MMX + +static inline void rec(unsigned char *s, unsigned char *d, int lx2, int h) +{ + int j; + for(j = 0; j < h; j++, s += lx2, d += lx2) + { + d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; d[3] = s[3]; + d[4] = s[4]; d[5] = s[5]; d[6] = s[6]; d[7] = s[7]; + d[8] = s[8]; d[9] = s[9]; d[10] = s[10]; d[11] = s[11]; + d[12] = s[12]; d[13] = s[13]; d[14] = s[14]; d[15] = s[15]; + } +} + + + +static inline void recc(unsigned char *s, unsigned char *d, int lx2, int h) +{ + int j; + for(j = 0; j < h; j++, s += lx2, d += lx2) + { + d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; d[3] = s[3]; + d[4] = s[4]; d[5] = s[5]; d[6] = s[6]; d[7] = s[7]; + } +} + +static inline void reca(unsigned char *s, unsigned char *d, int lx2, int h) +{ + int j; + for(j = 0; j < h; j++, s +=lx2, d +=lx2) + { + d[0] = (unsigned int)(d[0] + s[0] + 1) >> 1; + d[1] = (unsigned int)(d[1] + s[1] + 1) >> 1; + d[2] = (unsigned int)(d[2] + s[2] + 1) >> 1; + d[3] = (unsigned int)(d[3] + s[3] + 1) >> 1; + d[4] = (unsigned int)(d[4] + s[4] + 1) >> 1; + d[5] = (unsigned int)(d[5] + s[5] + 1) >> 1; + d[6] = (unsigned int)(d[6] + s[6] + 1) >> 1; + d[7] = (unsigned int)(d[7] + s[7] + 1) >> 1; + d[8] = (unsigned int)(d[8] + s[8] + 1) >> 1; + d[9] = (unsigned int)(d[9] + s[9] + 1) >> 1; + d[10] = (unsigned int)(d[10] + s[10] + 1) >> 1; + d[11] = (unsigned int)(d[11] + s[11] + 1) >> 1; + d[12] = (unsigned int)(d[12] + s[12] + 1) >> 1; + d[13] = (unsigned int)(d[13] + s[13] + 1) >> 1; + d[14] = (unsigned int)(d[14] + s[14] + 1) >> 1; + d[15] = (unsigned int)(d[15] + s[15] + 1) >> 1; + } +} + +static inline void recac(unsigned char *s, unsigned char *d, int lx2, int h) +{ + int j; + for(j = 0; j < h; j++, s += lx2, d += lx2) + { + d[0] = (unsigned int)(d[0] + s[0] + 1)>>1; + d[1] = (unsigned int)(d[1] + s[1] + 1)>>1; + d[2] = (unsigned int)(d[2] + s[2] + 1)>>1; + d[3] = (unsigned int)(d[3] + s[3] + 1)>>1; + d[4] = (unsigned int)(d[4] + s[4] + 1)>>1; + d[5] = (unsigned int)(d[5] + s[5] + 1)>>1; + d[6] = (unsigned int)(d[6] + s[6] + 1)>>1; + d[7] = (unsigned int)(d[7] + s[7] + 1)>>1; + } +} + +static inline void recv_(unsigned char *s, unsigned char *d, int lx, int lx2, int h) +{ + unsigned char *dp,*sp,*sp2; + int j; + sp = s; + sp2 = s + lx; + dp = d; + for(j = 0; j < h; j++) + { + dp[0] = (unsigned int)(sp[0] + sp2[0] + 1) >> 1; + dp[1] = (unsigned int)(sp[1] + sp2[1] + 1) >> 1; + dp[2] = (unsigned int)(sp[2] + sp2[2] + 1) >> 1; + dp[3] = (unsigned int)(sp[3] + sp2[3] + 1) >> 1; + dp[4] = (unsigned int)(sp[4] + sp2[4] + 1) >> 1; + dp[5] = (unsigned int)(sp[5] + sp2[5] + 1) >> 1; + dp[6] = (unsigned int)(sp[6] + sp2[6] + 1) >> 1; + dp[7] = (unsigned int)(sp[7] + sp2[7] + 1) >> 1; + dp[8] = (unsigned int)(sp[8] + sp2[8] + 1) >> 1; + dp[9] = (unsigned int)(sp[9] + sp2[9] + 1) >> 1; + dp[10] = (unsigned int)(sp[10] + sp2[10] + 1) >> 1; + dp[11] = (unsigned int)(sp[11] + sp2[11] + 1) >> 1; + dp[12] = (unsigned int)(sp[12] + sp2[12] + 1) >> 1; + dp[13] = (unsigned int)(sp[13] + sp2[13] + 1) >> 1; + dp[14] = (unsigned int)(sp[14] + sp2[14] + 1) >> 1; + dp[15] = (unsigned int)(sp[15] + sp2[15] + 1) >> 1; + sp+= lx2; + sp2+= lx2; + dp+= lx2; + } +} + +static inline void recvc(unsigned char *s, unsigned char *d, int lx, int lx2, int h) +{ + unsigned char *dp,*sp,*sp2; + int j; + + sp = s; + sp2 = s+lx; + dp = d; + for(j = 0; j < h; j++) + { + dp[0] = (unsigned int)(sp[0]+sp2[0]+1)>>1; + dp[1] = (unsigned int)(sp[1]+sp2[1]+1)>>1; + dp[2] = (unsigned int)(sp[2]+sp2[2]+1)>>1; + dp[3] = (unsigned int)(sp[3]+sp2[3]+1)>>1; + dp[4] = (unsigned int)(sp[4]+sp2[4]+1)>>1; + dp[5] = (unsigned int)(sp[5]+sp2[5]+1)>>1; + dp[6] = (unsigned int)(sp[6]+sp2[6]+1)>>1; + dp[7] = (unsigned int)(sp[7]+sp2[7]+1)>>1; + sp+= lx2; + sp2+= lx2; + dp+= lx2; + } +} + + +static inline void recva(unsigned char *s, unsigned char *d, int lx, int lx2, int h) +{ + unsigned char *dp,*sp,*sp2; + int j; + + sp = s; + sp2 = s+lx; + dp = d; + for (j=0; j<h; j++){ + dp[0] = (dp[0] + ((unsigned int)(sp[0]+sp2[0]+1)>>1) + 1)>>1; + dp[1] = (dp[1] + ((unsigned int)(sp[1]+sp2[1]+1)>>1) + 1)>>1; + dp[2] = (dp[2] + ((unsigned int)(sp[2]+sp2[2]+1)>>1) + 1)>>1; + dp[3] = (dp[3] + ((unsigned int)(sp[3]+sp2[3]+1)>>1) + 1)>>1; + dp[4] = (dp[4] + ((unsigned int)(sp[4]+sp2[4]+1)>>1) + 1)>>1; + dp[5] = (dp[5] + ((unsigned int)(sp[5]+sp2[5]+1)>>1) + 1)>>1; + dp[6] = (dp[6] + ((unsigned int)(sp[6]+sp2[6]+1)>>1) + 1)>>1; + dp[7] = (dp[7] + ((unsigned int)(sp[7]+sp2[7]+1)>>1) + 1)>>1; + dp[8] = (dp[8] + ((unsigned int)(sp[8]+sp2[8]+1)>>1) + 1)>>1; + dp[9] = (dp[9] + ((unsigned int)(sp[9]+sp2[9]+1)>>1) + 1)>>1; + dp[10] = (dp[10] + ((unsigned int)(sp[10]+sp2[10]+1)>>1) + 1)>>1; + dp[11] = (dp[11] + ((unsigned int)(sp[11]+sp2[11]+1)>>1) + 1)>>1; + dp[12] = (dp[12] + ((unsigned int)(sp[12]+sp2[12]+1)>>1) + 1)>>1; + dp[13] = (dp[13] + ((unsigned int)(sp[13]+sp2[13]+1)>>1) + 1)>>1; + dp[14] = (dp[14] + ((unsigned int)(sp[14]+sp2[14]+1)>>1) + 1)>>1; + dp[15] = (dp[15] + ((unsigned int)(sp[15]+sp2[15]+1)>>1) + 1)>>1; + sp+= lx2; + sp2+= lx2; + dp+= lx2; + } +} + + +static inline void recvac(unsigned char *s, unsigned char *d, int lx,int lx2, int h){ + unsigned char *dp,*sp,*sp2; + int j; + + sp = s; + sp2 = s+lx; + dp = d; + for (j=0; j<h; j++){ + dp[0] = (dp[0] + ((unsigned int)(sp[0]+sp2[0]+1)>>1) + 1)>>1; + dp[1] = (dp[1] + ((unsigned int)(sp[1]+sp2[1]+1)>>1) + 1)>>1; + dp[2] = (dp[2] + ((unsigned int)(sp[2]+sp2[2]+1)>>1) + 1)>>1; + dp[3] = (dp[3] + ((unsigned int)(sp[3]+sp2[3]+1)>>1) + 1)>>1; + dp[4] = (dp[4] + ((unsigned int)(sp[4]+sp2[4]+1)>>1) + 1)>>1; + dp[5] = (dp[5] + ((unsigned int)(sp[5]+sp2[5]+1)>>1) + 1)>>1; + dp[6] = (dp[6] + ((unsigned int)(sp[6]+sp2[6]+1)>>1) + 1)>>1; + dp[7] = (dp[7] + ((unsigned int)(sp[7]+sp2[7]+1)>>1) + 1)>>1; + sp+= lx2; + sp2+= lx2; + dp+= lx2; + } +} + + +static inline void rech(unsigned char *s, unsigned char *d, int lx2, int h){ + unsigned char *dp,*sp; + unsigned int s1,s2; + int j; + + sp = s; + dp = d; + for (j=0; j<h; j++){ + s1=sp[0]; + dp[0] = (unsigned int)(s1+(s2=sp[1])+1)>>1; + dp[1] = (unsigned int)(s2+(s1=sp[2])+1)>>1; + dp[2] = (unsigned int)(s1+(s2=sp[3])+1)>>1; + dp[3] = (unsigned int)(s2+(s1=sp[4])+1)>>1; + dp[4] = (unsigned int)(s1+(s2=sp[5])+1)>>1; + dp[5] = (unsigned int)(s2+(s1=sp[6])+1)>>1; + dp[6] = (unsigned int)(s1+(s2=sp[7])+1)>>1; + dp[7] = (unsigned int)(s2+(s1=sp[8])+1)>>1; + dp[8] = (unsigned int)(s1+(s2=sp[9])+1)>>1; + dp[9] = (unsigned int)(s2+(s1=sp[10])+1)>>1; + dp[10] = (unsigned int)(s1+(s2=sp[11])+1)>>1; + dp[11] = (unsigned int)(s2+(s1=sp[12])+1)>>1; + dp[12] = (unsigned int)(s1+(s2=sp[13])+1)>>1; + dp[13] = (unsigned int)(s2+(s1=sp[14])+1)>>1; + dp[14] = (unsigned int)(s1+(s2=sp[15])+1)>>1; + dp[15] = (unsigned int)(s2+sp[16]+1)>>1; + sp+= lx2; + dp+= lx2; + } +} + + +static inline void rechc(unsigned char *s,unsigned char *d, int lx2, int h){ + unsigned char *dp,*sp; + unsigned int s1,s2; + int j; + + sp = s; + dp = d; + for (j=0; j<h; j++){ + s1=sp[0]; + dp[0] = (unsigned int)(s1+(s2=sp[1])+1)>>1; + dp[1] = (unsigned int)(s2+(s1=sp[2])+1)>>1; + dp[2] = (unsigned int)(s1+(s2=sp[3])+1)>>1; + dp[3] = (unsigned int)(s2+(s1=sp[4])+1)>>1; + dp[4] = (unsigned int)(s1+(s2=sp[5])+1)>>1; + dp[5] = (unsigned int)(s2+(s1=sp[6])+1)>>1; + dp[6] = (unsigned int)(s1+(s2=sp[7])+1)>>1; + dp[7] = (unsigned int)(s2+sp[8]+1)>>1; + sp+= lx2; + dp+= lx2; + } +} + +static inline void recha(unsigned char *s, unsigned char *d,int lx2, int h) +{ + unsigned char *dp,*sp; + unsigned int s1,s2; + int j; + + sp = s; + dp = d; + for (j = 0; j < h; j++) + { + s1 = sp[0]; + dp[0] = (dp[0] + ((unsigned int)(s1 + (s2 = sp[1]) + 1) >> 1) + 1) >> 1; + dp[1] = (dp[1] + ((unsigned int)(s2 + (s1 = sp[2]) + 1) >> 1) + 1) >> 1; + dp[2] = (dp[2] + ((unsigned int)(s1 + (s2 = sp[3]) + 1) >> 1) + 1) >> 1; + dp[3] = (dp[3] + ((unsigned int)(s2 + (s1 = sp[4]) + 1) >> 1) + 1) >> 1; + dp[4] = (dp[4] + ((unsigned int)(s1 + (s2 = sp[5]) + 1) >> 1) + 1) >> 1; + dp[5] = (dp[5] + ((unsigned int)(s2 + (s1 = sp[6]) + 1) >> 1) + 1) >> 1; + dp[6] = (dp[6] + ((unsigned int)(s1 + (s2 = sp[7]) + 1) >> 1) + 1) >> 1; + dp[7] = (dp[7] + ((unsigned int)(s2 + (s1 = sp[8]) + 1) >> 1) + 1) >> 1; + dp[8] = (dp[8] + ((unsigned int)(s1 + (s2 = sp[9]) + 1) >> 1) + 1) >> 1; + dp[9] = (dp[9] + ((unsigned int)(s2 + (s1 = sp[10]) + 1) >> 1) + 1) >> 1; + dp[10] = (dp[10] + ((unsigned int)(s1 + (s2 = sp[11]) + 1) >> 1) + 1) >> 1; + dp[11] = (dp[11] + ((unsigned int)(s2 + (s1 = sp[12]) + 1) >> 1) + 1) >> 1; + dp[12] = (dp[12] + ((unsigned int)(s1 + (s2 = sp[13]) + 1) >> 1) + 1) >> 1; + dp[13] = (dp[13] + ((unsigned int)(s2 + (s1 = sp[14]) + 1) >> 1) + 1) >> 1; + dp[14] = (dp[14] + ((unsigned int)(s1 + (s2 = sp[15]) + 1) >> 1) + 1) >> 1; + dp[15] = (dp[15] + ((unsigned int)(s2 + sp[16] + 1) >> 1) + 1) >> 1; + sp += lx2; + dp += lx2; + } +} + + +static inline void rechac(unsigned char *s,unsigned char *d, int lx2, int h) +{ + unsigned char *dp,*sp; + unsigned int s1,s2; + int j; + + sp = s; + dp = d; + for(j = 0; j < h; j++) + { + s1 = sp[0]; + dp[0] = (dp[0] + ((unsigned int)(s1 + (s2 = sp[1]) + 1) >> 1) + 1) >> 1; + dp[1] = (dp[1] + ((unsigned int)(s2 + (s1 = sp[2]) + 1) >> 1) + 1) >> 1; + dp[2] = (dp[2] + ((unsigned int)(s1 + (s2 = sp[3]) + 1) >> 1) + 1) >> 1; + dp[3] = (dp[3] + ((unsigned int)(s2 + (s1 = sp[4]) + 1) >> 1) + 1) >> 1; + dp[4] = (dp[4] + ((unsigned int)(s1 + (s2 = sp[5]) + 1) >> 1) + 1) >> 1; + dp[5] = (dp[5] + ((unsigned int)(s2 + (s1 = sp[6]) + 1) >> 1) + 1) >> 1; + dp[6] = (dp[6] + ((unsigned int)(s1 + (s2 = sp[7]) + 1) >> 1) + 1) >> 1; + dp[7] = (dp[7] + ((unsigned int)(s2 + sp[8] + 1) >> 1) + 1) >> 1; + sp += lx2; + dp += lx2; + } +} + + +static inline void rec4(unsigned char *s, unsigned char *d, int lx, int lx2, int h) +{ + unsigned char *dp,*sp,*sp2; + unsigned int s1,s2,s3,s4; + int j; + + sp = s; + sp2 = s+lx; + dp = d; + for (j=0; j<h; j++){ + s1=sp[0]; s3=sp2[0]; + dp[0] = (unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2; + dp[1] = (unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2; + dp[2] = (unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2; + dp[3] = (unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2; + dp[4] = (unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2; + dp[5] = (unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2; + dp[6] = (unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2; + dp[7] = (unsigned int)(s2+(s1=sp[8])+s4+(s3=sp2[8])+2)>>2; + dp[8] = (unsigned int)(s1+(s2=sp[9])+s3+(s4=sp2[9])+2)>>2; + dp[9] = (unsigned int)(s2+(s1=sp[10])+s4+(s3=sp2[10])+2)>>2; + dp[10] = (unsigned int)(s1+(s2=sp[11])+s3+(s4=sp2[11])+2)>>2; + dp[11] = (unsigned int)(s2+(s1=sp[12])+s4+(s3=sp2[12])+2)>>2; + dp[12] = (unsigned int)(s1+(s2=sp[13])+s3+(s4=sp2[13])+2)>>2; + dp[13] = (unsigned int)(s2+(s1=sp[14])+s4+(s3=sp2[14])+2)>>2; + dp[14] = (unsigned int)(s1+(s2=sp[15])+s3+(s4=sp2[15])+2)>>2; + dp[15] = (unsigned int)(s2+sp[16]+s4+sp2[16]+2)>>2; + sp+= lx2; + sp2+= lx2; + dp+= lx2; + } +} + + +static inline void rec4c(unsigned char *s,unsigned char *d, int lx, int lx2, int h) +{ + unsigned char *dp,*sp,*sp2; + unsigned int s1,s2,s3,s4; + int j; + + sp = s; + sp2 = s+lx; + dp = d; + for (j=0; j<h; j++){ + s1=sp[0]; s3=sp2[0]; + dp[0] = (unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2; + dp[1] = (unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2; + dp[2] = (unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2; + dp[3] = (unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2; + dp[4] = (unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2; + dp[5] = (unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2; + dp[6] = (unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2; + dp[7] = (unsigned int)(s2+sp[8]+s4+sp2[8]+2)>>2; + sp+= lx2; + sp2+= lx2; + dp+= lx2; + } +} + + +static inline void rec4a(unsigned char *s,unsigned char *d, int lx, int lx2, int h) +{ + unsigned char *dp=d, *sp=s, *sp2=s+lx; + unsigned int s1, s2, s3, s4; + int j; + +/* + sp = s; + sp2 = s+lx; + dp = d; +*/ + for (j=0; j<h; j++){ + s1=sp[0]; s3=sp2[0]; + dp[0] = (dp[0] + ((unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2) + 1)>>1; + dp[1] = (dp[1] + ((unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2) + 1)>>1; + dp[2] = (dp[2] + ((unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2) + 1)>>1; + dp[3] = (dp[3] + ((unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2) + 1)>>1; + dp[4] = (dp[4] + ((unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2) + 1)>>1; + dp[5] = (dp[5] + ((unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2) + 1)>>1; + dp[6] = (dp[6] + ((unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2) + 1)>>1; + dp[7] = (dp[7] + ((unsigned int)(s2+(s1=sp[8])+s4+(s3=sp2[8])+2)>>2) + 1)>>1; + dp[8] = (dp[8] + ((unsigned int)(s1+(s2=sp[9])+s3+(s4=sp2[9])+2)>>2) + 1)>>1; + dp[9] = (dp[9] + ((unsigned int)(s2+(s1=sp[10])+s4+(s3=sp2[10])+2)>>2) + 1)>>1; + dp[10] = (dp[10] + ((unsigned int)(s1+(s2=sp[11])+s3+(s4=sp2[11])+2)>>2) + 1)>>1; + dp[11] = (dp[11] + ((unsigned int)(s2+(s1=sp[12])+s4+(s3=sp2[12])+2)>>2) + 1)>>1; + dp[12] = (dp[12] + ((unsigned int)(s1+(s2=sp[13])+s3+(s4=sp2[13])+2)>>2) + 1)>>1; + dp[13] = (dp[13] + ((unsigned int)(s2+(s1=sp[14])+s4+(s3=sp2[14])+2)>>2) + 1)>>1; + dp[14] = (dp[14] + ((unsigned int)(s1+(s2=sp[15])+s3+(s4=sp2[15])+2)>>2) + 1)>>1; + dp[15] = (dp[15] + ((unsigned int)(s2+sp[16]+s4+sp2[16]+2)>>2) + 1)>>1; + sp+= lx2; + sp2+= lx2; + dp+= lx2; + } +} + + +static inline void rec4ac(unsigned char *s,unsigned char *d, int lx, int lx2, int h) +{ + unsigned char *dp=d, *sp=s, *sp2=s+lx; + unsigned int s1,s2,s3,s4; + int j; + +/* + sp = s; + sp2 = s+lx; + dp = d; +*/ + for (j=0; j<h; j++) + { + s1=sp[0]; s3=sp2[0]; + dp[0] = (dp[0] + ((unsigned int)(s1+(s2=sp[1])+s3+(s4=sp2[1])+2)>>2) + 1)>>1; + dp[1] = (dp[1] + ((unsigned int)(s2+(s1=sp[2])+s4+(s3=sp2[2])+2)>>2) + 1)>>1; + dp[2] = (dp[2] + ((unsigned int)(s1+(s2=sp[3])+s3+(s4=sp2[3])+2)>>2) + 1)>>1; + dp[3] = (dp[3] + ((unsigned int)(s2+(s1=sp[4])+s4+(s3=sp2[4])+2)>>2) + 1)>>1; + dp[4] = (dp[4] + ((unsigned int)(s1+(s2=sp[5])+s3+(s4=sp2[5])+2)>>2) + 1)>>1; + dp[5] = (dp[5] + ((unsigned int)(s2+(s1=sp[6])+s4+(s3=sp2[6])+2)>>2) + 1)>>1; + dp[6] = (dp[6] + ((unsigned int)(s1+(s2=sp[7])+s3+(s4=sp2[7])+2)>>2) + 1)>>1; + dp[7] = (dp[7] + ((unsigned int)(s2+sp[8]+s4+sp2[8]+2)>>2) + 1)>>1; + sp+= lx2; + sp2+= lx2; + dp+= lx2; + } +} + +static inline +void recon_comp(mpeg3video_t *video, + unsigned char *src, + unsigned char *dst, + int lx, + int lx2, + int w, + int h, + int x, + int y, + int dx, + int dy, + int addflag) +{ + int switcher; + unsigned char *s, *d; + +/* half pel scaling */ + switcher = (dx & 1) << 3 | (dy & 1) << 2 | w; + if(addflag) switcher |= 2; +/* origins */ + s = src + lx * (y + (dy >> 1)) + x + (dx >> 1); + d = dst + lx * y + x; + +// Accelerated functions +#ifdef HAVE_3Dnow + if(video->have_mmx) + { + switch(switcher) + { + case 0x3: reca_mmx(s, d, lx2, h); break; + case 0x2: recac_mmx(s, d, lx2, h); break; + case 0x1: rec_mmx(s, d, lx2, h); break; + case 0x0: recc_mmx(s, d, lx2, h); break; + case 0x7: recva_mmx(s, d, lx, lx2, h); break; + case 0x6: recvac_mmx(s, d, lx, lx2, h); break; + case 0x5: recv_mmx(s, d, lx, lx2, h); break; + case 0x4: recvc_mmx(s, d, lx, lx2, h); break; + case 0x9: rech_mmx(s, d, lx2, h); break; + case 0x8: rechc_mmx(s, d, lx2, h); break; + } + } + else +#endif + { + switch(switcher) + { + case 0x3: reca(s, d, lx2, h); break; + case 0x2: recac(s, d, lx2, h); break; + case 0x1: rec(s, d, lx2, h); break; + case 0x0: recc(s, d, lx2, h); break; + case 0x7: recva(s, d, lx, lx2, h); break; + case 0x6: recvac(s, d, lx, lx2, h); break; + case 0x5: recv_(s, d, lx, lx2, h); break; + case 0x4: recvc(s, d, lx, lx2, h); break; + case 0x9: rech(s, d, lx2, h); break; + case 0x8: rechc(s, d, lx2, h); break; + } + } + +// Unaccelerated functions + switch(switcher) + { + case 0xb: recha(s, d, lx2, h); break; + case 0xa: rechac(s, d, lx2, h); break; + case 0xf: rec4a(s, d, lx, lx2, h); break; + case 0xe: rec4ac(s, d, lx, lx2, h); break; + case 0xd: rec4(s, d, lx, lx2, h); break; + case 0xc: rec4c(s, d, lx, lx2, h); break; + } +} + +/* + unsigned char *src[]; * prediction source buffer * + int sfield; * prediction source field number (0 or 1) * + unsigned char *dst[]; * prediction destination buffer * + int dfield; * prediction destination field number (0 or 1)* + int lx,lx2; * horizontal offsets * + int w,h; * prediction block/sub-block width, height * + int x,y; * pixel co-ordinates of top-left sample in current MB * + int dx,dy; * horizontal, vertical motion vector * + int addflag; * add prediction error to prediction ? * +*/ +static void recon(mpeg3video_t *video, + unsigned char *src[], + int sfield, + unsigned char *dst[], + int dfield, + int lx, + int lx2, + int w, + int h, + int x, + int y, + int dx, + int dy, + int addflag) +{ + +/* Y */ + recon_comp(video, (src[0] + (sfield ? (lx2 >> 1) : 0)), + dst[0] + (dfield ? (lx2 >> 1) : 0), + lx, lx2, w, h, x, y, dx, dy, addflag); + + if(video->chroma_format != CHROMA444) + { + lx >>= 1; + dx /= 2; + lx2 >>= 1; + w = 0; + x >>= 1; + } + + if(video->chroma_format == CHROMA420) + { + h >>= 1; + dy /= 2; + y >>= 1; + } + +/* Cb */ + recon_comp(video, (src[1] + (sfield ? (lx2 >> 1) : 0)), + dst[1] + (dfield ? (lx2 >> 1) : 0), + lx, lx2, w, h, x, y, dx, dy, addflag); + +/* Cr */ + recon_comp(video, (src[2] + (sfield ? (lx2 >> 1) : 0)), + dst[2] + (dfield ? (lx2 >> 1) : 0), + lx, lx2, w, h, x, y, dx, dy, addflag); +} + +#define WIDTH 1 + +int mpeg3video_reconstruct(mpeg3video_t *video, + int bx, + int by, + int mb_type, + int motion_type, + int PMV[2][2][2], + int mv_field_sel[2][2], + int dmvector[2], + int stwtype) +{ + int currentfield; + unsigned char **predframe; + int DMV[2][2]; + int stwtop, stwbot; + + stwtop = stwtype % 3; /* 0:temporal, 1 : (spat+temp) / 2, 2 : spatial */ + stwbot = stwtype / 3; + + if((mb_type & MB_FORWARD) || (video->pict_type == P_TYPE)) + { + if(video->pict_struct == FRAME_PICTURE) + { + if((motion_type == MC_FRAME) || !(mb_type & MB_FORWARD)) + { +/* frame-based prediction */ + { + if(stwtop < 2) + recon(video, video->oldrefframe, 0, video->newframe, 0, + video->coded_picture_width, video->coded_picture_width << 1, WIDTH, 8, bx, by, + PMV[0][0][0], PMV[0][0][1], stwtop); + + if(stwbot < 2) + recon(video, video->oldrefframe, 1, video->newframe, 1, + video->coded_picture_width, video->coded_picture_width << 1, WIDTH, 8, bx, by, + PMV[0][0][0], PMV[0][0][1], stwbot); + } + } + else if(motion_type == MC_FIELD) /* field-based prediction */ + { +/* top field prediction */ + if(stwtop < 2) + recon(video, video->oldrefframe, mv_field_sel[0][0], video->newframe, 0, + video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by >> 1, + PMV[0][0][0], PMV[0][0][1] >> 1, stwtop); + +/* bottom field prediction */ + if(stwbot < 2) + recon(video, video->oldrefframe, mv_field_sel[1][0], video->newframe, 1, + video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by >> 1, + PMV[1][0][0], PMV[1][0][1] >> 1, stwbot); + } + else if(motion_type == MC_DMV) + { +/* dual prime prediction */ +/* calculate derived motion vectors */ + mpeg3video_calc_dmv(video, + DMV, + dmvector, + PMV[0][0][0], + PMV[0][0][1] >> 1); + + if(stwtop < 2) + { +/* predict top field from top field */ + recon(video, video->oldrefframe, 0, video->newframe, 0, + video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by>>1, + PMV[0][0][0], PMV[0][0][1] >> 1, 0); + +/* predict and add to top field from bottom field */ + recon(video, video->oldrefframe, 1, video->newframe, 0, + video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by>>1, + DMV[0][0], DMV[0][1], 1); + } + + if(stwbot < 2) + { +/* predict bottom field from bottom field */ + recon(video, video->oldrefframe, 1, video->newframe, 1, + video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by>>1, + PMV[0][0][0], PMV[0][0][1]>>1, 0); + +/* predict and add to bottom field from top field */ + recon(video, video->oldrefframe, 0, video->newframe, 1, + video->coded_picture_width << 1, video->coded_picture_width<<1, WIDTH, 8, bx, by>>1, + DMV[1][0], DMV[1][1], 1); + } + } + else +/* invalid motion_type */ +/* fprintf(stderr, "reconstruct: invalid motion_type\n"); */ + ; + } + else + { +/* TOP_FIELD or BOTTOM_FIELD */ +/* field picture */ + currentfield = (video->pict_struct == BOTTOM_FIELD); + +/* determine which frame to use for prediction */ + if((video->pict_type == P_TYPE) && video->secondfield + && (currentfield != mv_field_sel[0][0])) + predframe = video->refframe; /* same frame */ + else + predframe = video->oldrefframe; /* previous frame */ + + if((motion_type == MC_FIELD) || !(mb_type & MB_FORWARD)) + { +/* field-based prediction */ + if(stwtop < 2) + recon(video, predframe,mv_field_sel[0][0],video->newframe,0, + video->coded_picture_width << 1,video->coded_picture_width << 1,WIDTH,16,bx,by, + PMV[0][0][0],PMV[0][0][1],stwtop); + } + else + if(motion_type == MC_16X8) + { + if(stwtop < 2) + { + recon(video, predframe, mv_field_sel[0][0], video->newframe, 0, + video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by, + PMV[0][0][0], PMV[0][0][1], stwtop); + + /* determine which frame to use for lower half prediction */ + if((video->pict_type==P_TYPE) && video->secondfield + && (currentfield!=mv_field_sel[1][0])) + predframe = video->refframe; /* same frame */ + else + predframe = video->oldrefframe; /* previous frame */ + + recon(video, predframe, mv_field_sel[1][0], video->newframe, 0, + video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by+8, + PMV[1][0][0], PMV[1][0][1], stwtop); + } + } + else + if(motion_type == MC_DMV) /* dual prime prediction */ + { + if(video->secondfield) + predframe = video->refframe; /* same frame */ + else + predframe = video->oldrefframe; /* previous frame */ + +/* calculate derived motion vectors */ + mpeg3video_calc_dmv(video, + DMV, + dmvector, + PMV[0][0][0], + PMV[0][0][1]); + +/* predict from field of same parity */ + recon(video, video->oldrefframe, currentfield, video->newframe, 0, + video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 16, bx, by, + PMV[0][0][0], PMV[0][0][1], 0); + +/* predict from field of opposite parity */ + recon(video, predframe, !currentfield, video->newframe, 0, + video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 16, bx, by, + DMV[0][0], DMV[0][1], 1); + } + else +/* invalid motion_type */ +/* fprintf(stderr, "reconstruct: invalid motion_type\n"); */ + ; + } + stwtop = stwbot = 1; + } + + if(mb_type & MB_BACKWARD) + { + if(video->pict_struct == FRAME_PICTURE) + { + if(motion_type == MC_FRAME) + { +/* frame-based prediction */ + if(stwtop < 2) + recon(video, video->refframe, 0, video->newframe, 0, + video->coded_picture_width, video->coded_picture_width << 1, WIDTH, 8, bx, by, + PMV[0][1][0], PMV[0][1][1], stwtop); + + if(stwbot < 2) + recon(video, video->refframe, 1, video->newframe, 1, + video->coded_picture_width, video->coded_picture_width << 1, WIDTH, 8, bx, by, + PMV[0][1][0], PMV[0][1][1], stwbot); + } + else + { +/* field-based prediction */ +/* top field prediction */ + if(stwtop < 2) + { + recon(video, video->refframe, mv_field_sel[0][1], video->newframe, 0, + (video->coded_picture_width << 1), (video->coded_picture_width<<1), WIDTH, 8, bx, (by >> 1), + PMV[0][1][0], (PMV[0][1][1] >> 1), stwtop); + } + +/* bottom field prediction */ + if(stwbot < 2) + { + recon(video, video->refframe, mv_field_sel[1][1], video->newframe, 1, (video->coded_picture_width << 1), + (video->coded_picture_width << 1), WIDTH, 8, bx, (by>>1), + PMV[1][1][0], (PMV[1][1][1]>>1), stwbot); + } + } + } + else + { +/* TOP_FIELD or BOTTOM_FIELD */ +/* field picture */ + if(motion_type == MC_FIELD) + { +/* field-based prediction */ + recon(video, video->refframe, mv_field_sel[0][1], video->newframe, 0, + video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 16, bx, by, + PMV[0][1][0], PMV[0][1][1], stwtop); + } + else if(motion_type==MC_16X8) + { + recon(video, video->refframe, mv_field_sel[0][1], video->newframe, 0, + video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by, + PMV[0][1][0], PMV[0][1][1], stwtop); + + recon(video, video->refframe, mv_field_sel[1][1], video->newframe, 0, + video->coded_picture_width << 1, video->coded_picture_width << 1, WIDTH, 8, bx, by+8, + PMV[1][1][0], PMV[1][1][1], stwtop); + } + else +/* invalid motion_type */ +/* fprintf(stderr, "reconstruct: invalid motion_type\n"); */ + ; + } + } /* mb_type & MB_BACKWARD */ + return 0; +} + + diff --git a/core/multimedia/opieplayer/libmpeg3/video/seek.c b/core/multimedia/opieplayer/libmpeg3/video/seek.c new file mode 100644 index 0000000..04faba4 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/seek.c @@ -0,0 +1,233 @@ +#include "../mpeg3private.h" +#include "../mpeg3protos.h" +#include "mpeg3video.h" +#include <stdlib.h> +#include <string.h> + +unsigned int mpeg3bits_next_startcode(mpeg3_bits_t* stream) +{ +/* Perform forwards search */ + mpeg3bits_byte_align(stream); + +/* Perform search */ + while((mpeg3bits_showbits32_noptr(stream) >> 8) != MPEG3_PACKET_START_CODE_PREFIX && + !mpeg3bits_eof(stream)) + { + mpeg3bits_getbyte_noptr(stream); + } + return mpeg3bits_showbits32_noptr(stream); +} + +/* Line up on the beginning of the next code. */ +int mpeg3video_next_code(mpeg3_bits_t* stream, unsigned int code) +{ + while(!mpeg3bits_eof(stream) && + mpeg3bits_showbits32_noptr(stream) != code) + { + mpeg3bits_getbyte_noptr(stream); + } + return mpeg3bits_eof(stream); +} + +/* Line up on the beginning of the previous code. */ +int mpeg3video_prev_code(mpeg3_bits_t* stream, unsigned int code) +{ + while(!mpeg3bits_bof(stream) && + mpeg3bits_showbits_reverse(stream, 32) != code) + { + mpeg3bits_getbits_reverse(stream, 8); + } + return mpeg3bits_bof(stream); +} + +long mpeg3video_goptimecode_to_frame(mpeg3video_t *video) +{ +/* printf("mpeg3video_goptimecode_to_frame %d %d %d %d %f\n", */ +/* video->gop_timecode.hour, video->gop_timecode.minute, video->gop_timecode.second, video->gop_timecode.frame, video->frame_rate); */ + return (long)(video->gop_timecode.hour * 3600 * video->frame_rate + + video->gop_timecode.minute * 60 * video->frame_rate + + video->gop_timecode.second * video->frame_rate + + video->gop_timecode.frame) - 1 - video->first_frame; +} + +int mpeg3video_match_refframes(mpeg3video_t *video) +{ + unsigned char *dst, *src; + int i, j, size; + + for(i = 0; i < 3; i++) + { + if(video->newframe[i]) + { + if(video->newframe[i] == video->refframe[i]) + { + src = video->refframe[i]; + dst = video->oldrefframe[i]; + } + else + { + src = video->oldrefframe[i]; + dst = video->refframe[i]; + } + + if(i == 0) + size = video->coded_picture_width * video->coded_picture_height + 32 * video->coded_picture_width; + else + size = video->chrom_width * video->chrom_height + 32 * video->chrom_width; + + memcpy(dst, src, size); + } + } + return 0; +} + +int mpeg3video_seek(mpeg3video_t *video) +{ + long this_gop_start; + int result = 0; + int back_step; + int attempts; + mpeg3_t *file = video->file; + mpeg3_bits_t *vstream = video->vstream; + double percentage; + long frame_number; + int match_refframes = 1; + +/* Seek to a percentage */ + if(video->percentage_seek >= 0) + { + percentage = video->percentage_seek; + video->percentage_seek = -1; + mpeg3bits_seek_percentage(vstream, percentage); +// Go to previous I-frame + mpeg3bits_start_reverse(vstream); + result = mpeg3video_prev_code(vstream, MPEG3_GOP_START_CODE); + if(!result) mpeg3bits_getbits_reverse(vstream, 32); + mpeg3bits_start_forward(vstream); + + if(mpeg3bits_tell_percentage(vstream) < 0) mpeg3bits_seek_percentage(vstream, 0); + +// Read up to the correct percentage + result = 0; + while(!result && mpeg3bits_tell_percentage(vstream) < percentage) + { + result = mpeg3video_read_frame_backend(video, 0); + if(match_refframes) + mpeg3video_match_refframes(video); + match_refframes = 0; + } + } + else +/* Seek to a frame */ + if(video->frame_seek >= 0) + { + frame_number = video->frame_seek; + video->frame_seek = -1; + if(frame_number < 0) frame_number = 0; + if(frame_number > video->maxframe) frame_number = video->maxframe; + +/* Seek to start of file */ + if(frame_number < 16) + { + video->repeat_count = video->current_repeat = 0; + mpeg3bits_seek_start(vstream); + video->framenum = 0; + result = mpeg3video_drop_frames(video, frame_number - video->framenum); + } + else + { +/* Seek to an I frame. */ + if((frame_number < video->framenum || frame_number - video->framenum > MPEG3_SEEK_THRESHOLD)) + { +/* Elementary stream */ + if(file->is_video_stream) + { + mpeg3_t *file = video->file; + mpeg3_vtrack_t *track = video->track; + long byte = (long)((float)(mpeg3demuxer_total_bytes(vstream->demuxer) / + track->total_frames) * + frame_number); + long minimum = 65535; + int done = 0; + +//printf("seek elementary %d\n", frame_number); +/* Get GOP just before frame */ + do + { + result = mpeg3bits_seek_byte(vstream, byte); + mpeg3bits_start_reverse(vstream); + if(!result) result = mpeg3video_prev_code(vstream, MPEG3_GOP_START_CODE); + mpeg3bits_start_forward(vstream); + mpeg3bits_getbits(vstream, 8); + if(!result) result = mpeg3video_getgophdr(video); + this_gop_start = mpeg3video_goptimecode_to_frame(video); + +//printf("wanted %ld guessed %ld byte %ld result %d\n", frame_number, this_gop_start, byte, result); + if(labs(this_gop_start - frame_number) >= labs(minimum)) + done = 1; + else + { + minimum = this_gop_start - frame_number; + byte += (long)((float)(frame_number - this_gop_start) * + (float)(mpeg3demuxer_total_bytes(vstream->demuxer) / + track->total_frames)); + if(byte < 0) byte = 0; + } + }while(!result && !done); + +//printf("wanted %d guessed %d\n", frame_number, this_gop_start); + if(!result) + { + video->framenum = this_gop_start; + result = mpeg3video_drop_frames(video, frame_number - video->framenum); + } + } + else +/* System stream */ + { + mpeg3bits_seek_time(vstream, (double)frame_number / video->frame_rate); + percentage = mpeg3bits_tell_percentage(vstream); +//printf("seek frame %ld percentage %f byte %ld\n", frame_number, percentage, mpeg3bits_tell(vstream)); + mpeg3bits_start_reverse(vstream); + mpeg3video_prev_code(vstream, MPEG3_GOP_START_CODE); + mpeg3bits_getbits_reverse(vstream, 32); + mpeg3bits_start_forward(vstream); +//printf("seek system 1 %f\n", (double)frame_number / video->frame_rate); + + while(!result && mpeg3bits_tell_percentage(vstream) < percentage) + { + result = mpeg3video_read_frame_backend(video, 0); + if(match_refframes) + mpeg3video_match_refframes(video); + +//printf("seek system 2 %f %f\n", mpeg3bits_tell_percentage(vstream) / percentage); + match_refframes = 0; + } +//printf("seek system 3 %f\n", (double)frame_number / video->frame_rate); + } + + video->framenum = frame_number; + } + else +// Drop frames + { + mpeg3video_drop_frames(video, frame_number - video->framenum); + } + } + } + + return result; +} + +int mpeg3video_drop_frames(mpeg3video_t *video, long frames) +{ + int result = 0; + long frame_number = video->framenum + frames; + +/* Read the selected number of frames and skip b-frames */ + while(!result && frame_number > video->framenum) + { + result = mpeg3video_read_frame_backend(video, frame_number - video->framenum); + } + return result; +} diff --git a/core/multimedia/opieplayer/libmpeg3/video/slice.c b/core/multimedia/opieplayer/libmpeg3/video/slice.c new file mode 100644 index 0000000..90891b0 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/slice.c @@ -0,0 +1,702 @@ +#include "../libmpeg3.h" +#include "../mpeg3protos.h" +#include "mpeg3video.h" +#include "mpeg3videoprotos.h" +#include "slice.h" + +#include <stdlib.h> + +static ULONGLONG MMX_128 = 0x80008000800080LL; + +int mpeg3_new_slice_buffer(mpeg3_slice_buffer_t *slice_buffer) +{ + pthread_mutexattr_t mutex_attr; + slice_buffer->data = (unsigned char*)malloc(1024); + slice_buffer->buffer_size = 0; + slice_buffer->buffer_allocation = 1024; + slice_buffer->current_position = 0; + slice_buffer->bits_size = 0; + slice_buffer->bits = 0; + slice_buffer->done = 0; + pthread_mutexattr_init(&mutex_attr); + pthread_mutex_init(&(slice_buffer->completion_lock), &mutex_attr); + return 0; +} + +int mpeg3_delete_slice_buffer(mpeg3_slice_buffer_t *slice_buffer) +{ + free(slice_buffer->data); + pthread_mutex_destroy(&(slice_buffer->completion_lock)); + return 0; +} + +int mpeg3_expand_slice_buffer(mpeg3_slice_buffer_t *slice_buffer) +{ + int i; + unsigned char *new_buffer = + (unsigned char*)malloc(slice_buffer->buffer_allocation * 2); + for(i = 0; i < slice_buffer->buffer_size; i++) + new_buffer[i] = slice_buffer->data[i]; + free(slice_buffer->data); + slice_buffer->data = new_buffer; + slice_buffer->buffer_allocation *= 2; + return 0; +} + +/* limit coefficients to -2048..2047 */ + +/* move/add 8x8-Block from block[comp] to refframe */ + +static inline int mpeg3video_addblock(mpeg3_slice_t *slice, + mpeg3video_t *video, + int comp, + int bx, + int by, + int dct_type, + int addflag) +{ + int cc, i, iincr; + unsigned char *rfp; + short *bp; + int spar = slice->sparse[comp]; +/* color component index */ + cc = (comp < 4) ? 0 : (comp & 1) + 1; + + if(cc == 0) + { +/* luminance */ + if(video->pict_struct == FRAME_PICTURE) + { + if(dct_type) + { +/* field DCT coding */ + rfp = video->newframe[0] + + video->coded_picture_width * (by + ((comp & 2) >> 1)) + bx + ((comp & 1) << 3); + iincr = (video->coded_picture_width << 1); + } + else + { +/* frame DCT coding */ + rfp = video->newframe[0] + + video->coded_picture_width * (by + ((comp & 2) << 2)) + bx + ((comp & 1) << 3); + iincr = video->coded_picture_width; + } + } + else + { +/* field picture */ + rfp = video->newframe[0] + + (video->coded_picture_width << 1) * (by + ((comp & 2) << 2)) + bx + ((comp & 1) << 3); + iincr = (video->coded_picture_width << 1); + } + } + else + { +/* chrominance */ + +/* scale coordinates */ + if(video->chroma_format != CHROMA444) bx >>= 1; + if(video->chroma_format == CHROMA420) by >>= 1; + if(video->pict_struct == FRAME_PICTURE) + { + if(dct_type && (video->chroma_format != CHROMA420)) + { +/* field DCT coding */ + rfp = video->newframe[cc] + + video->chrom_width * (by + ((comp & 2) >> 1)) + bx + (comp & 8); + iincr = (video->chrom_width << 1); + } + else + { +/* frame DCT coding */ + rfp = video->newframe[cc] + + video->chrom_width * (by + ((comp & 2) << 2)) + bx + (comp & 8); + iincr = video->chrom_width; + } + } + else + { +/* field picture */ + rfp = video->newframe[cc] + + (video->chrom_width << 1) * (by + ((comp & 2) << 2)) + bx + (comp & 8); + iincr = (video->chrom_width << 1); + } + } + + bp = slice->block[comp]; + + if(addflag) + { +#ifdef HAVE_MMX + if(video->have_mmx) + { + if(spar) + { + __asm__ __volatile__( + "movq (%2), %%mm6\n" /* 4 blockvals */ + "pxor %%mm4, %%mm4\n" + "punpcklwd %%mm6, %%mm6\n" + "punpcklwd %%mm6, %%mm6\n" + ".align 8\n" + "1:" + "movq (%1), %%mm0\n" /* 8 rindex1 */ + "movq %%mm0, %%mm2\n" + "punpcklbw %%mm4, %%mm0\n" + "punpckhbw %%mm4, %%mm2\n" + "paddw %%mm6, %%mm0\n" + "paddw %%mm6, %%mm2\n" + + "packuswb %%mm2, %%mm0\n" + "movq %%mm0, (%1)\n" + + "leal (%1, %3), %1\n" + "loop 1b\n" + : /* scr dest */ + : "c" (8),"r" (rfp), "r" (bp), "r" (iincr) + ); + } + else + { + __asm__ __volatile__( + "pxor %%mm4, %%mm4\n" + + ".align 8\n" + "1:" + "movq (%2), %%mm0\n" /* 8 rfp 0 1 2 3 4 5 6 7*/ + "movq (%1), %%mm6\n" /* 4 blockvals 0 1 2 3 */ + + "movq %%mm0, %%mm2\n" + "movq 8(%1), %%mm5\n" /* 4 blockvals 0 1 2 3 */ + "punpcklbw %%mm4, %%mm0\n" /* 0 2 4 6 */ + "punpckhbw %%mm4, %%mm2\n" /* 1 3 5 7 */ + + "paddw %%mm6, %%mm0\n" + "paddw %%mm5, %%mm2\n" + "packuswb %%mm2, %%mm0\n" + + "addl $16, %1\n" + "movq %%mm0, (%2)\n" + + "leal (%2,%3), %2\n" + "loop 1b\n" + : /* scr dest */ + : "c" (8),"r" (bp), "r" (rfp), "r" (iincr) + ); + } + } + else +#endif + for(i = 0; i < 8; i++) + { + rfp[0] = CLIP(bp[0] + rfp[0]); + rfp[1] = CLIP(bp[1] + rfp[1]); + rfp[2] = CLIP(bp[2] + rfp[2]); + rfp[3] = CLIP(bp[3] + rfp[3]); + rfp[4] = CLIP(bp[4] + rfp[4]); + rfp[5] = CLIP(bp[5] + rfp[5]); + rfp[6] = CLIP(bp[6] + rfp[6]); + rfp[7] = CLIP(bp[7] + rfp[7]); + rfp += iincr; + bp += 8; + } + } + else + { +#ifdef HAVE_MMX + if(video->have_mmx) + { + if(spar) + { + __asm__ __volatile__( + "movd (%2), %%mm0\n" /* " 0 0 0 v1" */ + "punpcklwd %%mm0, %%mm0\n" /* " 0 0 v1 v1" */ + "punpcklwd %%mm0, %%mm0\n" + "paddw MMX_128, %%mm0\n" + "packuswb %%mm0, %%mm0\n" + "leal (%0,%1,2), %%eax\n" + + "movq %%mm0, (%0, %1)\n" + "movq %%mm0, (%%eax)\n" + "leal (%%eax,%1,2), %0\n" + "movq %%mm0, (%%eax, %1)\n" + + "movq %%mm0, (%0)\n" + "leal (%0,%1,2), %%eax\n" + "movq %%mm0, (%0, %1)\n" + + "movq %%mm0, (%%eax)\n" + "movq %%mm0, (%%eax, %1)\n" + : + : "D" (rfp), "c" (iincr), "b" (bp) + : "eax"); + } + else + { + __asm__ __volatile__( + "movq MMX_128,%%mm4\n" + ".align 8\n" + "1:" + "movq (%1), %%mm0\n" + "movq 8(%1), %%mm1\n" + "paddw %%mm4, %%mm0\n" + + "movq 16(%1), %%mm2\n" + "paddw %%mm4, %%mm1\n" + + "movq 24(%1), %%mm3\n" + "paddw %%mm4, %%mm2\n" + + "packuswb %%mm1, %%mm0\n" + "paddw %%mm4, %%mm3\n" + + "addl $32, %1\n" + "packuswb %%mm3, %%mm2\n" + + "movq %%mm0, (%2)\n" + + "movq %%mm2, (%2,%3)\n" + + "leal (%2,%3,2), %2\n" + "loop 1b\n" + : + : "c" (4), "r" (bp), "r" (rfp), "r" (iincr) + ); + } + } + else +#endif + for(i = 0; i < 8; i++) + { + rfp[0] = CLIP(bp[0] + 128); + rfp[1] = CLIP(bp[1] + 128); + rfp[2] = CLIP(bp[2] + 128); + rfp[3] = CLIP(bp[3] + 128); + rfp[4] = CLIP(bp[4] + 128); + rfp[5] = CLIP(bp[5] + 128); + rfp[6] = CLIP(bp[6] + 128); + rfp[7] = CLIP(bp[7] + 128); + rfp+= iincr; + bp += 8; + } + } + return 0; +} + +int mpeg3_decode_slice(mpeg3_slice_t *slice) +{ + mpeg3video_t *video = slice->video; + int comp; + int mb_type, cbp, motion_type = 0, dct_type; + int macroblock_address, mba_inc, mba_max; + int slice_vert_pos_ext; + unsigned int code; + int bx, by; + int dc_dct_pred[3]; + int mv_count, mv_format, mvscale; + int pmv[2][2][2], mv_field_sel[2][2]; + int dmv, dmvector[2]; + int qs; + int stwtype, stwclass; + int snr_cbp; + int i; + mpeg3_slice_buffer_t *slice_buffer = slice->slice_buffer; + +/* number of macroblocks per picture */ + mba_max = video->mb_width * video->mb_height; + +/* field picture has half as many macroblocks as frame */ + if(video->pict_struct != FRAME_PICTURE) + mba_max >>= 1; + +/* macroblock address */ + macroblock_address = 0; +/* first macroblock in slice is not skipped */ + mba_inc = 0; + slice->fault = 0; + + code = mpeg3slice_getbits(slice_buffer, 32); +/* decode slice header (may change quant_scale) */ + slice_vert_pos_ext = mpeg3video_getslicehdr(slice, video); + +/* reset all DC coefficient and motion vector predictors */ + dc_dct_pred[0] = dc_dct_pred[1] = dc_dct_pred[2] = 0; + pmv[0][0][0] = pmv[0][0][1] = pmv[1][0][0] = pmv[1][0][1] = 0; + pmv[0][1][0] = pmv[0][1][1] = pmv[1][1][0] = pmv[1][1][1] = 0; + + for(i = 0; + slice_buffer->current_position < slice_buffer->buffer_size; + i++) + { + if(mba_inc == 0) + { +/* Done */ + if(!mpeg3slice_showbits(slice_buffer, 23)) return 0; +/* decode macroblock address increment */ + mba_inc = mpeg3video_get_macroblock_address(slice); + + if(slice->fault) return 1; + + if(i == 0) + { +/* Get the macroblock_address */ + macroblock_address = ((slice_vert_pos_ext << 7) + (code & 255) - 1) * video->mb_width + mba_inc - 1; +/* first macroblock in slice: not skipped */ + mba_inc = 1; + } + } + + if(slice->fault) return 1; + + if(macroblock_address >= mba_max) + { +/* mba_inc points beyond picture dimensions */ + /*fprintf(stderr, "mpeg3_decode_slice: too many macroblocks in picture\n"); */ + return 1; + } + +/* not skipped */ + if(mba_inc == 1) + { + mpeg3video_macroblock_modes(slice, + video, + &mb_type, + &stwtype, + &stwclass, + &motion_type, + &mv_count, + &mv_format, + &dmv, + &mvscale, + &dct_type); + + if(slice->fault) return 1; + + if(mb_type & MB_QUANT) + { + qs = mpeg3slice_getbits(slice_buffer, 5); + + if(video->mpeg2) + slice->quant_scale = video->qscale_type ? mpeg3_non_linear_mquant_table[qs] : (qs << 1); + else + slice->quant_scale = qs; + + if(video->scalable_mode == SC_DP) +/* make sure quant_scale is valid */ + slice->quant_scale = slice->quant_scale; + } + +/* motion vectors */ + + +/* decode forward motion vectors */ + if((mb_type & MB_FORWARD) || ((mb_type & MB_INTRA) && video->conceal_mv)) + { + if(video->mpeg2) + mpeg3video_motion_vectors(slice, + video, + pmv, + dmvector, + mv_field_sel, + 0, + mv_count, + mv_format, + video->h_forw_r_size, + video->v_forw_r_size, + dmv, + mvscale); + else + mpeg3video_motion_vector(slice, + video, + pmv[0][0], + dmvector, + video->forw_r_size, + video->forw_r_size, + 0, + 0, + video->full_forw); + } + if(slice->fault) return 1; + +/* decode backward motion vectors */ + if(mb_type & MB_BACKWARD) + { + if(video->mpeg2) + mpeg3video_motion_vectors(slice, + video, + pmv, + dmvector, + mv_field_sel, + 1, + mv_count, + mv_format, + video->h_back_r_size, + video->v_back_r_size, + 0, + mvscale); + else + mpeg3video_motion_vector(slice, + video, + pmv[0][1], + dmvector, + video->back_r_size, + video->back_r_size, + 0, + 0, + video->full_back); + } + + if(slice->fault) return 1; + +/* remove marker_bit */ + if((mb_type & MB_INTRA) && video->conceal_mv) + mpeg3slice_flushbit(slice_buffer); + +/* macroblock_pattern */ + if(mb_type & MB_PATTERN) + { + cbp = mpeg3video_get_cbp(slice); + if(video->chroma_format == CHROMA422) + { +/* coded_block_pattern_1 */ + cbp = (cbp << 2) | mpeg3slice_getbits2(slice_buffer); + } + else + if(video->chroma_format == CHROMA444) + { +/* coded_block_pattern_2 */ + cbp = (cbp << 6) | mpeg3slice_getbits(slice_buffer, 6); + } + } + else + cbp = (mb_type & MB_INTRA) ? ((1 << video->blk_cnt) - 1) : 0; + + if(slice->fault) return 1; +/* decode blocks */ + mpeg3video_clearblock(slice, 0, video->blk_cnt); + for(comp = 0; comp < video->blk_cnt; comp++) + { + if(cbp & (1 << (video->blk_cnt - comp - 1))) + { + if(mb_type & MB_INTRA) + { + if(video->mpeg2) + mpeg3video_getmpg2intrablock(slice, video, comp, dc_dct_pred); + else + mpeg3video_getintrablock(slice, video, comp, dc_dct_pred); + } + else + { + if(video->mpeg2) + mpeg3video_getmpg2interblock(slice, video, comp); + else + mpeg3video_getinterblock(slice, video, comp); + } + if(slice->fault) return 1; + } + } + +/* reset intra_dc predictors */ + if(!(mb_type & MB_INTRA)) + dc_dct_pred[0] = dc_dct_pred[1] = dc_dct_pred[2] = 0; + +/* reset motion vector predictors */ + if((mb_type & MB_INTRA) && !video->conceal_mv) + { +/* intra mb without concealment motion vectors */ + pmv[0][0][0] = pmv[0][0][1] = pmv[1][0][0] = pmv[1][0][1] = 0; + pmv[0][1][0] = pmv[0][1][1] = pmv[1][1][0] = pmv[1][1][1] = 0; + } + + if((video->pict_type == P_TYPE) && !(mb_type & (MB_FORWARD | MB_INTRA))) + { +/* non-intra mb without forward mv in a P picture */ + pmv[0][0][0] = pmv[0][0][1] = pmv[1][0][0] = pmv[1][0][1] = 0; + +/* derive motion_type */ + if(video->pict_struct == FRAME_PICTURE) + motion_type = MC_FRAME; + else + { + motion_type = MC_FIELD; +/* predict from field of same parity */ + mv_field_sel[0][0] = (video->pict_struct == BOTTOM_FIELD); + } + } + + if(stwclass == 4) + { +/* purely spatially predicted macroblock */ + pmv[0][0][0] = pmv[0][0][1] = pmv[1][0][0] = pmv[1][0][1] = 0; + pmv[0][1][0] = pmv[0][1][1] = pmv[1][1][0] = pmv[1][1][1] = 0; + } + } + else + { +/* mba_inc!=1: skipped macroblock */ + mpeg3video_clearblock(slice, 0, video->blk_cnt); + +/* reset intra_dc predictors */ + dc_dct_pred[0] = dc_dct_pred[1] = dc_dct_pred[2] = 0; + +/* reset motion vector predictors */ + if(video->pict_type == P_TYPE) + pmv[0][0][0] = pmv[0][0][1] = pmv[1][0][0] = pmv[1][0][1] = 0; + +/* derive motion_type */ + if(video->pict_struct == FRAME_PICTURE) + motion_type = MC_FRAME; + else + { + motion_type = MC_FIELD; +/* predict from field of same parity */ + mv_field_sel[0][0] = mv_field_sel[0][1] = (video->pict_struct == BOTTOM_FIELD); + } + +/* skipped I are spatial-only predicted, */ +/* skipped P and B are temporal-only predicted */ + stwtype = (video->pict_type == I_TYPE) ? 8 : 0; + +/* clear MB_INTRA */ + mb_type &= ~MB_INTRA; + +/* no block data */ + cbp = 0; + } + + snr_cbp = 0; + +/* pixel coordinates of top left corner of current macroblock */ + bx = 16 * (macroblock_address % video->mb_width); + by = 16 * (macroblock_address / video->mb_width); + +/* motion compensation */ + if(!(mb_type & MB_INTRA)) + mpeg3video_reconstruct(video, + bx, + by, + mb_type, + motion_type, + pmv, + mv_field_sel, + dmvector, + stwtype); + +/* copy or add block data into picture */ + for(comp = 0; comp < video->blk_cnt; comp++) + { + if((cbp | snr_cbp) & (1 << (video->blk_cnt - 1 - comp))) + { +#ifdef HAVE_MMX + if(video->have_mmx) + IDCT_mmx(slice->block[comp]); + else +#endif + mpeg3video_idct_conversion(slice->block[comp]); + + mpeg3video_addblock(slice, + video, + comp, + bx, + by, + dct_type, + (mb_type & MB_INTRA) == 0); + } + } + +/* advance to next macroblock */ + macroblock_address++; + mba_inc--; + } + + return 0; +} + +void mpeg3_slice_loop(mpeg3_slice_t *slice) +{ + mpeg3video_t *video = slice->video; + int result = 1; + + while(!slice->done) + { + pthread_mutex_lock(&(slice->input_lock)); + + if(!slice->done) + { +/* Get a buffer to decode */ + result = 1; + pthread_mutex_lock(&(video->slice_lock)); + if(slice->buffer_step > 0) + { + while(slice->current_buffer <= slice->last_buffer) + { + if(!video->slice_buffers[slice->current_buffer].done && + slice->current_buffer <= slice->last_buffer) + { + result = 0; + break; + } + slice->current_buffer += slice->buffer_step; + } + } + else + { + while(slice->current_buffer >= slice->last_buffer) + { + if(!video->slice_buffers[slice->current_buffer].done && + slice->current_buffer >= slice->last_buffer) + { + result = 0; + break; + } + slice->current_buffer += slice->buffer_step; + } + } + +/* Got one */ + if(!result && slice->current_buffer >= 0 && slice->current_buffer < video->total_slice_buffers) + { + slice->slice_buffer = &(video->slice_buffers[slice->current_buffer]); + slice->slice_buffer->done = 1; + pthread_mutex_unlock(&(video->slice_lock)); + pthread_mutex_unlock(&(slice->input_lock)); + mpeg3_decode_slice(slice); + pthread_mutex_unlock(&(slice->slice_buffer->completion_lock)); + } + else + pthread_mutex_unlock(&(video->slice_lock)); + } + + pthread_mutex_unlock(&(slice->output_lock)); + } +} + +int mpeg3_new_slice_decoder(mpeg3video_t *video, mpeg3_slice_t *slice) +{ + pthread_attr_t attr; + //struct sched_param param; + pthread_mutexattr_t mutex_attr; + + slice->video = video; + slice->done = 0; + pthread_mutexattr_init(&mutex_attr); + pthread_mutex_init(&(slice->input_lock), &mutex_attr); + pthread_mutex_lock(&(slice->input_lock)); + pthread_mutex_init(&(slice->output_lock), &mutex_attr); + pthread_mutex_lock(&(slice->output_lock)); + + pthread_attr_init(&attr); + pthread_create(&(slice->tid), &attr, + (void * (*)(void *))mpeg3_slice_loop, slice); + + return 0; +} + +int mpeg3_delete_slice_decoder(mpeg3_slice_t *slice) +{ + slice->done = 1; + pthread_mutex_unlock(&(slice->input_lock)); + pthread_join(slice->tid, 0); + pthread_mutex_destroy(&(slice->input_lock)); + pthread_mutex_destroy(&(slice->output_lock)); + return 0; +} diff --git a/core/multimedia/opieplayer/libmpeg3/video/slice.h b/core/multimedia/opieplayer/libmpeg3/video/slice.h new file mode 100644 index 0000000..e36ffef --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/slice.h @@ -0,0 +1,194 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef SLICE_H +#define SLICE_H + +#ifndef _WIN32 +#include <pthread.h> +#endif + +/* Array of these feeds the slice decoders */ +typedef struct +{ + unsigned char *data; /* Buffer for holding the slice data */ + int buffer_size; /* Size of buffer */ + int buffer_allocation; /* Space allocated for buffer */ + int current_position; /* Position in buffer */ + unsigned MPEG3_INT32 bits; + int bits_size; + pthread_mutex_t completion_lock; /* Lock slice until completion */ + int done; /* Signal for slice decoder to skip */ +} mpeg3_slice_buffer_t; + +/* Each slice decoder */ +typedef struct +{ + struct mpeg3video_rec *video; + mpeg3_slice_buffer_t *slice_buffer; + + int thread_number; /* Number of this thread */ + int current_buffer; /* Buffer this slice decoder is on */ + int buffer_step; /* Number of buffers to skip */ + int last_buffer; /* Last buffer this decoder should process */ + int fault; + int done; + int quant_scale; + int pri_brk; /* slice/macroblock */ + short block[12][64]; + int sparse[12]; + pthread_t tid; /* ID of thread */ + pthread_mutex_t input_lock, output_lock; +} mpeg3_slice_t; + +#define mpeg3slice_fillbits(buffer, nbits) \ + while(((mpeg3_slice_buffer_t*)(buffer))->bits_size < (nbits)) \ + { \ + if(((mpeg3_slice_buffer_t*)(buffer))->current_position < ((mpeg3_slice_buffer_t*)(buffer))->buffer_size) \ + { \ + ((mpeg3_slice_buffer_t*)(buffer))->bits <<= 8; \ + ((mpeg3_slice_buffer_t*)(buffer))->bits |= ((mpeg3_slice_buffer_t*)(buffer))->data[((mpeg3_slice_buffer_t*)(buffer))->current_position++]; \ + } \ + ((mpeg3_slice_buffer_t*)(buffer))->bits_size += 8; \ + } + +#define mpeg3slice_flushbits(buffer, nbits) \ + { \ + mpeg3slice_fillbits((buffer), (nbits)); \ + ((mpeg3_slice_buffer_t*)(buffer))->bits_size -= (nbits); \ + } + +#define mpeg3slice_flushbit(buffer) \ +{ \ + if(((mpeg3_slice_buffer_t*)(buffer))->bits_size) \ + ((mpeg3_slice_buffer_t*)(buffer))->bits_size--; \ + else \ + if(((mpeg3_slice_buffer_t*)(buffer))->current_position < ((mpeg3_slice_buffer_t*)(buffer))->buffer_size) \ + { \ + ((mpeg3_slice_buffer_t*)(buffer))->bits = \ + ((mpeg3_slice_buffer_t*)(buffer))->data[((mpeg3_slice_buffer_t*)(buffer))->current_position++]; \ + ((mpeg3_slice_buffer_t*)(buffer))->bits_size = 7; \ + } \ +} + +extern inline unsigned int mpeg3slice_getbit(mpeg3_slice_buffer_t *buffer) +{ + if(buffer->bits_size) + return (buffer->bits >> (--buffer->bits_size)) & 0x1; + else + if(buffer->current_position < buffer->buffer_size) + { + buffer->bits = buffer->data[buffer->current_position++]; + buffer->bits_size = 7; + return (buffer->bits >> 7) & 0x1; + } + return 0; // WWA - stop warn +} + +extern inline unsigned int mpeg3slice_getbits2(mpeg3_slice_buffer_t *buffer) +{ + if(buffer->bits_size >= 2) + return (buffer->bits >> (buffer->bits_size -= 2)) & 0x3; + else + if(buffer->current_position < buffer->buffer_size) + { + buffer->bits <<= 8; + buffer->bits |= buffer->data[buffer->current_position++]; + buffer->bits_size += 6; + return (buffer->bits >> buffer->bits_size) & 0x3; + } + return 0; // WWA - stop warn +} + +extern inline unsigned int mpeg3slice_getbyte(mpeg3_slice_buffer_t *buffer) +{ + if(buffer->bits_size >= 8) + return (buffer->bits >> (buffer->bits_size -= 8)) & 0xff; + else + if(buffer->current_position < buffer->buffer_size) + { + buffer->bits <<= 8; + buffer->bits |= buffer->data[buffer->current_position++]; + return (buffer->bits >> buffer->bits_size) & 0xff; + } + return 0; // WWA - stop warn +} + + +extern inline unsigned int mpeg3slice_getbits(mpeg3_slice_buffer_t *slice_buffer, int bits) +{ + if(bits == 1) return mpeg3slice_getbit(slice_buffer); + mpeg3slice_fillbits(slice_buffer, bits); + return (slice_buffer->bits >> (slice_buffer->bits_size -= bits)) & (0xffffffff >> (32 - bits)); +} + +extern inline unsigned int mpeg3slice_showbits16(mpeg3_slice_buffer_t *buffer) +{ + if(buffer->bits_size >= 16) + return (buffer->bits >> (buffer->bits_size - 16)) & 0xffff; + else + if(buffer->current_position < buffer->buffer_size) + { + buffer->bits <<= 16; + buffer->bits_size += 16; + buffer->bits |= (unsigned int)buffer->data[buffer->current_position++] << 8; + buffer->bits |= buffer->data[buffer->current_position++]; + return (buffer->bits >> (buffer->bits_size - 16)) & 0xffff; + } + return 0; // WWA - stop warn +} + +extern inline unsigned int mpeg3slice_showbits9(mpeg3_slice_buffer_t *buffer) +{ + if(buffer->bits_size >= 9) + return (buffer->bits >> (buffer->bits_size - 9)) & 0x1ff; + else + if(buffer->current_position < buffer->buffer_size) + { + buffer->bits <<= 16; + buffer->bits_size += 16; + buffer->bits |= (unsigned int)buffer->data[buffer->current_position++] << 8; + buffer->bits |= buffer->data[buffer->current_position++]; + return (buffer->bits >> (buffer->bits_size - 9)) & 0x1ff; + } + return 0; // WWA - stop warn +} + +extern inline unsigned int mpeg3slice_showbits5(mpeg3_slice_buffer_t *buffer) +{ + if(buffer->bits_size >= 5) + return (buffer->bits >> (buffer->bits_size - 5)) & 0x1f; + else + if(buffer->current_position < buffer->buffer_size) + { + buffer->bits <<= 8; + buffer->bits_size += 8; + buffer->bits |= buffer->data[buffer->current_position++]; + return (buffer->bits >> (buffer->bits_size - 5)) & 0x1f; + } + return 0; // WWA - stop warn +} + +extern inline unsigned int mpeg3slice_showbits(mpeg3_slice_buffer_t *slice_buffer, int bits) +{ + mpeg3slice_fillbits(slice_buffer, bits); + return (slice_buffer->bits >> (slice_buffer->bits_size - bits)) & (0xffffffff >> (32 - bits)); +} + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/video/vlc.c b/core/multimedia/opieplayer/libmpeg3/video/vlc.c new file mode 100644 index 0000000..4328d8a --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/vlc.c @@ -0,0 +1,421 @@ +#include "mpeg3video.h" +#include "vlc.h" + +/* variable length code tables */ + +/* Table B-3, mb_type in P-pictures, codes 001..1xx */ +mpeg3_VLCtab_t mpeg3_PMBtab0[8] = { + {ERROR,0}, + {MB_FORWARD,3}, + {MB_PATTERN,2}, {MB_PATTERN,2}, + {MB_FORWARD|MB_PATTERN,1}, {MB_FORWARD|MB_PATTERN,1}, + {MB_FORWARD|MB_PATTERN,1}, {MB_FORWARD|MB_PATTERN,1} +}; + +/* Table B-3, mb_type in P-pictures, codes 000001..00011x */ +mpeg3_VLCtab_t mpeg3_PMBtab1[8] = { + {ERROR,0}, + {MB_QUANT|MB_INTRA,6}, + {MB_QUANT|MB_PATTERN,5}, {MB_QUANT|MB_PATTERN,5}, + {MB_QUANT|MB_FORWARD|MB_PATTERN,5}, {MB_QUANT|MB_FORWARD|MB_PATTERN,5}, + {MB_INTRA,5}, {MB_INTRA,5} +}; + +/* Table B-4, mb_type in B-pictures, codes 0010..11xx */ +mpeg3_VLCtab_t mpeg3_BMBtab0[16] = { + {ERROR,0}, {ERROR,0}, + {MB_FORWARD,4}, + {MB_FORWARD|MB_PATTERN,4}, + {MB_BACKWARD,3}, {MB_BACKWARD,3}, + {MB_BACKWARD|MB_PATTERN,3}, {MB_BACKWARD|MB_PATTERN,3}, + {MB_FORWARD|MB_BACKWARD,2}, {MB_FORWARD|MB_BACKWARD,2}, + {MB_FORWARD|MB_BACKWARD,2}, {MB_FORWARD|MB_BACKWARD,2}, + {MB_FORWARD|MB_BACKWARD|MB_PATTERN,2}, + {MB_FORWARD|MB_BACKWARD|MB_PATTERN,2}, + {MB_FORWARD|MB_BACKWARD|MB_PATTERN,2}, + {MB_FORWARD|MB_BACKWARD|MB_PATTERN,2} +}; + +/* Table B-4, mb_type in B-pictures, codes 000001..00011x */ +mpeg3_VLCtab_t mpeg3_BMBtab1[8] = { + {ERROR,0}, + {MB_QUANT|MB_INTRA,6}, + {MB_QUANT|MB_BACKWARD|MB_PATTERN,6}, + {MB_QUANT|MB_FORWARD|MB_PATTERN,6}, + {MB_QUANT|MB_FORWARD|MB_BACKWARD|MB_PATTERN,5}, + {MB_QUANT|MB_FORWARD|MB_BACKWARD|MB_PATTERN,5}, + {MB_INTRA,5}, {MB_INTRA,5} +}; + +/* Table B-5, mb_type in spat. scal. I-pictures, codes 0001..1xxx */ +mpeg3_VLCtab_t mpeg3_spIMBtab[16] = { + {ERROR,0}, + {MB_CLASS4,4}, + {MB_QUANT|MB_INTRA,4}, + {MB_INTRA,4}, + {MB_CLASS4|MB_QUANT|MB_PATTERN,2}, {MB_CLASS4|MB_QUANT|MB_PATTERN,2}, + {MB_CLASS4|MB_QUANT|MB_PATTERN,2}, {MB_CLASS4|MB_QUANT|MB_PATTERN,2}, + {MB_CLASS4|MB_PATTERN,1}, {MB_CLASS4|MB_PATTERN,1}, + {MB_CLASS4|MB_PATTERN,1}, {MB_CLASS4|MB_PATTERN,1}, + {MB_CLASS4|MB_PATTERN,1}, {MB_CLASS4|MB_PATTERN,1}, + {MB_CLASS4|MB_PATTERN,1}, {MB_CLASS4|MB_PATTERN,1} +}; + +/* Table B-6, mb_type in spat. scal. P-pictures, codes 0010..11xx */ +mpeg3_VLCtab_t mpeg3_spPMBtab0[16] = +{ + {ERROR,0},{ERROR,0}, + {MB_FORWARD,4}, + {MB_WEIGHT|MB_FORWARD,4}, + {MB_QUANT|MB_FORWARD|MB_PATTERN,3}, {MB_QUANT|MB_FORWARD|MB_PATTERN,3}, + {MB_WEIGHT|MB_FORWARD|MB_PATTERN,3}, {MB_WEIGHT|MB_FORWARD|MB_PATTERN,3}, + {MB_FORWARD|MB_PATTERN,2}, {MB_FORWARD|MB_PATTERN,2}, + {MB_FORWARD|MB_PATTERN,2}, {MB_FORWARD|MB_PATTERN,2}, + {MB_WEIGHT|MB_QUANT|MB_FORWARD|MB_PATTERN,2}, + {MB_WEIGHT|MB_QUANT|MB_FORWARD|MB_PATTERN,2}, + {MB_WEIGHT|MB_QUANT|MB_FORWARD|MB_PATTERN,2}, + {MB_WEIGHT|MB_QUANT|MB_FORWARD|MB_PATTERN,2} +}; + +/* Table B-6, mb_type in spat. scal. P-pictures, codes 0000010..000111x */ +mpeg3_VLCtab_t mpeg3_spPMBtab1[16] = { + {ERROR,0},{ERROR,0}, + {MB_CLASS4|MB_QUANT|MB_PATTERN,7}, + {MB_CLASS4,7}, + {MB_PATTERN,7}, + {MB_CLASS4|MB_PATTERN,7}, + {MB_QUANT|MB_INTRA,7}, + {MB_INTRA,7}, + {MB_QUANT|MB_PATTERN,6}, {MB_QUANT|MB_PATTERN,6}, + {MB_WEIGHT|MB_QUANT|MB_PATTERN,6}, {MB_WEIGHT|MB_QUANT|MB_PATTERN,6}, + {MB_WEIGHT,6}, {MB_WEIGHT,6}, + {MB_WEIGHT|MB_PATTERN,6}, {MB_WEIGHT|MB_PATTERN,6} +}; + +/* Table B-7, mb_type in spat. scal. B-pictures, codes 0010..11xx */ +mpeg3_VLCtab_t mpeg3_spBMBtab0[14] = { + {MB_FORWARD,4}, + {MB_FORWARD|MB_PATTERN,4}, + {MB_BACKWARD,3}, {MB_BACKWARD,3}, + {MB_BACKWARD|MB_PATTERN,3}, {MB_BACKWARD|MB_PATTERN,3}, + {MB_FORWARD|MB_BACKWARD,2}, {MB_FORWARD|MB_BACKWARD,2}, + {MB_FORWARD|MB_BACKWARD,2}, {MB_FORWARD|MB_BACKWARD,2}, + {MB_FORWARD|MB_BACKWARD|MB_PATTERN,2}, + {MB_FORWARD|MB_BACKWARD|MB_PATTERN,2}, + {MB_FORWARD|MB_BACKWARD|MB_PATTERN,2}, + {MB_FORWARD|MB_BACKWARD|MB_PATTERN,2} +}; + +/* Table B-7, mb_type in spat. scal. B-pictures, codes 0000100..000111x */ +mpeg3_VLCtab_t mpeg3_spBMBtab1[12] = { + {MB_QUANT|MB_FORWARD|MB_PATTERN,7}, + {MB_QUANT|MB_BACKWARD|MB_PATTERN,7}, + {MB_INTRA,7}, + {MB_QUANT|MB_FORWARD|MB_BACKWARD|MB_PATTERN,7}, + {MB_WEIGHT|MB_FORWARD,6}, {MB_WEIGHT|MB_FORWARD,6}, + {MB_WEIGHT|MB_FORWARD|MB_PATTERN,6}, {MB_WEIGHT|MB_FORWARD|MB_PATTERN,6}, + {MB_WEIGHT|MB_BACKWARD,6}, {MB_WEIGHT|MB_BACKWARD,6}, + {MB_WEIGHT|MB_BACKWARD|MB_PATTERN,6}, {MB_WEIGHT|MB_BACKWARD|MB_PATTERN,6} +}; + +/* Table B-7, mb_type in spat. scal. B-pictures, codes 00000100x..000001111 */ +mpeg3_VLCtab_t mpeg3_spBMBtab2[8] = { + {MB_QUANT|MB_INTRA,8}, {MB_QUANT|MB_INTRA,8}, + {MB_WEIGHT|MB_QUANT|MB_FORWARD|MB_PATTERN,8}, + {MB_WEIGHT|MB_QUANT|MB_FORWARD|MB_PATTERN,8}, + {MB_WEIGHT|MB_QUANT|MB_BACKWARD|MB_PATTERN,9}, + {MB_CLASS4|MB_QUANT|MB_PATTERN,9}, + {MB_CLASS4,9}, + {MB_CLASS4|MB_PATTERN,9} +}; + +/* Table B-8, mb_type in spat. scal. B-pictures, codes 001..1xx */ +mpeg3_VLCtab_t mpeg3_SNRMBtab[8] = { + {ERROR,0}, + {0,3}, + {MB_QUANT|MB_PATTERN,2}, {MB_QUANT|MB_PATTERN,2}, + {MB_PATTERN,1}, {MB_PATTERN,1}, {MB_PATTERN,1}, {MB_PATTERN,1} +}; + +/* Table B-10, motion_code, codes 0001 ... 01xx */ +mpeg3_VLCtab_t mpeg3_MVtab0[8] = +{ {ERROR,0}, {3,3}, {2,2}, {2,2}, {1,1}, {1,1}, {1,1}, {1,1} +}; + +/* Table B-10, motion_code, codes 0000011 ... 000011x */ +mpeg3_VLCtab_t mpeg3_MVtab1[8] = +{ {ERROR,0}, {ERROR,0}, {ERROR,0}, {7,6}, {6,6}, {5,6}, {4,5}, {4,5} +}; + +/* Table B-10, motion_code, codes 0000001100 ... 000001011x */ +mpeg3_VLCtab_t mpeg3_MVtab2[12] = +{ {16,9}, {15,9}, {14,9}, {13,9}, + {12,9}, {11,9}, {10,8}, {10,8}, + {9,8}, {9,8}, {8,8}, {8,8} +}; + +/* Table B-9, coded_block_pattern, codes 01000 ... 111xx */ +mpeg3_VLCtab_t mpeg3_CBPtab0[32] = +{ {ERROR,0}, {ERROR,0}, {ERROR,0}, {ERROR,0}, + {ERROR,0}, {ERROR,0}, {ERROR,0}, {ERROR,0}, + {62,5}, {2,5}, {61,5}, {1,5}, {56,5}, {52,5}, {44,5}, {28,5}, + {40,5}, {20,5}, {48,5}, {12,5}, {32,4}, {32,4}, {16,4}, {16,4}, + {8,4}, {8,4}, {4,4}, {4,4}, {60,3}, {60,3}, {60,3}, {60,3} +}; + +/* Table B-9, coded_block_pattern, codes 00000100 ... 001111xx */ +mpeg3_VLCtab_t mpeg3_CBPtab1[64] = +{ {ERROR,0}, {ERROR,0}, {ERROR,0}, {ERROR,0}, + {58,8}, {54,8}, {46,8}, {30,8}, + {57,8}, {53,8}, {45,8}, {29,8}, {38,8}, {26,8}, {37,8}, {25,8}, + {43,8}, {23,8}, {51,8}, {15,8}, {42,8}, {22,8}, {50,8}, {14,8}, + {41,8}, {21,8}, {49,8}, {13,8}, {35,8}, {19,8}, {11,8}, {7,8}, + {34,7}, {34,7}, {18,7}, {18,7}, {10,7}, {10,7}, {6,7}, {6,7}, + {33,7}, {33,7}, {17,7}, {17,7}, {9,7}, {9,7}, {5,7}, {5,7}, + {63,6}, {63,6}, {63,6}, {63,6}, {3,6}, {3,6}, {3,6}, {3,6}, + {36,6}, {36,6}, {36,6}, {36,6}, {24,6}, {24,6}, {24,6}, {24,6} +}; + +/* Table B-9, coded_block_pattern, codes 000000001 ... 000000111 */ +mpeg3_VLCtab_t mpeg3_CBPtab2[8] = +{ {ERROR,0}, {0,9}, {39,9}, {27,9}, {59,9}, {55,9}, {47,9}, {31,9} +}; + +/* Table B-1, macroblock_address_increment, codes 00010 ... 011xx */ +mpeg3_VLCtab_t mpeg3_MBAtab1[16] = +{ {ERROR,0}, {ERROR,0}, {7,5}, {6,5}, {5,4}, {5,4}, {4,4}, {4,4}, + {3,3}, {3,3}, {3,3}, {3,3}, {2,3}, {2,3}, {2,3}, {2,3} +}; + +/* Table B-1, macroblock_address_increment, codes 00000011000 ... 0000111xxxx */ +mpeg3_VLCtab_t mpeg3_MBAtab2[104] = +{ + {33,11}, {32,11}, {31,11}, {30,11}, {29,11}, {28,11}, {27,11}, {26,11}, + {25,11}, {24,11}, {23,11}, {22,11}, {21,10}, {21,10}, {20,10}, {20,10}, + {19,10}, {19,10}, {18,10}, {18,10}, {17,10}, {17,10}, {16,10}, {16,10}, + {15,8}, {15,8}, {15,8}, {15,8}, {15,8}, {15,8}, {15,8}, {15,8}, + {14,8}, {14,8}, {14,8}, {14,8}, {14,8}, {14,8}, {14,8}, {14,8}, + {13,8}, {13,8}, {13,8}, {13,8}, {13,8}, {13,8}, {13,8}, {13,8}, + {12,8}, {12,8}, {12,8}, {12,8}, {12,8}, {12,8}, {12,8}, {12,8}, + {11,8}, {11,8}, {11,8}, {11,8}, {11,8}, {11,8}, {11,8}, {11,8}, + {10,8}, {10,8}, {10,8}, {10,8}, {10,8}, {10,8}, {10,8}, {10,8}, + {9,7}, {9,7}, {9,7}, {9,7}, {9,7}, {9,7}, {9,7}, {9,7}, + {9,7}, {9,7}, {9,7}, {9,7}, {9,7}, {9,7}, {9,7}, {9,7}, + {8,7}, {8,7}, {8,7}, {8,7}, {8,7}, {8,7}, {8,7}, {8,7}, + {8,7}, {8,7}, {8,7}, {8,7}, {8,7}, {8,7}, {8,7}, {8,7} +}; + +/* Table B-12, dct_dc_size_luminance, codes 00xxx ... 11110 */ +mpeg3_VLCtab_t mpeg3_DClumtab0[32] = +{ {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, + {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, + {0, 3}, {0, 3}, {0, 3}, {0, 3}, {3, 3}, {3, 3}, {3, 3}, {3, 3}, + {4, 3}, {4, 3}, {4, 3}, {4, 3}, {5, 4}, {5, 4}, {6, 5}, {ERROR, 0} +}; + +/* Table B-12, dct_dc_size_luminance, codes 111110xxx ... 111111111 */ +mpeg3_VLCtab_t mpeg3_DClumtab1[16] = +{ {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, {7, 6}, + {8, 7}, {8, 7}, {8, 7}, {8, 7}, {9, 8}, {9, 8}, {10,9}, {11,9} +}; + +/* Table B-13, dct_dc_size_chrominance, codes 00xxx ... 11110 */ +mpeg3_VLCtab_t mpeg3_DCchromtab0[32] = +{ {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, {0, 2}, + {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, + {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, {2, 2}, + {3, 3}, {3, 3}, {3, 3}, {3, 3}, {4, 4}, {4, 4}, {5, 5}, {ERROR, 0} +}; + +/* Table B-13, dct_dc_size_chrominance, codes 111110xxxx ... 1111111111 */ +mpeg3_VLCtab_t mpeg3_DCchromtab1[32] = +{ {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, + {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, {6, 6}, + {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, {7, 7}, + {8, 8}, {8, 8}, {8, 8}, {8, 8}, {9, 9}, {9, 9}, {10,10}, {11,10} +}; + +/* Table B-14, DCT coefficients table zero, + * codes 0100 ... 1xxx (used for first (DC) coefficient) + */ +mpeg3_DCTtab_t mpeg3_DCTtabfirst[12] = +{ + {0,2,4}, {2,1,4}, {1,1,3}, {1,1,3}, + {0,1,1}, {0,1,1}, {0,1,1}, {0,1,1}, + {0,1,1}, {0,1,1}, {0,1,1}, {0,1,1} +}; + +/* Table B-14, DCT coefficients table zero, + * codes 0100 ... 1xxx (used for all other coefficients) + */ +mpeg3_DCTtab_t mpeg3_DCTtabnext[12] = +{ + {0,2,4}, {2,1,4}, {1,1,3}, {1,1,3}, + {64,0,2}, {64,0,2}, {64,0,2}, {64,0,2}, /* EOB */ + {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2} +}; + +/* Table B-14, DCT coefficients table zero, + * codes 000001xx ... 00111xxx + */ +mpeg3_DCTtab_t mpeg3_DCTtab0[60] = +{ + {65,0,6}, {65,0,6}, {65,0,6}, {65,0,6}, /* Escape */ + {2,2,7}, {2,2,7}, {9,1,7}, {9,1,7}, + {0,4,7}, {0,4,7}, {8,1,7}, {8,1,7}, + {7,1,6}, {7,1,6}, {7,1,6}, {7,1,6}, + {6,1,6}, {6,1,6}, {6,1,6}, {6,1,6}, + {1,2,6}, {1,2,6}, {1,2,6}, {1,2,6}, + {5,1,6}, {5,1,6}, {5,1,6}, {5,1,6}, + {13,1,8}, {0,6,8}, {12,1,8}, {11,1,8}, + {3,2,8}, {1,3,8}, {0,5,8}, {10,1,8}, + {0,3,5}, {0,3,5}, {0,3,5}, {0,3,5}, + {0,3,5}, {0,3,5}, {0,3,5}, {0,3,5}, + {4,1,5}, {4,1,5}, {4,1,5}, {4,1,5}, + {4,1,5}, {4,1,5}, {4,1,5}, {4,1,5}, + {3,1,5}, {3,1,5}, {3,1,5}, {3,1,5}, + {3,1,5}, {3,1,5}, {3,1,5}, {3,1,5} +}; + +/* Table B-15, DCT coefficients table one, + * codes 000001xx ... 11111111 +*/ +mpeg3_DCTtab_t mpeg3_DCTtab0a[252] = +{ + {65,0,6}, {65,0,6}, {65,0,6}, {65,0,6}, /* Escape */ + {7,1,7}, {7,1,7}, {8,1,7}, {8,1,7}, + {6,1,7}, {6,1,7}, {2,2,7}, {2,2,7}, + {0,7,6}, {0,7,6}, {0,7,6}, {0,7,6}, + {0,6,6}, {0,6,6}, {0,6,6}, {0,6,6}, + {4,1,6}, {4,1,6}, {4,1,6}, {4,1,6}, + {5,1,6}, {5,1,6}, {5,1,6}, {5,1,6}, + {1,5,8}, {11,1,8}, {0,11,8}, {0,10,8}, + {13,1,8}, {12,1,8}, {3,2,8}, {1,4,8}, + {2,1,5}, {2,1,5}, {2,1,5}, {2,1,5}, + {2,1,5}, {2,1,5}, {2,1,5}, {2,1,5}, + {1,2,5}, {1,2,5}, {1,2,5}, {1,2,5}, + {1,2,5}, {1,2,5}, {1,2,5}, {1,2,5}, + {3,1,5}, {3,1,5}, {3,1,5}, {3,1,5}, + {3,1,5}, {3,1,5}, {3,1,5}, {3,1,5}, + {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3}, + {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3}, + {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3}, + {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3}, + {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3}, + {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3}, + {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3}, + {1,1,3}, {1,1,3}, {1,1,3}, {1,1,3}, + {64,0,4}, {64,0,4}, {64,0,4}, {64,0,4}, /* EOB */ + {64,0,4}, {64,0,4}, {64,0,4}, {64,0,4}, + {64,0,4}, {64,0,4}, {64,0,4}, {64,0,4}, + {64,0,4}, {64,0,4}, {64,0,4}, {64,0,4}, + {0,3,4}, {0,3,4}, {0,3,4}, {0,3,4}, + {0,3,4}, {0,3,4}, {0,3,4}, {0,3,4}, + {0,3,4}, {0,3,4}, {0,3,4}, {0,3,4}, + {0,3,4}, {0,3,4}, {0,3,4}, {0,3,4}, + {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2}, + {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2}, + {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2}, + {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2}, + {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2}, + {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2}, + {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2}, + {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2}, + {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2}, + {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2}, + {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2}, + {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2}, + {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2}, + {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2}, + {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2}, + {0,1,2}, {0,1,2}, {0,1,2}, {0,1,2}, + {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3}, + {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3}, + {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3}, + {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3}, + {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3}, + {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3}, + {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3}, + {0,2,3}, {0,2,3}, {0,2,3}, {0,2,3}, + {0,4,5}, {0,4,5}, {0,4,5}, {0,4,5}, + {0,4,5}, {0,4,5}, {0,4,5}, {0,4,5}, + {0,5,5}, {0,5,5}, {0,5,5}, {0,5,5}, + {0,5,5}, {0,5,5}, {0,5,5}, {0,5,5}, + {9,1,7}, {9,1,7}, {1,3,7}, {1,3,7}, + {10,1,7}, {10,1,7}, {0,8,7}, {0,8,7}, + {0,9,7}, {0,9,7}, {0,12,8}, {0,13,8}, + {2,3,8}, {4,2,8}, {0,14,8}, {0,15,8} +}; + +/* Table B-14, DCT coefficients table zero, + * codes 0000001000 ... 0000001111 + */ +mpeg3_DCTtab_t mpeg3_DCTtab1[8] = +{ + {16,1,10}, {5,2,10}, {0,7,10}, {2,3,10}, + {1,4,10}, {15,1,10}, {14,1,10}, {4,2,10} +}; + +/* Table B-15, DCT coefficients table one, + * codes 000000100x ... 000000111x + */ +mpeg3_DCTtab_t mpeg3_DCTtab1a[8] = +{ + {5,2,9}, {5,2,9}, {14,1,9}, {14,1,9}, + {2,4,10}, {16,1,10}, {15,1,9}, {15,1,9} +}; + +/* Table B-14/15, DCT coefficients table zero / one, + * codes 000000010000 ... 000000011111 + */ +mpeg3_DCTtab_t mpeg3_DCTtab2[16] = +{ + {0,11,12}, {8,2,12}, {4,3,12}, {0,10,12}, + {2,4,12}, {7,2,12}, {21,1,12}, {20,1,12}, + {0,9,12}, {19,1,12}, {18,1,12}, {1,5,12}, + {3,3,12}, {0,8,12}, {6,2,12}, {17,1,12} +}; + +/* Table B-14/15, DCT coefficients table zero / one, + * codes 0000000010000 ... 0000000011111 + */ +mpeg3_DCTtab_t mpeg3_DCTtab3[16] = +{ + {10,2,13}, {9,2,13}, {5,3,13}, {3,4,13}, + {2,5,13}, {1,7,13}, {1,6,13}, {0,15,13}, + {0,14,13}, {0,13,13}, {0,12,13}, {26,1,13}, + {25,1,13}, {24,1,13}, {23,1,13}, {22,1,13} +}; + +/* Table B-14/15, DCT coefficients table zero / one, + * codes 00000000010000 ... 00000000011111 + */ +mpeg3_DCTtab_t mpeg3_DCTtab4[16] = +{ + {0,31,14}, {0,30,14}, {0,29,14}, {0,28,14}, + {0,27,14}, {0,26,14}, {0,25,14}, {0,24,14}, + {0,23,14}, {0,22,14}, {0,21,14}, {0,20,14}, + {0,19,14}, {0,18,14}, {0,17,14}, {0,16,14} +}; + +/* Table B-14/15, DCT coefficients table zero / one, + * codes 000000000010000 ... 000000000011111 + */ +mpeg3_DCTtab_t mpeg3_DCTtab5[16] = +{ + {0,40,15}, {0,39,15}, {0,38,15}, {0,37,15}, + {0,36,15}, {0,35,15}, {0,34,15}, {0,33,15}, + {0,32,15}, {1,14,15}, {1,13,15}, {1,12,15}, + {1,11,15}, {1,10,15}, {1,9,15}, {1,8,15} +}; + +/* Table B-14/15, DCT coefficients table zero / one, + * codes 0000000000010000 ... 0000000000011111 + */ +mpeg3_DCTtab_t mpeg3_DCTtab6[16] = +{ + {1,18,16}, {1,17,16}, {1,16,16}, {1,15,16}, + {6,3,16}, {16,2,16}, {15,2,16}, {14,2,16}, + {13,2,16}, {12,2,16}, {11,2,16}, {31,1,16}, + {30,1,16}, {29,1,16}, {28,1,16}, {27,1,16} +}; diff --git a/core/multimedia/opieplayer/libmpeg3/video/vlc.h b/core/multimedia/opieplayer/libmpeg3/video/vlc.h new file mode 100644 index 0000000..727040b --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/vlc.h @@ -0,0 +1,164 @@ +/********************************************************************** +** Copyright (C) 2000 Trolltech AS. All rights reserved. +** +** This file is part of Qtopia Environment. +** +** This file may be distributed and/or modified under the terms of the +** GNU General Public License version 2 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +** See http://www.trolltech.com/gpl/ for GPL licensing information. +** +** Contact info@trolltech.com if any conditions of this licensing are +** not clear to you. +** +**********************************************************************/ +#ifndef VLC_H +#define VLC_H + +/* variable length code tables */ + +typedef struct { + char val, len; +} mpeg3_VLCtab_t; + +typedef struct { + char run, level, len; +} mpeg3_DCTtab_t; + +/* Added 03/38/96 by Alex de Jong : avoid IRIX GNU warning */ +#ifdef ERROR +#undef ERROR +#define ERROR 99 +#endif + +/* Table B-3, mb_type in P-pictures, codes 001..1xx */ +extern mpeg3_VLCtab_t mpeg3_PMBtab0[8]; + +/* Table B-3, mb_type in P-pictures, codes 000001..00011x */ +extern mpeg3_VLCtab_t mpeg3_PMBtab1[8]; + +/* Table B-4, mb_type in B-pictures, codes 0010..11xx */ +extern mpeg3_VLCtab_t mpeg3_BMBtab0[16]; + +/* Table B-4, mb_type in B-pictures, codes 000001..00011x */ +extern mpeg3_VLCtab_t mpeg3_BMBtab1[8]; + +/* Table B-5, mb_type in spat. scal. I-pictures, codes 0001..1xxx */ +extern mpeg3_VLCtab_t mpeg3_spIMBtab[16]; + +/* Table B-6, mb_type in spat. scal. P-pictures, codes 0010..11xx */ +extern mpeg3_VLCtab_t mpeg3_spPMBtab0[16]; + +/* Table B-6, mb_type in spat. scal. P-pictures, codes 0000010..000111x */ +extern mpeg3_VLCtab_t mpeg3_spPMBtab1[16]; + +/* Table B-7, mb_type in spat. scal. B-pictures, codes 0010..11xx */ +extern mpeg3_VLCtab_t mpeg3_spBMBtab0[14]; + +/* Table B-7, mb_type in spat. scal. B-pictures, codes 0000100..000111x */ +extern mpeg3_VLCtab_t mpeg3_spBMBtab1[12]; + +/* Table B-7, mb_type in spat. scal. B-pictures, codes 00000100x..000001111 */ +extern mpeg3_VLCtab_t mpeg3_spBMBtab2[8]; + +/* Table B-8, mb_type in spat. scal. B-pictures, codes 001..1xx */ +extern mpeg3_VLCtab_t mpeg3_SNRMBtab[8]; + +/* Table B-10, motion_code, codes 0001 ... 01xx */ +extern mpeg3_VLCtab_t mpeg3_MVtab0[8]; + +/* Table B-10, motion_code, codes 0000011 ... 000011x */ +extern mpeg3_VLCtab_t mpeg3_MVtab1[8]; + +/* Table B-10, motion_code, codes 0000001100 ... 000001011x */ +extern mpeg3_VLCtab_t mpeg3_MVtab2[12]; + +/* Table B-9, coded_block_pattern, codes 01000 ... 111xx */ +extern mpeg3_VLCtab_t mpeg3_CBPtab0[32]; + +/* Table B-9, coded_block_pattern, codes 00000100 ... 001111xx */ +extern mpeg3_VLCtab_t mpeg3_CBPtab1[64]; + +/* Table B-9, coded_block_pattern, codes 000000001 ... 000000111 */ +extern mpeg3_VLCtab_t mpeg3_CBPtab2[8]; + +/* Table B-1, macroblock_address_increment, codes 00010 ... 011xx */ +extern mpeg3_VLCtab_t mpeg3_MBAtab1[16]; + +/* Table B-1, macroblock_address_increment, codes 00000011000 ... 0000111xxxx */ +extern mpeg3_VLCtab_t mpeg3_MBAtab2[104]; + +/* Table B-12, dct_dc_size_luminance, codes 00xxx ... 11110 */ +extern mpeg3_VLCtab_t mpeg3_DClumtab0[32]; + +/* Table B-12, dct_dc_size_luminance, codes 111110xxx ... 111111111 */ +extern mpeg3_VLCtab_t mpeg3_DClumtab1[16]; + +/* Table B-13, dct_dc_size_chrominance, codes 00xxx ... 11110 */ +extern mpeg3_VLCtab_t mpeg3_DCchromtab0[32]; + +/* Table B-13, dct_dc_size_chrominance, codes 111110xxxx ... 1111111111 */ +extern mpeg3_VLCtab_t mpeg3_DCchromtab1[32]; + +/* Table B-14, DCT coefficients table zero, + * codes 0100 ... 1xxx (used for first (DC) coefficient) + */ +extern mpeg3_DCTtab_t mpeg3_DCTtabfirst[12]; + +/* Table B-14, DCT coefficients table zero, + * codes 0100 ... 1xxx (used for all other coefficients) + */ +extern mpeg3_DCTtab_t mpeg3_DCTtabnext[12]; + +/* Table B-14, DCT coefficients table zero, + * codes 000001xx ... 00111xxx + */ +extern mpeg3_DCTtab_t mpeg3_DCTtab0[60]; + +/* Table B-15, DCT coefficients table one, + * codes 000001xx ... 11111111 +*/ +extern mpeg3_DCTtab_t mpeg3_DCTtab0a[252]; + +/* Table B-14, DCT coefficients table zero, + * codes 0000001000 ... 0000001111 + */ +extern mpeg3_DCTtab_t mpeg3_DCTtab1[8]; + +/* Table B-15, DCT coefficients table one, + * codes 000000100x ... 000000111x + */ +extern mpeg3_DCTtab_t mpeg3_DCTtab1a[8]; + +/* Table B-14/15, DCT coefficients table zero / one, + * codes 000000010000 ... 000000011111 + */ +extern mpeg3_DCTtab_t mpeg3_DCTtab2[16]; + +/* Table B-14/15, DCT coefficients table zero / one, + * codes 0000000010000 ... 0000000011111 + */ +extern mpeg3_DCTtab_t mpeg3_DCTtab3[16]; + +/* Table B-14/15, DCT coefficients table zero / one, + * codes 00000000010000 ... 00000000011111 + */ +extern mpeg3_DCTtab_t mpeg3_DCTtab4[16]; + +/* Table B-14/15, DCT coefficients table zero / one, + * codes 000000000010000 ... 000000000011111 + */ +extern mpeg3_DCTtab_t mpeg3_DCTtab5[16]; + +/* Table B-14/15, DCT coefficients table zero / one, + * codes 0000000000010000 ... 0000000000011111 + */ +extern mpeg3_DCTtab_t mpeg3_DCTtab6[16]; + + +#endif diff --git a/core/multimedia/opieplayer/libmpeg3/video/worksheet.c b/core/multimedia/opieplayer/libmpeg3/video/worksheet.c new file mode 100644 index 0000000..c5a0553 --- a/dev/null +++ b/core/multimedia/opieplayer/libmpeg3/video/worksheet.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include <stdlib.h> +#include <time.h> + + +static LONGLONG mpeg3_MMX_601_Y_COEF = 0x0000004000400040; + +inline void mpeg3_601_mmx(unsigned long y, + unsigned long *output) +{ +asm(" +/* Output will be 0x00rrggbb */ + movd (%0), %%mm0; /* Load y 0x00000000000000yy */ +/* pmullw mpeg3_MMX_601_Y_COEF, %%mm0; // Scale y 0x00000000000000yy */ + psllw $6, %%mm0; /* Shift y coeffs 0x0000yyy0yyy0yyy0 */ + movd %%mm0, (%1); /* Store output */ + " +: +: "r" (&y), "r" (output)); +} + + +int main(int argc, char *argv[]) +{ + unsigned char output[1024]; + + memset(output, 0, 1024); + mpeg3_601_mmx(1, (unsigned long*)output); + printf("%02x%02x\n", *(unsigned char*)&output[1], *(unsigned char*)&output[0]); +} |