diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..6c6da92 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,89 @@ +#sources +*.c text +*.cc text +*.cxx text +*.cpp text +*.c++ text +*.hpp text +*.h text +*.h++ text +*.hh text + +# Compiled Object files +*.slo binary +*.lo binary +*.o binary +*.obj binary + +# Precompiled Headers +*.gch binary +*.pch binary + +# Compiled Dynamic libraries +*.so binary +*.dylib binary +*.dll binary + +# Compiled Static libraries +*.lai binary +*.la binary +*.a binary +*.lib binary + +# Executables +*.exe binary +*.out binary +*.app binary +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just comment the entries below and +# uncomment the group further below +############################################################################### + +*.sln text eol=crlf +*.csproj text eol=crlf +*.vbproj text eol=crlf +*.vcxproj text eol=crlf +*.vcproj text eol=crlf +*.dbproj text eol=crlf +*.fsproj text eol=crlf +*.lsproj text eol=crlf +*.wixproj text eol=crlf +*.modelproj text eol=crlf +*.sqlproj text eol=crlf +*.wmaproj text eol=crlf + +*.xproj text eol=crlf +*.props text eol=crlf +*.filters text eol=crlf +*.vcxitems text eol=crlf + + +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +#*.xproj merge=binary +#*.props merge=binary +#*.filters merge=binary +#*.vcxitems merge=binary diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..014f9bd --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,33 @@ +##### 1.3.0: + Changed `_SARDen`, `_SARNum` to display MPEG-4 PAR. (videoh) + Changed `_AspectRatio` type to array int. + +##### 1.2.6: + Restored previous behavior of frame property `_FieldBased`. + Fixed frame properties `_DurationNum` and `_DurationDen`. + Added frame properties `_SARDen`, `_SARNum`, `_FieldOrder`, `_FieldOperation`, `_TFF`, `_RFF`, `_Film`, `_ProgressiveFrame`, `_ChromaLocation`, `_AbsoluteTime`. (videoh) + Added parameters `nocrop` and `rff`. + +##### 1.2.5: + Fixed frame property `_FieldBased`. + +##### 1.2.4: + Fixed regression for relative file paths. + +##### 1.2.3: + Fixed FFSAR_NUM, FFSAR_DEN, FFSAR. + +##### 1.2.2: + Fixed values of frame properties _Quants* when info=0. + +##### 1.2.1: + Added support for path with forward slash (Windows). + +##### 1.2.0: + Added variables (ffms2 like) - FFSAR_NUM, FFSAR_DEN, FFSAR. + +##### 1.1.0: + Set frame properties - _DurationNum, _DurationDen, _FieldBased, _AspectRatio, _GOPNumber, _GOPPosition, _GOPClosed, _EncodedFrameTop, _EncodedFrameBottom, _PictType, _Matrix, _QuantsAverage, _QuantsAverage, _QuantsMax. + +##### 1.0.0: + Renamed the plugin and function to D2VSource. diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..df46bc7 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,67 @@ +cmake_minimum_required(VERSION 3.16) + +project(libd2vsource LANGUAGES CXX) + +find_package (Git) +if (GIT_FOUND) + execute_process (COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 + OUTPUT_VARIABLE ver + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +else () + message (STATUS "GIT not found") +endif () + +add_library(d2vsource SHARED + src/AVISynthAPI.cpp + src/color_convert.cpp + src/getbit.cpp + src/gethdr.cpp + src/getpic.cpp + src/global.cpp + src/idct_ap922_sse2.cpp + src/idct_llm_float_avx2.cpp + src/idct_llm_float_sse2.cpp + src/idct_ref_sse3.cpp + src/mc.cpp + src/misc.cpp + src/MPEG2Decoder.cpp + src/store.cpp + src/yv12pict.cpp +) + +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE) +endif() + +message(STATUS "Build type - ${CMAKE_BUILD_TYPE}") + +set_source_files_properties(src/idct_ap922_sse2.cpp PROPERTIES COMPILE_OPTIONS "-mfpmath=sse;-msse2") +set_source_files_properties(src/idct_llm_float_sse2.cpp PROPERTIES COMPILE_OPTIONS "-mfpmath=sse;-msse2") +set_source_files_properties(src/idct_ref_sse3.cpp PROPERTIES COMPILE_OPTIONS "-mssse3") +set_source_files_properties(src/idct_llm_float_avx2.cpp PROPERTIES COMPILE_OPTIONS "-mavx2;-mfma") + +target_include_directories(d2vsource PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/src + /usr/local/include/avisynth +) + +set_target_properties(d2vsource PROPERTIES OUTPUT_NAME "d2vsource.${ver}") + +target_compile_features(d2vsource PRIVATE cxx_std_17) + +include(GNUInstallDirs) + +INSTALL(TARGETS d2vsource + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/avisynth") + +# uninstall target +if(NOT TARGET uninstall) + configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" + IMMEDIATE @ONLY) + + add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) +endif() diff --git a/src/dgdecode/COPYING.txt b/COPYING.txt similarity index 100% rename from src/dgdecode/COPYING.txt rename to COPYING.txt diff --git a/src/dgdecode/History.txt b/History.txt similarity index 100% rename from src/dgdecode/History.txt rename to History.txt diff --git a/README.md b/README.md index d90e881..f6c1ab8 100644 --- a/README.md +++ b/README.md @@ -1,81 +1,184 @@ -# MPEG2DecPlus -これはDGDecode.dllをAvisynth+用に改造するプロジェクトです。 +## D2VSource -###やりたいこと: - - 改築を重ねた温泉旅館のようなコードをきれいにする。 - - VFAPI用コード、YUY2用コード等、現在では必要ないコードの排除。 - - アセンブラの排除による64bitへの対応、及びSSE2/AVX2でのintrinsicによる最適化。等 +This is a project (previously named as MPEG2DecPlus) to modify DGDecode.dll for AviSynth+. -###必要なもの: - - Windows Vista SP2 以降の Windows OS - - SSE3が使えるCPU(Intel Pentium4(prescott) または AMD Athlon64x2 以降) - - Avisynth+ r2172以降 またはAvisynth 2.60以降 - - Microsoft VisualC++ Redistributable Package 2015. +### Requirements: - ###使い方: - ``` - MPEG2Source(string "d2v", int "cpu", int "idct", bool "iPP", int "moderate_h", int "moderate_v", - bool "showQ", bool "fastMC", string "cpu2", int "info", int "upConv", bool "i420", bool "iCC") - ``` - d2v: dv2ファイルのパス - - cpu: 現在使用不可。設定しても何も起こらない。iPP, moderate_h, moderate_v, fastMC, cpu2も同様。 - - idct: 使用するiDCTアルゴリズム。 - 0: d2vの指定に従う。 - 1,2,3,6,7: AP922整数(SSE2MMXと同じもの)。 - 4: SSE2/AVX2 LLM(単精度浮動小数点、SSE2/AVX2の判定は自動)。 - 5: IEEE 1180 reference(倍精度浮動小数点)。 - - showQ: マクロブロックの量子化器を表示する。 - - info: デバッグ情報を出力する。 - 0: 表示しない。(デフォルト) - 1: 動画フレームにオーバーレイで表示。 - 2: OutputDebugString()で出力。(内容はDebugView.exeで確認) - 3: hintsをフレーム左上隅の64バイトに埋め込む。 +- AviSynth 2.60 / AviSynth+ 3.4 or later - upConv: フレームを出力するフォーマット。 - 0: YUV420なソースはYV12で出力、YUV422なソースはYV16で出力。 - 1: YV16で出力。 - 2: YV24で出力。 +- Microsoft VisualC++ Redistributable Package 2022 (can be downloaded from [here](https://github.com/abbodi1406/vcredist/releases)) - i420: trueであればYUV420をi420として出力する。現在ではどちらでもほぼ変わりはない。 +### Usage: - iCC: upConvにおけるYUV420の取扱いの設定。 - 未設定: フレームフラグに従ってinterlaced/progressiveを切り替える。 - true: 全フレームをinterlacedとして処理する。 - false: 全フレームをprogressiveとして処理する。 - -``` -Deblock(clip c, int "quant", int "aOffset", int "bOffset") -``` -H.264式デブロックフィルタ。manao氏のフィルタを取り込んだもの。 - - clip: Y8, YV12, YV16, YV411, YV24をサポート。 - - quant: 0~51(デフォルト25) - デブロックの強さ。 - - aOffset: 0 ~ 51-quant(デフォルト0) - ブロック検出の閾値。高いほどブロックと判定されやすくなる。 + ``` + D2VSource(string "d2v", int "idct", bool "showQ", int "info", int "upConv", bool "i420", bool "iCC", bool "nocrop", int "rff") + ``` - bOffset: 0 ~ 51-quant(デフォルト0) - デブロックの強さ及び検出率の補正値。 - 高いほどデブロックが強くかかり、ブロックと判定されやすくなる。 +### Parameters: + +- d2v\ + The path of the dv2 file. + +- idct\ + The iDCT algorithm to use.\ + 0: Follow the d2v specification.\ + 1,2,3,6,7: AP922 integer (same as SSE2/MMX).\ + 4: SSE2/AVX2 LLM (single precision floating point, SSE2/AVX2 determination is automatic).\ + 5: IEEE 1180 reference (double precision floating point).\ + Default: -1. + +- showQ\ + It displays macroblock quantizers..\ + Default: False. + +- info\ + It prints debug information.\ + 0: Do not display.\ + 1: Overlay on video frame.\ + 2: Output with OutputDebugString(). (The contents are confirmed by DebugView.exe).\ + 3: Embed hints in 64 bytes of the frame upper left corner.\ + Default: 0. + +- upConv\ + The output format.\ + 0: No conversion. YUV420 output is YV12, YUV422 output is YV16.\ + 1: Output YV16.\ + 2: Output YV24.\ + Default: 0. + +- i420\ + It determinates what is the output of YUV420.\ + True: The output is i410.\ + False: The output is YV12.\ + Default: False. -``` -LumaYUV(clip c, int "lumoff", int "lumgain") -``` -入力クリップの輝度をlumoffとlumgainの値によって変更する。出力Y = (入力y * lumgain) + lumoff +- iCC\ + It determinates how YUV420 is upscaled when upConv=true.\ + True: Force field-based upsampling.\ + False: Forse progressive upsampling.\ + Default: Auto determination based on the frame flag. + +- nocrop\ + Use direct-rendered buffer, which may need cropping.\ + It could provide a speedup when you know you need to crop your image anyway, by avoiding extra memcpy calls.\ + Default: False. - clip: Y8, YV12, YV16, YV411, YV24をサポート。 +- rff\ + Changes Field_Operation without the need of editing d2v or rescanning with different Field Operation.\ + 0: Honor Pulldowns Flags.\ + 1: Forced Film.\ + 2: Ignored Pulldowns Flags.\ + Default: -1 - read the value from d2v. + +### Exported variables: + +FFSAR_NUM, FFSAR_DEN, FFSAR (these indicate Generic PAR). + +### Frame properties + +_AbsoluteTime [float]\ +The frame’s absolute timestamp in seconds. + +_AspectRatio [int]\ +An array giving the display aspect ratio. + +_ChromaLocation [int]\ +Chroma sample position in YUV formats: +0=left, 1=center, 2=topleft, 3=top, 4=bottomleft, 5=bottom. + +_DurationNum [int], _DurationDen [int]\ +The frame’s duration in seconds as a rational number. + +_EncodedFrameTop [int], _EncodedFrameBottom [int]\ +Frame number (before pulldown) used to generate this frame's +top/bottom field. + +_FieldBased [int]\ +Describes the composition of the frame:\ +0=frame based (progressive), 1=bottom field first, 2=top field first.\ +Note that the GOP progressive flag is used to determine whether the frame is progressive. + +_FieldOperation [int]\ +Describes the field operation option in effect:\ +0=honor pulldown, 1=force film, 2=ignore pulldown. + +_FieldOrder [int]\ +Display field order of the frame:\ +0=bottom field first, 1=top field first. + +_Film [int]\ +Set if the frame is part of a 3:2 soft pulldown section.\ +Note that this uses the RFF history of several preceding\ +frames, and so is valid only when doing linear access. + +_GOPClosed [int]\ +Set if the current GOP is closed. + +_GOPNumber [int]\ +The 0-based GOP number that contains the frame. Note that\ +if this is set as the value x, then propShow displays it as\ +[x, y] where y is the 0-based frame number of the first frame\ +in the GOP. + +_GOPPosition [int]\ +The GOP position field from the D2V file for the GOP containing\ +the frame. + +_Matrix [int]\ +The matrix number field from the D2V file for the GOP containing\ +the frame. + +_PictType [data]\ +A single character describing the frame type. It uses the common\ +IPB characters but others may also be used for formats with\ +additional frame types. + +_ProgressiveFrame [int]\ +Set if the progress_frame flag is set for this frame. + +_QuantsAverage [int]\ +The average quantizer value for the frame. + +_QuantsMax [int]\ +The maximum quantizer value for the frame. + +_QuantsMin [int]\ +The minimum quantizer value for the frame. + +_RFF [int]\ +If _FieldOperation is 2 (ignore pulldown) then _RFF describes whether the stream specifies that a repeat field operation is to be performed on this frame. If _FieldOperation is 0 (honor pulldown) or 1 (force film) then _RFF describes whether the frame was composed with field repetition. + +_SARDen [int] +The denominator of the "pixel size" (MPEG-4 PAR), also called the\ +Sample Aspect Ratio (SAR). - lumoff: -255 ~ 255 (デフォルト0) +_SARNum [int] +The numerator of the "pixel size" (MPEG-4 PAR), also called the\ +Sample Aspect Ratio (SAR). - lumgain: 0.0 ~ 2.0 (デフォルト1.0) +_TFF [int]\ +If _FieldOperation is 2 (ignore pulldown) and _RFF is set, then _TFF\ +describes whether the stream specifies that the top field is to be repeated, otherwise the bottom field is to be repeated. If _FieldOperation is 0 (honor pulldown) or 1 (force film) then _TFF is inapplicable and is set to -1. -###ソースコード - https://github.com/chikuzen/MPEG2DecPlus/ +### Building: +- Windows\ + Use solution files. +- Linux + ``` + Requirements: + - Git + - C++17 compiler + - CMake >= 3.16 + ``` + ``` + git clone https://github.com/Asd-g/MPEG2DecPlus && \ + cd MPEG2DecPlus && \ + mkdir build && \ + cd build && \ + + cmake .. + make -j$(nproc) + sudo make install + ``` diff --git a/README_old.md b/README_old.md new file mode 100644 index 0000000..69f29fe --- /dev/null +++ b/README_old.md @@ -0,0 +1,65 @@ +# MPEG2DecPlus +これはDGDecode.dllをAvisynth+用に改造するプロジェクトです。 + +###やりたいこと: + - 改築を重ねた温泉旅館のようなコードをきれいにする。 + - VFAPI用コード、YUY2用コード等、現在では必要ないコードの排除。 + - アセンブラの排除による64bitへの対応、及びSSE2/AVX2でのintrinsicによる最適化。等 + +###必要なもの: + - Windows Vista SP2 以降の Windows OS + - SSE3が使えるCPU(Intel Pentium4(prescott) または AMD Athlon64x2 以降) + - Avisynth+ r2172以降 またはAvisynth 2.60以降 + - Microsoft VisualC++ Redistributable Package 2019. + + ###使い方: + ``` + MPEG2Source(string "d2v", int "cpu", int "idct", bool "iPP", int "moderate_h", int "moderate_v", + bool "showQ", bool "fastMC", string "cpu2", int "info", int "upConv", bool "i420", bool "iCC") + ``` + d2v: dv2ファイルのパス + + cpu: 現在使用不可。設定しても何も起こらない。iPP, moderate_h, moderate_v, fastMC, cpu2も同様。 + + idct: 使用するiDCTアルゴリズム。 + 0: d2vの指定に従う。 + 1,2,3,6,7: AP922整数(SSE2MMXと同じもの)。 + 4: SSE2/AVX2 LLM(単精度浮動小数点、SSE2/AVX2の判定は自動)。 + 5: IEEE 1180 reference(倍精度浮動小数点)。 + + showQ: マクロブロックの量子化器を表示する。 + + info: デバッグ情報を出力する。 + 0: 表示しない。(デフォルト) + 1: 動画フレームにオーバーレイで表示。 + 2: OutputDebugString()で出力。(内容はDebugView.exeで確認) + 3: hintsをフレーム左上隅の64バイトに埋め込む。 + + upConv: フレームを出力するフォーマット。 + 0: YUV420なソースはYV12で出力、YUV422なソースはYV16で出力。 + 1: YV16で出力。 + 2: YV24で出力。 + + i420: trueであればYUV420をi420として出力する。現在ではどちらでもほぼ変わりはない。 + + iCC: upConvにおけるYUV420の取扱いの設定。 + 未設定: フレームフラグに従ってinterlaced/progressiveを切り替える。 + true: 全フレームをinterlacedとして処理する。 + false: 全フレームをprogressiveとして処理する。 + + +``` +LumaYUV(clip c, int "lumoff", int "lumgain") +``` +入力クリップの輝度をlumoffとlumgainの値によって変更する。出力Y = (入力y * lumgain) + lumoff + + clip: Y8, YV12, YV16, YV411, YV24をサポート。 + + lumoff: -255 ~ 255 (デフォルト0) + + lumgain: 0.0 ~ 2.0 (デフォルト1.0) + +###ソースコード + https://github.com/chikuzen/MPEG2DecPlus/ + + diff --git a/bin/.gitkeep b/bin/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/bin/DGIndex.lang.ini b/bin/DGIndex.lang.ini deleted file mode 100644 index c39cf76..0000000 --- a/bin/DGIndex.lang.ini +++ /dev/null @@ -1,275 +0,0 @@ -; DGIndex language settings - -[MainMenu] -00=&File -01=&Stream -02=&Video -03=&Audio -04=&Options -05=&Tools -06=&Help - -[SubMenu0] -00=&Open [F2] -01=Load Project -02=&Close [F3] -03= -04=&Save Project [F4] -05=Save Project and Demux Video -06=Save BMP [F7] -07=Demux Audio-Only Stream -08= -09=Preview [F5] -10=Play [F6] -11=Stop [Esc] -12=Pause/Resume [Space] -13= -14= -15=Exit - -[SubMenu1] -00=Detect PIDs: PAT/PMT -01=Detect PIDs: PSIP -02=Detect PIDs: Raw -03=Set PIDs -04=Set Margin - -[SubMenu2] -00=iDCT Algorithm -01=Field Operation -02=YUV -> RGB -03=HD Display -04= -05=Luminance Filter -06=Cropping Filter -07= -08=Copy frame to clipboard [F8] - -[SubMenu2-0] -00=32-bit MMX -01=32-bit SSE MMX -02=32-bit SSE2 MMX -03=64-bit Floating Point -04=IEEE-1180 Reference -05=Skal SSE MMX -06=Simple MMX - -[SubMenu2-1] -00=Honor Pulldown Flags -01=Ignore Pulldown Flags -02=Forced Film - -[SubMenu2-2] -00=PC Scale -01=TV Scale - -[SubMenu2-3] -00=Full Sized -01=Shrink by Half -02=Top Left -03=Top Right -04=Bottom Left -05=Bottom Right - -[SubMenu3] -00=Output Method -01=Select Track(s) -02= -03=Dolby Digital Decode -04=48 -> 44.1KHz -05=Normalization - -[SubMenu3-0] -00=Disable -01=Demux Tracks -02=Demux All Tracks -03=Decode AC3 Track to WAV - -[SubMenu3-3] -00=Dynamic Range Control -01=Dolby Surround Downmix -02=Pre-Scale Decision [F9] - -[SubMenu3-3-0] -00=Off -01= -02=Light -03=Normal -04=Heavy - -[SubMenu3-4] -00=Off -01= -02=Low -03=Mid -04=High -05=UltraHigh - -[SubMenu4] -00=Loop Playback -01=Playback Speed -02=Process Priority -03=Use Full Paths -04=Force Fusion-Style Audio -05=Force Open GOPs in D2V File -06=Log Quant Matrices -07=Log Timestamps -08=AVS Template -09=BMP Save Path -10=Enable Info Log -11=Correct D2V - -[SubMenu4-1] -00=Single Step -01=Super Slow -02=Slow -03=Normal -04=Fast -05=Maximum - -[SubMenu4-2] -00=High -01=Normal -02=Low - -[SubMenu4-11] -00=Disable -01=Enable - -[SubMenu5] -00=Analyze Sync -01=Fix D2V -02=Parse D2V - -[SubMenu6] -00=Detected SIMD -01=VFAPI Plug-In -02= -03=About DGIndex -04=DGMPGDec Quick Start Guide -05=DGIndex User Manual -06=DGDecode User Manual -07= -08=jackei's Web Site -09=neuron2's Web Site - -[SubMenu6-0] -00=MMX -01=SSE MMX -02=SSE2 -03=SSE FPU -04=3D Now! - -[Dialog0] -;caption=Information -;font_size=8 -;font_name=Tahoma - -[Dialog1] -caption=Version -font_size=10 -font_name=Tahoma -00=OK -01=DGIndex is an evolution of jackei's original work called DVD2AVI. The name was changed to prevent versioning nightmares and to reflect the significant divergence of functionality. -02=I am using this About box to permanently record the origins of DGIndex and to acknowledge the original work of jackei, as well as my personal gratitude for his wonderful contribution to our community!" - -[Dialog2] -caption=File List -font_size=10 -font_name=Tahoma -00=ADD -01=UP -02=DOWN -03=DEL -04=DEL ALL -05=OK - -[Dialog3] -caption=Luminance Filter -font_size=10 -font_name=Tahoma -00=Enable Luminance Filter -01=Offset: -02=Gammna: - -[Dialog4] -caption=Normalization -font_size=10 -font_name=Tahoma -00=Enable Normalization -01=Volume - -[Dialog5] -caption=Set PIDs -font_size=10 -font_name=Tahoma -00=OK -01=Cancel -02=Video PID -03=Audio PID -04=PCR PID -05=[Please use hexadecimal values with no leading 0x.] - -[Dialog6] -caption=AVS Template -font_size=10 -font_name=Tahoma -00=Don't Use Template -01=Change Template File -02=Keep Current Template File -03=Your current AVS template file is: - -[Dialog7] -caption=BMP Save Path -font_size=10 -font_name=Tahoma -00=OK -01=Cancel -02=Your current BMP save path is: - -[Dialog8] -caption=Cropping -font_size=10 -font_name=Tahoma -00=Enable Cropping Filter -01=Left -02=Right -03=Top -04=Bottom -05=Width -06=Height - -[Dialog9] -caption=Detect PIDs -font_size=10 -font_name=Tahoma -00=Set Video -01=Set Audio -02=Set PCR -03=Done -04=Select a line and use these buttons to set that PID as the audio or video PID. - -[Dialog10] -caption=Select Track(s) -font_size=10 -font_name=Tahoma -00=OK -01=Cancel -02=List desired audio id's separated by commas - -[Dialog11] -caption=Select Track to Analyze -font_size=10 -font_name=Tahoma -00=OK -01=Cancel -02=Enter audio id to analyze in hex without the leading 0x - -[Dialog12] -caption=Set Margin -font_size=10 -font_name=Tahoma -00=OK -01=Cancel -02=Margin: -03=msec diff --git a/bin/DGIndex.lang_chi.ini b/bin/DGIndex.lang_chi.ini deleted file mode 100644 index 62e74dd..0000000 --- a/bin/DGIndex.lang_chi.ini +++ /dev/null @@ -1,276 +0,0 @@ -; DGIndex language settings -; coding: gb2312 - -[MainMenu] -00=ļ(&F) -01=(&S) -02=Ƶ(&V) -03=Ƶ(&A) -04=ѡ(&O) -05=(&T) -06=(&H) - -[SubMenu0] -00=(&O) [F2] -01=Ŀ -02=ر(&C) [F3] -03= -04=Ŀ(&S) [F4] -05=ĿƵ -06= BMP [F7] -07=Ƶ -08= -09=Ԥ [F5] -10= [F6] -11=ֹͣ [Esc] -12=ͣ/ָ [Space] -13= -14= -15=˳ - -[SubMenu1] -00= PID: PAT/PMT -01= PID: PSIP -02= PID: Raw -03= PID -04=ü - -[SubMenu2] -00=iDCT 㷨 -01= -02=YUV -> RGB -03=ʾ -04= -05=˾ -06=ü˾ -07= -08=֡Ƶ [F8] - -[SubMenu2-0] -00=32-bit MMX -01=32-bit SSE MMX -02=32-bit SSE2 MMX -03=64-bit Floating Point -04=IEEE-1180 Reference -05=Skal SSE MMX -06=Simple MMX - -[SubMenu2-1] -00=ѭ۵ -01=۵ -02=ǿƽƬ֡ - -[SubMenu2-2] -00=PC ɫ -01=TV ɫ - -[SubMenu2-3] -00=ԭʼС -01=һ -02= -03= -04= -05= - -[SubMenu3] -00=ʽ -01=ѡ -02= -03=űֽ -04=48 -> 44.1KHz -05=׼ - -[SubMenu3-0] -00= -01= -02= -03= AC3 Ϊ WAV - -[SubMenu3-3] -00=̬Χ -01=űȻ -02=Pre-Scale Decision [F9] - -[SubMenu3-3-0] -00=ر -01= -02=dz -03=׼ -04= - -[SubMenu3-4] -00=ر -01= -02= -03=׼ -04= -05=ܸ - -[SubMenu4] -00=ѭ -01=ٶ -02=ȼ -03=ʹ· -04=Force Fusion-Style Audio -05=Force Open GOPs in D2V File -06=Log Quant Matrices -07=¼ʱ -08=AVS ģ -09=BMP · -10=־ -11= D2V - -[SubMenu4-1] -00= -01= -02= -03=׼ -04= -05= - -[SubMenu4-2] -00= -01=׼ -02= - -[SubMenu4-11] -00= -01= - -[SubMenu5] -00=ͬ -01=޸ D2V -02= D2V - -[SubMenu6] -00=ͬ -01=VFAPI -02= -03= DGIndex -04=DGMPGDec ָ -05=DGIndex ûֲ -06=DGDecode ûֲ -07= -08=jackei վ -09=neuron2 վ - -[SubMenu6-0] -00=MMX -01=SSE MMX -02=SSE2 -03=SSE FPU -04=3D Now! - -[Dialog0] -;caption=Information -;font_size=8 -;font_name=Tahoma - -[Dialog1] -caption=汾 -font_size=10 -font_name=Tahoma -00=ȷ -01=DGIndex is an evolution of jackei's original work called DVD2AVI. The name was changed to prevent versioning nightmares and to reflect the significant divergence of functionality. -02=I am using this About box to permanently record the origins of DGIndex and to acknowledge the original work of jackei, as well as my personal gratitude for his wonderful contribution to our community!" - -[Dialog2] -caption=ļб -font_size=10 -font_name=Tahoma -00= -01= -02= -03=ɾ -04=ȫɾ -05=ȷ - -[Dialog3] -caption=˾ -font_size=10 -font_name=Tahoma -00=˾ -01=ƫ: -02=٤: - -[Dialog4] -caption=׼ -font_size=10 -font_name=Tahoma -00=׼ -01= - -[Dialog5] -caption= PID -font_size=10 -font_name=Tahoma -00=ȷ -01=ȡ -02=Ƶ PID -03=Ƶ PID -04=PCR PID -05=[ʹò '0x'ǰ׺ʮֵ] - -[Dialog6] -caption=AVS ģ -font_size=10 -font_name=Tahoma -00=ʹģ -01=ģļ -02=ֵǰģļ -03=ǰ AVS ģļΪ: - -[Dialog7] -caption=BMP · -font_size=10 -font_name=Tahoma -00=ȷ -01=ȡ -02=ǰ BMP ·Ϊ: - -[Dialog8] -caption=ü -font_size=10 -font_name=Tahoma -00=òü˾ -01= -02= -03= -04= -05= -06=߶ - -[Dialog9] -caption= PID -font_size=10 -font_name=Tahoma -00=Ƶ -01=Ƶ -02= PCR -03= -04=ѡһв PID ΪƵƵ PID - -[Dialog10] -caption=ѡ -font_size=10 -font_name=Tahoma -00=ȷ -01=ȡ -02=ҪƵ ID (Զŷָ) - -[Dialog11] -caption=ѡҪ -font_size=10 -font_name=Tahoma -00=ȷ -01=ȡ -02=Ƶ ID ԱʮƷ (Ҫǰ '0x') - -[Dialog12] -caption= -font_size=10 -font_name=Tahoma -00=ȷ -01=ȡ -02=: -03= diff --git a/bin/DGIndex.lang_jpn.ini b/bin/DGIndex.lang_jpn.ini deleted file mode 100644 index 7633957..0000000 --- a/bin/DGIndex.lang_jpn.ini +++ /dev/null @@ -1,276 +0,0 @@ -; DGIndex language settings -; coding: shift_jis - -[MainMenu] -00=t@C(&F) -01=Xg[(&S) -02=f(&V) -03=(&A) -04=IvV(&O) -05=c[(&T) -06=wv(&H) - -[SubMenu0] -00=J(&O) [F2] -01=vWFNgJ -02=‚(&C) [F3] -03= -04=vWFNg̕ۑ(&S) [F4] -05=vWFNgۑf𕪗 -06=BMPt@Cۑ [F7] -07=̂ݕ -08= -09=vr[ [F5] -10=Đ [F6] -11=~ [Esc] -12=ꎞ~ / ĊJ [Space] -13= -14= -15=I - -[SubMenu1] -00=PIĎo: PAT/PMT -01=PIĎo: PSIP -02=PIĎo: Raw -03=PID̐ݒ -04=}[W̐ݒ - -[SubMenu2] -00=iDCT ASY -01=tB[h -02=YUV -> RGB -03=HD \ -04= -05=Px -06=NbsO -07= -08=t[Nbv{[hɃRs[ [F8] - -[SubMenu2-0] -00=32-bit MMX -01=32-bit SSE MMX -02=32-bit SSE2 MMX -03=64-bit Floating Point -04=IEEE-1180 Reference -05=Skal SSE MMX -06=Simple MMX - -[SubMenu2-1] -00=v_EtOD悷 -01=v_EtO𖳎 -02=tBϊ - -[SubMenu2-2] -00=PCF -01=TVF - -[SubMenu2-3] -00=tTCY -01= -02=㕔 -03=E㕔 -04= -05=E - -[SubMenu3] -00=o͌` -01=gbN̑I -02= -03=hr[fW^ fR[h -04=48 -> 44.1KHz ϊ -05=ʐK - -[SubMenu3-0] -00=o͂Ȃ -01= -02=SgbNꊇ -03=AC3 gbN WAV - -[SubMenu3-3] -00=_Ci~bNWRg[ -01=hr[TEh _E~bNX -02=vXP[̌ [F9] - -[SubMenu3-3-0] -00=Ȃ -01= -02=Cg -03=m[} -04=wr[ - -[SubMenu3-4] -00=Ȃ -01= -02=ቹ -03=ʏ -04= -05=ō - -[SubMenu4] -00=[vĐ -01=Đx -02=^XNDx -03=tpXgp -04=t[WX^C -05=IOpen-GOPň -06=ʎq}gbNX̃O -07=^CX^ṽO -08=AVS ev[g -09=BMP ̕ۑpX -10=OLɂ -11=D2V ␳ - -[SubMenu4-1] -00=VOXebv -01=ᑬ -02=ᑬ -03=ʏ -04= -05=ō - -[SubMenu4-2] -00= -01=ʏ -02=Ⴂ - -[SubMenu4-11] -00= -01=L - -[SubMenu5] -00=̕ -01=D2V ̏C -02=D2V ̕ - -[SubMenu6] -00=񏈗Zp -01=VFAPI vOC -02= -03=o[W -04=DGMPGDec NCbNX^[gKCh -05=DGIndex [U[}jA -06=DGDecode [U[}jA -07= -08=jackeĩEFuTCg -09=neuron2̃EFuTCg - -[SubMenu6-0] -00=MMX -01=SSE MMX -02=SSE2 -03=SSE FPU -04=3D Now! - -[Dialog0] -;caption=Information -;font_size=8 -;font_name=Tahoma - -[Dialog1] -caption=o[W -font_size=10 -font_name=Tahoma -00=OK -01=DGIndex is an evolution of jackei's original work called DVD2AVI. The name was changed to prevent versioning nightmares and to reflect the significant divergence of functionality. -02=I am using this About box to permanently record the origins of DGIndex and to acknowledge the original work of jackei, as well as my personal gratitude for his wonderful contribution to our community!" - -[Dialog2] -caption=t@CXg -font_size=10 -font_name=Tahoma -00=lj -01= -02= -03=폜 -04=Sč폜 -05=OK - -[Dialog3] -caption=Px -font_size=10 -font_name=Tahoma -00=PxL -01=ItZbg: -02=K}: - -[Dialog4] -caption=ʐK -font_size=10 -font_name=Tahoma -00=ʐKL -01= - -[Dialog5] -caption=PID̐ݒ -font_size=10 -font_name=Tahoma -00=OK -01=LZ -02=f PID -03= PID -04=PCR PID -05=[0x‚Ȃ16i̒lgpĂB] - -[Dialog6] -caption=AVS ev[g -font_size=10 -font_name=Tahoma -00=ev[ggpȂ -01=ev[g̕ύX -02=݂̃t@Cێ -03=݂̃ev[gt@C: - -[Dialog7] -caption=BMP Save Path -font_size=10 -font_name=Tahoma -00=OK -01=Cancel -02=݂ BMP ۑpX: - -[Dialog8] -caption=NbsO -font_size=10 -font_name=Tahoma -00=NbsOL -01= -02=E -03= -04= -05= -06= - -[Dialog9] -caption=PIĎo -font_size=10 -font_name=Tahoma -00=fZbg -01=Zbg -02=PCRZbg -03= -04=fPIDƂăZbgɂ́AsIă{^ĂB - -[Dialog10] -caption=gbN̑I -font_size=10 -font_name=Tahoma -00=OK -01=LZ -02=I[fBIIDR}ŋ؂ė񋓂ĂB - -[Dialog11] -caption=͂gbN̑I -font_size=10 -font_name=Tahoma -00=OK -01=LZ -02=I[fBIID0x‚Ȃ16iŎw肵ĂB - -[Dialog12] -caption=}[W̐ݒ -font_size=10 -font_name=Tahoma -00=OK -01=LZ -02=}[W: -03=~b diff --git a/build/msvcX/DGDecode/DGDecode.vcxproj b/build/msvcX/DGDecode/DGDecode.vcxproj deleted file mode 100644 index 043587a..0000000 --- a/build/msvcX/DGDecode/DGDecode.vcxproj +++ /dev/null @@ -1,205 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {13BF3FBA-7CD9-4374-83D5-E001E722E3DE} - Win32Proj - DGDecode - 8.1 - MPEG2DecPlus - - - - - DynamicLibrary - true - MultiByte - - - DynamicLibrary - true - MultiByte - - - DynamicLibrary - false - true - MultiByte - v140 - - - DynamicLibrary - false - true - MultiByte - v140 - - - - - - - - - - - - - - - - - - - true - $(SolutionDir)..\..\bin\msvc$(VisualStudioVersion)\$(Configuration)\ - $(Configuration)\msvc$(VisualStudioVersion)\ - - - true - - - false - $(SolutionDir)..\..\bin\msvc$(VisualStudioVersion)\$(Configuration)\ - $(Configuration)\msvc$(VisualStudioVersion)\ - - - false - $(ProjectName)64 - - - - - - Level3 - Disabled - _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;DGDECODE_EXPORTS;%(PreprocessorDefinitions) - C:\my_projects\AviSynthPlus\avs_core\include;..\..\..\src\dgdecode - - - Windows - true - shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - - - - - - - Level3 - Disabled - _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;_USRDLL;DGDECODE_EXPORTS;%(PreprocessorDefinitions) - C:\my_projects\AviSynthPlus\avs_core\include;..\..\..\src\dgdecode - - - Windows - true - shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - - - - - Level3 - - - MaxSpeed - false - true - _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;DGDECODE_EXPORTS;%(PreprocessorDefinitions) - C:\my_projects\AviSynthPlus\avs_core\include;..\..\..\src\dgdecode - true - AnySuitable - StreamingSIMDExtensions2 - Fast - true - Speed - - - Windows - true - true - true - shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - false - - - - - Level3 - - - MaxSpeed - false - true - _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;_USRDLL;DGDECODE_EXPORTS;%(PreprocessorDefinitions) - C:\my_projects\AviSynthPlus\avs_core\include;..\..\..\src\dgdecode - true - AnySuitable - Speed - true - NotSet - Fast - - - Windows - true - true - true - shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - false - - - - - - - - - - - - - AdvancedVectorExtensions2 - AdvancedVectorExtensions2 - AdvancedVectorExtensions2 - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/build/msvcX/DGDecode/DGDecode.vcxproj.filters b/build/msvcX/DGDecode/DGDecode.vcxproj.filters deleted file mode 100644 index c2790ac..0000000 --- a/build/msvcX/DGDecode/DGDecode.vcxproj.filters +++ /dev/null @@ -1,99 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - {b92ffe8f-65a1-47d7-b2eb-8eafdef68fd7} - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - MPEG2DecPlus - - - MPEG2DecPlus - - - MPEG2DecPlus - - - MPEG2DecPlus - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files - - - MPEG2DecPlus - - - MPEG2DecPlus - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - \ No newline at end of file diff --git a/build/msvcX/DGIndex/DGIndex.vcxproj b/build/msvcX/DGIndex/DGIndex.vcxproj deleted file mode 100644 index 2181632..0000000 --- a/build/msvcX/DGIndex/DGIndex.vcxproj +++ /dev/null @@ -1,256 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {7BED3DC2-9B7C-446A-997F-9AD4560B1709} - Win32Proj - DGIndex - - - - - Application - true - MultiByte - - - Application - true - MultiByte - - - Application - false - true - MultiByte - - - Application - false - true - MultiByte - - - - - - - - - - - - - - - - - - - true - $(SolutionDir)..\..\bin\msvc$(VisualStudioVersion)\$(Configuration)\ - $(Configuration)\msvc$(VisualStudioVersion)\ - - - true - - - false - $(SolutionDir)..\..\bin\msvc$(VisualStudioVersion)\$(Configuration)\ - $(Configuration)\msvc$(VisualStudioVersion)\ - - - false - - - - - - Level3 - Disabled - _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - ..\..\..\src\dgindex - - - Windows - true - shlwapi.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - 4096000 - - - - - - - Level3 - Disabled - _CRT_SECURE_NO_WARNINGS;WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) - ..\..\..\src\dgindex - - - Windows - true - shlwapi.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - 4096000 - - - - - Level3 - - - MaxSpeed - true - true - _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - ..\..\..\src\dgindex - - - Windows - true - true - true - shlwapi.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - 4096000 - false - - - - - Level3 - - - MaxSpeed - true - true - _CRT_SECURE_NO_WARNINGS;WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) - ..\..\..\src\dgindex - - - Windows - true - true - true - shlwapi.lib;winmm.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) - 4096000 - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ml /c /coff /Cx /nologo /Fo $(IntDir)%(Filename).obj %(FullPath) - - ml /c /coff /Cx /nologo /Fo $(IntDir)%(Filename).obj %(FullPath) - - $(IntDir)%(Filename).obj;%(Outputs) - $(IntDir)%(Filename).obj;%(Outputs) - ml /c /coff /Cx /nologo /Fo $(IntDir)%(Filename).obj %(FullPath) - - ml /c /coff /Cx /nologo /Fo $(IntDir)%(Filename).obj %(FullPath) - - $(IntDir)%(Filename).obj;%(Outputs) - $(IntDir)%(Filename).obj;%(Outputs) - - - nasm -f win32 -DPREFIX -DWIN32 -o $(IntDir)%(Filename).obj %(FullPath) - - nasm -f win32 -DPREFIX -DWIN32 -o $(IntDir)%(Filename).obj %(FullPath) - - $(IntDir)%(Filename).obj;%(Outputs) - $(IntDir)%(Filename).obj;%(Outputs) - nasm -f win32 -DPREFIX -DWIN32 -o $(IntDir)%(Filename).obj %(FullPath) - - nasm -f win32 -DPREFIX -DWIN32 -o $(IntDir)%(Filename).obj %(FullPath) - - $(IntDir)%(Filename).obj;%(Outputs) - $(IntDir)%(Filename).obj;%(Outputs) - - - %40copy /Y ..\..\..\src\dgdecode\skl_nasm.h .\ >NUL -nasm -f win32 -DPREFIX -DWIN32 -o $(IntDir)%(Filename).obj %(FullPath) -%40del /Q .\*.h - - %40copy /Y ..\..\..\src\dgdecode\skl_nasm.h .\ >NUL -nasm -f win32 -DPREFIX -DWIN32 -o $(IntDir)%(Filename).obj %(FullPath) -%40del /Q .\*.h - - $(IntDir)%(Filename).obj;%(Outputs) - $(IntDir)%(Filename).obj;%(Outputs) - %40copy /Y ..\..\..\src\dgdecode\skl_nasm.h .\ >NUL -nasm -f win32 -DPREFIX -DWIN32 -o $(IntDir)%(Filename).obj %(FullPath) -%40del /Q .\*.h - - %40copy /Y ..\..\..\src\dgdecode\skl_nasm.h .\ >NUL -nasm -f win32 -DPREFIX -DWIN32 -o $(IntDir)%(Filename).obj %(FullPath) -%40del /Q .\*.h - - $(IntDir)%(Filename).obj;%(Outputs) - $(IntDir)%(Filename).obj;%(Outputs) - - - - - - \ No newline at end of file diff --git a/build/msvcX/DGIndex/DGIndex.vcxproj.filters b/build/msvcX/DGIndex/DGIndex.vcxproj.filters deleted file mode 100644 index 0dce877..0000000 --- a/build/msvcX/DGIndex/DGIndex.vcxproj.filters +++ /dev/null @@ -1,156 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - {a1228af4-4725-4835-8ecb-323a1e68029d} - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - AC3Dec - - - AC3Dec - - - AC3Dec - - - AC3Dec - - - AC3Dec - - - AC3Dec - - - AC3Dec - - - AC3Dec - - - AC3Dec - - - AC3Dec - - - AC3Dec - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - AC3Dec - - - AC3Dec - - - - - Resource Files - - - - - Resource Files - - - - - Source Files - - - Source Files - - - Source Files - - - \ No newline at end of file diff --git a/build/msvcX/DGMPGDec.sln b/build/msvcX/DGMPGDec.sln deleted file mode 100644 index 92db205..0000000 --- a/build/msvcX/DGMPGDec.sln +++ /dev/null @@ -1,38 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.25420.1 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DGIndex", "DGIndex\DGIndex.vcxproj", "{7BED3DC2-9B7C-446A-997F-9AD4560B1709}" -EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MPEG2DecPlus", "DGDecode\DGDecode.vcxproj", "{13BF3FBA-7CD9-4374-83D5-E001E722E3DE}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Debug|x64 = Debug|x64 - Release|Win32 = Release|Win32 - Release|x64 = Release|x64 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {7BED3DC2-9B7C-446A-997F-9AD4560B1709}.Debug|Win32.ActiveCfg = Debug|Win32 - {7BED3DC2-9B7C-446A-997F-9AD4560B1709}.Debug|Win32.Build.0 = Debug|Win32 - {7BED3DC2-9B7C-446A-997F-9AD4560B1709}.Debug|x64.ActiveCfg = Debug|x64 - {7BED3DC2-9B7C-446A-997F-9AD4560B1709}.Debug|x64.Build.0 = Debug|x64 - {7BED3DC2-9B7C-446A-997F-9AD4560B1709}.Release|Win32.ActiveCfg = Release|Win32 - {7BED3DC2-9B7C-446A-997F-9AD4560B1709}.Release|Win32.Build.0 = Release|Win32 - {7BED3DC2-9B7C-446A-997F-9AD4560B1709}.Release|x64.ActiveCfg = Release|x64 - {7BED3DC2-9B7C-446A-997F-9AD4560B1709}.Release|x64.Build.0 = Release|x64 - {13BF3FBA-7CD9-4374-83D5-E001E722E3DE}.Debug|Win32.ActiveCfg = Debug|Win32 - {13BF3FBA-7CD9-4374-83D5-E001E722E3DE}.Debug|Win32.Build.0 = Debug|Win32 - {13BF3FBA-7CD9-4374-83D5-E001E722E3DE}.Debug|x64.ActiveCfg = Debug|x64 - {13BF3FBA-7CD9-4374-83D5-E001E722E3DE}.Debug|x64.Build.0 = Debug|x64 - {13BF3FBA-7CD9-4374-83D5-E001E722E3DE}.Release|Win32.ActiveCfg = Release|Win32 - {13BF3FBA-7CD9-4374-83D5-E001E722E3DE}.Release|Win32.Build.0 = Release|Win32 - {13BF3FBA-7CD9-4374-83D5-E001E722E3DE}.Release|x64.ActiveCfg = Release|x64 - {13BF3FBA-7CD9-4374-83D5-E001E722E3DE}.Release|x64.Build.0 = Release|x64 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/build/msvcX/msvcX.props b/build/msvcX/msvcX.props deleted file mode 100644 index 2aade2b..0000000 --- a/build/msvcX/msvcX.props +++ /dev/null @@ -1,8 +0,0 @@ - - - - v110_xp - v120_xp - v140_xp - - diff --git a/cmake_uninstall.cmake.in b/cmake_uninstall.cmake.in new file mode 100644 index 0000000..c2d34d4 --- /dev/null +++ b/cmake_uninstall.cmake.in @@ -0,0 +1,21 @@ +if(NOT EXISTS "@CMAKE_BINARY_DIR@/install_manifest.txt") + message(FATAL_ERROR "Cannot find install manifest: @CMAKE_BINARY_DIR@/install_manifest.txt") +endif() + +file(READ "@CMAKE_BINARY_DIR@/install_manifest.txt" files) +string(REGEX REPLACE "\n" ";" files "${files}") +foreach(file ${files}) + message(STATUS "Uninstalling $ENV{DESTDIR}${file}") + if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + exec_program( + "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" + OUTPUT_VARIABLE rm_out + RETURN_VALUE rm_retval + ) + if(NOT "${rm_retval}" STREQUAL 0) + message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") + endif() + else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") + message(STATUS "File $ENV{DESTDIR}${file} does not exist.") + endif() +endforeach() diff --git a/config.sh b/config.sh deleted file mode 100755 index a783c4e..0000000 --- a/config.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh -ERR_EXIT () { - echo $1; exit 1 -} - -cwd="$(cd $(dirname $0); pwd)" - -version='' -clean='no' - -config_h="$cwd/src/config.h" - -# Parse options -for opt do - optarg="${opt#*=}" - case "$opt" in - --clean) - clean='yes' - ;; - *) - ERR_EXIT "Unknown option ... $opt" - ;; - esac -done - -# Output config.h -if [ "$clean" = 'yes' -o ! -d "$cwd/.git" ]; then - cat > "$config_h" << EOF -#undef DGMPGDEC_GIT_VERSION -EOF -else - cd "$cwd" - if [ -n "`git tag`" ]; then - version="`git describe --tags`" - echo "$version" - echo "#define DGMPGDEC_GIT_VERSION \"$version\"" > "$config_h" - else - echo "#undef DGMPGDEC_GIT_VERSION" > "$config_h" - fi -fi diff --git a/msvc/D2VSource.sln b/msvc/D2VSource.sln new file mode 100644 index 0000000..12a3121 --- /dev/null +++ b/msvc/D2VSource.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30204.135 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "D2VSource", "D2VSource.vcxproj", "{BE45DDEC-9C54-4E57-BE8C-3CDE734BEAA6}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BE45DDEC-9C54-4E57-BE8C-3CDE734BEAA6}.Debug|x64.ActiveCfg = Debug|x64 + {BE45DDEC-9C54-4E57-BE8C-3CDE734BEAA6}.Debug|x64.Build.0 = Debug|x64 + {BE45DDEC-9C54-4E57-BE8C-3CDE734BEAA6}.Debug|x86.ActiveCfg = Debug|Win32 + {BE45DDEC-9C54-4E57-BE8C-3CDE734BEAA6}.Debug|x86.Build.0 = Debug|Win32 + {BE45DDEC-9C54-4E57-BE8C-3CDE734BEAA6}.Release|x64.ActiveCfg = Release|x64 + {BE45DDEC-9C54-4E57-BE8C-3CDE734BEAA6}.Release|x64.Build.0 = Release|x64 + {BE45DDEC-9C54-4E57-BE8C-3CDE734BEAA6}.Release|x86.ActiveCfg = Release|Win32 + {BE45DDEC-9C54-4E57-BE8C-3CDE734BEAA6}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {80DFC486-AC15-406C-BBDA-6D722A495010} + EndGlobalSection +EndGlobal diff --git a/msvc/D2VSource.vcxproj b/msvc/D2VSource.vcxproj new file mode 100644 index 0000000..3d1ea44 --- /dev/null +++ b/msvc/D2VSource.vcxproj @@ -0,0 +1,191 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + {BE45DDEC-9C54-4E57-BE8C-3CDE734BEAA6} + Win32Proj + 10.0 + + + + Application + true + v142 + + + DynamicLibrary + false + v142 + + + DynamicLibrary + true + v142 + + + DynamicLibrary + false + v142 + + + + + + + + + + + + + + + + + + + + + true + + + false + ..\..\AviSynthPlus\avs_core\include;$(IncludePath) + + + ..\..\AviSynthPlus\avs_core\include;$(IncludePath) + false + + + ..\..\AviSynthPlus\avs_core\include;$(IncludePath) + + + + WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + MultiThreadedDebugDLL + Level3 + ProgramDatabase + Disabled + + + MachineX86 + true + Windows + + + + + WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + MultiThreadedDLL + Level3 + ProgramDatabase + true + AnySuitable + true + Speed + true + true + Precise + stdcpp17 + true + + + MachineX86 + true + Windows + true + true + UseLinkTimeCodeGeneration + + + + + true + AnySuitable + true + Speed + true + true + stdcpp17 + true + Precise + + + true + + + true + UseLinkTimeCodeGeneration + + + + + stdcpp17 + + + + + + + + + + + false + + + + AdvancedVectorExtensions2 + AdvancedVectorExtensions2 + AdvancedVectorExtensions2 + + + + + + + + + false + + + + + + + false + + + + + + + + false + + + + + + + + + \ No newline at end of file diff --git a/msvc/D2VSource.vcxproj.filters b/msvc/D2VSource.vcxproj.filters new file mode 100644 index 0000000..7cad7bd --- /dev/null +++ b/msvc/D2VSource.vcxproj.filters @@ -0,0 +1,98 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Resource Files + + + \ No newline at end of file diff --git a/src/AVISynthAPI.cpp b/src/AVISynthAPI.cpp new file mode 100644 index 0000000..56b652f --- /dev/null +++ b/src/AVISynthAPI.cpp @@ -0,0 +1,656 @@ +/* + * Avisynth 2.5 API for MPEG2Dec3 + * + * Changes to fix frame dropping and random frame access are + * Copyright (C) 2003-2008 Donald A. Graft + * + * Copyright (C) 2002-2003 Marc Fauconneau + * + * based of the intial MPEG2Dec Avisytnh API Copyright (C) Mathias Born - May 2001 + * + * This file is part of DGMPGDec, a free MPEG-2 decoder + * + * DGMPGDec 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. + * + * DGMPGDec is distributed in the hope that 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 +#include +#include +#include +#include +#include +#include +#include + +#include "AVISynthAPI.h" +#include "color_convert.h" +#include "misc.h" +#ifndef _WIN32 +#include + +#include "win_import_min.h" + +#define _MAX_PATH PATH_MAX +#endif + +#define VERSION "D2VSource 1.2.3" + +bool PutHintingData(uint8_t* video, uint32_t hint) +{ + constexpr uint32_t MAGIC_NUMBER = 0xdeadbeef; + + for (int i = 0; i < 32; ++i) { + *video &= ~1; + *video++ |= ((MAGIC_NUMBER & (1 << i)) >> i); + } + for (int i = 0; i < 32; i++) { + *video &= ~1; + *video++ |= ((hint & (1 << i)) >> i); + } + return false; +} + + +static void luminance_filter(uint8_t* luma, const int width, const int height, + const int pitch, const uint8_t* table) +{ + for (int y = 0; y < height; ++y) { + for (int x = 0; x < width; ++x) { + luma[x] = table[luma[x]]; + } + luma += pitch; + } +} + + +static void show_info(int n, CMPEG2Decoder& d, PVideoFrame& frame, + const VideoInfo& vi, IScriptEnvironment* env) +{ + uint32_t raw = std::max(d.FrameList[n].bottom, d.FrameList[n].top); + if (raw < d.BadStartingFrames) + raw = d.BadStartingFrames; + + uint32_t gop = 0; + do { + if (raw >= d.GOPList[gop].number) + if (raw < d.GOPList[static_cast(gop) + 1].number) + break; + } while (++gop < d.GOPList.size() - 1); + + const auto& rgop = d.GOPList[gop]; + const auto& fraw = d.FrameList[raw]; + const auto& fn = d.FrameList[n]; + + int pct = fraw.pct == I_TYPE ? 'I' : fraw.pct == B_TYPE ? 'B' : 'P'; + + const char* matrix[8] = { + "Forbidden", + "ITU-R BT.709", + "Unspecified Video", + "Reserved", + "FCC", + "ITU-R BT.470-2 System B, G", + "SMPTE 170M", + "SMPTE 240M (1987)", + }; + + if (d.info == 1) { + char msg1[1024]; + sprintf_s(msg1, "%s\n" + "---------------------------------------\n" + "Source: %s\n" + "Frame Rate: %3.6f fps (%u/%u) %s\n" + "Field Order: %s\n" + "Picture Size: %d x %d\n" + "Aspect Ratio: %s\n" + "Progr Seq: %s\n" + "GOP Number: %u (%u) GOP Pos = %I64d\n" + "Closed GOP: %s\n" + "Display Frame: %d\n" + "Encoded Frame: %d (top) %d (bottom)\n" + "Frame Type: %c (%d)\n" + "Progr Frame: %s\n" + "Colorimetry: %s (%d)\n" + "Quants: %d/%d/%d (avg/min/max)\n", + VERSION, + d.Infilename[rgop.file].c_str(), + double(d.VF_FrameRate_Num) / double(d.VF_FrameRate_Den), + d.VF_FrameRate_Num, + d.VF_FrameRate_Den, + (d.VF_FrameRate == 25000 || d.VF_FrameRate == 50000) ? "(PAL)" : + d.VF_FrameRate == 29970 ? "(NTSC)" : "", + d.Field_Order == 1 ? "Top Field First" : "Bottom Field First", + d.getLumaWidth(), d.getLumaHeight(), + d.Aspect_Ratio, + rgop.progressive ? "True" : "False", +#ifdef _WIN32 + gop, rgop.number, rgop.position, +#else + gop, rgop.number, static_cast(rgop.position), +#endif + rgop.closed ? "True" : "False", + n, + fn.top, fn.bottom, + pct, raw, + fraw.pf ? "True" : "False", + matrix[rgop.matrix], rgop.matrix, + d.avgquant, d.minquant, d.maxquant); + env->ApplyMessage(&frame, vi, msg1, 150, 0xdfffbf, 0x0, 0x0); + + } + else if (d.info == 2) { + dprintf(const_cast("MPEG2DecPlus: %s\n"), VERSION); + dprintf(const_cast("MPEG2DecPlus: Source: %s\n"), d.Infilename[rgop.file].c_str()); + dprintf(const_cast("MPEG2DecPlus: Frame Rate: %3.6f fps (%u/%u) %s\n"), + double(d.VF_FrameRate_Num) / double(d.VF_FrameRate_Den), + d.VF_FrameRate_Num, d.VF_FrameRate_Den, + (d.VF_FrameRate == 25000 || d.VF_FrameRate == 50000) ? "(PAL)" : d.VF_FrameRate == 29970 ? "(NTSC)" : ""); + dprintf(const_cast("MPEG2DecPlus: Field Order: %s\n"), d.Field_Order == 1 ? "Top Field First" : "Bottom Field First"); + dprintf(const_cast("MPEG2DecPlus: Picture Size: %d x %d\n"), d.getLumaWidth(), d.getLumaHeight()); + dprintf(const_cast("MPEG2DecPlus: Aspect Ratio: %s\n"), d.Aspect_Ratio); + dprintf(const_cast("MPEG2DecPlus: Progressive Seq: %s\n"), rgop.progressive ? "True" : "False"); + dprintf(const_cast("MPEG2DecPlus: GOP Number: %d (%d) GOP Pos = %I64d\n"), gop, rgop.number, rgop.position); + dprintf(const_cast("MPEG2DecPlus: Closed GOP: %s\n"), rgop.closed ? "True" : "False"); + dprintf(const_cast("MPEG2DecPlus: Display Frame: %d\n"), n); + dprintf(const_cast("MPEG2DecPlus: Encoded Frame: %d (top) %d (bottom)\n"), fn.top, fn.bottom); + dprintf(const_cast("MPEG2DecPlus: Frame Type: %c (%d)\n"), pct, raw); + dprintf(const_cast("MPEG2DecPlus: Progressive Frame: %s\n"), fraw.pf ? "True" : "False"); + dprintf(const_cast("MPEG2DecPlus: Colorimetry: %s (%d)\n"), matrix[rgop.matrix], rgop.matrix); + dprintf(const_cast("MPEG2DecPlus: Quants: %d/%d/%d (avg/min/max)\n"), d.avgquant, d.minquant, d.maxquant); + + } + else if (d.info == 3) { + constexpr uint32_t PROGRESSIVE = 0x00000001; + constexpr int COLORIMETRY_SHIFT = 2; + + uint32_t hint = 0; + if (fraw.pf == 1) hint |= PROGRESSIVE; + hint |= ((rgop.matrix & 7) << COLORIMETRY_SHIFT); + PutHintingData(frame->GetWritePtr(PLANAR_Y), hint); + } +} + + +D2VSource::D2VSource(const char* d2v, int idct, bool showQ, + int _info, int _upConv, bool _i420, int iCC, int _rff, + IScriptEnvironment* env) : + bufY(nullptr), bufU(nullptr), bufV(nullptr), decoder(nullptr) +{ + if (_rff < -1 || _rff > 2) + env->ThrowError("D2VSource: rff must be set to -1, 0, 1 or 2!"); + + if (iCC != -1 && iCC != 0 && iCC != 1) + env->ThrowError("D2VSource: iCC must be set to -1, 0, or 1!"); + + if (_upConv != 0 && _upConv != 1 && _upConv != 2) + env->ThrowError("D2VSource: upConv must be set to 0, 1, or 2!"); + + if (idct > 7) + env->ThrowError("D2VSource: iDCT invalid (1:MMX,2:SSEMMX,3:SSE2,4:FPU,5:REF,6:Skal's,7:Simple)"); + + FILE* f; +#ifdef _WIN32 + fopen_s(&f, d2v, "r"); +#else + f = fopen(d2v, "r"); +#endif + if (f == nullptr) + env->ThrowError("D2VSource: unable to load D2V file \"%s\" ", d2v); + + try { + decoder = new CMPEG2Decoder(f, d2v, idct, iCC, _upConv, _info, showQ, _i420, _rff, env->GetCPUFlags()); + } + catch (std::runtime_error& e) { + if (f) fclose(f); + env->ThrowError("D2VSource: %s", e.what()); + } + + env->AtExit([](void* p, IScriptEnvironment*) { delete reinterpret_cast(p); p = nullptr; }, decoder); + auto& d = *decoder; + + int chroma_format = d.getChromaFormat(); + + memset(&vi, 0, sizeof(vi)); + vi.width = d.Clip_Width; + vi.height = d.Clip_Height; + if (_upConv == 2) vi.pixel_type = VideoInfo::CS_YV24; + else if (chroma_format == 2 || _upConv == 1) vi.pixel_type = VideoInfo::CS_YV16; + else if (d.i420 == true) vi.pixel_type = VideoInfo::CS_I420; + else vi.pixel_type = VideoInfo::CS_YV12; + + vi.SetFPS(d.VF_FrameRate_Num, d.VF_FrameRate_Den); + vi.num_frames = static_cast(d.FrameList.size()); + vi.SetFieldBased(false); + + if (_upConv == 2) { + auto free_buf = [](void* p, IScriptEnvironment* e) { + _aligned_free(p); + p = nullptr; + }; + size_t ysize = ((static_cast(vi.width) + 31) & ~31) * (static_cast(vi.height) + 1); + size_t uvsize = ((static_cast(d.getChromaWidth()) + 15) & ~15) * (static_cast(vi.height) + 1); + void* ptr = _aligned_malloc(ysize + 2 * uvsize, 32); + if (!ptr) { + env->ThrowError("D2VSource: malloc failure (bufY, bufU, bufV)!"); + } + env->AtExit(free_buf, ptr); + bufY = reinterpret_cast(ptr); + bufU = bufY + ysize; + bufV = bufU + uvsize; + } + + luminanceFlag = (d.lumGamma != 0 || d.lumOffset != 0); + if (luminanceFlag) { + int lg = d.lumGamma; + int lo = d.lumOffset; + for (int i = 0; i < 256; ++i) { + double value = 255.0 * pow(i / 255.0, pow(2.0, -lg / 128.0)) + lo + 0.5; + + if (value < 0) + luminanceTable[i] = 0; + else if (value > 255.0) + luminanceTable[i] = 255; + else + luminanceTable[i] = static_cast(value); + } + } + + has_at_least_v8 = true; + try { env->CheckVersion(8); } + catch (const AvisynthError&) { has_at_least_v8 = false; } + + std::vector ar; + ar.reserve(2); + std::stringstream str(d.Aspect_Ratio); + int n; + char ch; + while (str >> n) + { + if (str >> ch) + ar.push_back(n); + else + ar.push_back(n); + } + + const double sar = ar[0] / static_cast(ar[1]) / (static_cast(vi.width) / vi.height); + double decimal_part = sar - static_cast(sar); + + std::valarray vec_1{ double(static_cast(sar)), 1 }, vec_2{ 1,0 }, temporary; + + while (decimal_part > 0.005) + { + const double new_number = 1 / decimal_part; + const double whole_part = static_cast(new_number); + + temporary = vec_1; + vec_1 = whole_part * vec_1 + vec_2; + vec_2 = temporary; + + decimal_part = new_number - whole_part; + } + + env->SetVar(env->Sprintf("%s", "FFSAR_NUM"), static_cast(vec_1[0])); + env->SetVar(env->Sprintf("%s", "FFSAR_DEN"), static_cast(vec_1[1])); + + if (vec_1[0] > 0 && vec_1[1] > 0) + env->SetVar(env->Sprintf("%s", "FFSAR"), sar); +} + + +unsigned int gcd(unsigned int a, unsigned int b) +{ + if (b == 0) + return a; + return gcd(b, a % b); +} + + +bool __stdcall D2VSource::GetParity(int) +{ + return decoder->Field_Order == 1; +} + + +PVideoFrame __stdcall D2VSource::GetFrame(int n, IScriptEnvironment* env) +{ + auto& d = *decoder; + PVideoFrame frame = env->NewVideoFrame(vi, 32); + YV12PICT out = (d.upConv != 2) ? YV12PICT(frame) : + YV12PICT(bufY, bufU, bufV, vi.width, d.getChromaWidth(), vi.height); + + d.Decode(n, out); + + if (luminanceFlag) + luminance_filter(out.y, out.ywidth, out.yheight, out.ypitch, luminanceTable); + + if (d.upConv == 2) { // convert 4:2:2 (planar) to 4:4:4 (planar) + env->BitBlt(frame->GetWritePtr(PLANAR_Y), frame->GetPitch(PLANAR_Y), + bufY, out.ypitch, vi.width, vi.height); + conv422to444(out.u, frame->GetWritePtr(PLANAR_U), out.uvpitch, + frame->GetPitch(PLANAR_U), vi.width, vi.height); + conv422to444(out.v, frame->GetWritePtr(PLANAR_V), out.uvpitch, + frame->GetPitch(PLANAR_V), vi.width, vi.height); + } + + if (d.info != 0) + show_info(n, d, frame, vi, env); + + if (has_at_least_v8) + { + AVSMap* props = env->getFramePropsRW(frame); + + /* Sample duration */ + env->propSetInt(props, "_DurationNum", d.VF_FrameRate_Den, 0); + env->propSetInt(props, "_DurationDen", d.VF_FrameRate_Num, 0); + /* BFF or TFF */ + uint32_t raw = std::max(d.FrameList[n].bottom, d.FrameList[n].top); + if (raw < d.BadStartingFrames) + raw = d.BadStartingFrames; + + uint32_t gop = 0; + do { + if (raw >= d.GOPList[gop].number) + if (raw < d.GOPList[static_cast(gop) + 1].number) + break; + } while (++gop < d.GOPList.size() - 1); + + const auto& rgop = d.GOPList[gop]; + + int field_based = 0; + if (!rgop.progressive) + field_based = d.Field_Order == 1 ? 2 : 1; + env->propSetInt(props, "_FieldBased", field_based, 0); + env->propSetInt(props, "_FieldOrder", d.Field_Order, 0); + /* AR */ + int64_t dar[2]; + static_cast(sscanf(d.Aspect_Ratio, "%lld:%lld", &dar[0], &dar[1])); + env->propSetIntArray(props, "_AspectRatio", dar, 2); + + auto par_num = 0; + auto par_den = 0; + if (d.D2V_Height > 576) + { + // HD. Use PAR 1:1. + par_num = 1; + par_den = 1; + } + else + { + // SD. We have 4 cases. + if (d.aspect_ratio_information == 2 && d.D2V_Height == 480) + { + par_num = 10; + par_den = 11; + } + else if (d.aspect_ratio_information == 2 && d.D2V_Height == 576) + { + par_num = 12; + par_den = 11; + } + else if (d.aspect_ratio_information == 3 && d.D2V_Height == 480) + { + par_num = 40; + par_den = 33; + } + else if (d.aspect_ratio_information == 3 && d.D2V_Height == 576) + { + par_num = 16; + par_den = 11; + } + else + { + // Not a standard SD case. Calculate the PAR. + switch (d.aspect_ratio_information) + { + case 0: + par_num = 0; + par_den = 0; + break; + case 1: + par_num = 1; + par_den = 1; + break; + case 2: + par_num = 4 * d.D2V_Height; + par_den = 3 * d.D2V_Width; + break; + case 3: + par_num = 16 * d.D2V_Height; + par_den = 9 * d.D2V_Width; + break; + case 4: + par_num = 221 * d.D2V_Height; + par_den = 100 * d.D2V_Width; + break; + default: + par_num = 0; + par_den = 0; + break; + } + int divisor = gcd(par_num, par_den); + par_num /= divisor; + par_den /= divisor; + } + } + env->propSetInt(props, "_SARNum", par_num, 0); + env->propSetInt(props, "_SARDen", par_den, 0); + /* GOP */ + int64_t gop_number[2] = { gop, rgop.number }; + env->propSetIntArray(props, "_GOPNumber", gop_number, 2); + env->propSetInt(props, "_GOPPosition", rgop.position, 0); + + int closed_gop = rgop.closed ? 1 : 0; + env->propSetInt(props, "_GOPClosed", closed_gop, 0); + /* Encoded frame */ + const auto& fn = d.FrameList[n]; + + env->propSetInt(props, "_EncodedFrameTop", fn.top, 0); + env->propSetInt(props, "_EncodedFrameBottom", fn.bottom, 0); + /* Picture type */ + const auto& fraw = d.FrameList[raw]; + const char* pct = fraw.pct == I_TYPE ? "I" : fraw.pct == B_TYPE ? "B" : "P"; + + env->propSetData(props, "_PictType", pct, 1, 0); + /* Matrix */ + env->propSetInt(props, "_Matrix", rgop.matrix, 0); + /* Quants */ + d.has_prop = true; + env->propSetInt(props, "_QuantsAverage", d.avgquant, 0); + env->propSetInt(props, "_QuantsMin", d.minquant, 0); + env->propSetInt(props, "_QuantsMax", d.maxquant, 0); + // Pulldown stuff. + env->propSetInt(props, "_FieldOperation", d.FO_Flag, 0); + if (d.FO_Flag == FO_RAW) + { + // Ignore pulldown. + env->propSetInt(props, "_TFF", (fn.type & 2) == 2, 0); + env->propSetInt(props, "_RFF", fn.type & 1, 0); + history[0] = history[1]; + history[1] = history[2]; + history[2] = history[3]; + history[3] = fn.type & 1; + if ((history[0] == 0 && history[1] == 1 && history[2] == 0 && history[3] == 1) || + (history[0] == 1 && history[1] == 0 && history[2] == 1 && history[3] == 0)) + env->propSetInt(props, "_Film", 1, 0); + else + env->propSetInt(props, "_Film", 0, 0); + } + else + { + // Honor pulldown or force film. + env->propSetInt(props, "_TFF", -1, 0); + env->propSetInt(props, "_RFF", fn.top != fn.bottom, 0); + history[0] = history[1]; + history[1] = history[2]; + history[2] = history[3]; + history[3] = history[4]; + history[4] = fn.top != fn.bottom; + if ((history[0] == 1 && history[1] == 1 && history[2] == 0 && history[3] == 0 && history[4] == 0) || + (history[0] == 0 && history[1] == 1 && history[2] == 1 && history[3] == 0 && history[4] == 0) || + (history[0] == 0 && history[1] == 0 && history[2] == 1 && history[3] == 1 && history[4] == 0) || + (history[0] == 0 && history[1] == 0 && history[2] == 0 && history[3] == 1 && history[4] == 1) || + (history[0] == 1 && history[1] == 0 && history[2] == 0 && history[3] == 0 && history[4] == 1)) + env->propSetInt(props, "_Film", 1, 0); + else + env->propSetInt(props, "_Film", 0, 0); + } + env->propSetInt(props, "_ProgressiveFrame", fraw.pf, 0); + env->propSetInt(props, "_ChromaLocation", d.mpeg_type == IS_MPEG2 ? 0 : 1, 0); + env->propSetFloat(props, "_AbsoluteTime", (static_cast(d.VF_FrameRate_Den) * n) / d.VF_FrameRate_Num, 0); + } + + return frame; +} + + +static void set_user_default(FILE* def, char* d2v, int& idct, bool& showq, + int& info, int upcnv, bool& i420, int& icc) +{ + char buf[512]; + auto load_str = [&buf](char* var, const char* name, int len) { + if (strncmp(buf, name, len) == 0) { + std::vector tmp(512, 0); + sscanf_s(buf, name, tmp.data()); + tmp.erase(std::remove(tmp.begin(), tmp.end(), '"'), tmp.end()); + strncpy_s(var, tmp.size() + 1, tmp.data(), tmp.size()); + } + }; + auto load_int = [&buf](int& var, const char* name, int len) { + if (strncmp(buf, name, len) == 0) { + sscanf_s(buf, name, &var); + } + }; + auto load_bool = [&buf](bool& var, const char* name, int len) { + if (strncmp(buf, name, len) == 0) { + char tmp[16]; + sscanf_s(buf, name, &tmp); + var = tmp[0] == 't'; + } + }; + auto load_bint = [&buf](int& var, const char* name, int len) { + if (strncmp(buf, name, len) == 0) { + char tmp[16]; + sscanf_s(buf, name, &tmp); + var = tmp[0] == 't' ? 1 : 0; + } + }; + + while (fgets(buf, 511, def) != 0) { + load_str(d2v, "d2v=%s", 4); + load_int(idct, "idct=%d", 5); + load_bool(showq, "showQ=%s", 6); + load_int(info, "info=%d", 5); + load_int(upcnv, "upConv=%d", 7); + load_bool(i420, "i420=%s", 5); + load_bint(icc, "iCC=%s", 4); + } +} + + +AVSValue __cdecl D2VSource::create(AVSValue args, void*, IScriptEnvironment* env) +{ + char d2v[512]; + int idct = -1; + + int iCC = args[6].IsBool() ? (args[6].AsBool() ? 1 : 0) : -1; + + bool showQ = false; + int info = 0; + int upConv = 0; + bool i420 = false; + + FILE* def; +#ifdef _WIN32 + fopen_s(&def, "MPEG2DecPlus.def", "r"); +#else + def = fopen("MPEG2DecPlus.def", "r"); +#endif + if (def != nullptr) { + set_user_default(def, d2v, idct, showQ, info, upConv, i420, iCC); + fclose(def); + } + + // check for uninitialised strings + if (strlen(d2v) >= _MAX_PATH) d2v[0] = 0; + + D2VSource* dec = new D2VSource( + args[0].AsString(d2v), + args[1].AsInt(idct), + args[2].AsBool(showQ), + args[3].AsInt(info), + args[4].AsInt(upConv), + args[5].AsBool(i420), + iCC, + args[8].AsInt(-1), + env); + + if (!args[7].AsBool(false)) + { + // Only bother invoking crop if we have to. + auto& d = *dec->decoder; + if (d.Clip_Top || d.Clip_Bottom || d.Clip_Left || d.Clip_Right || + // This is cheap but it works. The intent is to allow the + // display size to be different from the encoded size, while + // not requiring massive revisions to the code. So we detect the + // difference and crop it off. + d.vertical_size != d.Clip_Height || d.horizontal_size != d.Clip_Width || + d.vertical_size == 1088) + { + int vertical; + // Special case for 1088 to 1080 as directed by DGIndex. + if (d.vertical_size == 1088 && d.D2V_Height == 1080) + vertical = 1080; + else + vertical = d.vertical_size; + AVSValue CropArgs[] = { + dec, + d.Clip_Left, + d.Clip_Top, + -(d.Clip_Right + (d.Clip_Width - d.horizontal_size)), + -(d.Clip_Bottom + (d.Clip_Height - vertical)), + true + }; + + return env->Invoke("crop", AVSValue(CropArgs, 6)); + } + } + + return dec; +} + +const AVS_Linkage* AVS_linkage = nullptr; + +extern "C" __declspec(dllexport) const char* __stdcall +AvisynthPluginInit3(IScriptEnvironment * env, const AVS_Linkage* const vectors) +{ + AVS_linkage = vectors; + + const char* msargs = + "[d2v]s" + "[idct]i" + "[showQ]b" + "[info]i" + "[upConv]i" + "[i420]b" + "[iCC]b" + "[nocrop]b" + "[rff]i"; + + env->AddFunction("D2VSource", msargs, D2VSource::create, nullptr); + + return VERSION; +} + diff --git a/src/AVISynthAPI.h b/src/AVISynthAPI.h new file mode 100644 index 0000000..518ad69 --- /dev/null +++ b/src/AVISynthAPI.h @@ -0,0 +1,56 @@ +/* + * Avisynth 2.5 API for MPEG2Dec3 + * + * Copyright (C) 2002-2003 Marc Fauconneau + * + * based of the intial MPEG2Dec Avisytnh API Copyright (C) Mathias Born - May 2001 + * + * This file is part of MPEG2Dec3, a free MPEG-2 decoder + * + * MPEG2Dec3 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. + * + * MPEG2Dec3 is distributed in the hope that 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. + * + */ + +#ifndef MPEG2DECPLUS_AVS_API_H +#define MPEG2DECPLUS_AVS_API_H + +#include + +#include "avisynth.h" +#include "MPEG2Decoder.h" + + +class D2VSource : public IClip { + VideoInfo vi; + //int _PP_MODE; + uint8_t* bufY, * bufU, * bufV; // for 4:2:2 input support + CMPEG2Decoder* decoder; + bool luminanceFlag; + uint8_t luminanceTable[256]; + bool has_at_least_v8; + int history[5]; + +public: + D2VSource(const char* d2v, int idct, bool showQ, int _info, int _upConv, bool _i420, int iCC, int _rff, IScriptEnvironment* env); + ~D2VSource() {} + PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env); + bool __stdcall GetParity(int n); + void __stdcall GetAudio(void* buf, int64_t start, int64_t count, IScriptEnvironment* env) {}; + const VideoInfo& __stdcall GetVideoInfo() { return vi; } + int __stdcall SetCacheHints(int hints, int) { return hints == CACHE_GET_MTMODE ? MT_SERIALIZED : 0; }; + static AVSValue __cdecl create(AVSValue args, void*, IScriptEnvironment* env); +}; + +#endif diff --git a/src/dgdecode/MPEG2Decoder.cpp b/src/MPEG2Decoder.cpp similarity index 57% rename from src/dgdecode/MPEG2Decoder.cpp rename to src/MPEG2Decoder.cpp index f8f90b9..d5a13a6 100644 --- a/src/dgdecode/MPEG2Decoder.cpp +++ b/src/MPEG2Decoder.cpp @@ -20,25 +20,25 @@ * */ -/* - lots of code modified for YV12 / MPEG2Dec3 - MarcFD -*/ + /* + lots of code modified for YV12 / MPEG2Dec3 - MarcFD + */ #include -#include +#include #include +#include + #include "MPEG2Decoder.h" +#include "idct.h" #include "mc.h" #include "misc.h" -#include "idct.h" -#include "shlwapi.h" -static const int ChromaFormat[4] = { +static constexpr int ChromaFormat[4] = { 0, 6, 8, 12 }; - static void validate(bool cond, const char* msg) { if (cond) throw std::runtime_error(msg); @@ -46,12 +46,7 @@ static void validate(bool cond, const char* msg) // Open function modified by Donald Graft as part of fix for dropped frames and random frame access. // change function to constructor - chikuzen. -CMPEG2Decoder::CMPEG2Decoder(FILE* d2vf, const char* path, int _idct, int icc, - int upconv, int _info, bool showq, bool _i420) : - VF_FrameRate(0), - VF_FrameRate_Num(0), - VF_FrameRate_Den(0), - prev_frame(0xfffffffe), +CMPEG2Decoder::CMPEG2Decoder(FILE* d2vf, const char* path, int _idct, int icc, int upconv, int _info, bool showq, bool _i420, int _rff, int _cpu_flags) : Rdmax(nullptr), CurrentBfr(0), NextBfr(0), @@ -71,11 +66,16 @@ CMPEG2Decoder::CMPEG2Decoder(FILE* d2vf, const char* path, int _idct, int icc, quantizer_scale(0), auxFrame1(nullptr), auxFrame2(nullptr), - upConv(upconv), + prev_frame(0xfffffffe), + VF_FrameRate(0), + VF_FrameRate_Num(0), + VF_FrameRate_Den(0), + iCC(icc), showQ(showq), + upConv(upconv), + i420(_i420), info(_info), - iCC(icc), - i420(_i420) + cpu_flags(_cpu_flags) { memset(intra_quantizer_matrix, 0, sizeof(intra_quantizer_matrix)); memset(non_intra_quantizer_matrix, 0, sizeof(non_intra_quantizer_matrix)); @@ -93,45 +93,48 @@ CMPEG2Decoder::CMPEG2Decoder(FILE* d2vf, const char* path, int _idct, int icc, validate(fgets(buf, 2047, d2vf) == nullptr, "Invalid D2V file, it's empty!"); validate(strstr(buf, "DGIndexProjectFile") == nullptr, - "The input file is not a D2V project file."); + "The input file is not a D2V project file."); validate(strncmp(buf, "DGIndexProjectFile16", 20) != 0, - "DGIndex/MPEG2DecPlus mismatch. You are picking up\n" - "a version of MPEG2DecPlus, possibly from your plugins directory,\n" - "that does not match the version of DGIndex used to make the D2V\n" - "file. Search your hard disk for all copies of MPEG2DecPlus.dll\n" - "and delete or rename all of them except for the one that\n" - "has the same version number as the DGIndex.exe that was used\n" - "to make the D2V file."); + "DGIndex/MPEG2DecPlus mismatch. You are picking up\n" + "a version of MPEG2DecPlus, possibly from your plugins directory,\n" + "that does not match the version of DGIndex used to make the D2V\n" + "file. Search your hard disk for all copies of MPEG2DecPlus.dll\n" + "and delete or rename all of them except for the one that\n" + "has the same version number as the DGIndex.exe that was used\n" + "to make the D2V file."); create_file_lists(d2vf, path, buf); - fscanf(d2vf, "\nStream_Type=%d\n", &SystemStream_Flag); + fscanf_s(d2vf, "\nStream_Type=%d\n", &SystemStream_Flag); if (SystemStream_Flag == 2) { - fscanf(d2vf, "MPEG2_Transport_PID=%x,%x,%x\n", - &MPEG2_Transport_VideoPID, &MPEG2_Transport_AudioPID, &MPEG2_Transport_PCRPID); - fscanf(d2vf, "Transport_Packet_Size=%d\n", &TransportPacketSize); + fscanf_s(d2vf, "MPEG2_Transport_PID=%x,%x,%x\n", + &MPEG2_Transport_VideoPID, &MPEG2_Transport_AudioPID, &MPEG2_Transport_PCRPID); + fscanf_s(d2vf, "Transport_Packet_Size=%d\n", &TransportPacketSize); } - fscanf(d2vf, "MPEG_Type=%d\n", &mpeg_type); + fscanf_s(d2vf, "MPEG_Type=%d\n", &mpeg_type); int idct; - fscanf(d2vf, "iDCT_Algorithm=%d\n", &idct); + fscanf_s(d2vf, "iDCT_Algorithm=%d\n", &idct); if (_idct > 0) { idct = _idct; } setIDCT(idct); - fscanf(d2vf, "YUVRGB_Scale=%d\n", &i); + fscanf_s(d2vf, "YUVRGB_Scale=%d\n", &i); - fscanf(d2vf, "Luminance_Filter=%d,%d\n", &lumGamma, &lumOffset); + fscanf_s(d2vf, "Luminance_Filter=%d,%d\n", &lumGamma, &lumOffset); - fscanf(d2vf, "Clipping=%d,%d,%d,%d\n", + fscanf_s(d2vf, "Clipping=%d,%d,%d,%d\n", &Clip_Left, &Clip_Right, &Clip_Top, &Clip_Bottom); - fscanf(d2vf, "Aspect_Ratio=%s\n", Aspect_Ratio); - fscanf(d2vf, "Picture_Size=%dx%d\n", &D2V_Width, &D2V_Height); - fscanf(d2vf, "Field_Operation=%d\n", &FO_Flag); - fscanf(d2vf, "Frame_Rate=%d (%u/%u)\n", &(VF_FrameRate), &(VF_FrameRate_Num), &(VF_FrameRate_Den)); - fscanf(d2vf, "Location=%d,%X,%d,%X\n", &i, &j, &i, &j); + fscanf_s(d2vf, "Aspect_Ratio=%s\n", Aspect_Ratio, static_cast(sizeof(Aspect_Ratio))); + fscanf_s(d2vf, "Picture_Size=%dx%d\n", &D2V_Width, &D2V_Height); + fscanf_s(d2vf, "Field_Operation=%d\n", &FO_Flag); + fscanf_s(d2vf, "Frame_Rate=%d (%u/%u)\n", &(VF_FrameRate), &(VF_FrameRate_Num), &(VF_FrameRate_Den)); + fscanf_s(d2vf, "Location=%d,%X,%d,%X\n", &i, &j, &i, &j); + + if (_rff > -1) + FO_Flag = _rff; create_gop_and_frame_lists(d2vf, buf); fclose(d2vf); @@ -150,15 +153,18 @@ void CMPEG2Decoder::setIDCT(int idct) if (idct == IDCT_REF) { prefetchTables = prefetch_ref; idctFunction = idct_ref_sse3; - } else if (idct == IDCT_LLM_FLOAT) { - if (has_avx2()) { + } + else if (idct == IDCT_LLM_FLOAT) { + if (!!(cpu_flags & CPUF_AVX2)) { prefetchTables = prefetch_llm_float_avx2; idctFunction = idct_llm_float_avx2; - } else { + } + else { prefetchTables = prefetch_llm_float_sse2; idctFunction = idct_llm_float_sse2; } - } else { + } + else { prefetchTables = prefetch_ap922; idctFunction = idct_ap922_sse2; } @@ -173,13 +179,13 @@ void CMPEG2Decoder::set_clip_properties() do { validate(Fault_Flag == OUT_OF_BITS, - "Could not find a sequence header in the input stream."); + "Could not find a sequence header in the input stream."); Next_Start_Code(); } while (Get_Bits(32) != SEQUENCE_HEADER_CODE); Sequence_Header(); validate(chroma_format == CHROMA444, - "currently unsupported input color format (4:4:4)"); + "currently unsupported input color format (4:4:4)"); mb_width = (horizontal_size + 15) / 16; mb_height = progressive_sequence ? (vertical_size + 15) / 16 : 2 * ((vertical_size + 31) / 32); @@ -196,38 +202,43 @@ void CMPEG2Decoder::set_clip_properties() Clip_Height = Coded_Picture_Height; } - void CMPEG2Decoder::create_file_lists(FILE* d2vf, const char* path, char* buf) { int file_limit; - fscanf(d2vf, "%d\n", &file_limit); + fscanf_s(d2vf, "%d\n", &file_limit); Infile.reserve(file_limit); Infilename.reserve(file_limit); while (file_limit-- > 0) { fgets(buf, 2047, d2vf); - auto temp = std::string(buf); + std::string temp{ std::string(buf) }; temp.pop_back(); // Strip newline. - if (PathIsRelativeA(temp.c_str())) { - std::string d2v_stem; + if (temp.find('\r') != std::string::npos) { + temp.pop_back(); // remove further unwanted char CR... + } - if (PathIsRelativeA(path)) { - GetCurrentDirectoryA(_MAX_PATH, buf); - d2v_stem += buf; - if (d2v_stem.back() != '\\') d2v_stem.push_back('\\'); - } - d2v_stem += path; + const std::filesystem::path p(temp); - while (d2v_stem.back() != '\\') d2v_stem.pop_back(); - d2v_stem += temp; - PathCanonicalizeA(buf, d2v_stem.c_str()); - int in = _open(buf, _O_RDONLY | _O_BINARY); + if (p.is_relative()) { + const std::string d2v_stem{ std::filesystem::canonical(std::filesystem::path(path).parent_path().generic_string() + ((std::filesystem::path(path).has_parent_path()) ? "/" : "") + p.generic_string()).generic_string() }; +#ifdef _WIN32 + int in; + _sopen_s(&in, d2v_stem.c_str(), _O_RDONLY | _O_BINARY, _SH_DENYWR, 0); +#else + int in{ open(d2v_stem.c_str(), O_RDONLY) }; +#endif validate(in == -1, "Could not open one of the input files."); Infile.emplace_back(in); - Infilename.emplace_back(buf); - } else { - int in = _open(temp.c_str(), _O_RDONLY | _O_BINARY); + Infilename.emplace_back(d2v_stem); + } + else { +#ifdef _WIN32 + int in; + _sopen_s(&in, temp.c_str(), _O_RDONLY | _O_BINARY, _SH_DENYWR, 0); +#else + int in{ open(temp.c_str(), O_RDONLY) }; +#endif validate(in == -1, "Could not open one of the input files."); Infile.emplace_back(in); Infilename.emplace_back(temp); @@ -235,45 +246,44 @@ void CMPEG2Decoder::create_file_lists(FILE* d2vf, const char* path, char* buf) } } - void CMPEG2Decoder::create_gop_and_frame_lists(FILE* d2vf, char* buf) { uint32_t type, tff, rff, film, ntsc, top, bottom, mapping; int repeat_on, repeat_off, repeat_init; ntsc = film = top = bottom = mapping = repeat_on = repeat_off = repeat_init = 0; HaveRFFs = false; - + // These start with sizes of 1000000 (the old fixed default). If it // turns out that that is too small, the memory spaces are enlarged // 500000 at a time using realloc. -- tritical May 16, 2005 DirectAccess.reserve(1000000); FrameList.resize(1000000); GOPList.reserve(200000); - + fgets(buf, 2047, d2vf); char* buf_p = buf; - + while (true) { - sscanf(buf_p, "%x", &type); + sscanf_s(buf_p, "%x", &type); if (type == 0xff) break; if (type & 0x800) { // New I-frame line start. int matrix, file, ic, vob_id, cell_id; while (*buf_p++ != ' '); - sscanf(buf_p, "%d", &matrix); + sscanf_s(buf_p, "%d", &matrix); while (*buf_p++ != ' '); - sscanf(buf_p, "%d", &file); + sscanf_s(buf_p, "%d", &file); while (*buf_p++ != ' '); int64_t position = _atoi64(buf_p); while (*buf_p++ != ' '); - sscanf(buf_p, "%d", &ic); + sscanf_s(buf_p, "%d", &ic); while (*buf_p++ != ' '); - sscanf(buf_p, "%d %d", &vob_id, &cell_id); + sscanf_s(buf_p, "%d %d", &vob_id, &cell_id); while (*buf_p++ != ' '); while (*buf_p++ != ' '); GOPList.emplace_back(film, matrix, file, position, ic, type); - - sscanf(buf_p, "%x", &type); + + sscanf_s(buf_p, "%x", &type); } tff = (type & 0x2) >> 1; if (FO_Flag == FO_RAW) @@ -281,14 +291,14 @@ void CMPEG2Decoder::create_gop_and_frame_lists(FILE* d2vf, char* buf) else rff = type & 0x1; if (FO_Flag != FO_FILM && FO_Flag != FO_RAW && rff) HaveRFFs = true; - + if (!film) { if (tff) Field_Order = 1; else Field_Order = 0; } - + size_t listsize = FrameList.size() - 2; if (mapping >= listsize || ntsc >= listsize || film >= listsize) { FrameList.resize(listsize + 500002); @@ -302,26 +312,26 @@ void CMPEG2Decoder::create_gop_and_frame_lists(FILE* d2vf, char* buf) if (repeat_init) { - if (repeat_off-repeat_on == 5) + if (repeat_off - repeat_on == 5) { repeat_on = repeat_off = 0; } else { FrameList[mapping].top = FrameList[mapping].bottom = film; - mapping ++; + mapping++; } - - if (repeat_on-repeat_off == 5) + + if (repeat_on - repeat_off == 5) { repeat_on = repeat_off = 0; FrameList[mapping].top = FrameList[mapping].bottom = film; - mapping ++; + mapping++; } } else { - if (repeat_off-repeat_on == 3) + if (repeat_off - repeat_on == 3) { repeat_on = repeat_off = 0; repeat_init = 1; @@ -329,15 +339,15 @@ void CMPEG2Decoder::create_gop_and_frame_lists(FILE* d2vf, char* buf) else { FrameList[mapping].top = FrameList[mapping].bottom = film; - mapping ++; + mapping++; } - if (repeat_on-repeat_off == 3) + if (repeat_on - repeat_off == 3) { repeat_on = repeat_off = 0; repeat_init = 1; FrameList[mapping].top = FrameList[mapping].bottom = film; - mapping ++; + mapping++; } } } @@ -393,7 +403,7 @@ void CMPEG2Decoder::create_gop_and_frame_lists(FILE* d2vf, char* buf) FrameList[ntsc].bottom = film; bottom = 1; } - + if (top && bottom) { top = bottom = 0; @@ -405,6 +415,8 @@ void CMPEG2Decoder::create_gop_and_frame_lists(FILE* d2vf, char* buf) FrameList[film].pct = (unsigned char)((type & 0x30) >> 4); FrameList[film].pf = (unsigned char)((type & 0x40) >> 6); + // This is used only for FO_RAW. + FrameList[film].type = type; // Remember if this encoded frame requires the previous GOP to be decoded. // The previous GOP is required if DVD2AVI has marked it as such. @@ -425,12 +437,13 @@ void CMPEG2Decoder::create_gop_and_frame_lists(FILE* d2vf, char* buf) GOPList.shrink_to_fit(); DirectAccess.shrink_to_fit(); - if (FO_Flag==FO_FILM) { - while (FrameList[mapping-1].top >= film) + if (FO_Flag == FO_FILM) { + while (FrameList[mapping - 1].top >= film) --mapping; FrameList.resize(mapping); - } else { - while ((FrameList[ntsc-1].top >= film) || (FrameList[ntsc-1].bottom >= film)) + } + else { + while ((FrameList[ntsc - 1].top >= film) || (FrameList[ntsc - 1].bottom >= film)) --ntsc; FrameList.resize(ntsc); } @@ -468,9 +481,9 @@ void CMPEG2Decoder::destroy() void CMPEG2Decoder::allocate_buffers() { - QP = (int*)_aligned_malloc(sizeof(int)*mb_width*mb_height, 32); - backwardQP = (int*)_aligned_malloc(sizeof(int)*mb_width*mb_height, 32); - auxQP = (int*)_aligned_malloc(sizeof(int)*mb_width*mb_height, 32); + QP = (int*)_aligned_malloc(sizeof(int) * mb_width * mb_height, 32); + backwardQP = (int*)_aligned_malloc(sizeof(int) * mb_width * mb_height, 32); + auxQP = (int*)_aligned_malloc(sizeof(int) * mb_width * mb_height, 32); if (!QP || !backwardQP || !auxQP) { destroy(); throw std::runtime_error("failed to allocate QP buffers."); @@ -491,9 +504,9 @@ void CMPEG2Decoder::allocate_buffers() size_t size; for (int i = 0; i < 3; i++) { if (i == 0) - size = Coded_Picture_Width * Coded_Picture_Height; + size = static_cast(Coded_Picture_Width) * Coded_Picture_Height; else - size = Chroma_Width * Chroma_Height; + size = static_cast(Chroma_Width) * Chroma_Height; backward_reference_frame[i] = (unsigned char*)_aligned_malloc(2 * size + 4096, 32); //>>> cheap safety bump forward_reference_frame[i] = (unsigned char*)_aligned_malloc(2 * size + 4096, 32); @@ -509,7 +522,8 @@ void CMPEG2Decoder::allocate_buffers() try { auxFrame1 = new YV12PICT(Coded_Picture_Height, Coded_Picture_Width, cf); auxFrame2 = new YV12PICT(Coded_Picture_Height, Coded_Picture_Width, cf); - } catch (std::runtime_error& e) { + } + catch (std::runtime_error& e) { destroy(); throw e; } @@ -567,187 +581,171 @@ void CMPEG2Decoder::search_bad_starting() void CMPEG2Decoder::Decode(uint32_t frame, YV12PICT& dst) { -__try { - Fault_Flag = 0; - Second_Field = 0; - - // Skip initial non-decodable frames. - frame = std::max(frame, BadStartingFrames); - - uint32_t requested_frame = frame; - - // Decide whether to use random access or linear play to reach the - // requested frame. If the seek is just a few frames forward, it will - // be faster to play linearly to get there. This greatly speeds things up - // when a decimation like SelectEven() follows this filter. - if (frame && frame > BadStartingFrames && frame > prev_frame - && frame < prev_frame + SEEK_THRESHOLD) { - // Use linear play. - for (frame = prev_frame + 1; frame <= requested_frame; ++frame) { - - // If doing force film, we have to skip or repeat a frame as needed. - // This handles skipping. Repeating is handled below. - if ((FO_Flag==FO_FILM) - && (FrameList[frame].bottom == FrameList[frame-1].bottom + 2) - && (FrameList[frame].top == FrameList[frame-1].top + 2)) { - if (!Get_Hdr()) { - // Flush the final frame. - assembleFrame(backward_reference_frame, pf_backward, dst); - return; - } - Decode_Picture(dst); - if (Fault_Flag == OUT_OF_BITS) { - assembleFrame(backward_reference_frame, pf_backward, dst); - return; - } - if (picture_structure != FRAME_PICTURE) { - Get_Hdr(); + try { + Fault_Flag = 0; + Second_Field = 0; + + // Skip initial non-decodable frames. + frame = std::max(frame, BadStartingFrames); + + uint32_t requested_frame = frame; + + // Decide whether to use random access or linear play to reach the + // requested frame. If the seek is just a few frames forward, it will + // be faster to play linearly to get there. This greatly speeds things up + // when a decimation like SelectEven() follows this filter. + if (frame && frame > BadStartingFrames && frame > prev_frame + && frame < prev_frame + SEEK_THRESHOLD) { + // Use linear play. + for (frame = prev_frame + 1; frame <= requested_frame; ++frame) { + + // If doing force film, we have to skip or repeat a frame as needed. + // This handles skipping. Repeating is handled below. + if ((FO_Flag == FO_FILM) + && (FrameList[frame].bottom == FrameList[frame - 1].bottom + 2) + && (FrameList[frame].top == FrameList[frame - 1].top + 2)) { + if (!Get_Hdr()) { + // Flush the final frame. + assembleFrame(backward_reference_frame, pf_backward, dst); + return; + } Decode_Picture(dst); + if (Fault_Flag == OUT_OF_BITS) { + assembleFrame(backward_reference_frame, pf_backward, dst); + return; + } + if (picture_structure != FRAME_PICTURE) { + Get_Hdr(); + Decode_Picture(dst); + } } - } - /* When RFFs are present or we are doing FORCE FILM, we may have already decoded - the frame that we need. So decode the next frame only when we need to. */ - if (std::max(FrameList[frame].top, FrameList[frame].bottom) > - std::max(FrameList[frame-1].top, FrameList[frame-1].bottom)) { - if (!Get_Hdr()) { - assembleFrame(backward_reference_frame, pf_backward, dst); - return; - } - Decode_Picture(dst); - if (Fault_Flag == OUT_OF_BITS) { - assembleFrame(backward_reference_frame, pf_backward, dst); - return; - } - if (picture_structure != FRAME_PICTURE) { - Get_Hdr(); + /* When RFFs are present or we are doing FORCE FILM, we may have already decoded + the frame that we need. So decode the next frame only when we need to. */ + if (std::max(FrameList[frame].top, FrameList[frame].bottom) > + std::max(FrameList[frame - 1].top, FrameList[frame - 1].bottom)) { + if (!Get_Hdr()) { + assembleFrame(backward_reference_frame, pf_backward, dst); + return; + } Decode_Picture(dst); + if (Fault_Flag == OUT_OF_BITS) { + assembleFrame(backward_reference_frame, pf_backward, dst); + return; + } + if (picture_structure != FRAME_PICTURE) { + Get_Hdr(); + Decode_Picture(dst); + } + /* If RFFs are present we have to save the decoded frame to + be able to pull down from it when we decode the next frame. + If we are doing FORCE FILM, then we may need to repeat the + frame, so we'll save it for that purpose. */ + if (FO_Flag == FO_FILM || HaveRFFs) { + // Save the current frame without overwriting the last + // stored frame. + YV12PICT* tmp = saved_active; + saved_active = saved_store; + saved_store = tmp; + copy_all(dst, *saved_store); + } } - /* If RFFs are present we have to save the decoded frame to - be able to pull down from it when we decode the next frame. - If we are doing FORCE FILM, then we may need to repeat the - frame, so we'll save it for that purpose. */ - if (FO_Flag == FO_FILM || HaveRFFs) { - // Save the current frame without overwriting the last - // stored frame. - YV12PICT* tmp = saved_active; - saved_active = saved_store; - saved_store = tmp; - copy_all(dst, *saved_store); + else { + // We already decoded the needed frame. Retrieve it. + copy_all(*saved_store, dst); } - } else { - // We already decoded the needed frame. Retrieve it. - copy_all(*saved_store, dst); - } - // Perform pulldown if required. - if (HaveRFFs) { - if (FrameList[frame].top > FrameList[frame].bottom) { - copy_bottom(*saved_active, dst); - } else if (FrameList[frame].top < FrameList[frame].bottom) { - copy_top(*saved_active, dst); + // Perform pulldown if required. + if (HaveRFFs) { + if (FrameList[frame].top > FrameList[frame].bottom) { + copy_bottom(*saved_active, dst); + } + else if (FrameList[frame].top < FrameList[frame].bottom) { + copy_top(*saved_active, dst); + } } } + prev_frame = requested_frame; + return; } - prev_frame = requested_frame; - return; - } - prev_frame = requested_frame; - // Have to do random access. - uint32_t f = std::max(FrameList[frame].top, FrameList[frame].bottom); - - // Determine the GOP that the requested frame is in. - uint32_t gop; - for (gop = 0; gop < GOPList.size() - 1; ++gop) { - if (f >= GOPList[gop].number && f < GOPList[gop + 1].number) { - break; + prev_frame = requested_frame; + // Have to do random access. + uint32_t f = std::max(FrameList[frame].top, FrameList[frame].bottom); + + // Determine the GOP that the requested frame is in. + uint32_t gop; + for (gop = 0; gop < GOPList.size() - 1; ++gop) { + if (f >= GOPList[gop].number && f < GOPList[gop + static_cast(1)].number) { + break; + } } - } - - // Back off by one GOP if required. This ensures enough frames will - // be decoded that the requested frame is guaranteed to be decodable. - // The direct flag is written by DGIndex, who knows which frames - // require the previous GOP to be decoded. We also test whether - // the previous encoded frame requires it, because that one might be pulled - // down for this frame. This can be improved by actually testing if the - // previous frame will be pulled down. - // Obviously we can't decrement gop if it is 0. - if (gop) { - if (DirectAccess[f] == 0 || (f && DirectAccess[f - 1] == 0)) - gop--; - // This covers the special case where a field of the previous GOP is - // pulled down into the current GOP. - else if (f == GOPList[gop].number && FrameList[frame].top != FrameList[frame].bottom) - gop--; - } - - // Calculate how many frames to decode. - uint32_t count = f - GOPList[gop].number; - // Seek in the stream to the GOP to start decoding with. - File_Flag = GOPList[gop].file; - _lseeki64(Infile[GOPList[gop].file], - GOPList[gop].position, - SEEK_SET); - Initialize_Buffer(); + // Back off by one GOP if required. This ensures enough frames will + // be decoded that the requested frame is guaranteed to be decodable. + // The direct flag is written by DGIndex, who knows which frames + // require the previous GOP to be decoded. We also test whether + // the previous encoded frame requires it, because that one might be pulled + // down for this frame. This can be improved by actually testing if the + // previous frame will be pulled down. + // Obviously we can't decrement gop if it is 0. + if (gop) { + if (DirectAccess[f] == 0 || (f && DirectAccess[f - 1] == 0)) + gop--; + // This covers the special case where a field of the previous GOP is + // pulled down into the current GOP. + else if (f == GOPList[gop].number && FrameList[frame].top != FrameList[frame].bottom) + gop--; + } - // Start decoding. Stop when the requested frame is decoded. - // First decode the required I picture of the D2V index line. - // An indexed unit (especially a pack) can contain multiple I frames. - // If we did nothing we would have multiple D2V lines with the same position - // and the navigation code in DGDecode would be confused. We detect this in DGIndex - // by seeing how many previous lines we have written with the same position. - // We store that number in the D2V file and DGDecode uses that as the - // number of I frames to skip before settling on the required one. - // So, in fact, we are indexing position plus number of I frames to skip. - for (uint32_t i = 0; i <= GOPList[gop].I_count; ++i) { - bool HadI = false; - while (true) { - if (!Get_Hdr()) { - // Something is really messed up. - return; - } - Decode_Picture(dst); - if (picture_coding_type == I_TYPE) - HadI = true; - if (picture_structure != FRAME_PICTURE) { - Get_Hdr(); + // Calculate how many frames to decode. + uint32_t count = f - GOPList[gop].number; + + // Seek in the stream to the GOP to start decoding with. + File_Flag = GOPList[gop].file; + _lseeki64(Infile[GOPList[gop].file], + GOPList[gop].position, + SEEK_SET); + Initialize_Buffer(); + + // Start decoding. Stop when the requested frame is decoded. + // First decode the required I picture of the D2V index line. + // An indexed unit (especially a pack) can contain multiple I frames. + // If we did nothing we would have multiple D2V lines with the same position + // and the navigation code in DGDecode would be confused. We detect this in DGIndex + // by seeing how many previous lines we have written with the same position. + // We store that number in the D2V file and DGDecode uses that as the + // number of I frames to skip before settling on the required one. + // So, in fact, we are indexing position plus number of I frames to skip. + for (uint32_t i = 0; i <= GOPList[gop].I_count; ++i) { + bool HadI = false; + while (true) { + if (!Get_Hdr()) { + // Something is really messed up. + return; + } Decode_Picture(dst); if (picture_coding_type == I_TYPE) HadI = true; - // The reason for this next test is quite technical. For details - // refer to the file CodeNote1.txt. - if (Second_Field == 1) { + if (picture_structure != FRAME_PICTURE) { Get_Hdr(); Decode_Picture(dst); + if (picture_coding_type == I_TYPE) + HadI = true; + // The reason for this next test is quite technical. For details + // refer to the file CodeNote1.txt. + if (Second_Field == 1) { + Get_Hdr(); + Decode_Picture(dst); + } } + if (HadI) break; } - if (HadI) break; } - } - Second_Field = 0; - if (HaveRFFs == true && count == 0) { - copy_all(dst, *saved_active); - } - if (!Get_Hdr()) { - // Flush the final frame. - assembleFrame(backward_reference_frame, pf_backward, dst); - return; - } - Decode_Picture(dst); - if (Fault_Flag == OUT_OF_BITS) { - assembleFrame(backward_reference_frame, pf_backward, dst); - return; - } - if (picture_structure != FRAME_PICTURE) { - Get_Hdr(); - Decode_Picture(dst); - } - if (HaveRFFs && count == 1) { - copy_all(dst, *saved_active); - } - for (uint32_t i = 0; i < count; ++i) { + Second_Field = 0; + if (HaveRFFs == true && count == 0) { + copy_all(dst, *saved_active); + } if (!Get_Hdr()) { // Flush the final frame. assembleFrame(backward_reference_frame, pf_backward, dst); @@ -762,33 +760,54 @@ __try { Get_Hdr(); Decode_Picture(dst); } - if ((HaveRFFs == true) && (count > 1) && (i == count - 2)) { + if (HaveRFFs && count == 1) { copy_all(dst, *saved_active); } - } + for (uint32_t i = 0; i < count; ++i) { + if (!Get_Hdr()) { + // Flush the final frame. + assembleFrame(backward_reference_frame, pf_backward, dst); + return; + } + Decode_Picture(dst); + if (Fault_Flag == OUT_OF_BITS) { + assembleFrame(backward_reference_frame, pf_backward, dst); + return; + } + if (picture_structure != FRAME_PICTURE) { + Get_Hdr(); + Decode_Picture(dst); + } + if ((HaveRFFs == true) && (count > 1) && (i == count - 2)) { + copy_all(dst, *saved_active); + } + } - if (HaveRFFs) { - // Save for transition to non-random mode. - copy_all(dst, *saved_store); + if (HaveRFFs) { + // Save for transition to non-random mode. + copy_all(dst, *saved_store); - // Pull down a field if needed. - if (FrameList[frame].top > FrameList[frame].bottom) { - copy_bottom(*saved_active, dst); - } else if (FrameList[frame].top < FrameList[frame].bottom) { - copy_top(*saved_active, dst); + // Pull down a field if needed. + if (FrameList[frame].top > FrameList[frame].bottom) { + copy_bottom(*saved_active, dst); + } + else if (FrameList[frame].top < FrameList[frame].bottom) { + copy_top(*saved_active, dst); + } } + return; + } + catch (...) { + fprintf(stderr, "Exception caught\n"); + return; } - return; -} __except(EXCEPTION_EXECUTE_HANDLER) { - return; -} } __forceinline void CMPEG2Decoder::copy_all(YV12PICT& src, YV12PICT& dst) { - int t = (upConv > 0 && chroma_format == 1) ? Chroma_Height*2 : Chroma_Height; - fast_copy(src.y, src.ypitch, dst.y, dst.ypitch, dst.ywidth,Coded_Picture_Height); + int t = (upConv > 0 && chroma_format == 1) ? Chroma_Height * 2 : Chroma_Height; + fast_copy(src.y, src.ypitch, dst.y, dst.ypitch, dst.ywidth, Coded_Picture_Height); fast_copy(src.u, src.uvpitch, dst.u, dst.uvpitch, dst.uvwidth, t); fast_copy(src.v, src.uvpitch, dst.v, dst.uvpitch, dst.uvwidth, t); } @@ -825,11 +844,11 @@ copy_oddeven(const uint8_t* odd, const size_t opitch, const uint8_t* even, } while (--height != 0); } -void CMPEG2Decoder::CopyTopBot(YV12PICT *odd, YV12PICT *even, YV12PICT *dst) +void CMPEG2Decoder::CopyTopBot(YV12PICT* odd, YV12PICT* even, YV12PICT* dst) { - int tChroma_Height = (upConv > 0 && chroma_format == 1) ? Chroma_Height*2 : Chroma_Height; - copy_oddeven(odd->y,odd->ypitch*2,even->y+even->ypitch,even->ypitch*2,dst->y,dst->ypitch,dst->ywidth,Coded_Picture_Height>>1); - copy_oddeven(odd->u,odd->uvpitch*2,even->u+even->uvpitch,even->uvpitch*2,dst->u,dst->uvpitch,dst->uvwidth,tChroma_Height>>1); - copy_oddeven(odd->v,odd->uvpitch*2,even->v+even->uvpitch,even->uvpitch*2,dst->v,dst->uvpitch,dst->uvwidth,tChroma_Height>>1); + int tChroma_Height = (upConv > 0 && chroma_format == 1) ? Chroma_Height * 2 : Chroma_Height; + copy_oddeven(odd->y, odd->ypitch * 2, even->y + even->ypitch, even->ypitch * 2, dst->y, dst->ypitch, dst->ywidth, Coded_Picture_Height >> 1); + copy_oddeven(odd->u, odd->uvpitch * 2, even->u + even->uvpitch, even->uvpitch * 2, dst->u, dst->uvpitch, dst->uvwidth, tChroma_Height >> 1); + copy_oddeven(odd->v, odd->uvpitch * 2, even->v + even->uvpitch, even->uvpitch * 2, dst->v, dst->uvpitch, dst->uvwidth, tChroma_Height >> 1); } #endif diff --git a/src/dgdecode/MPEG2Decoder.h b/src/MPEG2Decoder.h similarity index 79% rename from src/dgdecode/MPEG2Decoder.h rename to src/MPEG2Decoder.h index 11bb297..a90cb6c 100644 --- a/src/dgdecode/MPEG2Decoder.h +++ b/src/MPEG2Decoder.h @@ -1,53 +1,51 @@ #ifndef MPEG2DECODER_H #define MPEG2DECODER_H - +#include #include #include -#include +#include #include #include -#include -#include - -#define WIN32_LEAN_AND_MEAN -#define NOMINMAX -#include -#include #include "yv12pict.h" +#ifndef _WIN32 +#include "win_import_min.h" +#else +#include +#endif /* code definition */ enum { - PICTURE_START_CODE = 0x100, - SLICE_START_CODE_MIN = 0x101, - SLICE_START_CODE_MAX = 0x1AF, - USER_DATA_START_CODE = 0x1B2, - SEQUENCE_HEADER_CODE = 0x1B3, - EXTENSION_START_CODE = 0x1B5, - SEQUENCE_END_CODE = 0x1B7, - GROUP_START_CODE = 0x1B8, - - SYSTEM_END_CODE = 0x1B9, - PACK_START_CODE = 0x1BA, - SYSTEM_START_CODE = 0x1BB, - PRIVATE_STREAM_1 = 0x1BD, + PICTURE_START_CODE = 0x100, + SLICE_START_CODE_MIN = 0x101, + SLICE_START_CODE_MAX = 0x1AF, + USER_DATA_START_CODE = 0x1B2, + SEQUENCE_HEADER_CODE = 0x1B3, + EXTENSION_START_CODE = 0x1B5, + SEQUENCE_END_CODE = 0x1B7, + GROUP_START_CODE = 0x1B8, + + SYSTEM_END_CODE = 0x1B9, + PACK_START_CODE = 0x1BA, + SYSTEM_START_CODE = 0x1BB, + PRIVATE_STREAM_1 = 0x1BD, VIDEO_ELEMENTARY_STREAM = 0x1E0, }; /* extension start code IDs */ enum { - SEQUENCE_EXTENSION_ID = 1, + SEQUENCE_EXTENSION_ID = 1, SEQUENCE_DISPLAY_EXTENSION_ID = 2, - QUANT_MATRIX_EXTENSION_ID = 3, - COPYRIGHT_EXTENSION_ID = 4, - PICTURE_DISPLAY_EXTENSION_ID = 7, - PICTURE_CODING_EXTENSION_ID = 8, + QUANT_MATRIX_EXTENSION_ID = 3, + COPYRIGHT_EXTENSION_ID = 4, + PICTURE_DISPLAY_EXTENSION_ID = 7, + PICTURE_CODING_EXTENSION_ID = 8, }; enum { - ZIG_ZAG = 0, + ZIG_ZAG = 0, MB_WEIGHT = 32, MB_CLASS4 = 64, }; @@ -60,16 +58,16 @@ enum { }; enum { - TOP_FIELD = 1, - BOTTOM_FIELD = 2, + TOP_FIELD = 1, + BOTTOM_FIELD = 2, FRAME_PICTURE = 3, }; enum { MC_FIELD = 1, MC_FRAME = 2, - MC_16X8 = 2, - MC_DMV = 3, + MC_16X8 = 2, + MC_DMV = 3, }; enum { @@ -87,16 +85,22 @@ enum { enum { - IDCT_AUTO = 0, + IDCT_AUTO = 0, IDCT_AP922_INT = 3, IDCT_LLM_FLOAT = 4, - IDCT_REF = 5, + IDCT_REF = 5, }; enum { FO_NONE = 0, FO_FILM = 1, - FO_RAW = 2, + FO_RAW = 2, +}; + +enum { + IS_NOT_MPEG = 0, + IS_MPEG1, + IS_MPEG2, }; // Fault_Flag values @@ -128,6 +132,7 @@ struct FRAMELIST { uint32_t bottom; uint8_t pf; uint8_t pct; + uint8_t type; // Valid only for FO_RAW. Records the TFF/RFF flags. }; @@ -155,9 +160,9 @@ class CMPEG2Decoder void Next_Start_Code(void); std::vector ReadBuffer; - uint8_t *Rdbfr, *Rdptr, *Rdmax; + uint8_t* Rdbfr, * Rdptr, * Rdmax; uint32_t CurrentBfr, NextBfr, BitsLeft, Val, Read; - uint8_t *buffer_invalid; + uint8_t* buffer_invalid; // gethdr.cpp int Get_Hdr(void); @@ -207,31 +212,30 @@ class CMPEG2Decoder void form_predictions(int bx, int by, int macroblock_type, int motion_type, int PMV[2][2][2], int motion_vertical_field_select[2][2], int dmvector[2]); - void form_prediction(uint8_t *src[], int sfield, uint8_t *dst[], int dfield, + void form_prediction(uint8_t* src[], int sfield, uint8_t* dst[], int dfield, int lx, int lx2, int w, int h, int x, int y, int dx, int dy, int average_flag); // motion.cpp void motion_vectors(int PMV[2][2][2], int dmvector[2], int motion_vertical_field_select[2][2], int s, int motion_vector_count, int mv_format, int h_r_size, int v_r_size, int dmv, int mvscale); - void Dual_Prime_Arithmetic(int DMV[][2], int *dmvector, int mvx, int mvy); + void Dual_Prime_Arithmetic(int DMV[][2], int* dmvector, int mvx, int mvy); - void motion_vector(int *PMV, int *dmvector, int h_r_size, int v_r_size, + void motion_vector(int* PMV, int* dmvector, int h_r_size, int v_r_size, int dmv, int mvscale, int full_pel_vector); - void decode_motion_vector(int *pred, int r_size, int motion_code, + void decode_motion_vector(int* pred, int r_size, int motion_code, int motion_residualesidual, int full_pel_vector); int Get_motion_code(void); int Get_dmvector(void); // store.cpp - void assembleFrame(uint8_t *src[], int pf, YV12PICT& dst); + void assembleFrame(uint8_t* src[], int pf, YV12PICT& dst); // decoder operation control flags int Fault_Flag; int File_Flag; - int FO_Flag; - void(__fastcall *idctFunction)(int16_t* block); - void(__fastcall *prefetchTables)(); + void(*idctFunction)(int16_t* block); + void(*prefetchTables)(); int SystemStream_Flag; // 0 = none, 1=program, 2=Transport 3=PVA int TransportPacketSize; @@ -258,17 +262,17 @@ class CMPEG2Decoder int alternate_scan; int quantizer_scale; - short *block[8], *p_block[8]; + short* block[8], * p_block[8]; int pf_backward, pf_forward, pf_current; // global values - uint8_t *backward_reference_frame[3], *forward_reference_frame[3]; - uint8_t *auxframe[3], *current_frame[3]; + uint8_t* backward_reference_frame[3], * forward_reference_frame[3]; + uint8_t* auxframe[3], * current_frame[3]; //uint8_t *u422, *v422; - YV12PICT *auxFrame1; - YV12PICT *auxFrame2; - YV12PICT *saved_active; - YV12PICT *saved_store; + YV12PICT* auxFrame1; + YV12PICT* auxFrame2; + YV12PICT* saved_active; + YV12PICT* saved_store; enum { ELEMENTARY_STREAM = 0, @@ -276,13 +280,6 @@ class CMPEG2Decoder MPEG2_PROGRAM_STREAM, }; - enum { - IS_NOT_MPEG = 0, - IS_MPEG1, - IS_MPEG2, - }; - - int mpeg_type; int Coded_Picture_Width, Coded_Picture_Height, Chroma_Width, Chroma_Height; int block_count, Second_Field; @@ -314,7 +311,7 @@ class CMPEG2Decoder void copy_top(YV12PICT& src, YV12PICT& dst); void copy_bottom(YV12PICT& src, YV12PICT& dst); - int *QP, *backwardQP, *auxQP; + int* QP, * backwardQP, * auxQP; uint32_t prev_frame; std::vector DirectAccess; @@ -328,8 +325,7 @@ class CMPEG2Decoder void destroy(); public: - CMPEG2Decoder(FILE* file, const char* path, int _idct, int icc, int upconv, - int info, bool showq, bool _i420); + CMPEG2Decoder(FILE* file, const char* path, int _idct, int icc, int upconv, int info, bool showq, bool _i420, int _rff, int _cpu_flags); ~CMPEG2Decoder() { destroy(); } void Decode(uint32_t frame, YV12PICT& dst); @@ -344,6 +340,8 @@ class CMPEG2Decoder std::vector GOPList; std::vector FrameList; + int mpeg_type; + int FO_Flag; int Field_Order; bool HaveRFFs; @@ -351,7 +349,7 @@ class CMPEG2Decoder uint32_t VF_FrameRate_Num; uint32_t VF_FrameRate_Den; - int horizontal_size, vertical_size, mb_width, mb_height; + int horizontal_size, vertical_size, mb_width, mb_height, aspect_ratio_information; //int iPP; int iCC; bool showQ; @@ -361,6 +359,7 @@ class CMPEG2Decoder // info option stuff int info; int minquant, maxquant, avgquant; + bool has_prop = false; // Luminance Code int lumGamma; @@ -370,6 +369,7 @@ class CMPEG2Decoder int getChromaWidth() { return Chroma_Width; } int getLumaWidth() { return Coded_Picture_Width; } int getLumaHeight() { return Coded_Picture_Height; } + int cpu_flags; }; @@ -377,7 +377,8 @@ __forceinline uint32_t CMPEG2Decoder::Show_Bits(uint32_t N) { if (N <= BitsLeft) { return (CurrentBfr << (32 - BitsLeft)) >> (32 - N);; - } else { + } + else { N -= BitsLeft; int shift = 32 - BitsLeft; //return (((CurrentBfr << shift) >> shift) << N) + (NextBfr >> (32 - N));; @@ -391,7 +392,8 @@ __forceinline uint32_t CMPEG2Decoder::Get_Bits(uint32_t N) Val = (CurrentBfr << (32 - BitsLeft)) >> (32 - N); BitsLeft -= N; return Val; - } else { + } + else { N -= BitsLeft; int shift = 32 - BitsLeft; Val = (CurrentBfr << shift) >> shift; @@ -409,7 +411,8 @@ __forceinline void CMPEG2Decoder::Flush_Buffer(uint32_t N) { if (N < BitsLeft) { BitsLeft -= N; - } else { + } + else { CurrentBfr = NextBfr; BitsLeft += 32 - N; Fill_Next(); @@ -435,35 +438,37 @@ __forceinline void CMPEG2Decoder::Fill_Next() if (Rdptr >= Rdmax) Next_Packet(); NextBfr |= Get_Byte(); - } else if (Rdptr < Rdbfr + BUFFER_SIZE - 3) { + } + else if (Rdptr < Rdbfr + BUFFER_SIZE - 3) { //NextBfr = (*Rdptr << 24) + (*(Rdptr+1) << 16) + (*(Rdptr+2) << 8) + *(Rdptr+3); NextBfr = _byteswap_ulong(*reinterpret_cast(Rdptr)); Rdptr += 4; - } else { + } + else { switch (Rdbfr + BUFFER_SIZE - Rdptr) { - case 1: - NextBfr = *Rdptr++ << 24; - Fill_Buffer(); - NextBfr |= (Rdptr[0] << 16) | (Rdptr[1] << 8) | Rdptr[2]; - Rdptr += 3; - break; - case 2: - NextBfr = (Rdptr[0] << 24) | (Rdptr[1] << 16); - Rdptr += 2; - Fill_Buffer(); - NextBfr |= (Rdptr[0] << 8) | Rdptr[1]; - Rdptr += 2; - break; - case 3: - NextBfr = (Rdptr[0] << 24) | (Rdptr[1] << 16) | (Rdptr[2] << 8); - Rdptr += 3; - Fill_Buffer(); - NextBfr |= *Rdptr++; - break; - default: - Fill_Buffer(); - NextBfr = _byteswap_ulong(*reinterpret_cast(Rdptr)); - Rdptr += 4; + case 1: + NextBfr = *Rdptr++ << 24; + Fill_Buffer(); + NextBfr |= (Rdptr[0] << 16) | (Rdptr[1] << 8) | Rdptr[2]; + Rdptr += 3; + break; + case 2: + NextBfr = (Rdptr[0] << 24) | (Rdptr[1] << 16); + Rdptr += 2; + Fill_Buffer(); + NextBfr |= (Rdptr[0] << 8) | Rdptr[1]; + Rdptr += 2; + break; + case 3: + NextBfr = (Rdptr[0] << 24) | (Rdptr[1] << 16) | (Rdptr[2] << 8); + Rdptr += 3; + Fill_Buffer(); + NextBfr |= *Rdptr++; + break; + default: + Fill_Buffer(); + NextBfr = _byteswap_ulong(*reinterpret_cast(Rdptr)); + Rdptr += 4; } } } @@ -499,7 +504,7 @@ __forceinline uint32_t CMPEG2Decoder::Get_Byte() __forceinline uint32_t CMPEG2Decoder::Get_Short() { uint32_t i = Get_Byte(); - return (i<<8) + Get_Byte(); + return (i << 8) + Get_Byte(); } diff --git a/src/dgdecode/color_convert.cpp b/src/color_convert.cpp similarity index 91% rename from src/dgdecode/color_convert.cpp rename to src/color_convert.cpp index 6cd4c1d..d1f327c 100644 --- a/src/dgdecode/color_convert.cpp +++ b/src/color_convert.cpp @@ -17,11 +17,14 @@ MPEG2Dec's colorspace convertions Copyright (C) Chia-chen Kuo - April 2001 #include #include #include "color_convert.h" +#ifndef _WIN32 +#include "win_import_min.h" +#endif #if 0 // C implementation -void conv420to422I_c(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch, int width, int height) +void conv420to422I_c(const uint8_t* src, uint8_t* dst, int src_pitch, int dst_pitch, int width, int height) { const uint8_t* s0 = src; const uint8_t* s1 = src + src_pitch; @@ -82,7 +85,7 @@ avg_weight_3_5(const __m128i& x, const __m128i& y, const __m128i& four) } -void conv420to422I(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch, int width, int height) +void conv420to422I(const uint8_t* src, uint8_t* dst, int src_pitch, int dst_pitch, int width, int height) { const uint8_t* src0 = src; const uint8_t* src1 = src + src_pitch; @@ -140,7 +143,7 @@ void conv420to422I(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitc #if 0 // C implementation -void conv420to422P_c(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch, +void conv420to422P_c(const uint8_t* src, uint8_t* dst, int src_pitch, int dst_pitch, int width, int height) { const uint8_t* s0 = src; @@ -180,7 +183,7 @@ void conv420to422P_c(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pi #endif -void conv420to422P(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch, +void conv420to422P(const uint8_t* src, uint8_t* dst, int src_pitch, int dst_pitch, int width, int height) { const uint8_t* s0 = src; @@ -244,14 +247,14 @@ void conv420to422P(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitc #if 0 // C implementation -void conv422to444_c(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch, +void conv422to444_c(const uint8_t* src, uint8_t* dst, int src_pitch, int dst_pitch, int width, int height) { width /= 2; for (int y = 0; y < height; ++y) { for (int x = 0; x < width - 1; ++x) { - dst[2 * x] = src[x]; + dst[2 * x] = src[x]; dst[2 * x + 1] = (src[x] + src[x + 1] + 1) / 2; } dst[2 * width - 2] = dst[2 * width - 1] = src[width - 1]; @@ -262,7 +265,7 @@ void conv422to444_c(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pit #endif -void conv422to444(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch, +void conv422to444(const uint8_t* src, uint8_t* dst, int src_pitch, int dst_pitch, int width, int height) { const int right = width - 1; @@ -275,8 +278,8 @@ void conv422to444(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch s1 = _mm_avg_epu8(s1, s0); __m128i d0 = _mm_unpacklo_epi8(s0, s1); __m128i d1 = _mm_unpackhi_epi8(s0, s1); - _mm_store_si128(reinterpret_cast<__m128i*>(dst + 2 * x), d0); - _mm_store_si128(reinterpret_cast<__m128i*>(dst + 2 * x + 16), d1); + _mm_store_si128(reinterpret_cast<__m128i*>(dst + static_cast(2) * x), d0); + _mm_store_si128(reinterpret_cast<__m128i*>(dst + static_cast(2) * x + 16), d1); } dst[right] = dst[right - 1]; src += src_pitch; @@ -289,12 +292,12 @@ void conv422to444(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch const int64_t mmmask_0001 = 0x0001000100010001; const int64_t mmmask_0128 = 0x0080008000800080; -void conv444toRGB24(const uint8_t *py, const uint8_t *pu, const uint8_t *pv, - uint8_t *dst, int src_pitchY, int src_pitchUV, int dst_pitch, int width, +void conv444toRGB24(const uint8_t* py, const uint8_t* pu, const uint8_t* pv, + uint8_t* dst, int src_pitchY, int src_pitchUV, int dst_pitch, int width, int height, int matrix, int pc_scale) { - __int64 RGB_Offset, RGB_Scale, RGB_CBU, RGB_CRV, RGB_CGX; - int dst_modulo = dst_pitch-(3*width); + int64_t RGB_Offset, RGB_Scale, RGB_CBU, RGB_CRV, RGB_CGX; + int dst_modulo = dst_pitch - (3 * width); if (pc_scale) { @@ -362,15 +365,15 @@ void conv444toRGB24(const uint8_t *py, const uint8_t *pu, const uint8_t *pv, mov ecx, [pv] // ecx = pv mov edx, [dst] // edx = dst mov edi, width // edi = width - xor esi, esi + xor esi, esi pxor mm0, mm0 - convRGB24: - movd mm1, [eax+esi] - movd mm3, [ebx+esi] + convRGB24 : + movd mm1, [eax + esi] + movd mm3, [ebx + esi] punpcklbw mm1, mm0 punpcklbw mm3, mm0 - movd mm5, [ecx+esi] + movd mm5, [ecx + esi] punpcklbw mm5, mm0 movq mm7, [mmmask_0128] psubw mm3, mm7 @@ -420,8 +423,8 @@ void conv444toRGB24(const uint8_t *py, const uint8_t *pu, const uint8_t *pv, por mm3, mm5 por mm4, mm6 - movd mm5, [ebx+esi] - movd mm6, [ecx+esi] + movd mm5, [ebx + esi] + movd mm6, [ecx + esi] punpcklbw mm5, mm0 punpcklbw mm6, mm0 movq mm7, [mmmask_0128] @@ -456,17 +459,17 @@ void conv444toRGB24(const uint8_t *py, const uint8_t *pu, const uint8_t *pv, psrlq mm3, 40 psllq mm6, 16 por mm3, mm6 - movd [edx], mm1 + movd[edx], mm1 psrld mm4, 16 psrlq mm5, 24 por mm5, mm4 - movd [edx+4], mm3 + movd[edx + 4], mm3 add edx, 0x0c add esi, 0x04 cmp esi, edi - movd [edx-4], mm5 + movd[edx - 4], mm5 jl convRGB24 @@ -474,7 +477,7 @@ void conv444toRGB24(const uint8_t *py, const uint8_t *pu, const uint8_t *pv, add ebx, src_pitchUV add ecx, src_pitchUV add edx, dst_modulo - xor esi, esi + xor esi, esi dec height jnz convRGB24 @@ -483,7 +486,7 @@ void conv444toRGB24(const uint8_t *py, const uint8_t *pu, const uint8_t *pv, } -void conv422PtoYUY2(const uint8_t *py, uint8_t *pu, uint8_t *pv, uint8_t *dst, +void conv422PtoYUY2(const uint8_t* py, uint8_t* pu, uint8_t* pv, uint8_t* dst, int pitch1Y, int pitch1UV, int pitch2, int width, int height) { width /= 2; @@ -507,7 +510,7 @@ void conv422PtoYUY2(const uint8_t *py, uint8_t *pu, uint8_t *pv, uint8_t *dst, } -void convYUY2to422P(const uint8_t *src, uint8_t *py, uint8_t *pu, uint8_t *pv, +void convYUY2to422P(const uint8_t* src, uint8_t* py, uint8_t* pu, uint8_t* pv, int pitch1, int pitch2y, int pitch2uv, int width, int height) { width /= 2; @@ -540,4 +543,3 @@ void convYUY2to422P(const uint8_t *src, uint8_t *py, uint8_t *pu, uint8_t *pv, } } #endif - diff --git a/src/color_convert.h b/src/color_convert.h new file mode 100644 index 0000000..74a6c16 --- /dev/null +++ b/src/color_convert.h @@ -0,0 +1,16 @@ +#ifndef MPEG2DECPLUS_COLOR_CONVERT_H +#define MPEG2DECPLUS_COLOR_CONVERT_H + +#include + +void conv420to422P(const uint8_t* src, uint8_t* dst, int src_pitch, int dst_pitch, + int width, int height); + +void conv420to422I(const uint8_t* src, uint8_t* dst, int src_pitch, int dst_pitch, + int width, int height); + +void conv422to444(const uint8_t* src, uint8_t* dst, int src_pitch, int dst_pitch, + int width, int height); + +#endif + diff --git a/src/config.h b/src/config.h deleted file mode 100644 index a70bdc6..0000000 --- a/src/config.h +++ /dev/null @@ -1 +0,0 @@ -#undef DGMPGDEC_GIT_VERSION diff --git a/src/d2vsource.rc b/src/d2vsource.rc new file mode 100644 index 0000000..63274ab --- /dev/null +++ b/src/d2vsource.rc @@ -0,0 +1,29 @@ +#include + +VS_VERSION_INFO VERSIONINFO +FILEVERSION 1,3,0,0 +PRODUCTVERSION 1,3,0,0 +FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +FILEFLAGS 0x0L +FILEOS VOS__WINDOWS32 +FILETYPE VFT_DLL +FILESUBTYPE VFT2_UNKNOWN +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904E4" + BEGIN + VALUE "Comments", "Modified DGDecode." + VALUE "FileDescription", "D2VSource for AviSynth 2.6 / AviSynth+" + VALUE "FileVersion", "1.3.0" + VALUE "InternalName", "D2VSource" + VALUE "OriginalFilename", "D2VSource.dll" + VALUE "ProductName", "D2VSource" + VALUE "ProductVersion", "1.3.0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END diff --git a/src/dgdecode/AVISynthAPI.cpp b/src/dgdecode/AVISynthAPI.cpp deleted file mode 100644 index f640e54..0000000 --- a/src/dgdecode/AVISynthAPI.cpp +++ /dev/null @@ -1,442 +0,0 @@ -/* - * Avisynth 2.5 API for MPEG2Dec3 - * - * Changes to fix frame dropping and random frame access are - * Copyright (C) 2003-2008 Donald A. Graft - * - * Copyright (C) 2002-2003 Marc Fauconneau - * - * based of the intial MPEG2Dec Avisytnh API Copyright (C) Mathias Born - May 2001 - * - * This file is part of DGMPGDec, a free MPEG-2 decoder - * - * DGMPGDec 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. - * - * DGMPGDec is distributed in the hope that 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 -#include -#include -#include -#include -#include -#include "AvisynthAPI.h" -#include "postprocess.h" -#include "color_convert.h" -#include "misc.h" -#include "idct.h" - - -#define VERSION "MPEG2DecPlus 0.2.0" - - -bool PutHintingData(uint8_t *video, uint32_t hint) -{ - constexpr uint32_t MAGIC_NUMBER = 0xdeadbeef; - - for (int i = 0; i < 32; ++i) { - *video &= ~1; - *video++ |= ((MAGIC_NUMBER & (1 << i)) >> i); - } - for (int i = 0; i < 32; i++) { - *video &= ~1; - *video++ |= ((hint & (1 << i)) >> i); - } - return false; -} - - -static void luminance_filter(uint8_t* luma, const int width, const int height, - const int pitch, const uint8_t* table) -{ - for (int y = 0; y < height; ++y) { - for (int x = 0; x < width; ++x) { - luma[x] = table[luma[x]]; - } - luma += pitch; - } -} - - -static void show_info(int n, CMPEG2Decoder& d, PVideoFrame& frame, - const VideoInfo& vi, IScriptEnvironment* env) -{ - uint32_t raw = std::max(d.FrameList[n].bottom, d.FrameList[n].top); - if (raw < d.BadStartingFrames) - raw = d.BadStartingFrames; - - uint32_t gop = 0; - do { - if (raw >= d.GOPList[gop].number) - if (raw < d.GOPList[gop+1].number) - break; - } while (++gop < d.GOPList.size() - 1); - - const auto& rgop = d.GOPList[gop]; - const auto& fraw = d.FrameList[raw]; - const auto& fn = d.FrameList[n]; - - int pct = fraw.pct == I_TYPE ? 'I' : fraw.pct == B_TYPE ? 'B' : 'P'; - - const char* matrix[8] = { - "Forbidden", - "ITU-R BT.709", - "Unspecified Video", - "Reserved", - "FCC", - "ITU-R BT.470-2 System B, G", - "SMPTE 170M", - "SMPTE 240M (1987)", - }; - - if (d.info == 1) { - char msg1[1024]; - sprintf(msg1,"%s\n" - "---------------------------------------\n" - "Source: %s\n" - "Frame Rate: %3.6f fps (%u/%u) %s\n" - "Field Order: %s\n" - "Picture Size: %d x %d\n" - "Aspect Ratio: %s\n" - "Progr Seq: %s\n" - "GOP Number: %u (%u) GOP Pos = %I64d\n" - "Closed GOP: %s\n" - "Display Frame: %d\n" - "Encoded Frame: %d (top) %d (bottom)\n" - "Frame Type: %c (%d)\n" - "Progr Frame: %s\n" - "Colorimetry: %s (%d)\n" - "Quants: %d/%d/%d (avg/min/max)\n", - VERSION, - d.Infilename[rgop.file].c_str(), - double(d.VF_FrameRate_Num) / double(d.VF_FrameRate_Den), - d.VF_FrameRate_Num, - d.VF_FrameRate_Den, - (d.VF_FrameRate == 25000 || d.VF_FrameRate == 50000) ? "(PAL)" : - d.VF_FrameRate == 29970 ? "(NTSC)" : "", - d.Field_Order == 1 ? "Top Field First" : "Bottom Field First", - d.getLumaWidth(), d.getLumaHeight(), - d.Aspect_Ratio, - rgop.progressive ? "True" : "False", - gop, rgop.number, rgop.position, - rgop.closed ? "True" : "False", - n, - fn.top, fn.bottom, - pct, raw, - fraw.pf ? "True" : "False", - matrix[rgop.matrix], rgop.matrix, - d.avgquant, d.minquant, d.maxquant); - env->ApplyMessage(&frame, vi, msg1, 150, 0xdfffbf, 0x0, 0x0); - - } else if (d.info == 2) { - dprintf("MPEG2DecPlus: %s\n", VERSION); - dprintf("MPEG2DecPlus: Source: %s\n", d.Infilename[rgop.file]); - dprintf("MPEG2DecPlus: Frame Rate: %3.6f fps (%u/%u) %s\n", - double(d.VF_FrameRate_Num) / double(d.VF_FrameRate_Den), - d.VF_FrameRate_Num, d.VF_FrameRate_Den, - (d.VF_FrameRate == 25000 || d.VF_FrameRate == 50000) ? "(PAL)" : d.VF_FrameRate == 29970 ? "(NTSC)" : ""); - dprintf("MPEG2DecPlus: Field Order: %s\n", d.Field_Order == 1 ? "Top Field First" : "Bottom Field First"); - dprintf("MPEG2DecPlus: Picture Size: %d x %d\n", d.getLumaWidth(), d.getLumaHeight()); - dprintf("MPEG2DecPlus: Aspect Ratio: %s\n", d.Aspect_Ratio); - dprintf("MPEG2DecPlus: Progressive Seq: %s\n", rgop.progressive ? "True" : "False"); - dprintf("MPEG2DecPlus: GOP Number: %d (%d) GOP Pos = %I64d\n", gop, rgop.number, rgop.position); - dprintf("MPEG2DecPlus: Closed GOP: %s\n", rgop.closed ? "True" : "False"); - dprintf("MPEG2DecPlus: Display Frame: %d\n", n); - dprintf("MPEG2DecPlus: Encoded Frame: %d (top) %d (bottom)\n", fn.top, fn.bottom); - dprintf("MPEG2DecPlus: Frame Type: %c (%d)\n", pct, raw); - dprintf("MPEG2DecPlus: Progressive Frame: %s\n", fraw.pf ? "True" : "False"); - dprintf("MPEG2DecPlus: Colorimetry: %s (%d)\n", matrix[rgop.matrix], rgop.matrix); - dprintf("MPEG2DecPlus: Quants: %d/%d/%d (avg/min/max)\n", d.avgquant, d.minquant, d.maxquant); - - } else if (d.info == 3) { - constexpr uint32_t PROGRESSIVE = 0x00000001; - constexpr int COLORIMETRY_SHIFT = 2; - - uint32_t hint = 0; - if (fraw.pf == 1) hint |= PROGRESSIVE; - hint |= ((rgop.matrix & 7) << COLORIMETRY_SHIFT); - PutHintingData(frame->GetWritePtr(PLANAR_Y), hint); - } -} - - -MPEG2Source::MPEG2Source(const char* d2v, int cpu, int idct, int iPP, - int moderate_h, int moderate_v, bool showQ, - bool fastMC, const char* _cpu2, int _info, - int _upConv, bool _i420, int iCC, - IScriptEnvironment* env) : - decoder(nullptr), bufY(nullptr), bufU(nullptr), bufV(nullptr) -{ - //if (iPP != -1 && iPP != 0 && iPP != 1) - // env->ThrowError("MPEG2Source: iPP must be set to -1, 0, or 1!"); - - if (iCC != -1 && iCC != 0 && iCC != 1) - env->ThrowError("MPEG2Source: iCC must be set to -1, 0, or 1!"); - - if (_upConv != 0 && _upConv != 1 && _upConv != 2) - env->ThrowError("MPEG2Source: upConv must be set to 0, 1, or 2!"); - - if (idct > 7) - env->ThrowError("MPEG2Source: iDCT invalid (1:MMX,2:SSEMMX,3:SSE2,4:FPU,5:REF,6:Skal's,7:Simple)"); - - FILE *f = fopen(d2v, "r"); - if (f == nullptr) - env->ThrowError("MPEG2Source: unable to load D2V file \"%s\" ", d2v); - - try { - decoder = new CMPEG2Decoder(f, d2v, idct, iCC, _upConv, _info, showQ, _i420); - } catch (std::runtime_error& e) { - if (f) fclose(f); - env->ThrowError("MPEG2Source: %s", e.what()); - } - - env->AtExit([](void* p, IScriptEnvironment*) { delete p; p = nullptr; }, decoder); - auto& d = *decoder; - - int chroma_format = d.getChromaFormat(); - - memset(&vi, 0, sizeof(vi)); - vi.width = d.Clip_Width; - vi.height = d.Clip_Height; - if (_upConv == 2) vi.pixel_type = VideoInfo::CS_YV24; - else if (chroma_format == 2 || _upConv == 1) vi.pixel_type = VideoInfo::CS_YV16; - else if (d.i420 == true) vi.pixel_type = VideoInfo::CS_I420; - else vi.pixel_type = VideoInfo::CS_YV12; - - vi.SetFPS(d.VF_FrameRate_Num, d.VF_FrameRate_Den); - vi.num_frames = static_cast(d.FrameList.size()); - vi.SetFieldBased(false); - - if (_upConv == 2) { - auto free_buf = [](void* p, IScriptEnvironment* e) { - _aligned_free(p); - p = nullptr; - }; - size_t ysize = ((vi.width + 31) & ~31) * (vi.height + 1); - size_t uvsize = ((d.getChromaWidth() + 15) & ~15) * (vi.height + 1); - void* ptr = _aligned_malloc(ysize + 2 * uvsize, 32); - if (!ptr) { - env->ThrowError("MPEG2Source: malloc failure (bufY, bufU, bufV)!"); - } - env->AtExit(free_buf, ptr); - bufY = reinterpret_cast(ptr); - bufU = bufY + ysize; - bufV = bufU + uvsize; - } - - luminanceFlag = (d.lumGamma != 0 || d.lumOffset != 0); - if (luminanceFlag) { - int lg = d.lumGamma; - int lo = d.lumOffset; - for (int i = 0; i < 256; ++i) { - double value = 255.0 * pow(i / 255.0, pow(2.0, -lg / 128.0)) + lo + 0.5; - - if (value < 0) - luminanceTable[i] = 0; - else if (value > 255.0) - luminanceTable[i] = 255; - else - luminanceTable[i] = static_cast(value); - } - } -} - - -bool __stdcall MPEG2Source::GetParity(int) -{ - return decoder->Field_Order == 1; -} - - -PVideoFrame __stdcall MPEG2Source::GetFrame(int n, IScriptEnvironment* env) -{ - auto& d = *decoder; - PVideoFrame frame = env->NewVideoFrame(vi, 32); - YV12PICT out = (d.upConv != 2) ? YV12PICT(frame) : - YV12PICT(bufY, bufU, bufV, vi.width, d.getChromaWidth(), vi.height); - - d.Decode(n, out); - - if (luminanceFlag ) - luminance_filter(out.y, out.ywidth, out.yheight, out.ypitch, luminanceTable); - - if (d.upConv == 2) { // convert 4:2:2 (planar) to 4:4:4 (planar) - env->BitBlt(frame->GetWritePtr(PLANAR_Y), frame->GetPitch(PLANAR_Y), - bufY, out.ypitch, vi.width, vi.height); - conv422to444(out.u, frame->GetWritePtr(PLANAR_U), out.uvpitch, - frame->GetPitch(PLANAR_U), vi.width, vi.height); - conv422to444(out.v, frame->GetWritePtr(PLANAR_V), out.uvpitch, - frame->GetPitch(PLANAR_V), vi.width, vi.height); - } - - if (d.info != 0) - show_info(n, d, frame, vi, env); - - return frame; -} - - -static void set_user_default(FILE* def, char* d2v, int& idct, bool& showq, - int& info, int upcnv, bool& i420, int& icc) -{ - char buf[512]; - auto load_str = [&buf](char* var, const char* name, int len) { - if (strncmp(buf, name, len) == 0) { - std::vector tmp(512, 0); - sscanf(buf, name, tmp.data()); - tmp.erase(std::remove(tmp.begin(), tmp.end(), '"'), tmp.end()); - strncpy(var, tmp.data(), tmp.size()); - } - }; - auto load_int = [&buf](int& var, const char* name, int len) { - if (strncmp(buf, name, len) == 0) { - sscanf(buf, name, &var); - } - }; - auto load_bool = [&buf](bool& var, const char* name, int len) { - if (strncmp(buf, name, len) == 0) { - char tmp[16]; - sscanf(buf, name, &tmp); - var = tmp[0] == 't'; - } - }; - auto load_bint = [&buf](int& var, const char* name, int len) { - if (strncmp(buf, name, len) == 0) { - char tmp[16]; - sscanf(buf, name, &tmp); - var = tmp[0] == 't' ? 1 : 0; - } - }; - - while(fgets(buf, 511, def) != 0) { - load_str(d2v, "d2v=%s", 4); - load_int(idct, "idct=%d", 5); - load_bool(showq, "showQ=%s", 6); - load_int(info, "info=%d", 5); - load_int(upcnv, "upConv=%d", 7); - load_bool(i420, "i420=%s", 5); - load_bint(icc, "iCC=%s", 4); - } -} - - -AVSValue __cdecl MPEG2Source::create(AVSValue args, void*, IScriptEnvironment* env) -{ - char d2v[512]; - int cpu = 0; - int idct = -1; - - // check if iPP is set, if it is use the set value... if not - // we set iPP to -1 which automatically switches between field - // and progressive pp based on pf flag -- same for iCC - int iPP = args[3].IsBool() ? (args[3].AsBool() ? 1 : 0) : -1; - int iCC = args[12].IsBool() ? (args[12].AsBool() ? 1 : 0) : -1; - - int moderate_h = 20; - int moderate_v = 40; - bool showQ = false; - bool fastMC = false; - char cpu2[255]; - int info = 0; - int upConv = 0; - bool i420 = false; - - FILE *def = fopen("MPEG2DecPlus.def", "r"); - if (def != nullptr) { - set_user_default(def, d2v, idct, showQ, info, upConv, i420, iCC); - fclose(def); - } - - // check for uninitialised strings - if (strlen(d2v) >= _MAX_PATH) d2v[0] = 0; - if (strlen(cpu2) >= 255) cpu2[0] = 0; - - MPEG2Source *dec = new MPEG2Source( args[0].AsString(d2v), - args[1].AsInt(cpu), - args[2].AsInt(idct), - iPP, - args[4].AsInt(moderate_h), - args[5].AsInt(moderate_v), - args[6].AsBool(showQ), - args[7].AsBool(fastMC), - args[8].AsString(cpu2), - args[9].AsInt(info), - args[10].AsInt(upConv), - args[11].AsBool(i420), - iCC, - env ); - // Only bother invoking crop if we have to. - auto& d = *dec->decoder; - if (d.Clip_Top || d.Clip_Bottom || d.Clip_Left || d.Clip_Right || - // This is cheap but it works. The intent is to allow the - // display size to be different from the encoded size, while - // not requiring massive revisions to the code. So we detect the - // difference and crop it off. - d.vertical_size != d.Clip_Height || d.horizontal_size != d.Clip_Width || - d.vertical_size == 1088) - { - int vertical; - // Special case for 1088 to 1080 as directed by DGIndex. - if (d.vertical_size == 1088 && d.D2V_Height == 1080) - vertical = 1080; - else - vertical = d.vertical_size; - AVSValue CropArgs[] = { - dec, - d.Clip_Left, - d.Clip_Top, - -(d.Clip_Right + (d.Clip_Width - d.horizontal_size)), - -(d.Clip_Bottom + (d.Clip_Height - vertical)), - true - }; - - return env->Invoke("crop", AVSValue(CropArgs, 6)); - } - - return dec; -} - - -const AVS_Linkage* AVS_linkage = nullptr; - - -extern "C" __declspec(dllexport) const char* __stdcall -AvisynthPluginInit3(IScriptEnvironment* env, const AVS_Linkage* const vectors) -{ - AVS_linkage = vectors; - - const char* msargs = - "[d2v]s" - "[cpu]i" - "[idct]i" - "[iPP]b" - "[moderate_h]i" - "[moderate_v]i" - "[showQ]b" - "[fastMC]b" - "[cpu2]s" - "[info]i" - "[upConv]i" - "[i420]b" - "[iCC]b"; - - env->AddFunction("MPEG2Source", msargs, MPEG2Source::create, nullptr); - env->AddFunction("LumaYUV","c[lumoff]i[lumgain]f", LumaYUV::create, nullptr); - env->AddFunction("Deblock", "c[quant]i[aOffset]i[bOffset]i", Deblock::create, nullptr); - // env->AddFunction("BlindPP", "c[quant]i[cpu]i[cpu2]s[iPP]b[moderate_h]i[moderate_v]i", BlindPP::create, nullptr); - - return VERSION; -} - diff --git a/src/dgdecode/AvisynthAPI.h b/src/dgdecode/AvisynthAPI.h deleted file mode 100644 index 8dc4c34..0000000 --- a/src/dgdecode/AvisynthAPI.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Avisynth 2.5 API for MPEG2Dec3 - * - * Copyright (C) 2002-2003 Marc Fauconneau - * - * based of the intial MPEG2Dec Avisytnh API Copyright (C) Mathias Born - May 2001 - * - * This file is part of MPEG2Dec3, a free MPEG-2 decoder - * - * MPEG2Dec3 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. - * - * MPEG2Dec3 is distributed in the hope that 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. - * - */ - -#ifndef MPEG2DECPLUS_AVS_API_H -#define MPEG2DECPLUS_AVS_API_H - -#include -#include -#include -#include "MPEG2Decoder.h" - - -class MPEG2Source: public IClip { - VideoInfo vi; - //int _PP_MODE; - uint8_t *bufY, *bufU, *bufV; // for 4:2:2 input support - CMPEG2Decoder* decoder; - bool luminanceFlag; - uint8_t luminanceTable[256]; - -public: - MPEG2Source(const char* d2v, int cpu, int idct, int iPP, int moderate_h, int moderate_v, bool showQ, bool fastMC, const char* _cpu2, int _info, int _upConv, bool _i420, int iCC, IScriptEnvironment* env); - ~MPEG2Source() {} - PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env); - bool __stdcall GetParity(int n); - void __stdcall GetAudio(void* buf, __int64 start, __int64 count, IScriptEnvironment* env) {}; - const VideoInfo& __stdcall GetVideoInfo() { return vi; } - int __stdcall SetCacheHints(int hints, int) { return hints == CACHE_GET_MTMODE ? MT_SERIALIZED : 0; }; - static AVSValue __cdecl create(AVSValue args, void*, IScriptEnvironment* env); -}; - -#if 0 -class BlindPP : public GenericVideoFilter { - int* QP; - bool iPP; - int PP_MODE; - int moderate_h, moderate_v; - -public: - BlindPP(AVSValue args, IScriptEnvironment* env); - PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env); - ~BlindPP() {} - int __stdcall SetCacheHints(int hints, int) { return hints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0; } - static AVSValue __cdecl create(AVSValue args, void*, IScriptEnvironment* env); -}; -#endif - -class Deblock : public GenericVideoFilter { - int alpha, beta, c0; - int numPlanes; - -public: - Deblock(PClip _child, int q, int aoff, int boff, IScriptEnvironment* env); - ~Deblock() {} - PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env); - int __stdcall SetCacheHints(int hints, int) { return hints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0; } - static AVSValue __cdecl create(AVSValue args, void*, IScriptEnvironment* env); -}; - - -class LumaYUV : public GenericVideoFilter { - int16_t* offsetMask; - int16_t* gainMask; - int numPlanes; - void(*mainProc)( - const uint8_t* srcp, uint8_t* dstp, const int spitch, const int dpitch, - const int width, const int height, const int16_t* offsets, - const int16_t* gains); - -public: - LumaYUV(PClip c, int16_t off, int16_t gain, IScriptEnvironment* env); - ~LumaYUV() {} - PVideoFrame __stdcall GetFrame(int n, IScriptEnvironment* env); - int __stdcall SetCacheHints(int hints, int) { return hints == CACHE_GET_MTMODE ? MT_NICE_FILTER : 0; } - static AVSValue __cdecl create(AVSValue args, void*, IScriptEnvironment* env); -}; - - -#endif diff --git a/src/dgdecode/BlindPP.cpp b/src/dgdecode/BlindPP.cpp deleted file mode 100644 index 57919f8..0000000 --- a/src/dgdecode/BlindPP.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include -#include "AvisynthAPI.h" -#include "PostProcess.h" -#include "color_convert.h" - - - - -BlindPP::BlindPP(AVSValue args, IScriptEnvironment* env) : GenericVideoFilter(args[0].AsClip()) -{ - int quant = args[1].AsInt(2); - if (vi.width%16!=0) - env->ThrowError("BlindPP : Need mod16 width"); - if (vi.height%16!=0) - env->ThrowError("BlindPP : Need mod16 height"); - if (!vi.IsYV12() && !vi.IsYV16()) - env->ThrowError("BlindPP : Only YV12 and YV16 supported"); - - int n = vi.width * vi.height / 256; - QP = reinterpret_cast( - static_cast( - env)->Allocate(n * sizeof(int), 4, AVS_NORMAL_ALLOC)); - if (QP == nullptr) - env->ThrowError("BlindPP: malloc failure!"); - env->AtExit([](void* p, IScriptEnvironment* e) { - static_cast(e)->Free(p); p = nullptr; }, QP); - std::fill_n(QP, n, quant); - - switch (args[2].AsInt(6)) { - case 0 : PP_MODE = 0; break; - case 1 : PP_MODE = PP_DEBLOCK_Y_H; break; - case 2 : PP_MODE = PP_DEBLOCK_Y_H | PP_DEBLOCK_Y_V; break; - case 3 : PP_MODE = PP_DEBLOCK_Y_H | PP_DEBLOCK_Y_V | PP_DEBLOCK_C_H; break; - case 4 : PP_MODE = PP_DEBLOCK_Y_H | PP_DEBLOCK_Y_V | PP_DEBLOCK_C_H | PP_DEBLOCK_C_V; break; - case 5 : PP_MODE = PP_DEBLOCK_Y_H | PP_DEBLOCK_Y_V | PP_DEBLOCK_C_H | PP_DEBLOCK_C_V | PP_DERING_Y; break; - case 6 : PP_MODE = PP_DEBLOCK_Y_H | PP_DEBLOCK_Y_V | PP_DEBLOCK_C_H | PP_DEBLOCK_C_V | PP_DERING_Y | PP_DERING_C; break; - default : env->ThrowError("BlindPP : cpu level invalid (0 to 6)"); - } - - const char* cpu2 = args[3].AsString(""); - if (strlen(cpu2)==6) { - PP_MODE = 0; - if (cpu2[0]=='x' || cpu2[0]=='X') { PP_MODE |= PP_DEBLOCK_Y_H; } - if (cpu2[1]=='x' || cpu2[1]=='X') { PP_MODE |= PP_DEBLOCK_Y_V; } - if (cpu2[2]=='x' || cpu2[2]=='X') { PP_MODE |= PP_DEBLOCK_C_H; } - if (cpu2[3]=='x' || cpu2[3]=='X') { PP_MODE |= PP_DEBLOCK_C_V; } - if (cpu2[4]=='x' || cpu2[4]=='X') { PP_MODE |= PP_DERING_Y; } - if (cpu2[5]=='x' || cpu2[5]=='X') { PP_MODE |= PP_DERING_C; } - } - - iPP = args[4].AsBool(false); - moderate_h = args[5].AsInt(20); - moderate_v = args[6].AsInt(40); -} - - -PVideoFrame __stdcall BlindPP::GetFrame(int n, IScriptEnvironment* env) -{ - PVideoFrame dstf = env->NewVideoFrame(vi); - PVideoFrame cf = child->GetFrame(n, env); - - uint8_t* src[3]; - uint8_t* dst[3]; - src[0] = const_cast(cf->GetReadPtr(PLANAR_Y)); - src[1] = const_cast(cf->GetReadPtr(PLANAR_U)); - src[2] = const_cast(cf->GetReadPtr(PLANAR_V)); - dst[0] = dstf->GetWritePtr(PLANAR_Y); - dst[1] = dstf->GetWritePtr(PLANAR_U); - dst[2] = dstf->GetWritePtr(PLANAR_V); - postprocess(src, cf->GetPitch(PLANAR_Y), cf->GetPitch(PLANAR_U), - dst, dstf->GetPitch(PLANAR_Y), dstf->GetPitch(PLANAR_U), - vi.width, vi.height, QP, vi.width/16, - PP_MODE, moderate_h, moderate_v, vi.Is422(), iPP); - - return dstf; -} - - - -AVSValue __cdecl BlindPP::create(AVSValue args, void*, IScriptEnvironment* env) -{ - return new BlindPP(args, env); -} diff --git a/src/dgdecode/LumaYUV.cpp b/src/dgdecode/LumaYUV.cpp deleted file mode 100644 index 6344cb8..0000000 --- a/src/dgdecode/LumaYUV.cpp +++ /dev/null @@ -1,160 +0,0 @@ - -// LumaYUV: -// a rewrite of LumaYV12 to eliminate inline ASM and support all planar 8bit YUV -// by OKA Motofumi - August 24, 2016 - - - -#include -#include -#include "AvisynthAPI.h" - - -#if 0 -// C implementation -// offset = lumoff, gain = int(lumgain * 128) -static void -main_proc_c(const uint8_t* srcp, uint8_t* dstp, const int spitch, - const int dpitch,const int width, const int height, - const int offset, const int gain) noexcept -{ - for (int y = 0; y < height; ++y) { - for (int x = 0; x < width; ++x) { - int val = srcp[x] * gain + 64 / 128 + offset; - dstp[x] = val < 0 ? 0 : val > 255 ? 255 : val; - } - srcp += spitch; - dstp += dpitch; - } -} -#endif - -enum { - NORMAL, - NO_GAIN_NEGATIVE_OFFSET, - NO_GAIN_POSITIVE_OFFSET, -}; - - -template -static void -main_proc_sse2(const uint8_t* srcp, uint8_t* dstp, const int spitch, - const int dpitch, const int width, const int height, - const int16_t* offsets, const int16_t* gains) noexcept -{ - const __m128i offs = _mm_load_si128(reinterpret_cast(offsets)); - - __m128i gain, zero, round; - if (PATTERN == NORMAL) { - gain = _mm_load_si128(reinterpret_cast(gains)); - round = _mm_set1_epi16(64); - zero = _mm_setzero_si128(); - } - - for (int y = 0; y < height; ++y) { - for (int x = 0; x < width; x += 16) { - __m128i s0 = _mm_load_si128(reinterpret_cast(srcp + x)); - - if (PATTERN == NORMAL) { - __m128i s1 = _mm_unpackhi_epi8(s0, zero); - s0 = _mm_unpacklo_epi8(s0, zero); - - s0 = _mm_mullo_epi16(s0, gain); - s1 = _mm_mullo_epi16(s1, gain); - - s0 = _mm_adds_epu16(s0, round); - s1 = _mm_adds_epu16(s1, round); - - s0 = _mm_srli_epi16(s0, 7); - s1 = _mm_srli_epi16(s1, 7); - - s0 = _mm_add_epi16(s0, offs); - s1 = _mm_add_epi16(s1, offs); - - s0 = _mm_packus_epi16(s0, s1); - - } else if (PATTERN == NO_GAIN_NEGATIVE_OFFSET) { - s0 = _mm_subs_epu8(s0, offs); - - } else { - s0 = _mm_adds_epu8(s0, offs); - } - - _mm_stream_si128(reinterpret_cast<__m128i*>(dstp + x), s0); - } - srcp += spitch; - dstp += dpitch; - } - -} - - -LumaYUV::LumaYUV(PClip c, int16_t offset, int16_t gain, IScriptEnvironment* env) : - GenericVideoFilter(c) -{ - numPlanes = vi.IsY8() ? 1 : vi.IsYUVA() ? 4 : 3; - - auto e2 = static_cast(env); - void* p = e2->Allocate(16 * sizeof(int16_t), 16, AVS_NORMAL_ALLOC); - if (!p) { - env->ThrowError("LumaYUV: failed to create masks."); - } - env->AtExit( - [](void* p, IScriptEnvironment* e) { - static_cast(e)->Free(p); - p = nullptr; - }, p); - - offsetMask = reinterpret_cast(p); - gainMask = offsetMask + 8; - - if (gain != 128) { - mainProc = main_proc_sse2; - std::fill_n(offsetMask, 8, offset); - std::fill_n(gainMask, 8, gain); - } else { - if (offset < 0) { - offset = -offset; - mainProc = main_proc_sse2; - } else { - mainProc = main_proc_sse2; - } - std::fill_n(reinterpret_cast(offsetMask), 16, static_cast(offset)); - } -} - - -PVideoFrame __stdcall LumaYUV::GetFrame(int n, IScriptEnvironment* env) -{ - auto src = child->GetFrame(n, env); - auto dst = env->NewVideoFrame(vi); - - static const int planes[] = { PLANAR_U, PLANAR_V, PLANAR_A }; - for (int p = 0; p < numPlanes - 1; ++p) { - const int plane = planes[p]; - env->BitBlt(dst->GetWritePtr(plane), dst->GetPitch(plane), - src->GetReadPtr(plane), src->GetPitch(plane), - dst->GetRowSize(plane), dst->GetHeight(plane)); - } - - mainProc(src->GetReadPtr(PLANAR_Y), dst->GetWritePtr(PLANAR_Y), - src->GetPitch(PLANAR_Y), dst->GetPitch(PLANAR_Y),vi.width, - vi.height, offsetMask, gainMask); - - return dst; -} - - -AVSValue __cdecl LumaYUV::create(AVSValue args, void*, IScriptEnvironment* env) -{ - PClip clip = args[0].AsClip(); - const VideoInfo& vi = clip->GetVideoInfo(); - if (!vi.IsPlanar() || vi.IsRGB() || vi.ComponentSize() != 1) { - env->ThrowError("LumaYUV: unsupported format."); - } - int off = std::min(std::max(args[1].AsInt(0), -255), 255); - float gain = std::min(std::max(args[2].AsFloatf(1.0f), 0.0f), 2.0f); - gain *= 128; - - return new LumaYUV(clip, static_cast(off), static_cast(gain), env); -} diff --git a/src/dgdecode/PostProcess.cpp b/src/dgdecode/PostProcess.cpp deleted file mode 100644 index 8b2f066..0000000 --- a/src/dgdecode/PostProcess.cpp +++ /dev/null @@ -1,2235 +0,0 @@ -#include -#include -#include -#include -#include - -#include "PostProcess.h" -#include "misc.h" - - -//#define DEBUGMODE -//#define SELFCHECK -//#define PREFETCH - -#ifdef PREFETCH -#define PREFETCH_AHEAD_V 8 -#define PREFETCH_AHEAD_H 8 -#define PREFETCH_ENABLE -#endif - -#ifdef SELFCHECK -#define PP_SELF_CHECK -#define SELF_CHECK -#endif - -#ifdef DEBUGMODE -#define SHOWDECISIONS_H -#define SHOW_DECISIONS -#define SHOWDECISIONS_V -#endif - -#pragma warning( disable : 4799 ) - -/* entry point for MMX postprocessing */ -void postprocess(unsigned char * src[], int src_stride, int UVsrc_stride, - unsigned char * dst[], int dst_stride, int UVdst_stride, - int horizontal_size, int vertical_size, - QP_STORE_T *QP_store, int QP_stride, - int mode, int moderate_h, int moderate_v, bool is422, bool iPP) -{ - - - uint8_t *puc_src; - uint8_t *puc_dst; - uint8_t *puc_flt; - QP_STORE_T *QP_ptr; - int y, i; - - if (iPP) vertical_size >>= 1; // field based post-processing - - /* this loop is (hopefully) going to improve performance */ - /* loop down the picture, copying and processing in vertical stripes, each four pixels high */ - for (y=0; y>4)*QP_stride]); - deblock_horiz(puc_flt, horizontal_size, dst_stride, QP_ptr, QP_stride, 0, moderate_h); - } - else - { - // top field - puc_flt = &((dst[0])[y*2*dst_stride]); - QP_ptr = &(QP_store[(y>>4)*2*QP_stride]); - deblock_horiz(puc_flt, horizontal_size, dst_stride*2, QP_ptr, QP_stride*2, 0, moderate_h); - // bottom field - puc_flt = &((dst[0])[(y*2+1)*dst_stride]); - QP_ptr = &(QP_store[((y>>4)*2+1)*QP_stride]); - deblock_horiz(puc_flt, horizontal_size, dst_stride*2, QP_ptr, QP_stride*2, 0, moderate_h); - } - } - - if (mode & PP_DEBLOCK_Y_V) - { - if ( (y%8) && (y-4)>5 ) - { - if (!iPP) - { - puc_flt = &((dst[0])[(y-4)*dst_stride]); - QP_ptr = &(QP_store[(y>>4)*QP_stride]); - deblock_vert( puc_flt, horizontal_size, dst_stride, QP_ptr, QP_stride, 0, moderate_v); - } - else - { - // top field - puc_flt = &((dst[0])[(y-4)*2*dst_stride]); - QP_ptr = &(QP_store[(y>>4)*2*QP_stride]); - deblock_vert( puc_flt, horizontal_size, dst_stride*2, QP_ptr, QP_stride*2, 0, moderate_v); - // bottom field - puc_flt = &((dst[0])[((y-4)*2+1)*dst_stride]); - QP_ptr = &(QP_store[((y>>4)*2+1)*QP_stride]); - deblock_vert( puc_flt, horizontal_size, dst_stride*2, QP_ptr, QP_stride*2, 0, moderate_v); - } - } - } - - } - - if (mode & PP_DERING_Y) - { - if (!iPP) dering(dst[0],horizontal_size,vertical_size,dst_stride,QP_store,QP_stride,0); - else - { - dering(dst[0],horizontal_size,vertical_size,dst_stride*2,QP_store,QP_stride*2,0); - dering(dst[0]+dst_stride,horizontal_size,vertical_size,dst_stride*2,QP_store+QP_stride,QP_stride*2,0); - } - } - - // adjust for chroma - if (!is422) vertical_size >>= 1; - horizontal_size >>= 1; - src_stride = UVsrc_stride; - dst_stride = UVdst_stride; - - - /* loop U then V */ - for (i=1; i<=2; i++) - { - for (y=0; y>4)*QP_stride]); - else QP_ptr = &(QP_store[(y>>3)*QP_stride]); - deblock_horiz(puc_flt, horizontal_size, dst_stride, QP_ptr, QP_stride, is422 ? 2 : 1, moderate_h); - } - else - { - // top field - puc_flt = &((dst[i])[y*2*dst_stride]); - if (is422) QP_ptr = &(QP_store[(y>>4)*2*QP_stride]); - else QP_ptr = &(QP_store[(y>>3)*2*QP_stride]); - deblock_horiz(puc_flt, horizontal_size, dst_stride*2, QP_ptr, QP_stride*2, is422 ? 2 : 1, moderate_h); - // bottom field - puc_flt = &((dst[i])[(y*2+1)*dst_stride]); - if (is422) QP_ptr = &(QP_store[((y>>4)*2+1)*QP_stride]); - else QP_ptr = &(QP_store[((y>>3)*2+1)*QP_stride]); - deblock_horiz(puc_flt, horizontal_size, dst_stride*2, QP_ptr, QP_stride*2, is422 ? 2 : 1, moderate_h); - } - } - - if (mode & PP_DEBLOCK_C_V) - { - if ( (y%8) && (y-4)>5 ) - { - if (!iPP) - { - puc_flt = &((dst[i])[(y-4)*dst_stride]); - if (is422) QP_ptr = &(QP_store[(y>>4)*QP_stride]); - else QP_ptr = &(QP_store[(y>>3)*QP_stride]); - deblock_vert( puc_flt, horizontal_size, dst_stride, QP_ptr, QP_stride, is422 ? 2 : 1, moderate_v); - } - else - { - // top field - puc_flt = &((dst[i])[(y-4)*2*dst_stride]); - if (is422) QP_ptr = &(QP_store[(y>>4)*2*QP_stride]); - else QP_ptr = &(QP_store[(y>>3)*2*QP_stride]); - deblock_vert( puc_flt, horizontal_size, dst_stride*2, QP_ptr, QP_stride*2, is422 ? 2 : 1, moderate_v); - // bottom field - puc_flt = &((dst[i])[((y-4)*2+1)*dst_stride]); - if (is422) QP_ptr = &(QP_store[((y>>4)*2+1)*QP_stride]); - else QP_ptr = &(QP_store[((y>>3)*2+1)*QP_stride]); - deblock_vert( puc_flt, horizontal_size, dst_stride*2, QP_ptr, QP_stride*2, is422 ? 2 : 1, moderate_v); - } - } - } - - } - } - - if (mode & PP_DERING_C) - { - if (!iPP) - { - dering(dst[1],horizontal_size,vertical_size,dst_stride,QP_store,QP_stride,is422 ? 2 : 1); - dering(dst[2],horizontal_size,vertical_size,dst_stride,QP_store,QP_stride,is422 ? 2 : 1); - } - else - { - dering(dst[1],horizontal_size,vertical_size,dst_stride*2,QP_store,QP_stride*2,is422 ? 2 : 1); - dering(dst[1]+dst_stride,horizontal_size,vertical_size,dst_stride*2,QP_store+QP_stride,QP_stride*2,is422 ? 2 : 1); - dering(dst[2],horizontal_size,vertical_size,dst_stride*2,QP_store,QP_stride*2,is422 ? 2 : 1); - dering(dst[2]+dst_stride,horizontal_size,vertical_size,dst_stride*2,QP_store+QP_stride,QP_stride*2,is422 ? 2 : 1); - } - } - - do_emms(); -} - - -///////////////////////////////////////////////////////////////////////// -// Post Processing Functions (MMX) // -// // -///////////////////////////////////////////////////////////////////////// - -// Set MMX state back to normal -static void do_emms() -{ - __asm emms; -} - - -/* this is a horizontal deblocking filter - i.e. it will smooth _vertical_ block edges */ -void deblock_horiz(uint8_t *image, int width, int stride, QP_STORE_T *QP_store, int QP_stride, int chromaFlag, int moderate_h) -{ - /* loop over every block boundary in that row */ - for (int x = 8; x < width; x += 8) { - int QP ; - /* extract QP from the decoder's array of QP values */ - if (chromaFlag == 0) { - QP = QP_store[x / 16]; - } else { - QP = QP_store[x / 8]; - } - - /* v points to pixel v0, in the left-hand block */ - uint8_t* v = image + x - 5; - - /* first decide whether to use default or DC offet mode */ - if (deblock_horiz_useDC(v, stride, moderate_h)) {/* use DC offset mode */ - if (deblock_horiz_DC_on(v, stride, QP)) { - deblock_horiz_lpf9(v, stride, QP); - } - } else { /* use default mode */ - deblock_horiz_default_filter(v, stride, QP); - } - } - __asm emms; -} - -/* decide whether the DC filter should be turned on accoding to QP */ -inline int deblock_horiz_DC_on(uint8_t *v, int stride, int QP) -{ - /* 99% of the time, this test turns out the same as the |max-min| strategy in the standard */ - QP *= 2; - for (int i = 0; i < 4; ++i) { - if (std::abs(v[0] - v[5]) >= QP) return false; - if (std::abs(v[1] - v[8]) >= QP) return false; - if (std::abs(v[1] - v[4]) >= QP) return false; - if (std::abs(v[2] - v[7]) >= QP) return false; - if (std::abs(v[3] - v[6]) >= QP) return false; - v += stride; - } - return true; -} - -/* horizontal deblocking filter used in default (non-DC) mode */ -inline void deblock_horiz_default_filter(uint8_t *v, int stride, int QP) -{ - for (int y = 0; y < 4; ++y) { - int q1 = v[4] - v[5]; - int q = q1 / 2; - if (q != 0) { - int a3_0 = 2 * (v[3] - v[6]) - 5 * q1; - int aa3_0 = std::abs(a3_0); - - /* apply the 'delta' function first and check there is a difference to avoid wasting time */ - if (aa3_0 < 8 * QP) { - int a3_1 = std::abs(5 * (v[3] - v[2]) + 2 * (v[1] - v[4])); - int a3_2 = std::abs(5 * (v[7] - v[8]) + 2 * (v[5] - v[8])); - - int d = aa3_0 - std::min(a3_1, a3_2); - - if (d > 6) { /* energy across boundary is greater than in one or both of the blocks */ - /* clip d in the range 0 ... q */ - if (q > 0) { - if (a3_0 < 0) { - if (d > q) { - v[4] -= q; - v[5] += q; - } else { - v[4] -= d; - v[5] += d; - } - } - } else { - if (a3_0 > 0) { - if (-d < q) { - v[4] -= q; - v[5] += q; - } else { - v[4] += d; - v[5] -= d; - } - } - } - } - } - } - v += stride; - } -} - - -const static uint64_t mm64_0008 = 0x0008000800080008; -const static uint64_t mm64_0101 = 0x0101010101010101; -static uint64_t mm64_temp; -const static uint64_t mm64_coefs[18] = { - 0x0001000200040006, /* p1 left */ 0x0000000000000001, /* v1 right */ - 0x0001000200020004, /* v1 left */ 0x0000000000010001, /* v2 right */ - 0x0002000200040002, /* v2 left */ 0x0000000100010002, /* v3 right */ - 0x0002000400020002, /* v3 left */ 0x0001000100020002, /* v4 right */ - 0x0004000200020001, /* v4 left */ 0x0001000200020004, /* v5 right */ - 0x0002000200010001, /* v5 left */ 0x0002000200040002, /* v6 right */ - 0x0002000100010000, /* v6 left */ 0x0002000400020002, /* v7 right */ - 0x0001000100000000, /* v7 left */ 0x0004000200020001, /* v8 right */ - 0x0001000000000000, /* v8 left */ 0x0006000400020001 /* p2 right */ -}; - - -/* The 9-tap low pass filter used in "DC" regions */ -/* I'm not sure that I like this implementation any more...! */ -inline void deblock_horiz_lpf9(uint8_t *v, int stride, int QP) -{ - for (int y = 0; y < 4; ++y) { - int ys = y * stride; - int p1 = (std::abs(v[0 + ys] - v[1 + ys]) < QP ) ? v[0 + ys] : v[1 + ys]; - int p2 = (std::abs(v[8 + ys] - v[9 + ys]) < QP ) ? v[9 + ys] : v[8 + ys]; - - uint32_t mm32_p1p2 = 0x0101 * ((p2 << 16) + p1); - - uint8_t* pmm1 = v + y * stride - 3; /* this is 64-aligned */ - - /* mm7 = 0, mm6 is left hand accumulator, mm5 is right hand acc */ - __asm - { - push eax - push ebx - mov eax, pmm1 - lea ebx, mm64_coefs - - #ifdef PREFETCH_ENABLE - prefetcht0 32[ebx] - #endif - - movd mm0, mm32_p1p2 /* mm0 = ________p2p2p1p1 0w1 2 3 4 5 6 7 */ - punpcklbw mm0, mm0 /* mm0 = p2p2p2p2p1p1p1p1 0m1 2 3 4 5 6 7 */ - - movq mm2, qword ptr [eax] /* mm2 = v4v3v2v1xxxxxxxx 0 1 2w3 4 5 6 7 */ - pxor mm7, mm7 /* mm7 = 0000000000000000 0 1 2 3 4 5 6 7w */ - - movq mm6, mm64_0008 /* mm6 = 0008000800080008 0 1 2 3 4 5 6w7 */ - punpckhbw mm2, mm2 /* mm2 = v4__v3__v2__v1__ 0 1 2m3 4 5 6 7 */ - - movq mm64_temp, mm0 /*temp = p2p2p2p2p1p1p1p1 0r1 2 3 4 5 6 7 */ - - punpcklbw mm0, mm7 /* mm0 = __p1__p1__p1__p1 0m1 2 3 4 5 6 7 */ - movq mm5, mm6 /* mm5 = 0008000800080008 0 1 2 3 4 5w6r7 */ - - pmullw mm0, [ebx] /* mm0 *= mm64_coefs[0] 0m1 2 3 4 5 6 7 */ - - movq mm1, mm2 /* mm1 = v4v4v3v3v2v2v1v1 0 1w2r3 4 5 6 7 */ - punpcklbw mm2, mm2 /* mm2 = v2v2v2v2v1v1v1v1 0 1 2m3 4 5 6 7 */ - - punpckhbw mm1, mm1 /* mm1 = v4v4v4v4v3v3v3v3 0 1m2 3 4 5 6 7 */ - - #ifdef PREFETCH_ENABLE - prefetcht0 32[ebx] - #endif - - movq mm3, mm2 /* mm3 = v2v2v2v2v1v1v1v1 0 1 2r3w4 5 6 7 */ - punpcklbw mm2, mm7 /* mm2 = __v1__v1__v1__v1 0 1 2m3 4 5 6 7 */ - - punpckhbw mm3, mm7 /* mm3 = __v2__v2__v2__v2 0 1 2 3m4 5 6 7 */ - paddw mm6, mm0 /* mm6 += mm0 0r1 2 3 4 5 6m7 */ - - movq mm0, mm2 /* mm0 = __v1__v1__v1__v1 0w1 2r3 4 5 6 7 */ - - pmullw mm0, 8[ebx] /* mm2 *= mm64_coefs[1] 0m1 2 3 4 5 6 7 */ - movq mm4, mm3 /* mm4 = __v2__v2__v2__v2 0 1 2 3r4w5 6 7 */ - - pmullw mm2, 16[ebx] /* mm2 *= mm64_coefs[2] 0 1 2m3 4 5 6 7 */ - - pmullw mm3, 32[ebx] /* mm3 *= mm64_coefs[4] 0 1 2 3m4 5 6 7 */ - - pmullw mm4, 24[ebx] /* mm3 *= mm64_coefs[3] 0 1 2 3 4m5 6 7 */ - paddw mm5, mm0 /* mm5 += mm0 0r1 2 3 4 5m6 7 */ - - paddw mm6, mm2 /* mm6 += mm2 0 1 2r3 4 5 6m7 */ - movq mm2, mm1 /* mm2 = v4v4v4v4v3v3v3v3 0 1 2 3 4 5 6 7 */ - - punpckhbw mm2, mm7 /* mm2 = __v4__v4__v4__v4 0 1 2m3 4 5 6 7r */ - paddw mm5, mm4 /* mm5 += mm4 0 1 2 3 4r5m6 7 */ - - punpcklbw mm1, mm7 /* mm1 = __v3__v3__v3__v3 0 1m2 3 4 5 6 7r */ - paddw mm6, mm3 /* mm6 += mm3 0 1 2 3r4 5 6m7 */ - - #ifdef PREFETCH_ENABLE - prefetcht0 64[ebx] - #endif - movq mm0, mm1 /* mm0 = __v3__v3__v3__v3 0w1 2 3 4 5 6 7 */ - - pmullw mm1, 48[ebx] /* mm1 *= mm64_coefs[6] 0 1m2 3 4 5 6 7 */ - - pmullw mm0, 40[ebx] /* mm0 *= mm64_coefs[5] 0m1 2 3 4 5 6 7 */ - movq mm4, mm2 /* mm4 = __v4__v4__v4__v4 0 1 2r3 4w5 6 7 */ - - pmullw mm2, 64[ebx] /* mm2 *= mm64_coefs[8] 0 1 2 3 4 5 6 7 */ - paddw mm6, mm1 /* mm6 += mm1 0 1 2 3 4 5 6 7 */ - - pmullw mm4, 56[ebx] /* mm4 *= mm64_coefs[7] 0 1 2 3 4m5 6 7 */ - pxor mm3, mm3 /* mm3 = 0000000000000000 0 1 2 3w4 5 6 7 */ - - movq mm1, 8[eax] /* mm1 = xxxxxxxxv8v7v6v5 0 1w2 3 4 5 6 7 */ - paddw mm5, mm0 /* mm5 += mm0 0r1 2 3 4 5 6 7 */ - - punpcklbw mm1, mm1 /* mm1 = v8v8v7v7v6v6v5v5 0 1m2 3m4 5 6 7 */ - paddw mm6, mm2 /* mm6 += mm2 0 1 2r3 4 5 6 7 */ - - #ifdef PREFETCH_ENABLE - prefetcht0 96[ebx] - #endif - - movq mm2, mm1 /* mm2 = v8v8v7v7v6v6v5v5 0 1r2w3 4 5 6 7 */ - paddw mm5, mm4 /* mm5 += mm4 0 1 2 3 4r5 6 7 */ - - punpcklbw mm2, mm2 /* mm2 = v6v6v6v6v5v5v5v5 0 1 2m3 4 5 6 7 */ - punpckhbw mm1, mm1 /* mm1 = v8v8v8v8v7v7v7v7 0 1m2 3 4 5 6 7 */ - - movq mm3, mm2 /* mm3 = v6v6v6v6v5v5v5v5 0 1 2r3w4 5 6 7 */ - punpcklbw mm2, mm7 /* mm2 = __v5__v5__v5__v5 0 1 2m3 4 5 6 7r */ - - punpckhbw mm3, mm7 /* mm3 = __v6__v6__v6__v6 0 1 2 3m4 5 6 7r */ - movq mm0, mm2 /* mm0 = __v5__v5__v5__v5 0w1 2b3 4 5 6 7 */ - - pmullw mm0, 72[ebx] /* mm0 *= mm64_coefs[9] 0m1 2 3 4 5 6 7 */ - movq mm4, mm3 /* mm4 = __v6__v6__v6__v6 0 1 2 3 4w5 6 7 */ - - pmullw mm2, 80[ebx] /* mm2 *= mm64_coefs[10] 0 1 2m3 4 5 6 7 */ - - pmullw mm3, 96[ebx] /* mm3 *= mm64_coefs[12] 0 1 2 3m4 5 6 7 */ - - pmullw mm4, 88[ebx] /* mm4 *= mm64_coefs[11] 0 1 2 3 4m5 6 7 */ - paddw mm5, mm0 /* mm5 += mm0 0r1 2 3 4 5 6 7 */ - - paddw mm6, mm2 /* mm6 += mm2 0 1 2r3 4 5 6 7 */ - movq mm2, mm1 /* mm2 = v8v8v8v8v7v7v7v7 0 1r2w3 4 5 6 7 */ - - paddw mm6, mm3 /* mm6 += mm3 0 1 2 3r4 5 6 7 */ - punpcklbw mm1, mm7 /* mm1 = __v7__v7__v7__v7 0 1m2 3 4 5 6 7r */ - - paddw mm5, mm4 /* mm5 += mm4 0 1 2 3 4r5 6 7 */ - punpckhbw mm2, mm7 /* mm2 = __v8__v8__v8__v8 0 1 2m3 4 5 6 7 */ - - #ifdef PREFETCH_ENABLE - prefetcht0 128[ebx] - #endif - - movq mm3, mm64_temp /* mm0 = p2p2p2p2p1p1p1p1 0 1 2 3w4 5 6 7 */ - movq mm0, mm1 /* mm0 = __v7__v7__v7__v7 0w1r2 3 4 5 6 7 */ - - pmullw mm0, 104[ebx] /* mm0 *= mm64_coefs[13] 0m1b2 3 4 5 6 7 */ - movq mm4, mm2 /* mm4 = __v8__v8__v8__v8 0 1 2r3 4w5 6 7 */ - - pmullw mm1, 112[ebx] /* mm1 *= mm64_coefs[14] 0 1w2 3 4 5 6 7 */ - punpckhbw mm3, mm7 /* mm0 = __p2__p2__p2__p2 0 1 2 3 4 5 6 7 */ - - pmullw mm2, 128[ebx] /* mm2 *= mm64_coefs[16] 0 1b2m3 4 5 6 7 */ - - pmullw mm4, 120[ebx] /* mm4 *= mm64_coefs[15] 0 1b2 3 4m5 6 7 */ - paddw mm5, mm0 /* mm5 += mm0 0r1 2 3 4 5m6 7 */ - - pmullw mm3, 136[ebx] /* mm0 *= mm64_coefs[17] 0 1 2 3m4 5 6 7 */ - paddw mm6, mm1 /* mm6 += mm1 0 1w2 3 4 5 6m7 */ - - paddw mm6, mm2 /* mm6 += mm2 0 1 2r3 4 5 6m7 */ - - paddw mm5, mm4 /* mm5 += mm4 0 1 2 3 4r5m6 7 */ - psrlw mm6, 4 /* mm6 /= 16 0 1 2 3 4 5 6m7 */ - - paddw mm5, mm3 /* mm6 += mm0 0 1 2 3r4 5m6 7 */ - - psrlw mm5, 4 /* mm5 /= 16 0 1 2 3 4 5m6 7 */ - - packuswb mm6, mm5 /* pack result into mm6 0 1 2 3 4 5r6m7 */ - - movq 4[eax], mm6 /* v[] = mm6 0 1 2 3 4 5 6r7 */ - - pop ebx - pop eax - }; - } -} - -/* decide DC mode or default mode for the horizontal filter */ -inline int deblock_horiz_useDC(uint8_t *v, int stride, int moderate_h) -{ - const uint64_t mm64_mask = 0x00fefefefefefefe; - uint32_t mm32_result; - uint64_t *pmm1; - int eq_cnt, useDC; - - pmm1 = (uint64_t *)(&(v[1])); /* this is a 32-bit aligned pointer, not 64-aligned */ - - __asm - { - push eax - mov eax, pmm1 - - /* first load some constants into mm4, mm5, mm6, mm7 */ - movq mm6, mm64_mask /*mm6 = 0x00fefefefefefefe */ - pxor mm4, mm4 /*mm4 = 0x0000000000000000 */ - - movq mm1, qword ptr [eax] /* mm1 = *pmm 0 1 2 3 4 5 6 7 */ - add eax, stride /* eax += stride/8 0 1 2 3 4 5 6 7 */ - - movq mm5, mm1 /* mm5 = mm1 0 1 2 3 4 5 6 7 */ - psrlq mm1, 8 /* mm1 >>= 8 0 1 2 3 4 5 6 7 */ - - movq mm2, mm5 /* mm2 = mm5 0 1 2 3 4 5 6 7 */ - psubusb mm5, mm1 /* mm5 -= mm1 0 1 2 3 4 5 6 7 */ - - movq mm3, qword ptr [eax] /* mm3 = *pmm 0 1 2 3 4 5 6 7 */ - psubusb mm1, mm2 /* mm1 -= mm2 0 1 2 3 4 5 6 7 */ - - add eax, stride /* eax += stride/8 0 1 2 3 4 5 6 7 */ - por mm5, mm1 /* mm5 |= mm1 0 1 2 3 4 5 6 7 */ - - movq mm0, mm3 /* mm0 = mm3 0 1 2 3 4 5 6 7 */ - pand mm5, mm6 /* mm5 &= 0xfefefefefefefefe */ - - pxor mm7, mm7 /*mm7 = 0x0000000000000000 */ - pcmpeqb mm5, mm4 /* are the bytes of mm5 == 0 ? */ - - movq mm1, qword ptr [eax] /* mm3 = *pmm 0 1 2 3 4 5 6 7 */ - psubb mm7, mm5 /* mm7 has running total of eqcnts */ - - psrlq mm3, 8 /* mm3 >>= 8 0 1 2 3 4 5 6 7 */ - movq mm5, mm0 /* mm5 = mm0 0 1 2 3 4 5 6 7 */ - - psubusb mm0, mm3 /* mm0 -= mm3 0 1 2 3 4 5 6 7 */ - - add eax, stride /* eax += stride/8 0 1 2 3 4 5 6 7 */ - psubusb mm3, mm5 /* mm3 -= mm5 0 1 2 3 4 5 6 7 */ - - movq mm5, qword ptr [eax] /* mm5 = *pmm 0 1 2 3 4 5 6 7 */ - por mm0, mm3 /* mm0 |= mm3 0 1 2 3 4 5 6 7 */ - - movq mm3, mm1 /* mm3 = mm1 0 1 2 3 4 5 6 7 */ - pand mm0, mm6 /* mm0 &= 0xfefefefefefefefe */ - - psrlq mm1, 8 /* mm1 >>= 8 0 1 2 3 4 5 6 7 */ - pcmpeqb mm0, mm4 /* are the bytes of mm0 == 0 ? */ - - movq mm2, mm3 /* mm2 = mm3 0 1 2 3 4 5 6 7 */ - psubb mm7, mm0 /* mm7 has running total of eqcnts */ - - psubusb mm3, mm1 /* mm3 -= mm1 0 1 2 3 4 5 6 7 */ - - psubusb mm1, mm2 /* mm1 -= mm2 0 1 2 3 4 5 6 7 */ - - por mm3, mm1 /* mm3 |= mm1 0 1 2 3 4 5 6 7 */ - movq mm1, mm5 /* mm1 = mm5 0 1 2 3 4 5 6 7 */ - - pand mm3, mm6 /* mm3 &= 0xfefefefefefefefe */ - psrlq mm5, 8 /* mm5 >>= 8 0 1 2 3 4 5 6 7 */ - - pcmpeqb mm3, mm4 /* are the bytes of mm3 == 0 ? */ - movq mm0, mm1 /* mm0 = mm1 0 1 2 3 4 5 6 7 */ - - psubb mm7, mm3 /* mm7 has running total of eqcnts */ - psubusb mm1, mm5 /* mm1 -= mm5 0 1 2 3 4 5 6 7 */ - - psubusb mm5, mm0 /* mm5 -= mm0 0 1 2 3 4 5 6 7 */ - por mm1, mm5 /* mm1 |= mm5 0 1 2 3 4 5 6 7 */ - - pand mm1, mm6 /* mm1 &= 0xfefefefefefefefe */ - - pcmpeqb mm1, mm4 /* are the bytes of mm1 == 0 ? */ - - psubb mm7, mm1 /* mm7 has running total of eqcnts */ - - movq mm1, mm7 /* mm1 = mm7 0 1w2 3 4 5 6 7r */ - psllq mm7, 8 /* mm7 >>= 24 0 1 2 3 4 5 6 7m */ - - psrlq mm1, 24 /* mm7 >>= 24 0 1 2 3 4 5 6 7m */ - - paddb mm7, mm1 /* mm7 has running total of eqcnts */ - - movq mm1, mm7 /* mm1 = mm7 0 1w2 3 4 5 6 7r */ - psrlq mm7, 16 /* mm7 >>= 16 0 1 2 3 4 5 6 7m */ - - paddb mm7, mm1 /* mm7 has running total of eqcnts */ - - movq mm1, mm7 /* mm1 = mm7 0 1w2 3 4 5 6 7r */ - psrlq mm7, 8 /* mm7 >>= 8 0 1 2 3 4 5 6 7m */ - - paddb mm7, mm1 /* mm7 has running total of eqcnts */ - - movd mm32_result, mm7 - - pop eax - }; - - eq_cnt = mm32_result & 0xff; - - useDC = eq_cnt >= moderate_h; - - return useDC; -} - -/* this is a vertical deblocking filter - i.e. it will smooth _horizontal_ block edges */ -void deblock_vert( uint8_t *image, int width, int stride, QP_STORE_T *QP_store, int QP_stride, int chromaFlag, int moderate_v) -{ - uint64_t v_local[20]; - uint64_t p1p2[4]; - int Bx, x, y; - int QP, QPx16; - uint8_t *v; - int useDC, DC_on; - - y = 0; - - /* loop over image's block boundary rows */ -// for (y=8; y= QP) return false; - if (std::abs(v[i + 1 * stride] - v[i + 4 * stride]) >= QP) return false; - if (std::abs(v[i + 1 * stride] - v[i + 8 * stride]) >= QP) return false; - if (std::abs(v[i + 2 * stride] - v[i + 7 * stride]) >= QP) return false; - if (std::abs(v[i + 3 * stride] - v[i + 6 * stride]) >= QP) return false; - } - return true; -} - - -/* Vertical deblocking filter for use in non-flat picture regions */ -inline void deblock_vert_default_filter(uint8_t *v, int stride, int QP) -{ - uint64_t *pmm1; - const uint64_t mm_0020 = 0x0020002000200020; - uint64_t mm_8_x_QP; - int i; - - ((uint32_t *)&mm_8_x_QP)[0] = ((uint32_t *)&mm_8_x_QP)[1] = 0x00080008 * QP; - - /* working in 4-pixel wide columns, left to right */ - /*i=0 in left, i=1 in right */ - for (i=0; i<2; i++) - { - /* v should be 64-bit aligned here */ - pmm1 = (uint64_t *)(&(v[4*i])); - /* pmm1 will be 32-bit aligned but this doesn't matter as we'll use movd not movq */ - - __asm - { - push ecx - mov ecx, pmm1 - - pxor mm7, mm7 /* mm7 = 0000000000000000 0 1 2 3 4 5 6 7w */ - add ecx, stride /* %0 += stride 0 1 2 3 4 5 6 7 */ - - movd mm0, [ecx] /* mm0 = v1v1v1v1v1v1v1v1 0w1 2 3 4 5 6 7 */ - punpcklbw mm0, mm7 /* mm0 = __v1__v1__v1__v1 L 0m1 2 3 4 5 6 7r */ - - add ecx, stride /* ecx += stride 0 1 2 3 4 5 6 7 */ - movd mm1, [ecx] /* mm1 = v2v2v2v2v2v2v2v2 0 1w2 3 4 5 6 7 */ - - add ecx, stride /* ecx += stride 0 1 2 3 4 5 6 7 */ - punpcklbw mm1, mm7 /* mm1 = __v2__v2__v2__v2 L 0 1m2 3 4 5 6 7r */ - - movd mm2, [ecx] /* mm2 = v3v3v3v3v3v3v3v3 0 1 2w3 4 5 6 7 */ - add ecx, stride /* ecx += stride 0 1 2 3 4 5 6 7 */ - - punpcklbw mm2, mm7 /* mm2 = __v3__v3__v3__v3 L 0 1 2m3 4 5 6 7r */ - - movd mm3, [ecx] /* mm3 = v4v4v4v4v4v4v4v4 0 1 2 3w4 5 6 7 */ - - punpcklbw mm3, mm7 /* mm3 = __v4__v4__v4__v4 L 0 1 2 3m4 5 6 7r */ - - psubw mm1, mm2 /* mm1 = v2 - v3 L 0 1m2r3 4 5 6 7 */ - - movq mm4, mm1 /* mm4 = v2 - v3 L 0 1r2 3 4w5 6 7 */ - psllw mm1, 2 /* mm1 = 4 * (v2 - v3) L 0 1m2 3 4 5 6 7 */ - - paddw mm1, mm4 /* mm1 = 5 * (v2 - v3) L 0 1m2 3 4r5 6 7 */ - psubw mm0, mm3 /* mm0 = v1 - v4 L 0m1 2 3r4 5 6 7 */ - - psllw mm0, 1 /* mm0 = 2 * (v1 - v4) L 0m1 2 3 4 5 6 7 */ - - psubw mm0, mm1 /* mm0 = a3_1 L 0m1r2 3 4 5 6 7 */ - - pxor mm1, mm1 /* mm1 = 0000000000000000 0 1w2 3 4 5 6 7 */ - - pcmpgtw mm1, mm0 /* is 0 > a3_1 ? L 0r1m2 3 4 5 6 7 */ - - add ecx, stride /* ecx += stride 0 1 2 3 4 5 6 7 */ - pxor mm0, mm1 /* mm0 = ABS(a3_1) step 1 L 0m1r2 3 4 5 6 7 */ - - psubw mm0, mm1 /* mm0 = ABS(a3_1) step 2 L 0m1r2 3 4 5 6 7 */ - - movd mm1, [ecx] /* mm1 = v5v5v5v5v5v5v5v5 0 1w2 3 4 5 6 7 */ - - punpcklbw mm1, mm7 /* mm1 = __v5__v5__v5__v5 L 0 1m2 3 4 5 6 7r */ - - - add ecx, stride /* ecx += stride 0 1 2 3 4 5 6 7 */ - psubw mm3, mm1 /* mm3 = v4 - v5 L 0 1r2 3m4 5 6 7 */ - - movd mm4, [ecx] /* mm4 = v6v6v6v6v6v6v6v6 0 1 2 3 4w5 6 7 */ - - punpcklbw mm4, mm7 /* mm4 = __v6__v6__v6__v6 L 0 1 2 3 4m5 6 7r */ - - add ecx, stride /* ecx += stride 0 1 2 3 4 5 6 7 */ - - movd mm5, [ecx] /* mm5 = v7v7v7v7v7v7v7v7 0 1 2 3 4 5w6 7 */ - psubw mm2, mm4 /* mm2 = v3 - v6 L 0 1 2m3 4r5 6 7 */ - - punpcklbw mm5, mm7 /* mm5 = __v7__v7__v7__v7 L 0 1 2 3 4 5m6 7r */ - - add ecx, stride /* ecx += stride 0 1 2 3 4 5 6 7 */ - psubw mm5, mm4 /* mm5 = v7 - v6 L 0 1 2 3 4r5m6 7 */ - - movq mm4, mm5 /* mm4 = v7 - v6 L 0 1 2 3 4w5r6 7 */ - - psllw mm4, 2 /* mm4 = 4 * (v7 - v6) L 0 1 2 3 4 5m6 7 */ - - paddw mm5, mm4 /* mm5 = 5 * (v7 - v6) L 0 1 2 3 4r5m6 7 */ - - movd mm4, [ecx] /* mm4 = v8v8v8v8v8v8v8v8 0 1 2 3 4w5 6 7 */ - - punpcklbw mm4, mm7 /* mm4 = __v8__v8__v8__v8 L 0 1 2 3 4m5 6 7r */ - - psubw mm1, mm4 /* mm1 = v5 - v8 L 0 1m2 3 4r5 6 7 */ - - pxor mm4, mm4 /* mm4 = 0000000000000000 0 1 2 3 4w5 6 7 */ - psllw mm1, 1 /* mm1 = 2 * (v5 - v8) L 0 1m2 3 4 5 6 7 */ - - paddw mm1, mm5 /* mm1 = a3_2 L 0 1m2 3 4 5r6 7 */ - - pcmpgtw mm4, mm1 /* is 0 > a3_2 ? L 0 1r2 3 4m5 6 7 */ - - pxor mm1, mm4 /* mm1 = ABS(a3_2) step 1 L 0 1m2 3 4r5 6 7 */ - - psubw mm1, mm4 /* mm1 = ABS(a3_2) step 2 L 0 1m2 3 4r5 6 7 */ - - /* at this point, mm0 = ABS(a3_1), mm1 = ABS(a3_2), mm2 = v3 - v6, mm3 = v4 - v5 */ - movq mm4, mm1 /* mm4 = ABS(a3_2) L 0 1r2 3 4w5 6 7 */ - - pcmpgtw mm1, mm0 /* is ABS(a3_2) > ABS(a3_1) 0r1m2 3 4 5 6 7 */ - - pand mm0, mm1 /* min() step 1 L 0m1r2 3 4 5 6 7 */ - - pandn mm1, mm4 /* min() step 2 L 0 1m2 3 4r5 6 7 */ - - por mm0, mm1 /* min() step 3 L 0m1r2 3 4 5 6 7 */ - - /* at this point, mm0 = MIN( ABS(a3_1), ABS(a3_2), mm2 = v3 - v6, mm3 = v4 - v5 */ - movq mm1, mm3 /* mm1 = v4 - v5 L 0 1w2 3r4 5 6 7 */ - psllw mm3, 2 /* mm3 = 4 * (v4 - v5) L 0 1 2 3m4 5 6 7 */ - - paddw mm3, mm1 /* mm3 = 5 * (v4 - v5) L 0 1r2 3m4 5 6 7 */ - psllw mm2, 1 /* mm2 = 2 * (v3 - v6) L 0 1 2m3 4 5 6 7 */ - - psubw mm2, mm3 /* mm2 = a3_0 L 0 1 2m3r4 5 6 7 */ - - /* at this point, mm0 = MIN( ABS(a3_1), ABS(a3_2), mm1 = v4 - v5, mm2 = a3_0 */ - movq mm4, mm2 /* mm4 = a3_0 L 0 1 2r3 4w5 6 7 */ - pxor mm3, mm3 /* mm3 = 0000000000000000 0 1 2 3w4 5 6 7 */ - - pcmpgtw mm3, mm2 /* is 0 > a3_0 ? L 0 1 2r3m4 5 6 7 */ - - movq mm2, mm_8_x_QP /* mm4 = 8*QP 0 1 2w3 4 5 6 7 */ - pxor mm4, mm3 /* mm4 = ABS(a3_0) step 1 L 0 1 2 3r4m5 6 7 */ - - psubw mm4, mm3 /* mm4 = ABS(a3_0) step 2 L 0 1 2 3r4m5 6 7 */ - - /* compare a3_0 against 8*QP */ - pcmpgtw mm2, mm4 /* is 8*QP > ABS(d) ? L 0 1 2m3 4r5 6 7 */ - - pand mm2, mm4 /* if no, d = 0 L 0 1 2m3 4r5 6 7 */ - - movq mm4, mm2 /* mm2 = a3_0 L 0 1 2r3 4w5 6 7 */ - - /* at this point, mm0 = MIN( ABS(a3_1), ABS(a3_2), mm1 = v4 - v5, mm2 = a3_0 , mm3 = SGN(a3_0), mm4 = ABS(a3_0) */ - psubusw mm4, mm0 /* mm0 = (A3_0 - a3_0) L 0r1 2 3 4m5 6 7 */ - - movq mm0, mm4 /* mm0=ABS(d) L 0w1 2 3 4r5 6 7 */ - - psllw mm0, 2 /* mm0 = 4 * (A3_0-a3_0) L 0m1 2 3 4 5 6 7 */ - - paddw mm0, mm4 /* mm0 = 5 * (A3_0-a3_0) L 0m1 2 3 4r5 6 7 */ - - paddw mm0, mm_0020 /* mm0 += 32 L 0m1 2 3 4 5 6 7 */ - - psraw mm0, 6 /* mm0 >>= 6 L 0m1 2 3 4 5 6 7 */ - - /* at this point, mm0 = ABS(d), mm1 = v4 - v5, mm3 = SGN(a3_0) */ - pxor mm2, mm2 /* mm2 = 0000000000000000 0 1 2w3 4 5 6 7 */ - - pcmpgtw mm2, mm1 /* is 0 > (v4 - v5) ? L 0 1r2m3 4 5 6 7 */ - - pxor mm1, mm2 /* mm1 = ABS(mm1) step 1 L 0 1m2r3 4 5 6 7 */ - - psubw mm1, mm2 /* mm1 = ABS(mm1) step 2 L 0 1m2r3 4 5 6 7 */ - - psraw mm1, 1 /* mm1 >>= 2 L 0 1m2 3 4 5 6 7 */ - - /* OK at this point, mm0 = ABS(d), mm1 = ABS(q), mm2 = SGN(q), mm3 = SGN(-d) */ - movq mm4, mm2 /* mm4 = SGN(q) L 0 1 2r3 4w5 6 7 */ - - pxor mm4, mm3 /* mm4 = SGN(q) ^ SGN(-d) L 0 1 2 3r4m5 6 7 */ - - movq mm5, mm0 /* mm5 = ABS(d) L 0r1 2 3 4 5w6 7 */ - - pcmpgtw mm5, mm1 /* is ABS(d) > ABS(q) ? L 0 1r2 3 4 5m6 7 */ - - pand mm1, mm5 /* min() step 1 L 0m1 2 3 4 5r6 7 */ - - pandn mm5, mm0 /* min() step 2 L 0 1r2 3 4 5m6 7 */ - - por mm1, mm5 /* min() step 3 L 0m1 2 3 4 5r6 7 */ - - pand mm1, mm4 /* if signs differ, set 0 L 0m1 2 3 4r5 6 7 */ - - pxor mm1, mm2 /* Apply sign step 1 L 0m1 2r3 4 5 6 7 */ - - psubw mm1, mm2 /* Apply sign step 2 L 0m1 2r3 4 5 6 7 */ - - /* at this point we have d in mm1 */ - pop ecx - }; - - if (i==0) - { - __asm movq mm6, mm1; - } - - } - - /* add d to rows l4 and l5 in memory... */ - pmm1 = (uint64_t *)(&(v[4*stride])); - __asm - { - push ecx - mov ecx, pmm1 - packsswb mm6, mm1 - movq mm0, [ecx] - psubb mm0, mm6 - movq [ecx], mm0 - add ecx, stride /* %0 += stride 0 1 2 3 4 5 6 7 */ - paddb mm6, [ecx] - movq [ecx], mm6 - pop ecx - }; -} - -const static uint64_t mm_fours = 0x0004000400040004; - - -/* Vertical 9-tap low-pass filter for use in "DC" regions of the picture */ -inline void deblock_vert_lpf9(uint64_t *v_local, uint64_t *p1p2, uint8_t *v, int stride) -{ - /* vertical DC filter in MMX - mm2 - p1/2 left - mm3 - p1/2 right - mm4 - psum left - mm5 - psum right */ - /* alternate between using mm0/mm1 and mm6/mm7 to accumlate left/right */ - - __asm - { - push eax - push ebx - push ecx - - mov eax, p1p2 - mov ebx, v_local - mov ecx, v - - /* load p1 left into mm2 and p1 right into mm3 */ - movq mm2, [eax] /* mm2 = p1p2[0] 0 1 2w3 4 5 6 7 */ - add ecx, stride /* ecx points at v[1*stride] 0 1 2 3 4 5 6 7 */ - - movq mm3, 8[eax] /* mm3 = p1p2[1] 0 1 2 3w4 5 6 7 */ - - movq mm4, mm_fours /* mm4 = 0x0004000400040004 0 1 2 3 4w5 6 7 */ - - /* psum = p1 + p1 + p1 + vv[1] + vv[2] + vv[3] + vv[4] + 4 */ - /* psum left will be in mm4, right in mm5 */ - - movq mm5, mm4 /* mm5 = 0x0004000400040004 0 1 2 3 4 5w6 7 */ - - paddsw mm4, 16[ebx] /* mm4 += vv[1] left 0 1 2 3 4m5 6 7 */ - paddw mm5, mm3 /* mm5 += p2 left 0 1 2 3r4 5m6 7 */ - - paddsw mm4, 32[ebx] /* mm4 += vv[2] left 0 1 2 3 4m5 6 7 */ - paddw mm5, mm3 /* mm5 += p2 left 0 1 2 3r4 5m6 7 */ - - paddsw mm4, 48[ebx] /* mm4 += vv[3] left 0 1 2 3 4m5 6 7 */ - paddw mm5, mm3 /* mm5 += p2 left 0 1 2 3r4 5m6 7 */ - - paddsw mm5, 24[ebx] /* mm5 += vv[1] right 0 1 2 3 4 5m6 7 */ - paddw mm4, mm2 /* mm4 += p1 left 0 1 2r3 4m5 6 7 */ - - paddsw mm5, 40[ebx] /* mm5 += vv[2] right 0 1 2 3 4 5m6 7 */ - paddw mm4, mm2 /* mm4 += p1 left 0 1 2r3 4m5 6 7 */ - - paddsw mm5, 56[ebx] /* mm5 += vv[3] right 0 1 2 3 4 5m6 7 */ - paddw mm4, mm2 /* mm4 += p1 left 0 1 2r3 4m5 6 7 */ - - paddsw mm4, 64[ebx] /* mm4 += vv[4] left 0 1 2 3 4m5 6 7 */ - - paddsw mm5, 72[ebx] /* mm5 += vv[4] right 0 1 2 3 4 5m6 7 */ - - /* v[1] = (((psum + vv[1]) << 1) - (vv[4] - vv[5])) >> 4 */ - /* compute this in mm0 (left) and mm1 (right) */ - - movq mm0, mm4 /* mm0 = psum left 0w1 2 3 4 5 6 7 */ - - paddsw mm0, 16[ebx] /* mm0 += vv[1] left 0m1 2 3 4 5 6 7 */ - movq mm1, mm5 /* mm1 = psum right 0 1w2 3 4 5r6 7 */ - - paddsw mm1, 24[ebx] /* mm1 += vv[1] right 0 1 2 3 4 5 6 7 */ - psllw mm0, 1 /* mm0 <<= 1 0m1 2 3 4 5 6 7 */ - - psubsw mm0, 64[ebx] /* mm0 -= vv[4] left 0m1 2 3 4 5 6 7 */ - psllw mm1, 1 /* mm1 <<= 1 0 1 2 3 4 5 6 7 */ - - psubsw mm1, 72[ebx] /* mm1 -= vv[4] right 0 1m2 3 4 5 6 7 */ - - paddsw mm0, 80[ebx] /* mm0 += vv[5] left 0m1 2 3 4 5 6 7 */ - - paddsw mm1, 88[ebx] /* mm1 += vv[5] right 0 1m2 3 4 5 6 7 */ - psrlw mm0, 4 /* mm0 >>= 4 0m1 2 3 4 5 6 7 */ - - /* psum += vv[5] - p1 */ - paddsw mm4, 80[ebx] /* mm4 += vv[5] left 0 1 2 3 4m5 6 7 */ - psrlw mm1, 4 /* mm1 >>= 4 0 1m2 3 4 5 6 7 */ - - paddsw mm5, 88[ebx] /* mm5 += vv[5] right 0 1 2 3 4 5 6 7 */ - psubsw mm4, [eax] /* mm4 -= p1 left 0 1 2 3 4 5 6 7 */ - - packuswb mm0, mm1 /* pack mm1, mm0 to mm0 0m1 2 3 4 5 6 7 */ - psubsw mm5, 8[eax] /* mm5 -= p1 right 0 1 2 3 4 5 6 7 */ - - /* v[2] = (((psum + vv[2]) << 1) - (vv[5] - vv[6])) >> 4 */ - /* compute this in mm6 (left) and mm7 (right) */ - movq mm6, mm4 /* mm6 = psum left 0 1 2 3 4 5 6 7 */ - - paddsw mm6, 32[ebx] /* mm6 += vv[2] left 0 1 2 3 4 5 6 7 */ - movq mm7, mm5 /* mm7 = psum right 0 1 2 3 4 5 6 7 */ - - paddsw mm7, 40[ebx] /* mm7 += vv[2] right 0 1 2 3 4 5 6 7 */ - psllw mm6, 1 /* mm6 <<= 1 0 1 2 3 4 5 6 7 */ - - psubsw mm6, 80[ebx] /* mm6 -= vv[5] left 0 1 2 3 4 5 6 7 */ - psllw mm7, 1 /* mm7 <<= 1 0 1 2 3 4 5 6 7 */ - - psubsw mm7, 88[ebx] /* mm7 -= vv[5] right 0 1 2 3 4 5 6 7 */ - - movq [ecx], mm0 /* v[1*stride] = mm0 0 1 2 3 4 5 6 7 */ - - paddsw mm6, 96[ebx] /* mm6 += vv[6] left 0 1 2 3 4 5 6 7 */ - add ecx, stride /* ecx points at v[2*stride] 0 1 2 3 4 5 6 7 */ - - paddsw mm7, 104[ebx] /* mm7 += vv[6] right 0 1 2 3 4 5 6 7 */ - - /* psum += vv[6] - p1 */ - - paddsw mm4, 96[ebx] /* mm4 += vv[6] left 0 1 2 3 4 5 6 7 */ - psrlw mm6, 4 /* mm6 >>= 4 0 1 2 3 4 5 6 7 */ - - paddsw mm5, 104[ebx] /* mm5 += vv[6] right 0 1 2 3 4 5 6 7 */ - psrlw mm7, 4 /* mm7 >>= 4 0 1 2 3 4 5 6 7 */ - - psubsw mm4, [eax] /* mm4 -= p1 left 0 1 2 3 4 5 6 7 */ - packuswb mm6, mm7 /* pack mm7, mm6 to mm6 0 1 2 3 4 5 6 7 */ - - psubsw mm5, 8[eax] /* mm5 -= p1 right 0 1 2 3 4 5 6 7 */ - - /* v[3] = (((psum + vv[3]) << 1) - (vv[6] - vv[7])) >> 4 */ - /* compute this in mm0 (left) and mm1 (right) */ - - movq mm0, mm4 /* mm0 = psum left 0 1 2 3 4 5 6 7 */ - - paddsw mm0, 48[ebx] /* mm0 += vv[3] left 0 1 2 3 4 5 6 7 */ - movq mm1, mm5 /* mm1 = psum right 0 1 2 3 4 5 6 7 */ - - paddsw mm1, 56[ebx] /* mm1 += vv[3] right 0 1 2 3 4 5 6 7 */ - psllw mm0, 1 /* mm0 <<= 1 0 1 2 3 4 5 6 7 */ - - psubsw mm0, 96[ebx] /* mm0 -= vv[6] left 0 1 2 3 4 5 6 7 */ - psllw mm1, 1 /* mm1 <<= 1 0 1 2 3 4 5 6 7 */ - - psubsw mm1, 104[ebx] /* mm1 -= vv[6] right 0 1 2 3 4 5 6 7 */ - - movq [ecx], mm6 /* v[2*stride] = mm6 0 1 2 3 4 5 6 7 */ - paddsw mm0, 112[ebx] /* mm0 += vv[7] left 0 1 2 3 4 5 6 7 */ - - paddsw mm1, 120[ebx] /* mm1 += vv[7] right 0 1 2 3 4 5 6 7 */ - add ecx, stride /* ecx points at v[3*stride] 0 1 2 3 4 5 6 7 */ - - /* psum += vv[7] - p1 */ - paddsw mm4, 112[ebx] /* mm4 += vv[5] left 0 1 2 3 4 5 6 7 */ - psrlw mm0, 4 /* mm0 >>= 4 0 1 2 3 4 5 6 7 */ - - paddsw mm5, 120[ebx] /* mm5 += vv[5] right 0 1 2 3 4 5 6 7 */ - psrlw mm1, 4 /* mm1 >>= 4 0 1 2 3 4 5 6 7 */ - - psubsw mm4, [eax] /* mm4 -= p1 left 0 1 2 3 4 5 6 7 */ - packuswb mm0, mm1 /* pack mm1, mm0 to mm0 0 1 2 3 4 5 6 7 */ - - psubsw mm5, 8[eax] /* mm5 -= p1 right 0 1 2 3 4 5 6 7 */ - - /* v[4] = (((psum + vv[4]) << 1) + p1 - vv[1] - (vv[7] - vv[8])) >> 4 */ - /* compute this in mm6 (left) and mm7 (right) */ - movq [ecx], mm0 /* v[3*stride] = mm0 0 1 2 3 4 5 6 7 */ - movq mm6, mm4 /* mm6 = psum left 0 1 2 3 4 5 6 7 */ - - paddsw mm6, 64[ebx] /* mm6 += vv[4] left 0 1 2 3 4 5 6 7 */ - movq mm7, mm5 /* mm7 = psum right 0 1 2 3 4 5 6 7 */ - - paddsw mm7, 72[ebx] /* mm7 += vv[4] right 0 1 2 3 4 5 6 7 */ - psllw mm6, 1 /* mm6 <<= 1 0 1 2 3 4 5 6 7 */ - - paddsw mm6, [eax] /* mm6 += p1 left 0 1 2 3 4 5 6 7 */ - psllw mm7, 1 /* mm7 <<= 1 0 1 2 3 4 5 6 7 */ - - paddsw mm7, 8[eax] /* mm7 += p1 right 0 1 2 3 4 5 6 7 */ - - psubsw mm6, 16[ebx] /* mm6 -= vv[1] left 0 1 2 3 4 5 6 7 */ - - psubsw mm7, 24[ebx] /* mm7 -= vv[1] right 0 1 2 3 4 5 6 7 */ - - psubsw mm6, 112[ebx] /* mm6 -= vv[7] left 0 1 2 3 4 5 6 7 */ - - psubsw mm7, 120[ebx] /* mm7 -= vv[7] right 0 1 2 3 4 5 6 7 */ - - paddsw mm6, 128[ebx] /* mm6 += vv[8] left 0 1 2 3 4 5 6 7 */ - add ecx, stride /* ecx points at v[4*stride] 0 1 2 3 4 5 6 7 */ - - paddsw mm7, 136[ebx] /* mm7 += vv[8] right 0 1 2 3 4 5 6 7 */ - /* psum += vv[8] - vv[1] */ - - paddsw mm4, 128[ebx] /* mm4 += vv[5] left 0 1 2 3 4 5 6 7 */ - psrlw mm6, 4 /* mm6 >>= 4 0 1 2 3 4 5 6 7 */ - - paddsw mm5, 136[ebx] /* mm5 += vv[5] right 0 1 2 3 4 5 6 7 */ - psrlw mm7, 4 /* mm7 >>= 4 0 1 2 3 4 5 6 7 */ - - psubsw mm4, 16[ebx] /* mm4 -= vv[1] left 0 1 2 3 4 5 6 7 */ - packuswb mm6, mm7 /* pack mm7, mm6 to mm6 0 1 2 3 4 5 6 7 */ - - psubsw mm5, 24[ebx] /* mm5 -= vv[1] right 0 1 2 3 4 5 6 7 */ - - /* v[5] = (((psum + vv[5]) << 1) + (vv[1] - vv[2]) - vv[8] + p2) >> 4 */ - /* compute this in mm0 (left) and mm1 (right) */ - movq mm0, mm4 /* mm0 = psum left 0 1 2 3 4 5 6 7 */ - - paddsw mm0, 80[ebx] /* mm0 += vv[5] left 0 1 2 3 4 5 6 7 */ - movq mm1, mm5 /* mm1 = psum right 0 1 2 3 4 5 6 7 */ - - paddsw mm1, 88[ebx] /* mm1 += vv[5] right 0 1 2 3 4 5 6 7 */ - psllw mm0, 1 /* mm0 <<= 1 0 1 2 3 4 5 6 7 */ - - paddsw mm0, 16[eax] /* mm0 += p2 left 0 1 2 3 4 5 6 7 */ - psllw mm1, 1 /* mm1 <<= 1 0 1 2 3 4 5 6 7 */ - - paddsw mm1, 24[eax] /* mm1 += p2 right 0 1 2 3 4 5 6 7 */ - - paddsw mm0, 16[ebx] /* mm0 += vv[1] left 0 1 2 3 4 5 6 7 */ - movq [ecx], mm6 /* v[4*stride] = mm6 0 1 2 3 4 5 6 7 */ - - paddsw mm1, 24[ebx] /* mm1 += vv[1] right 0 1 2 3 4 5 6 7 */ - - psubsw mm0, 32[ebx] /* mm0 -= vv[2] left 0 1 2 3 4 5 6 7 */ - - psubsw mm1, 40[ebx] /* mm1 -= vv[2] right 0 1 2 3 4 5 6 7 */ - - psubsw mm0, 128[ebx] /* mm0 -= vv[8] left 0 1 2 3 4 5 6 7 */ - - psubsw mm1, 136[ebx] /* mm1 -= vv[8] right 0 1 2 3 4 5 6 7 */ - - /* psum += p2 - vv[2] */ - paddsw mm4, 16[eax] /* mm4 += p2 left 0 1 2 3 4 5 6 7 */ - add ecx, stride /* ecx points at v[5*stride] 0 1 2 3 4 5 6 7 */ - - paddsw mm5, 24[eax] /* mm5 += p2 right 0 1 2 3 4 5 6 7 */ - - psubsw mm4, 32[ebx] /* mm4 -= vv[2] left 0 1 2 3 4 5 6 7 */ - - psubsw mm5, 40[ebx] /* mm5 -= vv[2] right 0 1 2 3 4 5 6 7 */ - - /* v[6] = (((psum + vv[6]) << 1) + (vv[2] - vv[3])) >> 4 */ - /* compute this in mm6 (left) and mm7 (right) */ - - movq mm6, mm4 /* mm6 = psum left 0 1 2 3 4 5 6 7 */ - - paddsw mm6, 96[ebx] /* mm6 += vv[6] left 0 1 2 3 4 5 6 7 */ - movq mm7, mm5 /* mm7 = psum right 0 1 2 3 4 5 6 7 */ - - paddsw mm7, 104[ebx] /* mm7 += vv[6] right 0 1 2 3 4 5 6 7 */ - psllw mm6, 1 /* mm6 <<= 1 0 1 2 3 4 5 6 7 */ - - paddsw mm6, 32[ebx] /* mm6 += vv[2] left 0 1 2 3 4 5 6 7 */ - psllw mm7, 1 /* mm7 <<= 1 0 1 2 3 4 5 6 7 */ - - paddsw mm7, 40[ebx] /* mm7 += vv[2] right 0 1 2 3 4 5 6 7 */ - psrlw mm0, 4 /* mm0 >>= 4 0 1 2 3 4 5 6 7 */ - - psubsw mm6, 48[ebx] /* mm6 -= vv[3] left 0 1 2 3 4 5 6 7 */ - psrlw mm1, 4 /* mm1 >>= 4 0 1 2 3 4 5 6 7 */ - - psubsw mm7, 56[ebx] /* mm7 -= vv[3] right 0 1 2 3 4 5 6 7 */ - packuswb mm0, mm1 /* pack mm1, mm0 to mm0 0 1 2 3 4 5 6 7 */ - - movq [ecx], mm0 /* v[5*stride] = mm0 0 1 2 3 4 5 6 7 */ - - /* psum += p2 - vv[3] */ - - paddsw mm4, 16[eax] /* mm4 += p2 left 0 1 2 3 4 5 6 7 */ - psrlw mm6, 4 /* mm6 >>= 4 0 1 2 3 4 5 6 7 */ - - paddsw mm5, 24[eax] /* mm5 += p2 right 0 1 2 3 4 5 6 7 */ - psrlw mm7, 4 /* mm7 >>= 4 0 1 2 3 4 5 6 7 */ - - psubsw mm4, 48[ebx] /* mm4 -= vv[3] left 0 1 2 3 4 5 6 7 */ - add ecx, stride /* ecx points at v[6*stride] 0 1 2 3 4 5 6 7 */ - - psubsw mm5, 56[ebx] /* mm5 -= vv[3] right 0 1 2 3 4 5 6 7 */ - - /* v[7] = (((psum + vv[7]) << 1) + (vv[3] - vv[4])) >> 4 */ - /* compute this in mm0 (left) and mm1 (right) */ - - movq mm0, mm4 /* mm0 = psum left 0 1 2 3 4 5 6 7 */ - - paddsw mm0, 112[ebx] /* mm0 += vv[7] left 0 1 2 3 4 5 6 7 */ - movq mm1, mm5 /* mm1 = psum right 0 1 2 3 4 5 6 7 */ - - paddsw mm1, 120[ebx] /* mm1 += vv[7] right 0 1 2 3 4 5 6 7 */ - psllw mm0, 1 /* mm0 <<= 1 0 1 2 3 4 5 6 7 */ - - paddsw mm0, 48[ebx] /* mm0 += vv[3] left 0 1 2 3 4 5 6 7 */ - psllw mm1, 1 /* mm1 <<= 1 0 1 2 3 4 5 6 7 */ - - paddsw mm1, 56[ebx] /* mm1 += vv[3] right 0 1 2 3 4 5 6 7 */ - packuswb mm6, mm7 /* pack mm7, mm6 to mm6 0 1 2 3 4 5 6 7 */ - - psubsw mm0, 64[ebx] /* mm0 -= vv[4] left 0 1 2 3 4 5 6 7 */ - - psubsw mm1, 72[ebx] /* mm1 -= vv[4] right 0 1 2 3 4 5 6 7 */ - psrlw mm0, 4 /* mm0 >>= 4 0 1 2 3 4 5 6 7 */ - - movq [ecx], mm6 /* v[6*stride] = mm6 0 1 2 3 4 5 6 7 */ - - /* psum += p2 - vv[4] */ - - paddsw mm4, 16[eax] /* mm4 += p2 left 0 1 2 3 4 5 6 7 */ - - paddsw mm5, 24[eax] /* mm5 += p2 right 0 1 2 3 4 5 6 7 */ - add ecx, stride /* ecx points at v[7*stride] 0 1 2 3 4 5 6 7 */ - - psubsw mm4, 64[ebx] /* mm4 -= vv[4] left 0 1 2 3 4 5 6 7 */ - psrlw mm1, 4 /* mm1 >>= 4 0 1 2 3 4 5 6 7 */ - - psubsw mm5, 72[ebx] /* mm5 -= vv[4] right 0 1 2 3 4 5 6 7 */ - - /* v[8] = (((psum + vv[8]) << 1) + (vv[4] - vv[5])) >> 4 */ - /* compute this in mm6 (left) and mm7 (right) */ - - movq mm6, mm4 /* mm6 = psum left 0 1 2 3 4 5 6 7 */ - - paddsw mm6, 128[ebx] /* mm6 += vv[8] left 0 1 2 3 4 5 6 7 */ - movq mm7, mm5 /* mm7 = psum right 0 1 2 3 4 5 6 7 */ - - paddsw mm7, 136[ebx] /* mm7 += vv[8] right 0 1 2 3 4 5 6 7 */ - psllw mm6, 1 /* mm6 <<= 1 0 1 2 3 4 5 6 7 */ - - paddsw mm6, 64[ebx] /* mm6 += vv[4] left 0 1 2 3 4 5 6 7 */ - psllw mm7, 1 /* mm7 <<= 1 0 1 2 3 4 5 6 7 */ - - paddsw mm7, 72[ebx] /* mm7 += vv[4] right 0 1 2 3 4 5 6 7 */ - packuswb mm0, mm1 /* pack mm1, mm0 to mm0 0 1 2 3 4 5 6 7 */ - - psubsw mm6, 80[ebx] /* mm6 -= vv[5] left 0 1 2 3 4 5 6 7 */ - - psubsw mm7, 88[ebx] /* mm7 -= vv[5] right 0 1 2 3 4 5 6 7 */ - psrlw mm6, 4 /* mm6 >>= 4 0 1 2 3 4 5 6 7 */ - - movq [ecx], mm0 /* v[7*stride] = mm0 0 1 2 3 4 5 6 7 */ - psrlw mm7, 4 /* mm7 >>= 4 0 1 2 3 4 5 6 7 */ - - packuswb mm6, mm7 /* pack mm7, mm6 to mm6 0 1 2 3 4 5 6 7 */ - - add ecx, stride /* ecx points at v[8*stride] 0 1 2 3 4 5 6 7 */ - - nop /* 0 1 2 3 4 5 6 7 */ - - movq [ecx], mm6 /* v[8*stride] = mm6 0 1 2 3 4 5 6 7 */ - - pop ecx - pop ebx - pop eax - }; -} - -/* decide DC mode or default mode in assembler */ -inline int deblock_vert_useDC(uint8_t *v, int stride, int moderate_v) -{ - const uint64_t mask = 0xfefefefefefefefe; - uint32_t mm_data1; - uint64_t *pmm1; - int eq_cnt, useDC; - - /* starting pointer is at v[stride] == v1 in mpeg4 notation */ - pmm1 = (uint64_t *)(&(v[stride])); - - /* first load some constants into mm4, mm6, mm7 */ - __asm - { - push eax - mov eax, pmm1 - - movq mm6, mask /*mm6 = 0xfefefefefefefefe */ - pxor mm7, mm7 /*mm7 = 0x0000000000000000 */ - - movq mm2, [eax] /* mm2 = *p_data */ - pxor mm4, mm4 /*mm4 = 0x0000000000000000 */ - - add eax, stride /* p_data += stride */ - movq mm3, mm2 /* mm3 = *p_data */ - }; - - __asm - { - movq mm2, [eax] /* mm2 = *p_data */ - movq mm0, mm3 /* mm0 = mm3 */ - - movq mm3, mm2 /* mm3 = *p_data */ - movq mm1, mm0 /* mm1 = mm0 */ - - psubusb mm0, mm2 /* mm0 -= mm2 */ - add eax, stride /* p_data += stride */ - - psubusb mm2, mm1 /* mm2 -= mm1 */ - por mm0, mm2 /* mm0 |= mm2 */ - - pand mm0, mm6 /* mm0 &= 0xfefefefefefefefe */ - pcmpeqb mm0, mm4 /* is mm0 == 0 ? */ - - movq mm2, [eax] /* mm2 = *p_data */ - psubb mm7, mm0 /* mm7 has running total of eqcnts */ - - movq mm5, mm3 /* mm5 = mm3 */ - movq mm3, mm2 /* mm3 = *p_data */ - - movq mm1, mm5 /* mm1 = mm5 */ - psubusb mm5, mm2 /* mm5 -= mm2 */ - - psubusb mm2, mm1 /* mm2 -= mm1 */ - por mm5, mm2 /* mm5 |= mm2 */ - - add eax, stride /* p_data += stride */ - pand mm5, mm6 /* mm5 &= 0xfefefefefefefefe */ - - pcmpeqb mm5, mm4 /* is mm0 == 0 ? */ - psubb mm7, mm5 /* mm7 has running total of eqcnts */ - - movq mm2, [eax] /* mm2 = *p_data */ - movq mm0, mm3 /* mm0 = mm3 */ - - movq mm3, mm2 /* mm3 = *p_data */ - movq mm1, mm0 /* mm1 = mm0 */ - - psubusb mm0, mm2 /* mm0 -= mm2 */ - add eax, stride /* p_data += stride */ - - psubusb mm2, mm1 /* mm2 -= mm1 */ - por mm0, mm2 /* mm0 |= mm2 */ - - pand mm0, mm6 /* mm0 &= 0xfefefefefefefefe */ - pcmpeqb mm0, mm4 /* is mm0 == 0 ? */ - - movq mm2, [eax] /* mm2 = *p_data */ - psubb mm7, mm0 /* mm7 has running total of eqcnts */ - - movq mm5, mm3 /* mm5 = mm3 */ - movq mm3, mm2 /* mm3 = *p_data */ - - movq mm1, mm5 /* mm1 = mm5 */ - psubusb mm5, mm2 /* mm5 -= mm2 */ - - psubusb mm2, mm1 /* mm2 -= mm1 */ - por mm5, mm2 /* mm5 |= mm2 */ - - add eax, stride /* p_data += stride */ - pand mm5, mm6 /* mm5 &= 0xfefefefefefefefe */ - - pcmpeqb mm5, mm4 /* is mm0 == 0 ? */ - psubb mm7, mm5 /* mm7 has running total of eqcnts */ - - movq mm2, [eax] /* mm2 = *p_data */ - movq mm0, mm3 /* mm0 = mm3 */ - - movq mm3, mm2 /* mm3 = *p_data */ - movq mm1, mm0 /* mm1 = mm0 */ - - psubusb mm0, mm2 /* mm0 -= mm2 */ - add eax, stride /* p_data += stride */ - - psubusb mm2, mm1 /* mm2 -= mm1 */ - por mm0, mm2 /* mm0 |= mm2 */ - - pand mm0, mm6 /* mm0 &= 0xfefefefefefefefe */ - pcmpeqb mm0, mm4 /* is mm0 == 0 ? */ - - movq mm2, [eax] /* mm2 = *p_data */ - psubb mm7, mm0 /* mm7 has running total of eqcnts */ - - movq mm5, mm3 /* mm5 = mm3 */ - movq mm3, mm2 /* mm3 = *p_data */ - - movq mm1, mm5 /* mm1 = mm5 */ - psubusb mm5, mm2 /* mm5 -= mm2 */ - - psubusb mm2, mm1 /* mm2 -= mm1 */ - por mm5, mm2 /* mm5 |= mm2 */ - - add eax, stride /* p_data += stride */ - pand mm5, mm6 /* mm5 &= 0xfefefefefefefefe */ - - pcmpeqb mm5, mm4 /* is mm0 == 0 ? */ - psubb mm7, mm5 /* mm7 has running total of eqcnts */ - - movq mm2, [eax] /* mm2 = *p_data */ - movq mm0, mm3 /* mm0 = mm3 */ - - movq mm3, mm2 /* mm3 = *p_data */ - movq mm1, mm0 /* mm1 = mm0 */ - - psubusb mm0, mm2 /* mm0 -= mm2 */ - add eax, stride /* p_data += stride */ - - psubusb mm2, mm1 /* mm2 -= mm1 */ - por mm0, mm2 /* mm0 |= mm2 */ - - pand mm0, mm6 /* mm0 &= 0xfefefefefefefefe */ - pcmpeqb mm0, mm4 /* is mm0 == 0 ? */ - - psubb mm7, mm0 /* mm7 has running total of eqcnts */ - - pop eax - }; - - /* now mm7 contains negative eq_cnt for all 8-columns */ - /* copy this to mm_data1 */ - /* sum all 8 bytes in mm7 */ - __asm - { - movq mm1, mm7 /* mm1 = mm7 0 1w2 3 4 5 6 7r */ - psrlq mm7, 32 /* mm7 >>= 32 0 1 2 3 4 5 6 7m */ - - paddb mm7, mm1 /* mm7 has running total of eqcnts */ - - movq mm1, mm7 /* mm1 = mm7 0 1w2 3 4 5 6 7r */ - psrlq mm7, 16 /* mm7 >>= 16 0 1 2 3 4 5 6 7m */ - - paddb mm1, mm7 /* mm7 has running total of eqcnts */ - - movq mm7, mm1 /* mm1 = mm7 0 1w2 3 4 5 6 7r */ - psrlq mm7, 8 /* mm7 >>= 8 0 1 2 3 4 5 6 7m */ - - paddb mm7, mm1 /* mm7 has running total of eqcnts */ - - movd mm_data1, mm7 /* mm_data1 = mm7 */ - }; - - eq_cnt = mm_data1 & 0xff; - - useDC = (eq_cnt > moderate_v); - -#ifdef PP_SELF_CHECK - if (useDC != useDC2) dprintf("ERROR: MMX version of useDC is incorrect\n"); -#endif - - return useDC; -} - - -/* this is the deringing filter */ -// new MMXSSE version - trbarry 3/15/2002 - -void dering( uint8_t *image, int width, int height, int stride, QP_STORE_T *QP_store, int QP_stride, int chroma) -{ - int x, y; - uint8_t *b8x8, *b10x10; - uint8_t b8x8filtered[64]; - int QP, max_diff; - uint8_t min, max, thr, range; - uint8_t max_diffq[8]; // a qword value of max_diff - - /* loop over all the 8x8 blocks in the image... */ - /* don't process outer row of blocks for the time being. */ - for (y=8; y>3)*QP_stride+(x>>3)] // Nick: QP_store[y/8*QP_stride+x/8] - : chroma == 0 ? QP_store[(y>>4)*QP_stride+(x>>4)] //Nick: QP_store[y/16*QP_stride+x/16]; - : QP_store[(y>>4)*QP_stride+(x>>3)]; - - /* pointer to the top left pixel in 8x8 block */ - b8x8 = &(image[stride*y + x]); - - /* pointer to the top left pixel in 10x10 block */ - b10x10 = &(image[stride*(y-1) + (x-1)]); - - // Threshold determination - find min and max grey levels in the block - // but remove loop thru 64 bytes. trbarry 03/13/2002 - - __asm - { - mov esi, b8x8 // the block addr - mov eax, stride // offset to next qword in block - - movq mm0, qword ptr[esi] // row 0, 1st qword is our min - movq mm1, mm0 // .. and our max - - pminub mm0, qword ptr[esi+eax] // row 1 - pmaxub mm1, qword ptr[esi+eax] - - lea esi, [esi+2*eax] // bump for next 2 - pminub mm0, qword ptr[esi] // row 2 - pmaxub mm1, qword ptr[esi] - - pminub mm0, qword ptr[esi+eax] // row 3 - pmaxub mm1, qword ptr[esi+eax] - - lea esi, [esi+2*eax] // bump for next 2 - pminub mm0, qword ptr[esi] // row 4 - pmaxub mm1, qword ptr[esi] - - pminub mm0, qword ptr[esi+eax] // row 5 - pmaxub mm1, qword ptr[esi+eax] - - lea esi, [esi+2*eax] // bump for next 2 - pminub mm0, qword ptr[esi] // row 6 - pmaxub mm1, qword ptr[esi] - - pminub mm0, qword ptr[esi+eax] // row 7 - pmaxub mm1, qword ptr[esi+eax] - - // get min of 8 bytes in mm0 - pshufw mm2, mm0, (3 << 2) + 2 // words 3,2 into low words of mm2 - pminub mm0, mm2 // now 4 min bytes in low half of mm0 - pshufw mm2, mm0, 1 // get word 1 of mm0 in low word of mm2 - pminub mm0, mm2 // got it down to 2 bytes - movq mm2, mm0 - psrlq mm2, 8 // byte 1 to low byte - pminub mm0, mm2 // our answer in low order byte - movd eax, mm0 - mov min, al // save answer - - // get max of 8 bytes in mm1 - pshufw mm2, mm1, (3 << 2) + 2 // words 3,2 into low words of mm2 - pmaxub mm1, mm2 // now 4 max bytes in low half of mm1 - pshufw mm2, mm1, 1 // get word 1 of mm1 in low word of mm2 - pmaxub mm1, mm2 // got it down to 2 bytes - movq mm2, mm1 - psrlq mm2, 8 // byte 1 to low byte - pmaxub mm1, mm2 // our answer in low order byte - movd eax, mm1 - mov max, al // save answer - - emms; - } - - /* Threshold detirmination - compute threshold and dynamic range */ - thr = (max + min + 1) >> 1; // Nick / 2 changed to >> 1 - range = max - min; - - max_diff = QP>>1; - max_diffq[0] = max_diffq[1] = max_diffq[2] = max_diffq[3] - = max_diffq[4] = max_diffq[5] = max_diffq[6] = max_diffq[7] - = max_diff; - - /* To opimize in MMX it's better to always fill in the b8x8filtered[] array - - b8x8filtered[8*v + h] = ( 8 - + 1 * b10x10[stride*(v+0) + (h+0)] + 2 * b10x10[stride*(v+0) + (h+1)] - + 1 * b10x10[stride*(v+0) + (h+2)] - + 2 * b10x10[stride*(v+1) + (h+0)] + 4 * b10x10[stride*(v+1) + (h+1)] - + 2 * b10x10[stride*(v+1) + (h+2)] - + 1 * b10x10[stride*(v+2) + (h+0)] + 2 * b10x10[stride*(v+2) + (h+1)] - + 1 * b10x10[stride*(v+2) + (h+2)] - >> 4; // Nick / 16 changed to >> 4 - - Note - As near as I can see, (a + 2*b + c)/4 = avg( avg(a,c), b) and likewise vertical. So since - there is a nice pavgb MMX instruction that gives a rounded vector average we may as well use it. - */ - // Fill in b10x10 array completely with 2 dim center weighted average - // This section now also includes the clipping step. - // trbarry 03/14/2002 - - _asm - { - mov esi, b10x10 // ptr to 10x10 source array - lea edi, b8x8filtered // ptr to 8x8 output array - mov eax, stride // amt to bump source ptr for next row - - movq mm7, qword ptr[esi] // this is really line -1 - pavgb mm7, qword ptr[esi+2] // avg( b[v,h], b[v,h+2] } - pavgb mm7, qword ptr[esi+1] // center weighted avg of 3 pixels w=1,2,1 - - lea esi, [esi+eax] // bump src ptr to point at line 0 - movq mm0, qword ptr[esi] // really line 0 - pavgb mm0, qword ptr[esi+2] - movq mm2, qword ptr[esi+1] // save orig line 0 vals for later clip - pavgb mm0, mm2 - - movq mm1, qword ptr[esi+eax] // get line 1 - pavgb mm1, qword ptr[esi+eax+2] - movq mm3, qword ptr[esi+eax+1] // save orig line 1 vals for later clip - pavgb mm1, mm3 - - // 0 - pavgb mm7, mm1 // avg lines surrounding line 0 - pavgb mm7, mm0 // center weighted avg of lines -1,0,1 - - movq mm4, mm2 // value for clip min - psubusb mm4, max_diffq // min - pmaxub mm7, mm4 // must be at least min - paddusb mm2, max_diffq // max - pminub mm7, mm2 // but no greater than max - - movq qword ptr[edi], mm7 - - lea esi, [esi+2*eax] // bump source ptr 2 lines - movq mm2, qword ptr[esi] // get line 2 - pavgb mm2, qword ptr[esi+2] - movq mm4, qword ptr[esi+1] // save orig line 2 vals for later clip - pavgb mm2, mm4 - - // 1 - pavgb mm0, mm2 // avg lines surrounding line 1 - pavgb mm0, mm1 // center weighted avg of lines 0,1,2 - - movq mm5, mm3 // value for clip min - psubusb mm5, max_diffq // min - pmaxub mm0, mm5 // must be at least min - paddusb mm3, max_diffq // max - pminub mm0, mm3 // but no greater than max - - movq qword ptr[edi+8], mm0 - - movq mm3, qword ptr[esi+eax] // get line 3 - pavgb mm3, qword ptr[esi+eax+2] - movq mm5, qword ptr[esi+eax+1] // save orig line 3 vals for later clip - pavgb mm3, mm5 - - // 2 - pavgb mm1, mm3 // avg lines surrounding line 2 - pavgb mm1, mm2 // center weighted avg of lines 1,2,3 - - movq mm6, mm4 // value for clip min - psubusb mm6, max_diffq // min - pmaxub mm1, mm6 // must be at least min - paddusb mm4, max_diffq // max - pminub mm1, mm4 // but no greater than max - - movq qword ptr[edi+16], mm1 - - lea esi, [esi+2*eax] // bump source ptr 2 lines - movq mm4, qword ptr[esi] // get line 4 - pavgb mm4, qword ptr[esi+2] - movq mm6, qword ptr[esi+1] // save orig line 4 vals for later clip - pavgb mm4, mm6 - - // 3 - pavgb mm2, mm4 // avg lines surrounding line 3 - pavgb mm2, mm3 // center weighted avg of lines 2,3,4 - - movq mm7, mm5 // save value for clip min - psubusb mm7, max_diffq // min - pmaxub mm2, mm7 // must be at least min - paddusb mm5, max_diffq // max - pminub mm2, mm5 // but no greater than max - - movq qword ptr[edi+24], mm2 - - movq mm5, qword ptr[esi+eax] // get line 5 - pavgb mm5, qword ptr[esi+eax+2] - movq mm7, qword ptr[esi+eax+1] // save orig line 5 vals for later clip - pavgb mm5, mm7 - - // 4 - pavgb mm3, mm5 // avg lines surrounding line 4 - pavgb mm3, mm4 // center weighted avg of lines 3,4,5 - - movq mm0, mm6 // save value for clip min - psubusb mm0, max_diffq // min - pmaxub mm3, mm0 // must be at least min - paddusb mm6, max_diffq // max - pminub mm3, mm6 // but no greater than max - - movq qword ptr[edi+32], mm3 - - lea esi, [esi+2*eax] // bump source ptr 2 lines - movq mm6, qword ptr[esi] // get line 6 - pavgb mm6, qword ptr[esi+2] - movq mm0, qword ptr[esi+1] // save orig line 6 vals for later clip - pavgb mm6, mm0 - - // 5 - pavgb mm4, mm6 // avg lines surrounding line 5 - pavgb mm4, mm5 // center weighted avg of lines 4,5,6 - - movq mm1, mm7 // save value for clip min - psubusb mm1, max_diffq // min - pmaxub mm4, mm1 // must be at least min - paddusb mm7, max_diffq // max - pminub mm4, mm7 // but no greater than max - - movq qword ptr[edi+40], mm4 - - movq mm7, qword ptr[esi+eax] // get line 7 - pavgb mm7, qword ptr[esi+eax+2] - movq mm1, qword ptr[esi+eax+1] // save orig line 7 vals for later clip - pavgb mm7, mm1 - - // 6 - pavgb mm5, mm7 // avg lines surrounding line 6 - pavgb mm5, mm6 // center weighted avg of lines 5,6,7 - - movq mm2, mm0 // save value for clip min - psubusb mm2, max_diffq // min - pmaxub mm5, mm2 // must be at least min - paddusb mm0, max_diffq // max - pminub mm5, mm0 // but no greater than max - - movq qword ptr[edi+48], mm5 - - movq mm0, qword ptr[esi+2*eax] // get line 8 - pavgb mm0, qword ptr[esi+2*eax+2] - pavgb mm0, qword ptr[esi+2*eax+1] - - // 7 - pavgb mm6, mm0 // avg lines surrounding line 7 - pavgb mm6, mm7 // center weighted avg of lines 6,7,8 - - movq mm3, mm1 // save value for clip min - psubusb mm3, max_diffq // min - pmaxub mm6, mm3 // must be at least min - paddusb mm1, max_diffq // max - pminub mm6, mm1 // but no greater than max - - movq qword ptr[edi+56], mm6 - - emms - } - - // trbarry 03-15-2002 - // If I (hopefully) understand all this correctly then we are supposed to only use the filtered - // pixels created above in the case where the orig pixel and all its 8 surrounding neighbors - // are either all above or all below the threashold. Since a mmx compare sets the mmx reg - // bytes to either 00 or ff we will just check a lopside average of all 9 of these to see - // if it is still 00 or ff. - // register notes: - // esi b10x10 - // edi b8x8filtered - // eax stride - // mm0 line 0, 3, or 6 compare average - // mm1 line 1, 4, or 7 " - // mm2 line 2, 5, 8, or -1 " - // mm3 odd line original pixel value - // mm4 even line original pixel value - // mm5 - // mm6 8 00's - // mm7 8 copies of threshold - - _asm - { - mov esi, b10x10 // ptr to 10x10 source array - lea edi, b8x8filtered // ptr to 8x8 output array - mov eax, stride // amt to bump source ptr for next row - mov bh, thr - mov bl, thr - psubusb mm6, mm6 // all 00 - movd mm7, ebx - pshufw mm7, mm7, 0 // low word to all words - - // get compare avg of row -1 - movq mm3, qword ptr[esi+1] // save center pixels of line -1 - - movq mm2, mm7 - psubusb mm2, qword ptr[esi] // left pixels >= threshold? - pcmpeqb mm2, mm6 // ff if >= else 00 - - movq mm5, mm7 - psubusb mm5, mm3 // center pixels >= threshold? - pcmpeqb mm5, mm6 - pavgb mm2, mm5 // combine answers - - movq mm5, mm7 - psubusb mm5, qword ptr[esi+2] // right pixels >= threshold? - pcmpeqb mm5, mm6 - pavgb mm2, mm5 // combine answers - - lea esi, [esi+eax] // &row 0 - - // get compare avg of row 0 - movq mm4, qword ptr[esi+1] // save center pixels - - movq mm0, mm7 - psubusb mm0, qword ptr[esi] // left pixels >= threshold? - pcmpeqb mm0, mm6 // ff if >= else 00 - - movq mm5, mm7 - psubusb mm5, mm4 // center pixels >= threshold? - pcmpeqb mm5, mm6 - pavgb mm0, mm5 // combine answers - - movq mm5, mm7 - psubusb mm5, qword ptr[esi+2] // right pixels >= threshold? - pcmpeqb mm5, mm6 - pavgb mm0, mm5 // combine answers - - // get compare avg of row 1 - - movq mm3, qword ptr[esi+eax+1] // save center pixels - - movq mm1, mm7 - psubusb mm1, qword ptr[esi+eax] // left pixels >= threshold? - pcmpeqb mm1, mm6 // ff if >= else 00 - - movq mm5, mm7 - psubusb mm5, mm3 // center pixels >= threshold? - pcmpeqb mm5, mm6 - pavgb mm1, mm5 // combine answers - - movq mm5, mm7 - psubusb mm5, qword ptr[esi+eax+2] // right pixels >= threshold? - pcmpeqb mm5, mm6 - pavgb mm1, mm5 // combine answers - - // decide whether to move filtered or orig pixels to row 0, move them - - pavgb mm2, mm0 - pavgb mm2, mm1 - pcmpeqb mm5, mm5 // all ff - pcmpeqb mm5, mm2 // 00 or ff - pcmpeqb mm5, mm2 // mm2 = ff or 00 ? ff : 00 - psubusb mm2, mm2 // 00 - pcmpeqb mm2, mm5 // opposite of mm5 - pand mm2, mm4 // use orig vales if thresh's diff, else 00 - pand mm5, qword ptr[edi] // use filterd vales if thresh's same, else 00 - por mm5, mm2 // one of them hsa a value - movq qword ptr[esi+1], mm5 // and store 8 pixels - - lea esi, [esi+eax] // &row 1 - - // get compare avg of row 2 - - movq mm4, qword ptr[esi+eax+1] // save center pixels - - movq mm2, mm7 - psubusb mm2, qword ptr[esi+eax] // left pixels >= threshold? - pcmpeqb mm2, mm6 // ff if >= else 00 - - movq mm5, mm7 - psubusb mm5, mm4 // center pixels >= threshold? - pcmpeqb mm5, mm6 - pavgb mm2, mm5 // combine answers - - movq mm5, mm7 - psubusb mm5, qword ptr[esi+eax+2] // right pixels >= threshold? - pcmpeqb mm5, mm6 - pavgb mm2, mm5 // combine answers - - // decide whether to move filtered or orig pixels to row 1, move them - - pavgb mm0, mm1 - pavgb mm0, mm2 - pcmpeqb mm5, mm5 // all ff - pcmpeqb mm5, mm0 // 00 or ff - pcmpeqb mm5, mm0 // mm2 = ff or 00 ? ff : 00 - psubusb mm0, mm0 // 00 - pcmpeqb mm0, mm5 // opposite of mm5 - pand mm0, mm3 // use orig vales if thresh's diff, else 00 - pand mm5, qword ptr[edi+1*8] // use filterd vales if thresh's same, else 00 - por mm5, mm0 // one of them hsa a value - movq qword ptr[esi+1], mm5 // and store 8 pixels - - lea esi, [esi+eax] // &row 2 - - // get compare avg of row 3 - - movq mm3, qword ptr[esi+eax+1] // save center pixels - - movq mm0, mm7 - psubusb mm0, qword ptr[esi+eax] // left pixels >= threshold? - pcmpeqb mm0, mm6 // ff if >= else 00 - - movq mm5, mm7 - psubusb mm5, mm3 // center pixels >= threshold? - pcmpeqb mm5, mm6 - pavgb mm0, mm5 // combine answers - - movq mm5, mm7 - psubusb mm5, qword ptr[esi+eax+2] // right pixels >= threshold? - pcmpeqb mm5, mm6 - pavgb mm0, mm5 // combine answers - - // decide whether to move filtered or orig pixels to row 2, move them - - pavgb mm1, mm0 - pavgb mm1, mm2 - pcmpeqb mm5, mm5 // all ff - pcmpeqb mm5, mm1 // 00 or ff - pcmpeqb mm5, mm1 // mm2 = ff or 00 ? ff : 00 - psubusb mm1, mm1 // 00 - pcmpeqb mm1, mm5 // opposite of mm5 - pand mm1, mm4 // use orig vales if thresh's diff, else 00 - pand mm5, qword ptr[edi+2*8] // use filterd vales if thresh's same, else 00 - por mm5, mm1 // one of them hsa a value - movq qword ptr[esi+1], mm5 // and store 8 pixels - - lea esi, [esi+eax] // &row 3 - - // get compare avg of row 4 - - movq mm4, qword ptr[esi+eax+1] // save center pixels - - movq mm1, mm7 - psubusb mm1, qword ptr[esi+eax] // left pixels >= threshold? - pcmpeqb mm1, mm6 // ff if >= else 00 - - movq mm5, mm7 - psubusb mm5, mm4 // center pixels >= threshold? - pcmpeqb mm5, mm6 - pavgb mm1, mm5 // combine answers - - movq mm5, mm7 - psubusb mm5, qword ptr[esi+eax+2] // right pixels >= threshold? - pcmpeqb mm5, mm6 - pavgb mm1, mm5 // combine answers - - // decide whether to move filtered or orig pixels to row 3, move them - - pavgb mm2, mm0 - pavgb mm2, mm1 - pcmpeqb mm5, mm5 // all ff - pcmpeqb mm5, mm2 // 00 or ff - pcmpeqb mm5, mm2 // mm2 = ff or 00 ? ff : 00 - psubusb mm2, mm2 // 00 - pcmpeqb mm2, mm5 // opposite of mm5 - pand mm2, mm3 // use orig vales if thresh's diff, else 00 - pand mm5, qword ptr[edi+3*8] // use filterd vales if thresh's same, else 00 - por mm5, mm2 // one of them hsa a value - movq qword ptr[esi+1], mm5 // and store 8 pixels - - lea esi, [esi+eax] // &row 4 - - // get compare avg of row 5 - - movq mm3, qword ptr[esi+eax+1] // save center pixels - - movq mm2, mm7 - psubusb mm2, qword ptr[esi+eax] // left pixels >= threshold? - pcmpeqb mm2, mm6 // ff if >= else 00 - - movq mm5, mm7 - psubusb mm5, mm3 // center pixels >= threshold? - pcmpeqb mm5, mm6 - pavgb mm2, mm5 // combine answers - - movq mm5, mm7 - psubusb mm5, qword ptr[esi+eax+2] // right pixels >= threshold? - pcmpeqb mm5, mm6 - pavgb mm2, mm5 // combine answers - - // decide whether to move filtered or orig pixels to row 4, move them - - pavgb mm0, mm2 - pavgb mm0, mm1 - pcmpeqb mm5, mm5 // all ff - pcmpeqb mm5, mm0 // 00 or ff - pcmpeqb mm5, mm0 // mm2 = ff or 00 ? ff : 00 - psubusb mm0, mm0 // 00 - pcmpeqb mm0, mm5 // opposite of mm5 - pand mm0, mm4 // use orig vales if thresh's diff, else 00 - pand mm5, qword ptr[edi+4*8] // use filterd vales if thresh's same, else 00 - por mm5, mm0 // one of them hsa a value - movq qword ptr[esi+1], mm5 // and store 8 pixels - - lea esi, [esi+eax] // &row 5 - - // get compare avg of row 6 - - movq mm4, qword ptr[esi+eax+1] // save center pixels - - movq mm0, mm7 - psubusb mm0, qword ptr[esi+eax] // left pixels >= threshold? - pcmpeqb mm0, mm6 // ff if >= else 00 - - movq mm5, mm7 - psubusb mm5, mm4 // center pixels >= threshold? - pcmpeqb mm5, mm6 - pavgb mm0, mm5 // combine answers - - movq mm5, mm7 - psubusb mm5, qword ptr[esi+eax+2] // right pixels >= threshold? - pcmpeqb mm5, mm6 - pavgb mm0, mm5 // combine answers - - // decide whether to move filtered or orig pixels to row 5, move them - - pavgb mm1, mm0 - pavgb mm1, mm2 - pcmpeqb mm5, mm5 // all ff - pcmpeqb mm5, mm1 // 00 or ff - pcmpeqb mm5, mm1 // mm2 = ff or 00 ? ff : 00 - psubusb mm1, mm1 // 00 - pcmpeqb mm1, mm5 // opposite of mm5 - pand mm1, mm3 // use orig vales if thresh's diff, else 00 - pand mm5, qword ptr[edi+5*8] // use filterd vales if thresh's same, else 00 - por mm5, mm1 // one of them hsa a value - movq qword ptr[esi+1], mm5 // and store 8 pixels - - lea esi, [esi+eax] // &row 6 - - // get compare avg of row 7 - - movq mm3, qword ptr[esi+eax+1] // save center pixels - - movq mm1, mm7 - psubusb mm1, qword ptr[esi+eax] // left pixels >= threshold? - pcmpeqb mm1, mm6 // ff if >= else 00 - - movq mm5, mm7 - psubusb mm5, mm3 // center pixels >= threshold? - pcmpeqb mm5, mm6 - pavgb mm1, mm5 // combine answers - - movq mm5, mm7 - psubusb mm5, qword ptr[esi+eax+2] // right pixels >= threshold? - pcmpeqb mm5, mm6 - pavgb mm1, mm5 // combine answers - - // decide whether to move filtered or orig pixels to row 6, move them - - pavgb mm2, mm0 - pavgb mm2, mm1 - pcmpeqb mm5, mm5 // all ff - pcmpeqb mm5, mm2 // 00 or ff - pcmpeqb mm5, mm2 // mm2 = ff or 00 ? ff : 00 - psubusb mm2, mm2 // 00 - pcmpeqb mm2, mm5 // opposite of mm5 - pand mm2, mm4 // use orig vales if thresh's diff, else 00 - pand mm5, qword ptr[edi+6*8] // use filterd vales if thresh's same, else 00 - por mm5, mm2 // one of them hsa a value - movq qword ptr[esi+1], mm5 // and store 8 pixels - - lea esi, [esi+eax] // &row 7 - - // get compare avg of row 8 - - movq mm4, qword ptr[esi+eax+1] // save center pixels - - movq mm2, mm7 - psubusb mm2, qword ptr[esi+eax] // left pixels >= threshold? - pcmpeqb mm2, mm6 // ff if >= else 00 - - movq mm5, mm7 - psubusb mm5, mm4 // center pixels >= threshold? - pcmpeqb mm5, mm6 - pavgb mm2, mm5 // combine answers - - movq mm5, mm7 - psubusb mm5, qword ptr[esi+eax+2] // right pixels >= threshold? - pcmpeqb mm5, mm6 - pavgb mm2, mm5 // combine answers - - // decide whether to move filtered or orig pixels to row 7, move them - - pavgb mm0, mm1 - pavgb mm0, mm2 - pcmpeqb mm5, mm5 // all ff - pcmpeqb mm5, mm0 // 00 or ff - pcmpeqb mm5, mm0 // mm2 = ff or 00 ? ff : 00 - psubusb mm0, mm0 // 00 - pcmpeqb mm0, mm5 // opposite of mm5 - pand mm0, mm3 // use orig vales if thresh's diff, else 00 - pand mm5, qword ptr[edi+7*8] // use filterd vales if thresh's same, else 00 - por mm5, mm0 // one of them hsa a value - movq qword ptr[esi+1], mm5 // and store 8 pixels - - emms - } - } - } -} - diff --git a/src/dgdecode/PostProcess.h b/src/dgdecode/PostProcess.h deleted file mode 100644 index f87d0b5..0000000 --- a/src/dgdecode/PostProcess.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef _POSTPROCESS_H -#define _POSTPROCESS_H - -#include - -#define DEC_MBC 45+300 -#define DEC_MBR 36+300 - -/**** mode flags to control postprocessing actions ****/ -#define PP_DEBLOCK_Y_H 0x00000001 /* Luma horizontal deblocking */ -#define PP_DEBLOCK_Y_V 0x00000002 /* Luma vertical deblocking */ -#define PP_DEBLOCK_C_H 0x00000004 /* Chroma horizontal deblocking */ -#define PP_DEBLOCK_C_V 0x00000008 /* Chroma vertical deblocking */ -#define PP_DERING_Y 0x00000010 /* Luma deringing */ -#define PP_DERING_C 0x00000020 /* Chroma deringing */ -#define PP_DONT_COPY 0x10000000 /* Postprocessor will not copy src -> dst */ - /* instead, it will operate on dst only */ - -/******************* general, useful macros ****************/ -#define SIGN(a) ( (a)<0 ? -1 : 1 ) - -typedef int QP_STORE_T; - -/******************** component function prototypes **************/ -int deblock_horiz_useDC(uint8_t *v, int stride, int moderate_h); -int deblock_horiz_DC_on(uint8_t *v, int stride, int QP); -void deblock_horiz_lpf9(uint8_t *v, int stride, int QP); -void deblock_horiz_default_filter(uint8_t *v, int stride, int QP); -void deblock_horiz(uint8_t *image, int width, int stride, QP_STORE_T *QP_store, int QP_stride, int chromaFlag, int moderate_h); -int deblock_vert_useDC(uint8_t *v, int stride, int moderate_v); -int deblock_vert_DC_on(uint8_t *v, int stride, int QP); -void deblock_vert_copy_and_unpack(int stride, uint8_t *source, uint64_t *dest, int n); -void deblock_vert_choose_p1p2(uint8_t *v, int stride, uint64_t *p1p2, int QP); -void deblock_vert_lpf9(uint64_t *v_local, uint64_t *p1p2, uint8_t *v, int stride); -void deblock_vert_default_filter(uint8_t *v, int stride, int QP); -void deblock_vert( uint8_t *image, int width, int stride, QP_STORE_T *QP_store, int QP_stride, int chromaFlag, int moderate_v); -void dering( uint8_t *image, int width, int height, int stride, int *QP_store, int QP_stride, int chroma); - -void postprocess(uint8_t * src[], int src_stride, int UVsrc_stride, - uint8_t * dst[], int dst_stride, int UVdst_stride, - - int horizontal_size, int vertical_size, - QP_STORE_T *QP_store, int QP_stride, - int mode, int moderate_h, int moderate_v, bool is422, bool iPP); -void do_emms(); - -// New Deringing Algo: -struct DERING_INFO -{ - uint8_t *rangearray; - uint8_t *thrarray; -}; - - -#endif diff --git a/src/dgdecode/color_convert.h b/src/dgdecode/color_convert.h deleted file mode 100644 index 7b09d47..0000000 --- a/src/dgdecode/color_convert.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef MPEG2DECPLUS_COLOR_CONVERT_H -#define MPEG2DECPLUS_COLOR_CONVERT_H - -#include - - -void conv420to422P(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch, - int width, int height); - -void conv420to422I(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch, - int width, int height); - -void conv422to444(const uint8_t *src, uint8_t *dst, int src_pitch, int dst_pitch, - int width, int height); -#if 0 -void conv444toRGB24(const uint8_t *py, const uint8_t *pu, const uint8_t *pv, - uint8_t *dst, int src_pitchY, int src_pitchUV, int dst_pitch, int width, - int height, int matrix, int pc_scale); - -void convYUY2to422P(const uint8_t *src, uint8_t *py, uint8_t *pu, uint8_t *pv, - int pitch1, int pitch2y, int pitch2uv, int width, int height); - -void conv422PtoYUY2(const uint8_t *py, uint8_t *pu, uint8_t *pv, uint8_t *dst, - int pitch1Y, int pitch1UV, int pitch2, int width, int height); -#endif - -#endif - diff --git a/src/dgdecode/deblock.cpp b/src/dgdecode/deblock.cpp deleted file mode 100644 index 47a570a..0000000 --- a/src/dgdecode/deblock.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* -A rewite of Deblock filter for support all planar 8bit YUV. -Almost same as tp7's version. -*/ - -#include "AvisynthAPI.h" - - -static inline int sat(int x, int min, int max) -{ - return (x < min) ? min : ((x > max) ? max : x); -} - - -static inline int absdiff(int x, int y) -{ - return x > y ? x - y : y - x; -} - - -static const int alphas[52] = { - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 4, 4, - 5, 6, 7, 8, 9, 10, - 12, 13, 15, 17, 20, - 22, 25, 28, 32, 36, - 40, 45, 50, 56, 63, - 71, 80, 90, 101, 113, - 127, 144, 162, 182, - 203, 226, 255, 255 -}; - -static const int betas[52] = { - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 2, 2, - 2, 3, 3, 3, 3, 4, - 4, 4, 6, 6, - 7, 7, 8, 8, 9, 9, - 10, 10, 11, 11, 12, - 12, 13, 13, 14, 14, - 15, 15, 16, 16, 17, - 17, 18, 18 -}; - -static const int cs[52] = { - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 1, 1, - 1, 1, 1, 1, 1, 1, - 1, 2, 2, 2, 2, 3, - 3, 3, 4, 4, 5, 5, - 6, 7, 8, 8, 10, - 11, 12, 13, 15, 17 -}; - - -static void deblock_h_edge(uint8_t *srcp, int srcPitch, const int alpha, const int beta, const int c0) -{ - uint8_t *sq0 = srcp; - uint8_t *sq1 = srcp + srcPitch; - uint8_t *sq2 = srcp + 2 * srcPitch; - uint8_t *sp0 = srcp - srcPitch; - uint8_t *sp1 = srcp - 2 * srcPitch; - uint8_t *sp2 = srcp - 3 * srcPitch; - - for (int i = 0; i < 4; ++i) { - if ((absdiff(sp0[i], sq0[i]) < alpha) - && (absdiff(sp1[i], sp0[i]) < beta) - && (absdiff(sq0[i], sq1[i]) < beta)) { - int ap = absdiff(sp2[i], sp0[i]); - int aq = absdiff(sq2[i], sq0[i]); - - int c = c0; - if (aq < beta) ++c; - if (ap < beta) ++c; - - int delta = sat((((sq0[i] - sp0[i]) * 4) + (sp1[i] - sq1[i]) + 4) >> 3, -c, c); - int avg = (sp0[i] + sq0[i] + 1) / 2; - int deltap1 = sat((sp2[i] + avg - sp1[i] * 2) / 2, -c0, c0); - int deltaq1 = sat((sq2[i] + avg - sq1[i] * 2) / 2, -c0, c0); - - if (ap < beta) sp1[i] = sp1[i] + deltap1; - sp0[i] = sat(sp0[i] + delta, 0, 255); - sq0[i] = sat(sq0[i] - delta, 0, 255); - if (aq < beta) sq1[i] = sq1[i] + deltaq1; - } - } -} - - -static void deblock_v_edge(uint8_t *s, int srcPitch, const int alpha, const int beta, const int c0) -{ - for (int i = 0; i < 4; ++i) { - if ((absdiff(s[0], s[-1]) < alpha) - && (absdiff(s[0], s[1]) < beta) - && (absdiff(s[-1], s[-2]) < beta)) { - int ap = absdiff(s[0], s[2]); - int aq = absdiff(s[-3], s[-1]); - - int c = c0; - if (aq < beta) ++c; - if (ap < beta) ++c; - - int delta = sat((((s[0] - s[-1]) * 4) + (s[-2] - s[1]) + 4) / 8, -c, c); - int avg = (s[0] + s[-1] + 1) / 2; - int deltaq1 = sat((s[2] + avg - s[1] * 2) / 2, -c0, c0); - int deltap1 = sat((s[-3] + avg - s[-2] * 2) / 2, -c0, c0); - - if (aq < beta) s[-2] = (s[-2] + deltap1); - s[-1] = sat(s[-1] + delta, 0, 255); - s[0] = sat(s[0] - delta, 0, 255); - if (ap < beta) s[1] = (s[1] + deltaq1); - } - s += srcPitch; - } -} - - -static void deblock_picture(uint8_t *srcp, int srcPitch, int w, int h, - const int alpha, const int beta, const int c0) -{ - for (int j = 0; j < h; j += 4 ) { - for (int i = 0; i < w; i += 4) { - if ( j > 0 ) - deblock_h_edge(srcp + i, srcPitch, alpha, beta, c0); - if ( i > 0 ) - deblock_v_edge(srcp + i, srcPitch, alpha, beta, c0); - } - srcp += 4 * srcPitch; - } -} - - -Deblock::Deblock(PClip _child, int q, int aoff, int boff, IScriptEnvironment* env) : - GenericVideoFilter(_child) -{ - q = sat(q, 0, 51); - int a = sat(q + aoff, 0, 51); - int b = sat(q + boff, 0, 51); - alpha = alphas[a]; - beta = betas[b]; - c0 = cs[a]; - - if (!vi.IsPlanar() || !vi.IsYUV()) - env->ThrowError("Deblock: need planar yuv input."); - if (vi.IsYUVA()) { - env->ThrowError("Deblock: alpha is not supported."); - } - if ((vi.width & 7) || (vi.height & 7)) - env->ThrowError("Deblock : width and height must be mod 8"); - - numPlanes = vi.IsY8() ? 1 : 3; -} - - -PVideoFrame __stdcall Deblock::GetFrame(int n, IScriptEnvironment *env) -{ - PVideoFrame src = child->GetFrame(n, env); - env->MakeWritable(&src); - - static const int planes[] = { PLANAR_Y, PLANAR_U, PLANAR_V }; - for (int p = 0; p < numPlanes; ++p) { - const int plane = planes[p]; - deblock_picture(src->GetWritePtr(plane), src->GetPitch(plane), - src->GetRowSize(plane), src->GetHeight(plane), - alpha, beta, c0); - } - - return src; -} - - -AVSValue __cdecl Deblock::create(AVSValue args, void* user_data, IScriptEnvironment* env) -{ - int quant = args[1].AsInt(25); - int aoffset = args[2].AsInt(0); - int boffset = args[3].AsInt(0); - return new Deblock(args[0].AsClip(), quant, aoffset, boffset, env); -} diff --git a/src/dgdecode/idct.h b/src/dgdecode/idct.h deleted file mode 100644 index c71d72f..0000000 --- a/src/dgdecode/idct.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef MPEG2DECPLUS_IDCT_H -#define MPEG2DECPLUS_IDCT_H - -#include - -void __fastcall idct_ref_sse3(int16_t* block) noexcept; - -void __fastcall prefetch_ref() noexcept; - -void __fastcall idct_ap922_sse2(int16_t* block) noexcept; - -void __fastcall prefetch_ap922() noexcept; - -void __fastcall idct_llm_float_sse2(int16_t* block) noexcept; - -void __fastcall idct_llm_float_avx2(int16_t* block) noexcept; - -void __fastcall prefetch_llm_float_sse2() noexcept; - -void __fastcall prefetch_llm_float_avx2() noexcept; - -#endif diff --git a/src/dgdecode/misc.cpp b/src/dgdecode/misc.cpp deleted file mode 100644 index 5b19b41..0000000 --- a/src/dgdecode/misc.cpp +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Misc Stuff for MPEG2Dec3 - * - * Copyright (C) 2002-2003 Marc Fauconneau - * - * This file is part of MPEG2Dec3, a free MPEG-2 decoder - * - * MPEG2Dec3 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. - * - * MPEG2Dec3 is distributed in the hope that 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 -#include -#define WIN32_LEAN_AND_MEAN -#define NOMINMAX -#include - -#include "misc.h" - - -size_t __cdecl dprintf(char* fmt, ...) -{ - char printString[1024]; - - va_list argp; - - va_start(argp, fmt); - vsprintf(printString, fmt, argp); - va_end(argp); - OutputDebugString(printString); - return strlen(printString); -} - - -void __stdcall -fast_copy(const uint8_t* src, const int src_stride, uint8_t* dst, - const int dst_stride, const int horizontal_size, int vertical_size) noexcept -{ - if (vertical_size == 0) { - return; - } else if (horizontal_size == src_stride && src_stride == dst_stride) { - memcpy(dst, src, horizontal_size * vertical_size); - } else { - do { - memcpy(dst, src, horizontal_size); - dst += dst_stride; - src += src_stride; - } while (--vertical_size != 0); - } -} - - -enum { - CPU_NO_X86_SIMD = 0x000000, - CPU_SSE2_SUPPORT = 0x000001, - CPU_SSE3_SUPPORT = 0x000002, - CPU_SSSE3_SUPPORT = 0x000004, - CPU_SSE4_1_SUPPORT = 0x000008, - CPU_SSE4_2_SUPPORT = 0x000010, - CPU_SSE4_A_SUPPORT = 0x000020, - CPU_FMA4_SUPPORT = 0x000040, - CPU_FMA3_SUPPORT = 0x000080, - CPU_AVX_SUPPORT = 0x000100, - CPU_AVX2_SUPPORT = 0x000200, - CPU_AVX512F_SUPPORT = 0x000400, - CPU_AVX512DQ_SUPPORT = 0x000800, - CPU_AVX512IFMA52_SUPPORT = 0x001000, - CPU_AVX512PF_SUPPORT = 0x002000, - CPU_AVX512ER_SUPPORT = 0x004000, - CPU_AVX512CD_SUPPORT = 0x008000, - CPU_AVX512BW_SUPPORT = 0x010000, - CPU_AVX512VL_SUPPORT = 0x020000, - CPU_AVX512VBMI_SUPPORT = 0x040000, -}; - - -static __forceinline bool is_bit_set(int bitfield, int bit) noexcept -{ - return (bitfield & (1 << bit)) != 0; -} - -static uint32_t get_simd_support_info(void) noexcept -{ - uint32_t ret = 0; - int regs[4] = {0}; - - __cpuid(regs, 0x00000001); - if (is_bit_set(regs[3], 26)) { - ret |= CPU_SSE2_SUPPORT; - } - if (is_bit_set(regs[2], 0)) { - ret |= CPU_SSE3_SUPPORT; - } - if (is_bit_set(regs[2], 9)) { - ret |= CPU_SSSE3_SUPPORT; - } - if (is_bit_set(regs[2], 19)) { - ret |= CPU_SSE4_1_SUPPORT; - } - if (is_bit_set(regs[2], 26)) { - ret |= CPU_SSE4_2_SUPPORT; - } - if (is_bit_set(regs[2], 27)) { - if (is_bit_set(regs[2], 28)) { - ret |= CPU_AVX_SUPPORT; - } - if (is_bit_set(regs[2], 12)) { - ret |= CPU_FMA3_SUPPORT; - } - } - - regs[3] = 0; - __cpuid(regs, 0x80000001); - if (is_bit_set(regs[3], 6)) { - ret |= CPU_SSE4_A_SUPPORT; - } - if (is_bit_set(regs[3], 16)) { - ret |= CPU_FMA4_SUPPORT; - } - - __cpuid(regs, 0x00000000); - if (regs[0] < 7) { - return ret; - } - - __cpuidex(regs, 0x00000007, 0); - if (is_bit_set(regs[1], 5)) { - ret |= CPU_AVX2_SUPPORT; - } - if (!is_bit_set(regs[1], 16)) { - return ret; - } - - ret |= CPU_AVX512F_SUPPORT; - if (is_bit_set(regs[1], 17)) { - ret |= CPU_AVX512DQ_SUPPORT; - } - if (is_bit_set(regs[1], 21)) { - ret |= CPU_AVX512IFMA52_SUPPORT; - } - if (is_bit_set(regs[1], 26)) { - ret |= CPU_AVX512PF_SUPPORT; - } - if (is_bit_set(regs[1], 27)) { - ret |= CPU_AVX512ER_SUPPORT; - } - if (is_bit_set(regs[1], 28)) { - ret |= CPU_AVX512CD_SUPPORT; - } - if (is_bit_set(regs[1], 30)) { - ret |= CPU_AVX512BW_SUPPORT; - } - if (is_bit_set(regs[1], 31)) { - ret |= CPU_AVX512VL_SUPPORT; - } - if (is_bit_set(regs[2], 1)) { - ret |= CPU_AVX512VBMI_SUPPORT; - } - - return ret; -} - -bool has_sse2() noexcept -{ - return (get_simd_support_info() & CPU_SSE2_SUPPORT) != 0; -} - -bool has_sse3() noexcept -{ - return (get_simd_support_info() & CPU_SSE4_1_SUPPORT) != 0; -} - -bool has_avx2() noexcept -{ - uint32_t flags = CPU_AVX2_SUPPORT | CPU_FMA3_SUPPORT; - return (get_simd_support_info() & flags) == flags; -} - diff --git a/src/dgindex/AC3Dec/ac3.h b/src/dgindex/AC3Dec/ac3.h deleted file mode 100644 index eff4af8..0000000 --- a/src/dgindex/AC3Dec/ac3.h +++ /dev/null @@ -1,356 +0,0 @@ -/* - * Copyright (C) Aaron Holtzman - May 1999 - * - * This file is part of ac3dec, a free Dolby AC-3 stream decoder. - * - * ac3dec 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. - * - * ac3dec is distributed in the hope that 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 - -#ifdef AC3_GLOBAL -#define AXTN -#else -#define AXTN extern -#endif - -typedef unsigned int uint_32; -typedef unsigned short uint_16; -typedef unsigned char uint_8; - -typedef signed int sint_32; -typedef signed short sint_16; -typedef signed char sint_8; - -uint_32 ac3_decode_data(uint_8 *data_start, uint_32 length, uint_32 start); - -/* Exponent strategy constants */ -#define EXP_REUSE (0) -#define EXP_D15 (1) -#define EXP_D25 (2) -#define 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) - -/* samples work structure */ -typedef double stream_samples_t[6][256]; - -typedef struct syncinfo_s -{ - /* Sync word == 0x0B77 */ - uint_16 syncword; - /* crc for the first 5/8 of the sync block */ - /* uint_16 crc1; */ - /* Stream Sampling Rate (kHz) 0 = 48, 1 = 44.1, 2 = 32, 3 = reserved */ - uint_16 fscod; - /* Frame size code */ - uint_16 frmsizecod; - - /* Information not in the AC-3 bitstream, but derived */ - /* Frame size in 16 bit words */ - uint_16 frame_size; - /* Bit rate in kilobits */ - uint_16 bit_rate; - /* sampling rate in hertz */ - uint_32 sampling_rate; -} syncinfo_t; - -typedef struct bsi_s -{ - /* Bit stream identification == 0x8 */ - uint_16 bsid; - /* Bit stream mode */ - uint_16 bsmod; - /* Audio coding mode */ - uint_16 acmod; - /* If we're using the centre channel then */ - /* centre mix level */ - uint_16 cmixlev; - /* If we're using the surround channel then */ - /* surround mix level */ - uint_16 surmixlev; - /* If we're in 2/0 mode then */ - /* Dolby surround mix level - NOT USED - */ - uint_16 dsurmod; - /* Low frequency effects on */ - uint_16 lfeon; - /* Dialogue Normalization level */ - uint_16 dialnorm; - /* Compression exists */ - uint_16 compre; - /* Compression level */ - uint_16 compr; - /* Language code exists */ - uint_16 langcode; - /* Language code */ - uint_16 langcod; - /* Audio production info exists*/ - uint_16 audprodie; - uint_16 mixlevel; - uint_16 roomtyp; - /* If we're in dual mono mode (acmod == 0) then extra stuff */ - uint_16 dialnorm2; - uint_16 compr2e; - uint_16 compr2; - uint_16 langcod2e; - uint_16 langcod2; - uint_16 audprodi2e; - uint_16 mixlevel2; - uint_16 roomtyp2; - /* Copyright bit */ - uint_16 copyrightb; - /* Original bit */ - uint_16 origbs; - /* Timecode 1 exists */ - uint_16 timecod1e; - /* Timecode 1 */ - uint_16 timecod1; - /* Timecode 2 exists */ - uint_16 timecod2e; - /* Timecode 2 */ - uint_16 timecod2; - /* Additional bit stream info exists */ - uint_16 addbsie; - /* Additional bit stream length - 1 (in bytes) */ - uint_16 addbsil; - /* Additional bit stream information (max 64 bytes) */ - uint_8 addbsi[64]; - - /* Information not in the AC-3 bitstream, but derived */ - /* Number of channels (excluding LFE) - * Derived from acmod */ - uint_16 nfchans; -} bsi_t; - -/* more pain */ -typedef struct audblk_s -{ - /* block switch bit indexed by channel num */ - uint_16 blksw[5]; - /* dither enable bit indexed by channel num */ - uint_16 dithflag[5]; - /* dynamic range gain exists */ - uint_16 dynrnge; - /* dynamic range gain */ - uint_16 dynrng; - /* if acmod==0 then */ - /* dynamic range 2 gain exists */ - uint_16 dynrng2e; - /* dynamic range 2 gain */ - uint_16 dynrng2; - /* coupling strategy exists */ - uint_16 cplstre; - /* coupling in use */ - uint_16 cplinu; - /* channel coupled */ - uint_16 chincpl[5]; - /* if acmod==2 then */ - /* Phase flags in use */ - uint_16 phsflginu; - /* coupling begin frequency code */ - uint_16 cplbegf; - /* coupling end frequency code */ - uint_16 cplendf; - /* coupling band structure bits */ - uint_16 cplbndstrc[18]; - /* Do coupling co-ords exist for this channel? */ - uint_16 cplcoe[5]; - /* Master coupling co-ordinate */ - uint_16 mstrcplco[5]; - /* Per coupling band coupling co-ordinates */ - uint_16 cplcoexp[5][18]; - uint_16 cplcomant[5][18]; - /* Phase flags for dual mono */ - uint_16 phsflg[18]; - /* Is there a rematrixing strategy */ - uint_16 rematstr; - /* Rematrixing bits */ - uint_16 rematflg[4]; - /* Coupling exponent strategy */ - uint_16 cplexpstr; - /* Exponent strategy for full bandwidth channels */ - uint_16 chexpstr[5]; - /* Exponent strategy for lfe channel */ - uint_16 lfeexpstr; - /* Channel bandwidth for independent channels */ - uint_16 chbwcod[5]; - /* The absolute coupling exponent */ - uint_16 cplabsexp; - /* Coupling channel exponents (D15 mode gives 18 * 12 /3 encoded exponents */ - uint_16 cplexps[18 * 12 / 3]; - - /* fbw channel exponents */ - uint_16 exps[5][252 / 3]; - /* channel gain range */ - uint_16 gainrng[5]; - /* low frequency exponents */ - uint_16 lfeexps[3]; - - /* Bit allocation info */ - uint_16 baie; - /* Slow decay code */ - uint_16 sdcycod; - /* Fast decay code */ - uint_16 fdcycod; - /* Slow gain code */ - uint_16 sgaincod; - /* dB per bit code */ - uint_16 dbpbcod; - /* masking floor code */ - uint_16 floorcod; - - /* SNR offset info */ - uint_16 snroffste; - /* coarse SNR offset */ - uint_16 csnroffst; - /* coupling fine SNR offset */ - uint_16 cplfsnroffst; - /* coupling fast gain code */ - uint_16 cplfgaincod; - /* fbw fine SNR offset */ - uint_16 fsnroffst[5]; - /* fbw fast gain code */ - uint_16 fgaincod[5]; - /* lfe fine SNR offset */ - uint_16 lfefsnroffst; - /* lfe fast gain code */ - uint_16 lfefgaincod; - - /* Coupling leak info */ - uint_16 cplleake; - /* coupling fast leak initialization */ - uint_16 cplfleak; - /* coupling slow leak initialization */ - uint_16 cplsleak; - - /* delta bit allocation info */ - uint_16 deltbaie; - /* coupling delta bit allocation exists */ - uint_16 cpldeltbae; - /* fbw delta bit allocation exists */ - uint_16 deltbae[5]; - /* number of cpl delta bit segments */ - uint_16 cpldeltnseg; - /* coupling delta bit allocation offset */ - uint_16 cpldeltoffst[8]; - /* coupling delta bit allocation length */ - uint_16 cpldeltlen[8]; - /* coupling delta bit allocation length */ - uint_16 cpldeltba[8]; - /* number of delta bit segments */ - uint_16 deltnseg[5]; - /* fbw delta bit allocation offset */ - uint_16 deltoffst[5][8]; - /* fbw delta bit allocation length */ - uint_16 deltlen[5][8]; - /* fbw delta bit allocation length */ - uint_16 deltba[5][8]; - - /* skip length exists */ - uint_16 skiple; - /* skip length */ - uint_16 skipl; - - //Removed Feb 2000 -ah - /* channel mantissas */ - //sint_16 chmant[5][256]; - - /* coupling mantissas */ - sint_16 cplmant[256]; - - //Removed Feb 2000 -ah - /* coupling mantissas */ - //sint_16 lfemant[7]; - - /* Number of coupling sub-bands */ - uint_16 ncplsubnd; - - /* Number of combined coupling sub-bands - * Derived from ncplsubnd and cplbndstrc */ - uint_16 ncplbnd; - - /* Number of exponent groups by channel - * Derived from strmant, endmant */ - uint_16 nchgrps[5]; - - /* Number of coupling exponent groups - * Derived from cplbegf, cplendf, cplexpstr */ - uint_16 ncplgrps; - - /* End mantissa numbers of fbw channels */ - uint_16 endmant[5]; - - /* Start and end mantissa numbers for the coupling channel */ - uint_16 cplstrtmant; - uint_16 cplendmant; - - /* Decoded exponent info */ - uint_16 fbw_exp[5][256]; - uint_16 cpl_exp[256]; - uint_16 lfe_exp[7]; - - /* Bit allocation pointer results */ - uint_16 fbw_bap[5][256]; - uint_16 cpl_bap[256]; - uint_16 lfe_bap[7]; -} audblk_t; - -/* coeff */ -void mantissa_init(void); -void coeff_unpack(bsi_t *bsi, audblk_t *audblk, stream_samples_t samples); - -/* crc */ -int crc_process_frame(uint_8 *data,uint_32 num_bytes); - -/* downmix */ -void drc_init(void); -void downmix(audblk_t *audblk, bsi_t* bsi, stream_samples_t stream_samples, sint_16 *s16_samples); - -/* exponent */ -#define UNPACK_FBW 1 -#define UNPACK_CPL 2 -#define UNPACK_LFE 4 - -void exponent_init(void); -void exponent_unpack( bsi_t *bsi, audblk_t *audblk); - -/* imdct */ -void imdct(bsi_t *bsi,audblk_t *audblk, stream_samples_t samples); -void imdct_init(void); - -/* parse */ -void parse_syncinfo(syncinfo_t *syncinfo,uint_8 *data); -void parse_audblk(bsi_t *bsi,audblk_t *audblk); -void parse_bsi(bsi_t *bsi); - -/* rematrix */ -void rematrix(audblk_t *audblk, stream_samples_t samples); - -/* sanity check */ -void sanity_check(bsi_t *bsi, audblk_t *audblk); - -void InitialAC3(void); -AXTN unsigned char AC3Dec_Buffer[49152]; // 48KB/frame for 64~448 Kbps - -AXTN uint_32 error_flag; - -AXTN uint_8 *buffer_start; -AXTN uint_32 bits_left; -AXTN uint_32 current_word; diff --git a/src/dgindex/AC3Dec/bit_allocate.cpp b/src/dgindex/AC3Dec/bit_allocate.cpp deleted file mode 100644 index 2b75a9f..0000000 --- a/src/dgindex/AC3Dec/bit_allocate.cpp +++ /dev/null @@ -1,458 +0,0 @@ -/* - * Copyright (C) Aaron Holtzman - May 1999 - * - * This file is part of ac3dec, a free Dolby AC-3 stream decoder. - * - * ac3dec 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. - * - * ac3dec is distributed in the hope that 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. - * - */ - -#define AC3_GLOBAL -#include "ac3.h" - -#define maxvalue(a, b) (a > b ? a : b) -#define minvalue(a, b) (a < b ? a : b) - -static sint_16 calc_lowcomp(sint_16 a,sint_16 b0,sint_16 b1,sint_16 bin); -static void ba_compute_psd(sint_16 start, sint_16 end, sint_16 exps[], - sint_16 psd[], sint_16 bndpsd[]); -static void ba_compute_excitation(sint_16 start, sint_16 end,sint_16 fgain, - sint_16 fastleak, sint_16 slowleak, sint_16 bndpsd[], sint_16 excite[]); -static void ba_compute_mask(sint_16 start, sint_16 end, uint_16 fscod, - uint_16 deltbae, uint_16 deltnseg, uint_16 deltoffst[], uint_16 deltba[], - uint_16 deltlen[], sint_16 excite[], sint_16 mask[]); -static void ba_compute_bap(sint_16 start, sint_16 end, sint_16 snroffset, - sint_16 psd[], sint_16 mask[], sint_16 bap[]); - -/* Misc LUTs for bit allocation process */ -static sint_16 slowdec[] = { 0x0f, 0x11, 0x13, 0x15 }; -static sint_16 fastdec[] = { 0x3f, 0x53, 0x67, 0x7b }; -static sint_16 slowgain[] = { 0x540, 0x4d8, 0x478, 0x410 }; -static sint_16 dbpbtab[] = { 0x000, 0x700, 0x900, 0xb00 }; - -static uint_16 floortab[] = { 0x2f0, 0x2b0, 0x270, 0x230, 0x1f0, 0x170, 0x0f0, 0xf800 }; -static sint_16 fastgain[] = { 0x080, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380, 0x400 }; - -static sint_16 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 sint_16 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 sint_16 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 sint_16 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 sint_16 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 sint_16 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 }; - -static sint_16 sdecay; -static sint_16 fdecay; -static sint_16 sgain; -static sint_16 dbknee; -static sint_16 floor; -static sint_16 psd[256]; -static sint_16 bndpsd[256]; -static sint_16 excite[256]; -static sint_16 mask[256]; - -__forceinline static sint_16 logadd(sint_16 a, sint_16 b) -{ - if (a >= b) - return a + latab[minvalue((a - b)>>1, 255)]; - else - return b + latab[minvalue((b - a)>>1, 255)]; -} - -void bit_allocate(uint_16 fscod, bsi_t *bsi, audblk_t *audblk) -{ - uint_16 i; - sint_16 fgain; - sint_16 snroffset; - sint_16 start; - sint_16 end; - sint_16 fastleak; - sint_16 slowleak; - - /* 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; - - /* Do some setup before we do the bit alloc */ - sdecay = slowdec[audblk->sdcycod]; - fdecay = fastdec[audblk->fdcycod]; - sgain = slowgain[audblk->sgaincod]; - dbknee = dbpbtab[audblk->dbpbcod]; - floor = 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) - { - ZeroMemory(audblk->fbw_bap, sizeof(uint_16) * 256 * 5); - ZeroMemory(audblk->cpl_bap, sizeof(uint_16) * 256); - ZeroMemory(audblk->lfe_bap, sizeof(uint_16) * 7); - return; - } - - for(i = 0; i < bsi->nfchans; i++) - { - start = 0; - end = audblk->endmant[i] ; - fgain = fastgain[audblk->fgaincod[i]]; - snroffset = (((audblk->csnroffst - 15) << 4) + audblk->fsnroffst[i]) << 2 ; - fastleak = 0; - slowleak = 0; - - ba_compute_psd(start, end, (short *) audblk->fbw_exp[i], psd, bndpsd); - - ba_compute_excitation(start, end, fgain, fastleak, slowleak, bndpsd, excite); - - ba_compute_mask(start, end, fscod, audblk->deltbae[i], audblk->deltnseg[i], - audblk->deltoffst[i], audblk->deltba[i], audblk->deltlen[i], excite, mask); - - ba_compute_bap(start, end, snroffset, psd, mask, (short *) audblk->fbw_bap[i]); - } - - if(audblk->cplinu) - { - start = audblk->cplstrtmant; - end = audblk->cplendmant; - fgain = fastgain[audblk->cplfgaincod]; - snroffset = (((audblk->csnroffst - 15) << 4) + audblk->cplfsnroffst) << 2 ; - fastleak = (audblk->cplfleak << 8) + 768; - slowleak = (audblk->cplsleak << 8) + 768; - - ba_compute_psd(start, end, (short *)audblk->cpl_exp, psd, bndpsd); - - ba_compute_excitation(start, end , fgain, fastleak, slowleak, bndpsd, excite); - - ba_compute_mask(start, end, fscod, audblk->cpldeltbae, audblk->cpldeltnseg, - audblk->cpldeltoffst, audblk->cpldeltba, audblk->cpldeltlen, excite, mask); - - ba_compute_bap(start, end, snroffset, psd, mask, (short *)audblk->cpl_bap); - } - - if(bsi->lfeon) - { - start = 0; - end = 7; - fgain = fastgain[audblk->lfefgaincod]; - snroffset = (((audblk->csnroffst - 15) << 4) + audblk->lfefsnroffst) << 2 ; - fastleak = 0; - slowleak = 0; - - ba_compute_psd(start, end, (short *)audblk->lfe_exp, psd, bndpsd); - - ba_compute_excitation(start, end , fgain, fastleak, slowleak, bndpsd, excite); - - /* Perform no delta bit allocation for lfe */ - ba_compute_mask(start, end, fscod, 2, 0, 0, 0, 0, excite, mask); - - ba_compute_bap(start, end, snroffset, psd, mask, (short *)audblk->lfe_bap); - } -} - -static void ba_compute_psd(sint_16 start, sint_16 end, sint_16 exps[], - sint_16 psd[], sint_16 bndpsd[]) -{ - int bin, i, j, k; - sint_16 lastbin = 0; - - /* Map the exponents into dBs */ - for (bin=start; bin lastbin); -} - -static void ba_compute_excitation(sint_16 start, sint_16 end, sint_16 fgain, - sint_16 fastleak, sint_16 slowleak, - sint_16 bndpsd[], sint_16 excite[]) -{ - int bin; - sint_16 bndstrt; - sint_16 bndend; - sint_16 lowcomp = 0; - sint_16 begin = 0; - - /* Compute excitation function */ - bndstrt = masktab[start]; - bndend = masktab[end - 1] + 1; - - if (bndstrt == 0) /* For fbw and lfe channels */ - { - lowcomp = calc_lowcomp(lowcomp, bndpsd[0], bndpsd[1], 0); - excite[0] = bndpsd[0] - fgain - lowcomp; - lowcomp = calc_lowcomp(lowcomp, bndpsd[1], bndpsd[2], 1); - excite[1] = bndpsd[1] - fgain - lowcomp; - begin = 7 ; - - /* Note: Do not call calc_lowcomp() for the last band of the lfe channel, (bin = 6) */ - for (bin = 2; bin < 7; bin++) - { - if (bndend!= 7 || bin!=6) - lowcomp = calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin+1], bin); - fastleak = bndpsd[bin] - fgain; - slowleak = bndpsd[bin] - sgain; - excite[bin] = fastleak - lowcomp; - - if (bndend!= 7 || bin!=6) - { - if (bndpsd[bin] <= bndpsd[bin+1]) - { - begin = bin + 1 ; - break; - } - } - } - - for (bin = begin; bin < minvalue(bndend, 22); bin++) - { - if (bndend!= 7 || bin!=6) - lowcomp = calc_lowcomp(lowcomp, bndpsd[bin], bndpsd[bin+1], bin); - fastleak -= fdecay ; - fastleak = maxvalue(fastleak, bndpsd[bin] - fgain); - slowleak -= sdecay ; - slowleak = maxvalue(slowleak, bndpsd[bin] - sgain); - excite[bin] = maxvalue(fastleak - lowcomp, slowleak); - } - begin = 22; - } - else /* For coupling channel */ - { - begin = bndstrt; - } - - for (bin = begin; bin < bndend; bin++) - { - fastleak -= fdecay; - fastleak = maxvalue(fastleak, bndpsd[bin] - fgain); - slowleak -= sdecay; - slowleak = maxvalue(slowleak, bndpsd[bin] - sgain); - excite[bin] = maxvalue(fastleak, slowleak) ; - } -} - -static void ba_compute_mask(sint_16 start, sint_16 end, uint_16 fscod, - uint_16 deltbae, uint_16 deltnseg, uint_16 deltoffst[], uint_16 deltba[], - uint_16 deltlen[], sint_16 excite[], sint_16 mask[]) -{ - int bin,k; - sint_16 bndstrt; - sint_16 bndend; - sint_16 delta; - - bndstrt = masktab[start]; - bndend = masktab[end - 1] + 1; - - /* Compute the masking curve */ - - for (bin = bndstrt; bin < bndend; bin++) - { - if (bndpsd[bin] < dbknee) - { - excite[bin] += ((dbknee - bndpsd[bin]) >> 2); - } - mask[bin] = maxvalue(excite[bin], hth[fscod][bin]); - } - - /* Perform delta bit modulation if necessary */ - if ((deltbae == DELTA_BIT_REUSE) || (deltbae == DELTA_BIT_NEW)) - { - sint_16 band = 0; - sint_16 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++; - } - } - } -} - -static void ba_compute_bap(sint_16 start, sint_16 end, sint_16 snroffset, - sint_16 psd[], sint_16 mask[], sint_16 bap[]) -{ - int i,j,k; - sint_16 lastbin = 0; - sint_16 address = 0; - - /* Compute the bit allocation pointer for each bin */ - i = start; - j = masktab[start]; - - do - { - lastbin = minvalue(bndtab[j] + bndsz[j], end); - mask[j] -= snroffset; - mask[j] -= floor; - - if (mask[j] < 0) - mask[j] = 0; - - mask[j] &= 0x1fe0; - mask[j] += floor; - for (k = i; k < lastbin; k++) - { - address = (psd[i] - mask[j]) >> 5; - address = minvalue(63, maxvalue(0, address)); - bap[i] = baptab[address]; - i++; - } - j++; - } while (end > lastbin); -} - -static sint_16 calc_lowcomp(sint_16 a, sint_16 b0, sint_16 b1, sint_16 bin) -{ - if (bin < 7) - { - if ((b0 + 256) == b1) - a = 384; - else if (b0 > b1) - a = maxvalue(0, a - 64); - } - else if (bin < 20) - { - if ((b0 + 256) == b1) - a = 320; - else if (b0 > b1) - a = maxvalue(0, a - 64) ; - } - else - a = maxvalue(0, a - 128); - - return a; -} diff --git a/src/dgindex/AC3Dec/bitstream.cpp b/src/dgindex/AC3Dec/bitstream.cpp deleted file mode 100644 index d0d3d40..0000000 --- a/src/dgindex/AC3Dec/bitstream.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) Aaron Holtzman - May 1999 - * - * This file is part of ac3dec, a free Dolby AC-3 stream decoder. - * - * ac3dec 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. - * - * ac3dec is distributed in the hope that 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 "ac3.h" -#include "bitstream.h" - -uint_32 bitstream_get_bh(uint_32 num_bits) -{ - uint_32 result; - - num_bits -= bits_left; - result = (current_word << (32 - bits_left)) >> (32 - bits_left); - - current_word = (*buffer_start << 24) + (*(buffer_start+1) << 16) + (*(buffer_start+2) << 8) + *(buffer_start+3); - buffer_start +=4; - - if(num_bits != 0) - result = (result << num_bits) + (current_word >> (32 - num_bits)); - - bits_left = 32 - num_bits; - - return result; -} - -void bitstream_init(uint_8 *start) -{ - // initialize the start of the buffer - buffer_start = start; - bits_left = 0; -} diff --git a/src/dgindex/AC3Dec/bitstream.h b/src/dgindex/AC3Dec/bitstream.h deleted file mode 100644 index 7b2ecf8..0000000 --- a/src/dgindex/AC3Dec/bitstream.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) Aaron Holtzman - May 1999 - * - * This file is part of ac3dec, a free Dolby AC-3 stream decoder. - * - * ac3dec 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. - * - * ac3dec is distributed in the hope that 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. - * - */ - -void bitstream_init(uint_8 *start); -uint_32 bitstream_get_bh(uint_32 num_bits); - -__forceinline static uint_32 bitstream_get(uint_32 num_bits) -{ - uint_32 result; - - if (num_bits < bits_left) - { - result = (current_word << (32 - bits_left)) >> (32 - num_bits); - bits_left -= num_bits; - return result; - } - - return bitstream_get_bh(num_bits); -} diff --git a/src/dgindex/AC3Dec/coeff.cpp b/src/dgindex/AC3Dec/coeff.cpp deleted file mode 100644 index 39f4d74..0000000 --- a/src/dgindex/AC3Dec/coeff.cpp +++ /dev/null @@ -1,311 +0,0 @@ -/* - * Copyright (C) Aaron Holtzman - May 1999 - * - * This file is part of ac3dec, a free Dolby AC-3 stream decoder. - * - * ac3dec 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. - * - * ac3dec is distributed in the hope that 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 "ac3.h" -#include "bitstream.h" - -// Lookup tables of 0.15 two's complement quantization values -static const sint_16 q_1[3] = -{ - ( -2 << 15)/3, 0,( 2 << 15)/3 -}; - -static const sint_16 q_2[5] = -{ - ( -4 << 15)/5,( -2 << 15)/5, 0, - ( 2 << 15)/5,( 4 << 15)/5 -}; - -static const sint_16 q_3[7] = -{ - ( -6 << 15)/7,( -4 << 15)/7,( -2 << 15)/7, 0, - ( 2 << 15)/7,( 4 << 15)/7,( 6 << 15)/7 -}; - -static const sint_16 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 const sint_16 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 -}; - -// Scale factors for convert_to_double -static const uint_32 u32_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 float *scale_factor = (float*)u32_scale_factors; - -// These store the persistent state of the packed mantissas -static sint_16 m_1_pointer; -static sint_16 m_2_pointer; -static sint_16 m_4_pointer; - -static sint_16 M_1[27][3]; -static sint_16 M_2[125][3]; -static sint_16 M_4[121][2]; - -// Conversion from bap to number of bits in the mantissas -static uint_16 qnttztab[16] = { 0, 0, 0, 3, 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16 }; - -static sint_16 coeff_get_mantissa(uint_16 bap, uint_16 dithflag); -static void coeff_uncouple_ch(double samples[], bsi_t *bsi, audblk_t *audblk, uint_32 ch); - -void mantissa_init() -{ - int i; - - for (i=0; i<27; i++) - { - M_1[i][0] = i / 9; - M_1[i][1] = (i % 9) / 3; - M_1[i][2] = (i % 9) % 3; - } - - for (i=0; i<125; i++) - { - M_2[i][0] = i / 25; - M_2[i][1] = (i % 25) / 5; - M_2[i][2] = (i % 25) % 5; - } - - for (i=0; i<121; i++) - { - M_4[i][0] = i / 11; - M_4[i][1] = i % 11; - } -} - -void coeff_unpack(bsi_t *bsi, audblk_t *audblk, stream_samples_t samples) -{ - uint_16 i,j; - uint_32 done_cpl = 0; - sint_16 mantissa; - - m_1_pointer = m_2_pointer = m_4_pointer = 3; - - for(i=0; infchans; i++) - { - for(j=0; jendmant[i]; j++) - { - mantissa = coeff_get_mantissa(audblk->fbw_bap[i][j], audblk->dithflag[i]); - samples[i][j] = mantissa * scale_factor[audblk->fbw_exp[i][j]]; - } - - if(audblk->cplinu && audblk->chincpl[i] && !done_cpl) - { - // ncplmant is equal to 12 * ncplsubnd - // Don't dither coupling channel until channel separation so that - // interchannel noise is uncorrelated - for(j=audblk->cplstrtmant; jcplendmant; j++) - audblk->cplmant[j] = coeff_get_mantissa(audblk->cpl_bap[j], 0); - done_cpl = 1; - } - } - - // uncouple the channel if necessary - if(audblk->cplinu) - { - for(i=0; infchans; i++) - { - if(audblk->chincpl[i]) - coeff_uncouple_ch(samples[i], bsi, audblk, i); - } - } - - if(bsi->lfeon) - { - // There are always 7 mantissas for lfe, no dither for lfe - for(j=0; j<7; j++) - { - mantissa = coeff_get_mantissa(audblk->lfe_bap[j], 0); - samples[5][j] = mantissa * scale_factor[audblk->lfe_exp[j]]; - } - } -} - -// Fetch a mantissa from the bitstream -// The mantissa returned is a signed 0.15 fixed point number -static sint_16 coeff_get_mantissa(uint_16 bap, uint_16 dithflag) -{ - sint_16 mantissa; - uint_16 group_code; - static sint_16 *m_1, *m_2, *m_4; - - switch(bap) - { - case 0: - if (dithflag) - mantissa = (uint_16)(46340.0 * rand() / RAND_MAX) - 23170; - else - mantissa = 0; - break; - - case 1: - if(m_1_pointer > 2) - { - group_code = bitstream_get(5); - - if (group_code > 26) - goto error; - - m_1 = &M_1[group_code][0]; - m_1_pointer = 0; - } - mantissa = m_1[m_1_pointer++]; - mantissa = q_1[mantissa]; - break; - - case 2: - if(m_2_pointer > 2) - { - group_code = bitstream_get(7); - - if (group_code > 124) - goto error; - - m_2 = &M_2[group_code][0]; - m_2_pointer = 0; - } - mantissa = m_2[m_2_pointer++]; - mantissa = q_2[mantissa]; - break; - - case 3: - mantissa = bitstream_get(3); - - if(mantissa > 6) - goto error; - - mantissa = q_3[mantissa]; - break; - - case 4: - if(m_4_pointer > 1) - { - group_code = bitstream_get(7); - - if (group_code > 120) - goto error; - - m_4 = &M_4[group_code][0]; - m_4_pointer = 0; - } - mantissa = m_4[m_4_pointer++]; - mantissa = q_4[mantissa]; - break; - - case 5: - mantissa = bitstream_get(4); - - if(mantissa > 14) - goto error; - - mantissa = q_5[mantissa]; - break; - - default: - mantissa = bitstream_get(qnttztab[bap]); - mantissa <<= 16 - qnttztab[bap]; - } - - return mantissa; - -error: - error_flag = 1; - return 0; -} - -// Uncouple the coupling channel into a fbw channel -static void coeff_uncouple_ch(double samples[], bsi_t *bsi,audblk_t *audblk, uint_32 ch) -{ - uint_32 bnd = 0; - uint_32 sub_bnd = 0; - uint_32 i, j; - double cpl_coord = 1.0; - uint_32 cpl_mant_tmp; - sint_16 mantissa; - - for (i=audblk->cplstrtmant; icplendmant;) - { - if (!audblk->cplbndstrc[sub_bnd++]) - { - if (audblk->cplcoexp[ch][bnd] == 15) - cpl_mant_tmp = (audblk->cplcomant[ch][bnd]) << 11; - else - cpl_mant_tmp = (16 + audblk->cplcomant[ch][bnd]) << 10; - - cpl_coord = (cpl_mant_tmp * scale_factor[audblk->cplcoexp[ch][bnd] + 3 * audblk->mstrcplco[ch]]) * 8.0; - - // Invert the phase for the right channel if necessary - if (bsi->acmod==0x2 && audblk->phsflginu && ch==1 && audblk->phsflg[bnd]) - cpl_coord = -cpl_coord; - - bnd++; - } - - for (j=0; j<12; j++) - { - // Get new dither values for each channel if necessary - if(audblk->dithflag[ch] && audblk->cpl_bap[i]==0) - mantissa = (uint_16)(46340.0 * rand() / RAND_MAX) - 23170; - else - mantissa = audblk->cplmant[i]; - - samples[i] = (mantissa * scale_factor[audblk->cpl_exp[i]]) * cpl_coord; - - i++; - } - } -} diff --git a/src/dgindex/AC3Dec/crc.cpp b/src/dgindex/AC3Dec/crc.cpp deleted file mode 100644 index 01c6d34..0000000 --- a/src/dgindex/AC3Dec/crc.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) Aaron Holtzman - May 1999 - * - * This file is part of ac3dec, a free Dolby AC-3 stream decoder. - * - * ac3dec 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. - * - * ac3dec is distributed in the hope that 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 "ac3.h" - -static const uint_16 crc_lut[256] = -{ - 0x0000,0x8005,0x800f,0x000a,0x801b,0x001e,0x0014,0x8011, - 0x8033,0x0036,0x003c,0x8039,0x0028,0x802d,0x8027,0x0022, - 0x8063,0x0066,0x006c,0x8069,0x0078,0x807d,0x8077,0x0072, - 0x0050,0x8055,0x805f,0x005a,0x804b,0x004e,0x0044,0x8041, - 0x80c3,0x00c6,0x00cc,0x80c9,0x00d8,0x80dd,0x80d7,0x00d2, - 0x00f0,0x80f5,0x80ff,0x00fa,0x80eb,0x00ee,0x00e4,0x80e1, - 0x00a0,0x80a5,0x80af,0x00aa,0x80bb,0x00be,0x00b4,0x80b1, - 0x8093,0x0096,0x009c,0x8099,0x0088,0x808d,0x8087,0x0082, - 0x8183,0x0186,0x018c,0x8189,0x0198,0x819d,0x8197,0x0192, - 0x01b0,0x81b5,0x81bf,0x01ba,0x81ab,0x01ae,0x01a4,0x81a1, - 0x01e0,0x81e5,0x81ef,0x01ea,0x81fb,0x01fe,0x01f4,0x81f1, - 0x81d3,0x01d6,0x01dc,0x81d9,0x01c8,0x81cd,0x81c7,0x01c2, - 0x0140,0x8145,0x814f,0x014a,0x815b,0x015e,0x0154,0x8151, - 0x8173,0x0176,0x017c,0x8179,0x0168,0x816d,0x8167,0x0162, - 0x8123,0x0126,0x012c,0x8129,0x0138,0x813d,0x8137,0x0132, - 0x0110,0x8115,0x811f,0x011a,0x810b,0x010e,0x0104,0x8101, - 0x8303,0x0306,0x030c,0x8309,0x0318,0x831d,0x8317,0x0312, - 0x0330,0x8335,0x833f,0x033a,0x832b,0x032e,0x0324,0x8321, - 0x0360,0x8365,0x836f,0x036a,0x837b,0x037e,0x0374,0x8371, - 0x8353,0x0356,0x035c,0x8359,0x0348,0x834d,0x8347,0x0342, - 0x03c0,0x83c5,0x83cf,0x03ca,0x83db,0x03de,0x03d4,0x83d1, - 0x83f3,0x03f6,0x03fc,0x83f9,0x03e8,0x83ed,0x83e7,0x03e2, - 0x83a3,0x03a6,0x03ac,0x83a9,0x03b8,0x83bd,0x83b7,0x03b2, - 0x0390,0x8395,0x839f,0x039a,0x838b,0x038e,0x0384,0x8381, - 0x0280,0x8285,0x828f,0x028a,0x829b,0x029e,0x0294,0x8291, - 0x82b3,0x02b6,0x02bc,0x82b9,0x02a8,0x82ad,0x82a7,0x02a2, - 0x82e3,0x02e6,0x02ec,0x82e9,0x02f8,0x82fd,0x82f7,0x02f2, - 0x02d0,0x82d5,0x82df,0x02da,0x82cb,0x02ce,0x02c4,0x82c1, - 0x8243,0x0246,0x024c,0x8249,0x0258,0x825d,0x8257,0x0252, - 0x0270,0x8275,0x827f,0x027a,0x826b,0x026e,0x0264,0x8261, - 0x0220,0x8225,0x822f,0x022a,0x823b,0x023e,0x0234,0x8231, - 0x8213,0x0216,0x021c,0x8219,0x0208,0x820d,0x8207,0x0202 -}; - -int crc_process_frame(uint_8 *data, uint_32 num_bytes) -{ - uint_16 state = 0; - uint_32 i; - - for(i=0; i>8)] ^ (state<<8); - - return state; -} diff --git a/src/dgindex/AC3Dec/decode.cpp b/src/dgindex/AC3Dec/decode.cpp deleted file mode 100644 index 550d6ba..0000000 --- a/src/dgindex/AC3Dec/decode.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (C) Aaron Holtzman - May 1999 - * - * This file is part of ac3dec, a free Dolby AC-3 stream decoder. - * - * ac3dec 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. - * - * ac3dec is distributed in the hope that 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 "../global.h" -#include "ac3.h" -#include "bitstream.h" - -void bit_allocate(uint_16 fscod, bsi_t *bsi, audblk_t *audblk); - -static audblk_t audblk; -static bsi_t bsi; -static syncinfo_t syncinfo; - -// the floating point samples for one audblk -static stream_samples_t samples; - -// the integer samples for the entire frame (with enough space for 2 ch out) -// if this size change, be sure to change the size when muting -static sint_16 s16_samples[2 * 6 * 256]; -static short *ptrAC3Dec_Buffer = (short*)AC3Dec_Buffer; - -// storage for the syncframe -#define BUFFER_MAX_SIZE 4096 -static uint_8 buffer[BUFFER_MAX_SIZE]; -static sint_32 buffer_size; - -uint_32 decode_buffer_syncframe(syncinfo_t *syncinfo, uint_8 **start, uint_8 *end) -{ - uint_8 *cur = *start; - uint_16 syncword = syncinfo->syncword; - uint_32 ret = 0; - - // find an ac3 sync frame -resync: - while(syncword != 0x0b77) - { - if(cur >= end) - goto done; - syncword = (syncword << 8) + *cur++; - } - - // need the next 3 bytes to decide how big the frame is - while(buffer_size < 3) - { - if(cur >= end) - goto done; - - buffer[buffer_size++] = *cur++; - } - - parse_syncinfo(syncinfo, buffer); - - if (syncinfo->frame_size==0) // CRITICAL CONDITION - goto done; - - while (buffer_size < (syncinfo->frame_size<<1) - 2) - { - if(cur >= end) - goto done; - - buffer[buffer_size++] = *cur++; - } - - // check the crc over the entire frame - if (crc_process_frame(buffer, (syncinfo->frame_size<<1) - 2)) - { - SetDlgItemText(hDlg, IDC_INFO, "audio error"); - - syncword = 0xffff; - buffer_size = 0; - goto resync; - } - - // if we got to this point, we found a valid ac3 frame to decode - bitstream_init(buffer); - // get rid of the syncinfo struct as we already parsed it - bitstream_get(24); - - // reset the syncword for next time - syncword = 0xffff; - buffer_size = 0; - ret = 1; - -done: - syncinfo->syncword = syncword; - *start = cur; - return ret; -} - -uint_32 ac3_decode_data(uint_8 *data_start, uint_32 length, uint_32 start) -{ - uint_8 *data_end = data_start + length; - uint_32 i, j = start; - - while (decode_buffer_syncframe(&syncinfo, &data_start, data_end)) - { - if (error_flag) - { - SetDlgItemText(hDlg, IDC_INFO, "audio error"); - ZeroMemory(s16_samples, sizeof(sint_16) * 256 * 2 * 6); - error_flag = 0; - continue; - } - - parse_bsi(&bsi); - - for (i=0; i<6; i++) - { - ZeroMemory(samples, sizeof(double) * 256 * (bsi.nfchans + bsi.lfeon)); - - parse_audblk(&bsi, &audblk); - - exponent_unpack(&bsi, &audblk); - if (error_flag) - goto error; - - bit_allocate(syncinfo.fscod, &bsi, &audblk); - - coeff_unpack(&bsi, &audblk, samples); - if (error_flag) - goto error; - - if (bsi.acmod == 0x2) - rematrix(&audblk, samples); - - imdct(&bsi, &audblk, samples); - - downmix(&audblk, &bsi, samples, &s16_samples[i * 512]); - - sanity_check(&bsi, &audblk); - if (error_flag) - goto error; - } - - memcpy(&AC3Dec_Buffer[start], s16_samples, 6144); - start += 6144; -error: - ; - } - - if (Decision_Flag || (!SRC_Flag && Norm_Flag)) - for (i=(j>>1); i<(start>>1); i++) - if (Sound_Max < abs(ptrAC3Dec_Buffer[i])) - { - Sound_Max = abs(ptrAC3Dec_Buffer[i]); - - if (Decision_Flag && Sound_Max > Norm_Ratio) - { - sprintf(szBuffer, "%.2f", 327.68 * Norm_Ratio / Sound_Max); - SetDlgItemText(hDlg, IDC_INFO, szBuffer); - } - } - - return start; -} - -void InitialAC3() -{ - int i, count; - - if (AudioOnly_Flag) - { - MessageBox(hWnd, "The \'Demux Audio Only\' feature is intended for demuxing, not decoding.\nDeselect \'Decode AC3 Track to WAV\' in Audio/Output Method.", NULL, MB_OK | MB_ICONERROR); - ThreadKill(MISC_KILL); - } - for (i = 0x80, count = 0; i < 0x88; i++) - { - if (audio[i].selected_for_demux) - count++; - } - if (count > 1) - { - MessageBox(hWnd, "Cannot decode multiple AC3 streams at the same time.\nMake sure only one track is selected.", NULL, MB_OK | MB_ICONERROR); - ThreadKill(MISC_KILL); - } - - error_flag = buffer_size = 0; - - ZeroMemory(&syncinfo, sizeof(syncinfo)); - ZeroMemory(&bsi, sizeof(bsi)); - ZeroMemory(&audblk, sizeof(audblk)); - - drc_init(); - imdct_init(); - exponent_init(); - mantissa_init(); - - srand(0); -} diff --git a/src/dgindex/AC3Dec/downmix.cpp b/src/dgindex/AC3Dec/downmix.cpp deleted file mode 100644 index 02fb798..0000000 --- a/src/dgindex/AC3Dec/downmix.cpp +++ /dev/null @@ -1,420 +0,0 @@ -/* - * Copyright (C) Aaron Holtzman - May 1999 - * - * This file is part of ac3dec, a free Dolby AC-3 stream decoder. - * - * ac3dec 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. - * - * ac3dec is distributed in the hope that 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 -#include "../global.h" -#include "ac3.h" - -static double drc[256]; -static double DRCScale[4] = { 1.0, 1.5, 2.0, 4.0 }; -static double ds_x1, ds_x2, ds_y1, ds_y2; - -__forceinline short SaturateRound(double flt) -{ - int tmp; - - __asm - { - fld [flt] - fistp [tmp] - } - - return (tmp<-32768) ? -32768 : ((tmp>32767) ? 32767 : tmp); -} - -void drc_init() -{ - int i; - - for (i=0; i<128; i++) - drc[i] = pow(DRCScale[DRC_Flag], i/32.0); - - for (i=128; i<256; i++) - drc[i] = pow(DRCScale[DRC_Flag], (i-256)/32.0); - - ds_x1 = ds_x2 = ds_y1 = ds_y2 = 0; -} - -static double cmixlev_lut[4] = { 0.2928, 0.2468, 0.2071, 0.2468 }; -static double smixlev_lut[4] = { 0.2928, 0.2071, 0.0 , 0.2071 }; - -static void downmix_3f_2r_to_2ch(double gain, bsi_t* bsi, stream_samples_t samples, sint_16 *s16_samples) -{ - uint_32 j; - double tmp, clev, slev; - double *centre = 0, *left = 0, *right = 0, *left_sur = 0, *right_sur = 0, *lfe = 0; - - left = samples[0]; - centre = samples[1]; - right = samples[2]; - left_sur = samples[3]; - right_sur = samples[4]; - - if (bsi->lfeon) - lfe = samples[5]; - - clev = cmixlev_lut[bsi->cmixlev]; - slev = smixlev_lut[bsi->surmixlev]; - - if (bsi->lfeon) - for (j = 0; j < 512; j += 2) - { - tmp = (0.4143 * (*left++ + *lfe) + clev * *centre + slev * *left_sur++) * gain; - s16_samples[j] = SaturateRound(tmp); - - tmp = (0.4143 * (*right++ + *lfe++) + clev * *centre++ + slev * *right_sur++) * gain; - s16_samples[j+1] = SaturateRound(tmp); - } - else - for (j = 0; j < 512; j += 2) - { - tmp = (0.4143 * *left++ + clev * *centre + slev * *left_sur++) * gain; - s16_samples[j] = SaturateRound(tmp); - - tmp = (0.4143 * *right++ + clev * *centre++ + slev * *right_sur++) * gain; - s16_samples[j+1] = SaturateRound(tmp); - } -} - -static void downmix_2f_2r_to_2ch(double gain, bsi_t* bsi, stream_samples_t samples, sint_16 *s16_samples) -{ - uint_32 j; - double tmp, slev; - double *left = 0, *right = 0, *left_sur = 0, *right_sur = 0; - - left = samples[0]; - right = samples[1]; - left_sur = samples[2]; - right_sur = samples[3]; - - slev = smixlev_lut[bsi->surmixlev]; - - for (j = 0; j < 512; j += 2) - { - tmp = (0.4143 * *left++ + slev * *left_sur++) * gain; - s16_samples[j] = SaturateRound(tmp); - - tmp = (0.4143 * *right++ + slev * *right_sur++) * gain; - s16_samples[j+1] = SaturateRound(tmp); - } -} - -static void downmix_3f_1r_to_2ch(double gain, bsi_t* bsi, stream_samples_t samples, sint_16 *s16_samples) -{ - uint_32 j; - double tmp, clev, slev; - double *centre = 0, *left = 0, *right = 0, *sur = 0; - - left = samples[0]; - centre = samples[1]; - right = samples[2]; - sur = samples[3]; - - clev = cmixlev_lut[bsi->cmixlev]; - slev = smixlev_lut[bsi->surmixlev]; - - for (j = 0; j < 512; j += 2) - { - tmp = (0.4143 * *left++ + clev * *centre + slev * *sur) * gain; - s16_samples[j] = SaturateRound(tmp); - - tmp = (0.4143 * *right++ + clev * *centre++ + slev * *sur++) * gain; - s16_samples[j+1] = SaturateRound(tmp); - } -} - -static void downmix_2f_1r_to_2ch(double gain, bsi_t* bsi, stream_samples_t samples, sint_16 *s16_samples) -{ - uint_32 j; - double tmp, slev; - double *left = 0, *right = 0, *sur = 0; - - left = samples[0]; - right = samples[1]; - sur = samples[2]; - - slev = smixlev_lut[bsi->surmixlev]; - - for (j = 0; j < 512; j += 2) - { - tmp = (0.4143 * *left++ + slev * *sur) * gain; - s16_samples[j] = SaturateRound(tmp); - - tmp = (0.4143 * *right++ + slev * *sur++) * gain; - s16_samples[j+1] = SaturateRound(tmp); - } -} - -static void downmix_3f_0r_to_2ch(double gain, bsi_t* bsi, stream_samples_t samples, sint_16 *s16_samples) -{ - uint_32 j; - double tmp, clev; - double *centre = 0, *left = 0, *right = 0; - - left = samples[0]; - centre = samples[1]; - right = samples[2]; - - clev = cmixlev_lut[bsi->cmixlev]; - - for (j = 0; j < 512; j += 2) - { - tmp = (0.4143 * *left++ + clev * *centre) * gain; - s16_samples[j] = SaturateRound(tmp); - - tmp = (0.4143 * *right++ + clev * *centre++) * gain; - s16_samples[j+1] = SaturateRound(tmp); - } -} - -static void downmix_2f_0r_to_2ch(double gain, stream_samples_t samples, sint_16 *s16_samples) -{ - uint_32 j; - double tmp; - double *left = 0, *right = 0; - - left = samples[0]; - right = samples[1]; - - for (j = 0; j < 512; j += 2) - { - tmp = *left++ * gain; - s16_samples[j] = SaturateRound(tmp); - - tmp = *right++ * gain; - s16_samples[j+1] = SaturateRound(tmp); - } -} - -static void downmix_1f_0r_to_2ch(double gain, double *centre, sint_16 *s16_samples) -{ - uint_32 j; - double tmp; - - for (j = 0; j < 512; j += 2) - { - tmp = 0.7071 * *centre++ * gain; - - s16_samples[j] = SaturateRound(tmp); - s16_samples[j+1] = SaturateRound(tmp); - } -} - -static void downmix_3f_2r_to_2ch_dolby(double gain, bsi_t* bsi, stream_samples_t samples, sint_16 *s16_samples) -{ - uint_32 j; - double tmp, ds_sur; - double *centre = 0, *left = 0, *right = 0, *left_sur = 0, *right_sur = 0, *lfe = 0; - - left = samples[0]; - centre = samples[1]; - right = samples[2]; - left_sur = samples[3]; - right_sur = samples[4]; - - if (bsi->lfeon) - { - lfe = samples[5]; - - for (j = 0; j < 512; j += 2) - { - ds_sur = (ds_x2 + ds_x1 * 2.0 + *left_sur + *right_sur) * 0.12531781 + - ds_y1 * 0.77997062 - ds_y2 * 0.28124186; - - ds_x2 = ds_x1; - ds_x1 = *left_sur++ + *right_sur++; - ds_y2 = ds_y1; - ds_y1 = ds_sur; - - tmp = (0.3204 * (*left++ + *lfe) + 0.2265 * (*centre - ds_sur)) * gain; - s16_samples[j] = SaturateRound(tmp); - - tmp = (0.3204 * (*right++ + *lfe++) + 0.2265 * (*centre++ + ds_sur)) * gain; - s16_samples[j+1] = SaturateRound(tmp); - } - } - else - { - for (j = 0; j < 512; j += 2) - { - ds_sur = (ds_x2 + ds_x1 * 2.0 + *left_sur + *right_sur) * 0.12531781 + - ds_y1 * 0.77997062 - ds_y2 * 0.28124186; - - ds_x2 = ds_x1; - ds_x1 = *left_sur++ + *right_sur++; - ds_y2 = ds_y1; - ds_y1 = ds_sur; - - tmp = (0.3204 * *left++ + 0.2265 * (*centre - ds_sur)) * gain; - s16_samples[j] = SaturateRound(tmp); - - tmp = (0.3204 * *right++ + 0.2265 * (*centre++ + ds_sur)) * gain; - s16_samples[j+1] = SaturateRound(tmp); - } - } -} - -static void downmix_2f_2r_to_2ch_dolby(double gain, stream_samples_t samples, sint_16 *s16_samples) -{ - uint_32 j; - double tmp, ds_sur; - double *left = 0, *right = 0, *left_sur = 0, *right_sur = 0; - - left = samples[0]; - right = samples[1]; - left_sur = samples[2]; - right_sur = samples[3]; - - for (j = 0; j < 512; j += 2) - { - ds_sur = (ds_x2 + ds_x1 * 2.0 + *left_sur + *right_sur) * 0.12531781 + - ds_y1 * 0.77997062 - ds_y2 * 0.28124186; - - ds_x2 = ds_x1; - ds_x1 = *left_sur++ + *right_sur++; - ds_y2 = ds_y1; - ds_y1 = ds_sur; - - tmp = (0.4143 * *left++ - 0.2928 * ds_sur) * gain; - s16_samples[j] = SaturateRound(tmp); - - tmp = (0.4143 * *right++ + 0.2928 * ds_sur) * gain; - s16_samples[j+1] = SaturateRound(tmp); - } -} - -static void downmix_3f_1r_to_2ch_dolby(double gain, stream_samples_t samples, sint_16 *s16_samples) -{ - uint_32 j; - double tmp, ds_sur; - double *centre = 0, *left = 0, *right = 0, *sur = 0; - - left = samples[0]; - centre = samples[1]; - right = samples[2]; - sur = samples[3]; - - for (j = 0; j < 512; j += 2) - { - ds_sur = (ds_x2 + ds_x1 * 2.0 + *sur) * 0.12531781 + - ds_y1 * 0.77997062 - ds_y2 * 0.28124186; - - ds_x2 = ds_x1; - ds_x1 = *sur++; - ds_y2 = ds_y1; - ds_y1 = ds_sur; - - tmp = (0.4143 * *left++ + 0.2928 * (*centre - ds_sur)) * gain; - s16_samples[j] = SaturateRound(tmp); - - tmp = (0.4143 * *right++ + 0.2928 * (*centre++ + ds_sur)) * gain; - s16_samples[j+1] = SaturateRound(tmp); - } -} - -static void downmix_2f_1r_to_2ch_dolby(double gain, stream_samples_t samples, sint_16 *s16_samples) -{ - uint_32 j; - double tmp, ds_sur; - double *left = 0, *right = 0, *sur = 0; - - left = samples[0]; - right = samples[1]; - sur = samples[2]; - - for (j = 0; j < 512; j += 2) - { - ds_sur = (ds_x2 + ds_x1 * 2.0 + *sur) * 0.12531781 + - ds_y1 * 0.77997062 - ds_y2 * 0.28124186; - - ds_x2 = ds_x1; - ds_x1 = *sur++; - ds_y2 = ds_y1; - ds_y1 = ds_sur; - - tmp = (0.5857 * *left++ - 0.4143 * ds_sur) * gain; - s16_samples[j] = SaturateRound(tmp); - - tmp = (0.5857 * *right++ + 0.4143 * ds_sur) * gain; - s16_samples[j+1] = SaturateRound(tmp); - } -} - -void downmix(audblk_t *audblk, bsi_t* bsi, stream_samples_t samples, sint_16 *s16_samples) -{ - double gain; - - if (DRC_Flag>2) - gain = 32768.0 * drc[bsi->compr] * PreScale_Ratio; - else - gain = 32768.0 * drc[audblk->dynrng] * PreScale_Ratio; - - switch (bsi->acmod) - { - // 3/2 - case 7: - if (DSDown_Flag) - downmix_3f_2r_to_2ch_dolby(gain, bsi, samples, s16_samples); - else - downmix_3f_2r_to_2ch(gain, bsi, samples, s16_samples); - break; - - // 2/2 - case 6: - if (DSDown_Flag) - downmix_2f_2r_to_2ch_dolby(gain, samples, s16_samples); - else - downmix_2f_2r_to_2ch(gain, bsi, samples, s16_samples); - break; - - // 3/1 - case 5: - if (DSDown_Flag) - downmix_3f_1r_to_2ch_dolby(gain, samples, s16_samples); - else - downmix_3f_1r_to_2ch(gain, bsi, samples, s16_samples); - break; - - // 2/1 - case 4: - if (DSDown_Flag) - downmix_2f_1r_to_2ch_dolby(gain, samples, s16_samples); - else - downmix_2f_1r_to_2ch(gain, bsi, samples, s16_samples); - break; - - // 3/0 - case 3: - downmix_3f_0r_to_2ch(gain, bsi, samples, s16_samples); - break; - - // 2/0 - case 2: - downmix_2f_0r_to_2ch(gain, samples, s16_samples); - break; - - // 1/0, 1+1, discard dynrng2 :p - case 1: - case 0: - downmix_1f_0r_to_2ch(gain, samples[0], s16_samples); - break; - } -} diff --git a/src/dgindex/AC3Dec/exponent.cpp b/src/dgindex/AC3Dec/exponent.cpp deleted file mode 100644 index 33b1639..0000000 --- a/src/dgindex/AC3Dec/exponent.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) Aaron Holtzman - May 1999 - * - * This file is part of ac3dec, a free Dolby AC-3 stream decoder. - * - * ac3dec 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. - * - * ac3dec is distributed in the hope that 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 "ac3.h" - -static sint_16 EXPT[125][3]; - -static void exp_unpack_ch(uint_16 type,uint_16 expstr,uint_16 ngrps,uint_16 initial_exp, uint_16 exps[], uint_16 *dest); - -void exponent_init() -{ - int i; - - for (i=0; i<125; i++) - { - EXPT[i][0] = i / 25; - EXPT[i][1] = (i - EXPT[i][0] * 25) / 5; - EXPT[i][2] = i - EXPT[i][0] * 25 - EXPT[i][1] * 5; - EXPT[i][0] -= 2; - EXPT[i][1] -= 2; - EXPT[i][2] -= 2; - } -} - -void exponent_unpack( bsi_t *bsi, audblk_t *audblk) -{ - uint_16 i; - - for(i=0; i< bsi->nfchans; i++) - 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) - exp_unpack_ch(UNPACK_CPL, audblk->cplexpstr, audblk->ncplgrps, audblk->cplabsexp << 1, - audblk->cplexps, &audblk->cpl_exp[audblk->cplstrtmant]); - - if(bsi->lfeon) - exp_unpack_ch(UNPACK_LFE, audblk->lfeexpstr, 2, audblk->lfeexps[0], - &audblk->lfeexps[1], audblk->lfe_exp); -} - - -static void exp_unpack_ch(uint_16 type,uint_16 expstr,uint_16 ngrps,uint_16 initial_exp, - uint_16 exps[], uint_16 *dest) -{ - uint_16 i,j; - sint_16 exp_acc; - - if(expstr == EXP_REUSE) - return; - - /* Handle the initial absolute exponent */ - exp_acc = initial_exp; - j = 0; - - /* In the case of a fbw channel then the initial absolute values 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 124) - { - error_flag = 1; - return; - } - - exp_acc += EXPT[exps[i]][0]; - - switch (expstr) - { - case EXP_D45: - dest[j++] = exp_acc; - dest[j++] = exp_acc; - case EXP_D25: - dest[j++] = exp_acc; - case EXP_D15: - dest[j++] = exp_acc; - } - - exp_acc += EXPT[exps[i]][1]; - - switch (expstr) - { - case EXP_D45: - dest[j++] = exp_acc; - dest[j++] = exp_acc; - case EXP_D25: - dest[j++] = exp_acc; - case EXP_D15: - dest[j++] = exp_acc; - } - - exp_acc += EXPT[exps[i]][2]; - - switch (expstr) - { - case EXP_D45: - dest[j++] = exp_acc; - dest[j++] = exp_acc; - case EXP_D25: - dest[j++] = exp_acc; - case EXP_D15: - dest[j++] = exp_acc; - } - } -} diff --git a/src/dgindex/AC3Dec/imdct.cpp b/src/dgindex/AC3Dec/imdct.cpp deleted file mode 100644 index 088a22e..0000000 --- a/src/dgindex/AC3Dec/imdct.cpp +++ /dev/null @@ -1,414 +0,0 @@ -/* - * Copyright (C) Aaron Holtzman - May 1999 - * - * This file is part of ac3dec, a free Dolby AC-3 stream decoder. - * - * ac3dec 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. - * - * ac3dec is distributed in the hope that 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 -#include "ac3.h" - -#define M_PI 3.1415926535897932384626433832795 -#define N 512 - -void imdct_do_256(double data[], double delay[]); -void imdct_do_512(double data[], double delay[]); - -typedef struct complex_s -{ - double real; - double imag; -} complex_t; - -static uint_8 bit_reverse_512[128] = { - 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 uint_8 bit_reverse_256[64] = { - 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}; - -static complex_t buf[128]; - -/* Twiddle factor LUT */ -static complex_t *w[7]; -static complex_t w_1[1]; -static complex_t w_2[2]; -static complex_t w_4[4]; -static complex_t w_8[8]; -static complex_t w_16[16]; -static complex_t w_32[32]; -static complex_t w_64[64]; - -/* Twiddle factors for IMDCT */ -static double xcos1[128]; -static double xsin1[128]; -static double xcos2[64]; -static double xsin2[64]; - -/* Delay buffer for time domain interleaving */ -static double delay[6][256]; - -/* Windowing function for Modified DCT */ -static double 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 }; - -static complex_t cmplx_mult(complex_t a, complex_t b) -{ - 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; -} - -void imdct_init() -{ - int i, k; - complex_t angle_step; - complex_t current_angle; - - /* Twiddle factors to turn IFFT into IMDCT */ - for(i=0; i<128; i++) - { - xcos1[i] = cos(2.0 * M_PI * (8*i+1)/(8*N)); - xsin1[i] = sin(2.0 * M_PI * (8*i+1)/(8*N)); - } - - /* More twiddle factors to turn IFFT into IMDCT */ - for(i=0; i<64; i++) - { - xcos2[i] = cos(2.0 * M_PI * (8*i+1)/(4*N)); - xsin2[i] = sin(2.0 * M_PI * (8*i+1)/(4*N)); - } - - /* Canonical twiddle factors for FFT */ - w[0] = w_1; - w[1] = w_2; - w[2] = w_4; - w[3] = w_8; - w[4] = w_16; - w[5] = w_32; - w[6] = w_64; - - for( i = 0; i < 7; i++) - { - angle_step.real = cos(-2.0 * M_PI / (1 << (i+1))); - angle_step.imag = sin(-2.0 * M_PI / (1 << (i+1))); - - current_angle.real = 1.0; - current_angle.imag = 0.0; - - for (k = 0; k < 1 << i; k++) - { - w[i][k] = current_angle; - current_angle = cmplx_mult(current_angle, angle_step); - } - } - - ZeroMemory(&delay, sizeof(delay)); -} - -void imdct_do_512(double data[], double delay[]) -{ - int i, k; - int p, q; - int m; - int two_m; - int two_m_plus_one; - - double tmp_a_i, tmp_a_r, tmp_b_i, tmp_b_r; - double *data_ptr, *delay_ptr, *window_ptr; - - // Pre IFFT complex multiply plus IFFT cmplx conjugate and bit reverse permutation - for(i=0; i < 128; i++) - { - k = bit_reverse_512[i]; - - /* z[i] = (X[256-2*i-1] + j * X[2*i]) * (xcos1[i] + j * xsin1[i]) ; */ - buf[k].real = data[255 - (i<<1)] * xcos1[i] - data[i<<1] * xsin1[i]; - buf[k].imag = - data[i<<1] * xcos1[i] - data[255 - (i<<1)] * xsin1[i]; - } - - // FFT Merge - for (m=0; m<7; m++) - { - if (m) - two_m = 1<nfchans; i++) - { - if(audblk->blksw[i]) - imdct_do_256(samples[i], delay[i]); - else - imdct_do_512(samples[i], delay[i]); - } - - if (bsi->lfeon) - imdct_do_512(samples[5], delay[5]); -} diff --git a/src/dgindex/AC3Dec/parse.cpp b/src/dgindex/AC3Dec/parse.cpp deleted file mode 100644 index 38ff64b..0000000 --- a/src/dgindex/AC3Dec/parse.cpp +++ /dev/null @@ -1,532 +0,0 @@ -/* - * Copyright (C) Aaron Holtzman - May 1999 - * - * This file is part of ac3dec, a free Dolby AC-3 stream decoder. - * - * ac3dec 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. - * - * ac3dec is distributed in the hope that 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 "ac3.h" -#include "bitstream.h" - -/* Misc LUT */ -static const uint_16 nfchans[8] = {2,1,2,3,3,4,4,5}; - -struct frmsize_s -{ - uint_16 bit_rate; - uint_16 frm_size[3]; -}; - -static const struct frmsize_s frmsizecod_tbl[64] = -{ - { 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 } } -}; - -/* Parse a syncinfo structure, minus the sync word */ -void parse_syncinfo(syncinfo_t *syncinfo,uint_8 *data) -{ - // - // We need to read in the entire syncinfo struct (0x0b77 + 24 bits) - // in order to determine how big the frame is - // - - // Get the sampling rate - syncinfo->fscod = (data[2] >> 6) & 0x03; - - switch (syncinfo->fscod) - { - case 0: - syncinfo->sampling_rate = 48000; - break; - - case 1: - syncinfo->sampling_rate = 44100; - break; - - case 2: - syncinfo->sampling_rate = 32000; - break; - - default: - error_flag = 1; - return; - } - - // Get the frame size code - syncinfo->frmsizecod = data[2] & 0x3f; - - // Calculate the frame size and bitrate - syncinfo->frame_size = frmsizecod_tbl[syncinfo->frmsizecod].frm_size[syncinfo->fscod]; - syncinfo->bit_rate = frmsizecod_tbl[syncinfo->frmsizecod].bit_rate; -} - -/* - * This routine fills a bsi struct from the AC3 stream - */ - -void parse_bsi(bsi_t *bsi) -{ - sint_32 i; - - /* Check the AC-3 version number */ - bsi->bsid = bitstream_get(5); - - /* Get the audio service provided by the steram */ - bsi->bsmod = bitstream_get(3); - - /* Get the audio coding mode (ie how many channels)*/ - bsi->acmod = bitstream_get(3); - /* Predecode the number of full bandwidth channels as we use this - * number a lot */ - bsi->nfchans = nfchans[bsi->acmod]; - - /* If it is in use, get the centre channel mix level */ - if ((bsi->acmod & 0x1) && bsi->acmod!=0x1) - bsi->cmixlev = bitstream_get(2); - - /* If it is in use, get the surround channel mix level */ - if (bsi->acmod & 0x4) - bsi->surmixlev = bitstream_get(2); - - /* Get the dolby surround mode if in 2/0 mode */ - if(bsi->acmod == 0x2) - bsi->dsurmod= bitstream_get(2); - - /* Is the low frequency effects channel on? */ - bsi->lfeon = bitstream_get(1); - - /* Get the dialogue normalization level */ - bsi->dialnorm = bitstream_get(5); - - /* Does compression gain exist? */ - bsi->compre = bitstream_get(1); - if (bsi->compre) - { - /* Get compression gain */ - bsi->compr = bitstream_get(8); - } - - /* Does language code exist? */ - bsi->langcode = bitstream_get(1); - if (bsi->langcode) - { - /* Get langauge code */ - bsi->langcod = bitstream_get(8); - } - - /* Does audio production info exist? */ - bsi->audprodie = bitstream_get(1); - if (bsi->audprodie) - { - /* Get mix level */ - bsi->mixlevel = bitstream_get(5); - - /* Get room type */ - bsi->roomtyp = bitstream_get(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 = bitstream_get(5); - - /* Does compression gain two exist? */ - bsi->compr2e = bitstream_get(1); - if (bsi->compr2e) - { - /* Get compression gain two */ - bsi->compr2 = bitstream_get(8); - } - - /* Does language code two exist? */ - bsi->langcod2e = bitstream_get(1); - if (bsi->langcod2e) - { - /* Get langauge code two */ - bsi->langcod2 = bitstream_get(8); - } - - /* Does audio production info two exist? */ - bsi->audprodi2e = bitstream_get(1); - if (bsi->audprodi2e) - { - /* Get mix level two */ - bsi->mixlevel2 = bitstream_get(5); - - /* Get room type two */ - bsi->roomtyp2 = bitstream_get(2); - } - } - - /* Get the copyright bit */ - bsi->copyrightb = bitstream_get(1); - - /* Get the original bit */ - bsi->origbs = bitstream_get(1); - - /* Does timecode one exist? */ - bsi->timecod1e = bitstream_get(1); - - if(bsi->timecod1e) - bsi->timecod1 = bitstream_get(14); - - /* Does timecode two exist? */ - bsi->timecod2e = bitstream_get(1); - - if(bsi->timecod2e) - bsi->timecod2 = bitstream_get(14); - - /* Does addition info exist? */ - bsi->addbsie = bitstream_get(1); - - if(bsi->addbsie) - { - /* Get how much info is there */ - bsi->addbsil = bitstream_get(6); - - /* Get the additional info */ - for(i=0; i<(bsi->addbsil+1); i++) - bsi->addbsi[i] = bitstream_get(8); - } -} - -/* More pain inducing parsing */ -void parse_audblk(bsi_t *bsi,audblk_t *audblk) -{ - int i,j; - - for (i=0; infchans; i++) - { - /* Is this channel an interleaved 256 + 256 block ? */ - audblk->blksw[i] = bitstream_get(1); - } - - for (i=0; infchans; i++) - { - /* Should we dither this channel? */ - audblk->dithflag[i] = bitstream_get(1); - } - - /* Does dynamic range control exist? */ - audblk->dynrnge = bitstream_get(1); - if (audblk->dynrnge) - { - /* Get dynamic range info */ - audblk->dynrng = bitstream_get(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 = bitstream_get(1); - if (audblk->dynrng2e) - { - /* Get dynamic range info */ - audblk->dynrng2 = bitstream_get(8); - } - } - - /* Does coupling strategy exist? */ - audblk->cplstre = bitstream_get(1); - if (audblk->cplstre) - { - /* Is coupling turned on? */ - audblk->cplinu = bitstream_get(1); - if(audblk->cplinu) - { - for(i=0;i < bsi->nfchans; i++) - audblk->chincpl[i] = bitstream_get(1); - if(bsi->acmod == 0x2) - audblk->phsflginu = bitstream_get(1); - audblk->cplbegf = bitstream_get(4); - audblk->cplendf = bitstream_get(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; incplsubnd; i++) - { - audblk->cplbndstrc[i] = bitstream_get(1); - audblk->ncplbnd -= audblk->cplbndstrc[i]; - } - } - } - - if(audblk->cplinu) - { - /* Loop through all the channels and get their coupling co-ords */ - for(i=0; infchans;i++) - { - if(!audblk->chincpl[i]) - continue; - - /* Is there new coupling co-ordinate info? */ - audblk->cplcoe[i] = bitstream_get(1); - - if(audblk->cplcoe[i]) - { - audblk->mstrcplco[i] = bitstream_get(2); - for(j=0;j < audblk->ncplbnd; j++) - { - audblk->cplcoexp[i][j] = bitstream_get(4); - audblk->cplcomant[i][j] = bitstream_get(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] = bitstream_get(1); - } - } - - /* If we're in dual mono mode, there may be a rematrix strategy */ - if(bsi->acmod == 0x2) - { - audblk->rematstr = bitstream_get(1); - if(audblk->rematstr) - { - if (audblk->cplinu == 0) - { - for(i = 0; i < 4; i++) - audblk->rematflg[i] = bitstream_get(1); - } - if(audblk->cplbegf>2 && audblk->cplinu) - { - for(i = 0; i < 4; i++) - audblk->rematflg[i] = bitstream_get(1); - } - if(audblk->cplbegf<=2 && audblk->cplinu) - { - for(i = 0; i < 3; i++) - audblk->rematflg[i] = bitstream_get(1); - } - if(audblk->cplbegf==0 && audblk->cplinu) - for(i = 0; i < 2; i++) - audblk->rematflg[i] = bitstream_get(1); - } - } - - if (audblk->cplinu) - { - /* Get the coupling channel exponent strategy */ - audblk->cplexpstr = bitstream_get(2); - audblk->ncplgrps = (audblk->cplendmant - audblk->cplstrtmant) / - (3 << (audblk->cplexpstr-1)); - } - - for(i = 0; i < bsi->nfchans; i++) - audblk->chexpstr[i] = bitstream_get(2); - - /* Get the exponent strategy for lfe channel */ - if(bsi->lfeon) - audblk->lfeexpstr = bitstream_get(1); - - /* Determine the bandwidths of all the fbw channels */ - for(i = 0; i < bsi->nfchans; i++) - { - uint_16 grp_size; - - if(audblk->chexpstr[i] != EXP_REUSE) - { - if (audblk->cplinu && audblk->chincpl[i]) - { - audblk->endmant[i] = audblk->cplstrtmant; - } - else - { - audblk->chbwcod[i] = bitstream_get(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!=EXP_REUSE) - { - audblk->cplabsexp = bitstream_get(4); - for(i=0;i< audblk->ncplgrps;i++) - audblk->cplexps[i] = bitstream_get(7); - } - - /* Get the fwb channel exponents */ - for(i=0;i < bsi->nfchans; i++) - { - if(audblk->chexpstr[i] != EXP_REUSE) - { - audblk->exps[i][0] = bitstream_get(4); - for(j=1;j<=audblk->nchgrps[i];j++) - audblk->exps[i][j] = bitstream_get(7); - audblk->gainrng[i] = bitstream_get(2); - } - } - - /* Get the lfe channel exponents */ - if(bsi->lfeon && audblk->lfeexpstr!=EXP_REUSE) - { - audblk->lfeexps[0] = bitstream_get(4); - audblk->lfeexps[1] = bitstream_get(7); - audblk->lfeexps[2] = bitstream_get(7); - } - - /* Get the parametric bit allocation parameters */ - audblk->baie = bitstream_get(1); - - if(audblk->baie) - { - audblk->sdcycod = bitstream_get(2); - audblk->fdcycod = bitstream_get(2); - audblk->sgaincod = bitstream_get(2); - audblk->dbpbcod = bitstream_get(2); - audblk->floorcod = bitstream_get(3); - } - - /* Get the SNR off set info if it exists */ - audblk->snroffste = bitstream_get(1); - - if(audblk->snroffste) - { - audblk->csnroffst = bitstream_get(6); - - if(audblk->cplinu) - { - audblk->cplfsnroffst = bitstream_get(4); - audblk->cplfgaincod = bitstream_get(3); - } - - for(i=0; infchans; i++) - { - audblk->fsnroffst[i] = bitstream_get(4); - audblk->fgaincod[i] = bitstream_get(3); - } - if(bsi->lfeon) - { - audblk->lfefsnroffst = bitstream_get(4); - audblk->lfefgaincod = bitstream_get(3); - } - } - - /* Get coupling leakage info if it exists */ - if(audblk->cplinu) - { - audblk->cplleake = bitstream_get(1); - - if(audblk->cplleake) - { - audblk->cplfleak = bitstream_get(3); - audblk->cplsleak = bitstream_get(3); - } - } - - /* Get the delta bit alloaction info */ - audblk->deltbaie = bitstream_get(1); - - if(audblk->deltbaie) - { - if(audblk->cplinu) - audblk->cpldeltbae = bitstream_get(2); - - for(i = 0;i < bsi->nfchans; i++) - audblk->deltbae[i] = bitstream_get(2); - - if (audblk->cplinu && audblk->cpldeltbae==DELTA_BIT_NEW) - { - audblk->cpldeltnseg = bitstream_get(3); - for(i = 0;i < audblk->cpldeltnseg + 1; i++) - { - audblk->cpldeltoffst[i] = bitstream_get(5); - audblk->cpldeltlen[i] = bitstream_get(4); - audblk->cpldeltba[i] = bitstream_get(3); - } - } - - for(i = 0;i < bsi->nfchans; i++) - { - if (audblk->deltbae[i] == DELTA_BIT_NEW) - { - audblk->deltnseg[i] = bitstream_get(3); - for(j = 0; j < audblk->deltnseg[i] + 1; j++) - { - audblk->deltoffst[i][j] = bitstream_get(5); - audblk->deltlen[i][j] = bitstream_get(4); - audblk->deltba[i][j] = bitstream_get(3); - } - } - } - } - - /* Check to see if there's any dummy info to get */ - if((audblk->skiple = bitstream_get(1))) - { - uint_16 skip_data; - - audblk->skipl = bitstream_get(9); - - for(i = 0; i < audblk->skipl ; i++) - skip_data = bitstream_get(8); - } -} diff --git a/src/dgindex/AC3Dec/rematrix.cpp b/src/dgindex/AC3Dec/rematrix.cpp deleted file mode 100644 index 25b95f7..0000000 --- a/src/dgindex/AC3Dec/rematrix.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) Aaron Holtzman - May 1999 - * - * This file is part of ac3dec, a free Dolby AC-3 stream decoder. - * - * ac3dec 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. - * - * ac3dec is distributed in the hope that 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 "ac3.h" - -struct rematrix_band_s -{ - uint_32 start; - uint_32 end; -}; - -static struct rematrix_band_s rematrix_band[] = {{13,24}, {25,36}, {37,60}, {61,252}}; - -/* This routine simply does stereo rematixing for the 2 channel stereo mode */ -void rematrix(audblk_t *audblk, stream_samples_t samples) -{ - uint_32 num_bands; - uint_32 start; - uint_32 end; - uint_32 i, j; - double 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; irematflg[i]) - continue; - - start = rematrix_band[i].start; - - if (i==num_bands-1 && audblk->cplinu) - end = 12 * audblk->cplbegf + 36; - else - end = rematrix_band[i].end; - - 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; - } - } -} diff --git a/src/dgindex/AC3Dec/sanity_check.cpp b/src/dgindex/AC3Dec/sanity_check.cpp deleted file mode 100644 index 42ab042..0000000 --- a/src/dgindex/AC3Dec/sanity_check.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) Aaron Holtzman - May 1999 - * - * This file is part of ac3dec, a free Dolby AC-3 stream decoder. - * - * ac3dec 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. - * - * ac3dec is distributed in the hope that 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 "ac3.h" - -void sanity_check(bsi_t *bsi, audblk_t *audblk) -{ - int i; - - for(i=0; i<5 ; i++) - { - if (audblk->fbw_exp[i][255] !=0 || audblk->fbw_exp[i][254] !=0 || audblk->fbw_exp[i][253] !=0) - error_flag = 1; - - if (audblk->fbw_bap[i][255] !=0 || audblk->fbw_bap[i][254] !=0 || audblk->fbw_bap[i][253] !=0) - error_flag = 1; - } - - if (audblk->cpl_exp[255] !=0 || audblk->cpl_exp[254] !=0 || audblk->cpl_exp[253] !=0) - error_flag = 1; - - if (audblk->cpl_bap[255] !=0 || audblk->cpl_bap[254] !=0 || audblk->cpl_bap[253] !=0) - error_flag = 1; - - if (audblk->cplmant[255] !=0 || audblk->cplmant[254] !=0 || audblk->cplmant[253] !=0) - error_flag = 1; - - for(i=0; i < bsi->nfchans; i++) - if(audblk->chincpl[i]==0 && audblk->chbwcod[i]>60) - error_flag = 1; -} diff --git a/src/dgindex/COPYING.txt b/src/dgindex/COPYING.txt deleted file mode 100644 index bee9f8d..0000000 --- a/src/dgindex/COPYING.txt +++ /dev/null @@ -1,340 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/src/dgindex/d2vparse.cpp b/src/dgindex/d2vparse.cpp deleted file mode 100644 index 28b4ee8..0000000 --- a/src/dgindex/d2vparse.cpp +++ /dev/null @@ -1,525 +0,0 @@ -// ParseD2V by Donald A. Graft -// Released under the Gnu Public Licence (GPL) - -#include -#include -#include -#include "global.h" - -int parse_d2v(HWND hWnd, char *szInput) -{ - FILE *fp, *wfp; - char line[2048], *p; - int i, fill, val, prev_val = -1, ndx = 0, count = 0, fdom = -1; - int D2Vformat = 0; - int vob, cell; - unsigned int gop_field, field_operation, frame_rate, hour, min; - double sec; - char render[128], temp[20]; - int type; - - // Open the D2V file to be parsed. - fp = fopen(szInput, "r"); - if (fp == 0) - { - MessageBox(hWnd, "Cannot open the D2V file!", NULL, MB_OK | MB_ICONERROR); - return 0; - } - // Mutate the file name to the output text file to receive the parsed data. - p = &szInput[strlen(szInput)]; - while (*p != '.') p--; - p[1] = 0; - strcat(p, "parse.txt"); - // Open the output file. - wfp = fopen(szInput, "w"); - if (wfp == 0) - { - MessageBox(hWnd, "Cannot create the parse output file!", NULL, MB_OK | MB_ICONERROR); - return 0; - } - - fprintf(wfp, "D2V Parse Output\n\n"); - // Pick up the D2V format number - fgets(line, 2048, fp); - if (strncmp(line, "DGIndexProjectFile", 18) != 0) - { - MessageBox(hWnd, "The file is not a DGIndex project file!", NULL, MB_OK | MB_ICONERROR); - fclose(fp); - fclose(wfp); - return 0; - } - sscanf(line, "DGIndexProjectFile%d", &D2Vformat); - if (D2Vformat != D2V_FILE_VERSION) - { - MessageBox(hWnd, "Obsolete D2V file.\nRecreate it with this version of DGIndex.", NULL, MB_OK | MB_ICONERROR); - fclose(fp); - fclose(wfp); - return 0; - } - fprintf(wfp, "Encoded Frame: Display Frames....Flags Byte (* means in 3:2 pattern)\n"); - fprintf(wfp, "--------------------------------------------------------------------\n\n"); - // Get the field operation flag. - while (fgets(line, 2048, fp) != 0) - { - if (strncmp(line, "Field_Operation", 8) == 0) break; - } - sscanf(line, "Field_Operation=%d", &field_operation); - if (field_operation == 1) - fprintf(wfp, "[Forced Film, ignoring flags]\n"); - else if (field_operation == 2) - fprintf(wfp, "[Raw Frames, ignoring flags]\n"); - else - fprintf(wfp, "[Field Operation None, using flags]\n"); - // Get framerate. - fgets(line, 2048, fp); - sscanf(line, "Frame_Rate=%d", &frame_rate); - // Skip past the rest of the D2V header info to the data lines. - while (fgets(line, 2048, fp) != 0) - { - if (strncmp(line, "Location", 8) == 0) break; - } - while (fgets(line, 2048, fp) != 0) - { - if (line[0] != '\n') break; - } - // Process the data lines. - do - { - // Skip to the TFF/RFF flags entries. - p = line; - sscanf(p, "%x", &gop_field); - if (gop_field & 0x100) - { - if (gop_field & 0x400) - fprintf(wfp, "[GOP: closed]\n"); - else - fprintf(wfp, "[GOP: open]\n"); - } - while (*p++ != ' '); - while (*p++ != ' '); - while (*p++ != ' '); - while (*p++ != ' '); - while (*p++ != ' '); - sscanf(p, "%d", &vob); - while (*p++ != ' '); - sscanf(p, "%d", &cell); - while (*p++ != ' '); - // Process the flags entries. - while ((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f')) - { - sscanf(p, "%x", &val); - if (val == 0xff) - { - fprintf(wfp, "[EOF]\n"); - break; - } - // Pick up the frame type. - type = (val & 0x30) >> 4; - sprintf(temp, "%d [%s]", ndx, type == 1 ? "I" : (type == 2 ? "P" : "B")); - // Isolate the TFF/RFF bits. - val &= 0x3; - // Determine field dominance. - if (fdom == -1) - { - fdom = (val >> 1) & 1; - fprintf(wfp, "[Clip is %s]\n", fdom ? "TFF" : "BFF"); - } - - // Show encoded-to-display mapping. - if (field_operation == 0) - { - if ((count % 2) && (val == 1 || val == 3)) - { - sprintf(render, "%s: %d,%d,%d", temp, ndx + count/2, ndx + count/2 + 1, ndx + count/2 + 1); - } - else if ((count % 2) && !(val == 1 || val == 3)) - { - sprintf(render, "%s: %d,%d", temp, ndx + count/2, ndx + count/2 + 1); - } - else if (!(count % 2) && (val == 1 || val == 3)) - { - sprintf(render, "%s: %d,%d,%d", temp, ndx + count/2, ndx + count/2, ndx + count/2 + 1); - } - else if (!(count % 2) && !(val == 1 || val == 3)) - { - sprintf(render, "%s: %d,%d", temp, ndx + count/2, ndx + count/2); - } - fill = 32 - strlen(render); - for (i = 0; i < fill; i++) strcat(render, "."); - sprintf(temp, "%x", val); - fprintf(wfp, "%s%s", render, temp); - } - else - { - sprintf(render, "%s: %d,%d", temp, ndx, ndx); - fill = 32 - strlen(render); - for (i = 0; i < fill; i++) strcat(render, "."); - sprintf(temp, "%x", val); - fprintf(wfp, "%s%s", render, temp); - } - - // Show vob cell id. -// printf(" [vob/cell=%d/%d]", vob, cell); - - // Print warnings for 3:2 breaks and field order transitions. - if ((prev_val >= 0) && ((val == 0 && prev_val == 3) || (val != 0 && val == prev_val + 1))) - { - fprintf(wfp, " *"); - } - - if (prev_val >= 0) - { - if ((val == 2 && prev_val == 0) || (val == 2 && prev_val == 0)) - fprintf(wfp, " [FIELD ORDER TRANSITION!]"); - else if ((val == 3 && prev_val == 0) || (val == 2 && prev_val == 0)) - fprintf(wfp, " [FIELD ORDER TRANSITION!]"); - else if ((val == 0 && prev_val == 1) || (val == 2 && prev_val == 0)) - fprintf(wfp, " [FIELD ORDER TRANSITION!]"); - else if ((val == 1 && prev_val == 1) || (val == 2 && prev_val == 0)) - fprintf(wfp, " [FIELD ORDER TRANSITION!]"); - else if ((val == 0 && prev_val == 2) || (val == 2 && prev_val == 0)) - fprintf(wfp, " [FIELD ORDER TRANSITION!]"); - else if ((val == 1 && prev_val == 2) || (val == 2 && prev_val == 0)) - fprintf(wfp, " [FIELD ORDER TRANSITION!]"); - else if ((val == 2 && prev_val == 3) || (val == 2 && prev_val == 0)) - fprintf(wfp, " [FIELD ORDER TRANSITION!]"); - else if ((val == 3 && prev_val == 3) || (val == 2 && prev_val == 0)) - fprintf(wfp, " [FIELD ORDER TRANSITION!]"); - } - - fprintf(wfp, "\n"); - - // Count the encoded frames. - ndx++; - // Count the number of pulled-down fields. - if (val == 1 || val == 3) count++; - // Move to the next flags entry. - while (*p != ' ' && *p != '\n') p++; - p++; - prev_val = val; - } - } while ((fgets(line, 2048, fp) != 0) && - ((line[0] >= '0' && line[0] <= '9') || (line[0] >= 'a' && line[0] <= 'f'))); - sec = ((float)(ndx + count / 2)) * 1000.0 / frame_rate; - hour = (int) (sec / 3600); - sec -= hour * 3600; - min = (int) (sec / 60); - sec -= min * 60; - fprintf(wfp, "Running time = %d hours, %d minutes, %f seconds\n", hour, min, sec); - - fclose(fp); - fclose(wfp); - return 1; -} - -int analyze_sync(HWND hWnd, char *Input, int audio_id) -{ - FILE *fp, *wfp; - char line[2048], *p; - __int64 vpts, apts; - int delay, ref; - double rate, picture_period; - int leadingBframes; - char audio_id_str[10], tmp[20]; - - sprintf(audio_id_str, " A%02x", audio_id); - fp = fopen(Input, "r"); - if (fp == 0) - { - MessageBox(hWnd, "Cannot open the dump file!", NULL, MB_OK | MB_ICONERROR); - return 0; - } - // Check that it is a timestamps dump file - fgets(line, 1024, fp); - if (strncmp(line, "DGIndex Timestamps Dump", 23) != 0) - { - MessageBox(hWnd, "The file is not a DGIndex timestamps dump file!", NULL, MB_OK | MB_ICONERROR); - fclose(fp); - return 0; - } - - // Mutate the file name to the output text file to receive the parsed data. - p = &szInput[strlen(Input)]; - while (*p != '.') p--; - p[1] = 0; - sprintf(tmp, "delayT%x.txt", audio_id); - strcat(p, tmp); - // Open the output file. - wfp = fopen(szInput, "w"); - if (wfp == 0) - { - MessageBox(hWnd, "Cannot create the output file!", NULL, MB_OK | MB_ICONERROR); - return 0; - } - fprintf(wfp, "Delay Analysis Output (Audio ID %x)\n\n", audio_id); - - fgets(line, 1024, fp); - fgets(line, 1024, fp); - p = line; - while (*p++ != '='); - sscanf(p, "%Lf", &rate); - fgets(line, 1024, fp); - p = line; - while (*p++ != '='); - sscanf(p, "%d", &leadingBframes); -next_vpts: - while (fgets(line, 1024, fp) != 0) - { - if (!strncmp(line, "V PTS", 5)) - { - p = line; - while (*p++ != 'S'); - vpts = _atoi64(p); - while (fgets(line, 1024, fp) != 0) - { - if (!strncmp(line, "Decode picture", 14)) - { - p = line + 35; - sscanf(p, "%d", &ref); - while (*p++ != '['); - if (*p != 'I') - goto next_vpts; - fprintf(wfp, "%s", line); - break; - } - } - picture_period = 1.0 / rate; - vpts -= (int) (leadingBframes * picture_period * 90000); - while (fgets(line, 1024, fp) != 0) - { - if (!strncmp(line, audio_id_str, 4)) - { - p = line; - while (*p++ != 'S'); - apts = _atoi64(p); - delay = (int) ((apts - vpts) / 90); - fprintf(wfp, "delay = %d\n", delay); - break; - } - } - } - } - fclose(fp); - fclose(wfp); - - return 1; -} - -// Return 1 if a transition was detected in test_only mode and the user wants to correct it, otherwise 0. -int fix_d2v(HWND hWnd, char *Input, int test_only) -{ - FILE *fp, *wfp, *dfp; - char line[2048], prev_line[2048], wfile[2048], logfile[2048], *p, *q; - int val, mval, prev_val, mprev_val, fix; - bool first, found; - int D2Vformat = 0; - unsigned int info; - - fp = fopen(Input, "r"); - if (fp == 0) - { - MessageBox(hWnd, "Cannot open the D2V file!", NULL, MB_OK | MB_ICONERROR); - return 0; - } - // Pick up the D2V format number - fgets(line, 1024, fp); - if (strncmp(line, "DGIndexProjectFile", 18) != 0) - { - MessageBox(hWnd, "The file is not a DGIndex project file!", NULL, MB_OK | MB_ICONERROR); - fclose(fp); - return 0; - } - sscanf(line, "DGIndexProjectFile%d", &D2Vformat); - if (D2Vformat != D2V_FILE_VERSION) - { - MessageBox(hWnd, "Obsolete D2V file.\nRecreate it with this version of DGIndex.", NULL, MB_OK | MB_ICONERROR); - fclose(fp); - return 0; - } - - if (!test_only) - { - strcpy(wfile, Input); - strcat(wfile,".fixed"); - wfp = fopen(wfile, "w"); - if (wfp == 0) - { - MessageBox(hWnd, "Cannot create the fixed D2V file!", NULL, MB_OK | MB_ICONERROR); - fclose(fp); - return 0; - } - fputs(line, wfp); - // Mutate the file name to the output text file to receive processing status information. - strcpy(logfile, Input); - p = &logfile[strlen(logfile)]; - while (*p != '.') p--; - p[1] = 0; - strcat(p, "fix.txt"); - // Open the output file. - dfp = fopen(logfile, "w"); - if (dfp == 0) - { - fclose(fp); - fclose(wfp); - MessageBox(hWnd, "Cannot create the info output file!", NULL, MB_OK | MB_ICONERROR); - return 0; - } - - fprintf(dfp, "D2V Fix Output\n\n"); - } - - while (fgets(line, 1024, fp) != 0) - { - if (!test_only) fputs(line, wfp); - if (strncmp(line, "Location", 8) == 0) break; - } - fgets(line, 1024, fp); - if (!test_only) fputs(line, wfp); - fgets(line, 1024, fp); - prev_line[0] = 0; - prev_val = -1; - mprev_val = -1; - found = false; - do - { - p = line; - sscanf(p, "%x", &info); - // If it's a progressive sequence then we can't have any transitions. - if (info & (1 << 9)) - continue; - while (*p++ != ' '); - while (*p++ != ' '); - while (*p++ != ' '); - while (*p++ != ' '); - while (*p++ != ' '); - while (*p++ != ' '); - while (*p++ != ' '); - first = true; - while ((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f')) - { - fix = -1; - sscanf(p, "%x", &val); - if (val == 0xff) break; - // Isolate the TFF/RFF bits. - mval = val & 0x3; - if (prev_val >= 0) mprev_val = prev_val & 0x3; - // Detect field order transitions. - if (mval == 2 && mprev_val == 0) fix = 1; - else if (mval == 3 && mprev_val == 0) fix = 1; - else if (mval == 0 && mprev_val == 1) fix = 0; - else if (mval == 1 && mprev_val == 1) fix = 0; - else if (mval == 0 && mprev_val == 2) fix = 3; - else if (mval == 1 && mprev_val == 2) fix = 3; - else if (mval == 2 && mprev_val == 3) fix = 2; - else if (mval == 3 && mprev_val == 3) fix = 2; - // Correct the field order transition. - if (fix >= 0) - { - found = true; - if (!test_only) fprintf(dfp, "Field order transition: %x -> %x\n", mprev_val, mval); - if (!test_only) fprintf(dfp, prev_line); - if (!test_only) fprintf(dfp, line); - if (first == false) - { - q = p; - while (*q-- != ' '); - } - else - { - q = prev_line; - while (*q != '\n') q++; - while (!((*q >= '0' && *q <= '9') || (*q >= 'a' && *q <= 'f'))) q--; - } - *q = (char) fix + '0'; - if (!test_only) fprintf(dfp, "corrected...\n"); - if (!test_only) fprintf(dfp, prev_line); - if (!test_only) fprintf(dfp, line); - if (!test_only) fprintf(dfp, "\n"); - } - while (*p != ' ' && *p != '\n') p++; - p++; - prev_val = val; - first = false; - } - if (!test_only) fputs(prev_line, wfp); - strcpy(prev_line, line); - } while ((fgets(line, 2048, fp) != 0) && - ((line[0] >= '0' && line[0] <= '9') || (line[0] >= 'a' && line[0] <= 'f'))); - if (!test_only) fputs(prev_line, wfp); - if (!test_only) fputs(line, wfp); - while (fgets(line, 2048, fp) != 0) - if (!test_only) fputs(line, wfp); - fclose(fp); - if (!test_only) fclose(wfp); - if (test_only) - { - if (!CorrectFieldOrderTrans) - return 0; - if (found == true) - { - if (!CLIActive) - { - if (MessageBox(hWnd, "A field order transition was detected.\n" - "It is not possible to decide automatically if this should be corrected.\n" - "Refer to the DGIndex Users Manual for an explanation.\n" - "You can choose to correct it by hitting the Yes button below or\n" - "you can correct it later using the Fix D2V tool.\n\n" - "Correct the field order transition?", - "Field Order Transition Detected", MB_YESNO | MB_ICONWARNING) == IDYES) - return 1; - else - return 0; - } - else - return 1; - } - return 0; - } - if (found == false) - { - fprintf(dfp, "No errors found.\n"); - fclose(dfp); - _unlink(wfile); - MessageBox(hWnd, "No errors found.", "Fix D2V", MB_OK | MB_ICONINFORMATION); - return 0; - } - else - { - FILE *bad, *good, *fixed; - char c; - - fclose(dfp); - // Copy the D2V file to *.d2v.bad version. - good = fopen(Input, "r"); - if (good == 0) - return 0; - sprintf(line, "%s.bad", Input); - bad = fopen(line, "w"); - if (bad == 0) - { - fclose(good); - return 0; - } - while ((c = fgetc(good)) != EOF) fputc(c, bad); - fclose(good); - fclose(bad); - // Copy the *.d2v.fixed version to the D2V file. - good = fopen(Input, "w"); - if (good == 0) - return 0; - sprintf(line, "%s.fixed", Input); - fixed = fopen(line, "r"); - while ((c = fgetc(fixed)) != EOF) fputc(c, good); - fclose(good); - fclose(fixed); - // Ditch the *.d2v.fixed version. - _unlink(line); - if (!CLIActive) - { - MessageBox(hWnd, "Field order corrected. The original version was\nsaved with the extension \".bad\".", "Correct Field Order", MB_OK | MB_ICONINFORMATION); - ShellExecute(hDlg, "open", logfile, NULL, NULL, SW_SHOWNORMAL); - } - } - - return 0; -} diff --git a/src/dgindex/filter.h b/src/dgindex/filter.h deleted file mode 100644 index 6c0aff8..0000000 --- a/src/dgindex/filter.h +++ /dev/null @@ -1,955 +0,0 @@ -/* - * Mutated into DGIndex. Modifications Copyright (C) 2004, Donald Graft - * - * Copyright (C) Chia-chen Kuo - June 2002 - * - * This file is part of DVD2AVI, a free MPEG-2 decoder - * - * DVD2AVI 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. - * - * DVD2AVI is distributed in the hope that 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 - -int half_height, pheight, iheight; -static int DOUBLE_WIDTH, HALF_WIDTH, LUM_AREA, PROGRESSIVE_HEIGHT, INTERLACED_HEIGHT; -static int HALF_WIDTH_D8, RGB_DOWN1, RGB_DOWN2; - -static int NINE_CLIP_WIDTH, QUAD_CLIP_WIDTH, DOUBLE_CLIP_WIDTH, HALF_CLIP_WIDTH; -static int CLIP_AREA, HALF_CLIP_AREA, CLIP_STEP, CLIP_HALF_STEP; - -static const __int64 mmmask_0001 = 0x0001000100010001; -static const __int64 mmmask_0002 = 0x0002000200020002; -static const __int64 mmmask_0003 = 0x0003000300030003; -static const __int64 mmmask_0004 = 0x0004000400040004; -static const __int64 mmmask_0005 = 0x0005000500050005; -static const __int64 mmmask_0007 = 0x0007000700070007; -static const __int64 mmmask_0064 = 0x0040004000400040; -static const __int64 mmmask_0128 = 0x0080008000800080; -static const __int64 lastmask = 0xFF00000000000000; -static const __int64 mmmask_0101 = 0x0101010101010101; - -static unsigned char LuminanceTable[256]; - -static void InitializeFilter() -{ - int i; - double value; - - for (i=0; i<256; i++) - { - value = 255.0 * pow(i/255.0, pow(2.0, -LumGamma/128.0)) + LumOffset + 0.5; - - if (value < 0) - LuminanceTable[i] = 0; - else if (value > 255.0) - LuminanceTable[i] = 255; - else - LuminanceTable[i] = (unsigned char)value; - } -} - -static void LuminanceFilter(unsigned char *src, unsigned char *dst) -{ - int i; - - src += CLIP_AREA; - dst += CLIP_AREA; - - for (i=0; i>1)-8 - mov edx, HALF_WIDTH - xor esi, esi // esi = 0 - movq mm7, lastmask - -xloop: - movq mm0, [eax+esi] // mm7 = hgfedcba - movq mm1, [eax+esi+1]// mm1 = ihgfedcb - pavgb mm1, mm0 - movq mm2, mm0 - punpcklbw mm0,mm1 - punpckhbw mm2,mm1 - - movq [ebx+esi*2], mm0 // store mm0 - movq [ebx+esi*2+8], mm2 // store mm2 - - add esi, 8 - cmp esi, ecx - jl xloop // loop back if not to last 8 pixels - - movq mm0, [eax+esi] // mm7 = hgfedcba - movq mm1, mm0 // mm1 = hgfedcba - movq mm2, mm0 // mm2 = hgfedcba - psrlq mm1, 8 // mm1 = 0hgfedcb - pand mm2, mm7 // mm2 = h0000000 - por mm1, mm2 // mm1 = hhgfedcb - pavgb mm1, mm0 - movq mm2, mm0 - punpcklbw mm0,mm1 - punpckhbw mm2,mm1 - - movq [ebx+esi*2], mm0 // store mm0 - movq [ebx+esi*2+8], mm2 // store mm2 - - add eax, edx - add ebx, Coded_Picture_Width - xor esi, esi - dec edi - jnz xloop - emms - } -} - -static void conv422to444(unsigned char *src, unsigned char *dst) -{ - if (cpu.ssemmx) - { - conv422to444_iSSE(src, dst); - return; - } - - src += HALF_CLIP_AREA; - dst += CLIP_AREA; - - __asm - { - mov eax, [src] // eax = src - mov ebx, [dst] // ebx = dst - mov edi, Clip_Height // edi = height - mov ecx, HALF_WIDTH_D8 // ecx = (width>>1)-8 - movq mm1, mmmask_0001 // mm1 = 1's - pxor mm0, mm0 // mm0 = 0's - -convyuv444init: - movq mm7, [eax] // mm7 = hgfedcba - xor esi, esi // esi = 0 - -convyuv444: - movq mm2, mm7 // mm2 = hgfedcba - movq mm7, [eax+esi+8] // mm7 = ponmlkji - movq mm3, mm2 // mm3 = hgfedcba - movq mm4, mm7 // mm4 = ponmlkji - - psrlq mm3, 8 // mm3 = 0hgfedcb - psllq mm4, 56 // mm4 = i0000000 - por mm3, mm4 // mm3 = ihgfedcb - - movq mm4, mm2 // mm4 = hgfedcba - movq mm5, mm3 // mm5 = ihgfedcb - - punpcklbw mm4, mm0 // 0d0c0b0a - punpcklbw mm5, mm0 // 0e0d0c0b - - movq mm6, mm4 // mm6 = 0d0c0b0a - paddusw mm4, mm1 - paddusw mm4, mm5 - psrlw mm4, 1 // average mm4/mm5 (d/e,c/d,b/c,a/b) - psllq mm4, 8 // mm4 = z0z0z0z0 - por mm4, mm6 // mm4 = zdzczbza - - punpckhbw mm2, mm0 // 0h0g0f0e - punpckhbw mm3, mm0 // 0i0h0g0f - - movq mm6, mm2 // mm6 = 0h0g0f0e - paddusw mm2, mm1 - paddusw mm2, mm3 - psrlw mm2, 1 // average mm2/mm3 (h/i,g/h,f/g,e/f) - psllq mm2, 8 // mm2 = z0z0z0z0 - por mm2, mm6 // mm2 = zhzgzfze - - movq [ebx+esi*2], mm4 // store zdzczbza - movq [ebx+esi*2+8], mm2 // store zhzgzfze - - add esi, 8 - cmp esi, ecx - jl convyuv444 // loop back if not to last 8 pixels - - movq mm2, mm7 // mm2 = ponmlkji - - punpcklbw mm2, mm0 // mm2 = 0l0k0j0i - punpckhbw mm7, mm0 // mm7 = 0p0o0n0m - - movq mm3, mm2 // mm3 = 0l0k0j0i - movq mm4, mm7 // mm4 = 0p0o0n0m - - psrlq mm2, 16 // mm2 = 000l0k0j - psllq mm4, 48 // mm4 = 0m000000 - por mm2, mm4 // mm2 = 0m0l0k0j - - paddusw mm2, mm1 - paddusw mm2, mm3 - psrlw mm2, 1 // average mm2/mm3 (m/l,l/k,k/j,j/i) - psllq mm2, 8 // mm2 = z0z0z0z0 - por mm2, mm3 // mm2 = zlzkzjzi - - movq mm6, mm7 // mm6 = 0p0o0n0m - movq mm4, mm7 // mm4 = 0p0o0n0m - - psrlq mm6, 48 // mm6 = 0000000p - psrlq mm4, 16 // mm4 = 000p0o0n - psllq mm6, 48 // mm6 = 0p000000 - por mm4,mm6 // mm4 = 0p0p0o0n - - paddusw mm4, mm1 - paddusw mm4, mm7 - psrlw mm4, 1 // average mm4/mm7 (p/p,p/o,o/n,n/m) - psllq mm4, 8 // mm4 = z0z0z0z0 - por mm4, mm7 // mm4 = zpzoznzm - - movq [ebx+esi*2], mm2 // store mm2 - movq [ebx+esi*2+8], mm4 // store mm4 - - add eax, HALF_WIDTH - add ebx, Coded_Picture_Width - dec edi - jnz convyuv444init - - emms - } -} - -static void conv420to422P_iSSE(const unsigned char *src, unsigned char *dst) -{ - pheight = PROGRESSIVE_HEIGHT; - - __asm - { - mov eax, [src] // eax = src - mov ebx, [dst] // ebx = dst - mov ecx, ebx // ecx = dst - mov edi, HALF_WIDTH - add ecx, edi // ecx = dst + dst_pitch - mov edx, eax // edx = src - add edx, edi // edx = src + src_pitch - xor esi, esi - movq mm6, mmmask_0101 - movq mm7, mm6 - -convyuv422topp: - movq mm0, [eax+esi] - movq mm1, [edx+esi] - movq [ebx+esi], mm0 - psubusb mm1, mm7 - pavgb mm1, mm0 - pavgb mm1, mm0 - movq [ecx+esi], mm1 - add esi, 0x08 - cmp esi, edi - jl convyuv422topp - add eax, edi - add ebx, Coded_Picture_Width - add ecx, Coded_Picture_Width - xor esi, esi - -convyuv422p: - movq mm0, [eax+esi] - mov edx, eax // edx = src - movq mm1, mm0 - sub edx, edi - movq mm2, [edx+esi] - add edx, Coded_Picture_Width - movq mm3, [edx+esi] - psubusb mm2, mm6 - psubusb mm3, mm7 - pavgb mm2, mm0 - pavgb mm3, mm1 - pavgb mm2, mm0 - pavgb mm3, mm1 - movq [ebx+esi], mm2 - movq [ecx+esi], mm3 - add esi, 0x08 - cmp esi, edi - jl convyuv422p - add eax, edi - add ebx, Coded_Picture_Width - add ecx, Coded_Picture_Width - xor esi, esi - dec pheight - jnz convyuv422p - mov edx, eax - sub edx, edi - -convyuv422bottomp: - movq mm0, [eax+esi] - movq mm1, [edx+esi] - movq [ecx+esi], mm0 - psubusb mm1, mm7 - pavgb mm1, mm0 - pavgb mm1, mm0 - movq [ebx+esi], mm1 - add esi, 0x08 - cmp esi, edi - jl convyuv422bottomp - emms - } -} - -static void conv420to422(const unsigned char *src, unsigned char *dst, bool frame_type) -{ - pheight = PROGRESSIVE_HEIGHT; - iheight = INTERLACED_HEIGHT; - - if (frame_type) - { - if (cpu.ssemmx) - { - conv420to422P_iSSE(src, dst); - return; - } - - __asm - { - mov eax, [src] // eax = src - mov ebx, [dst] // ebx = dst - mov ecx, ebx // ecx = dst - mov edi, HALF_WIDTH - add ecx, edi // ecx = dst + dst_pitch - xor esi, esi - movq mm3, [mmmask_0003] - pxor mm0, mm0 - movq mm4, [mmmask_0002] - - mov edx, eax // edx = src - add edx, edi // edx = src + src_pitch - -convyuv422topp: - movd mm1, [eax+esi] - movd mm2, [edx+esi] - movd [ebx+esi], mm1 - punpcklbw mm1, mm0 - pmullw mm1, mm3 - paddusw mm1, mm4 - punpcklbw mm2, mm0 - paddusw mm2, mm1 - psrlw mm2, 0x02 - packuswb mm2, mm0 - - add esi, 0x04 - cmp esi, edi - movd [ecx+esi-4], mm2 - jl convyuv422topp - - add eax, edi - add ebx, Coded_Picture_Width - add ecx, Coded_Picture_Width - xor esi, esi - -convyuv422p: - movd mm1, [eax+esi] - - punpcklbw mm1, mm0 - mov edx, eax // edx = src - - pmullw mm1, mm3 - sub edx, edi - - movd mm5, [edx+esi] - add edx, Coded_Picture_Width - movd mm2, [edx+esi] - - punpcklbw mm5, mm0 - punpcklbw mm2, mm0 - paddusw mm5, mm1 - paddusw mm2, mm1 - paddusw mm5, mm4 - paddusw mm2, mm4 - psrlw mm5, 0x02 - psrlw mm2, 0x02 - packuswb mm5, mm0 - packuswb mm2, mm0 - - add esi, 0x04 - cmp esi, edi - movd [ebx+esi-4], mm5 - movd [ecx+esi-4], mm2 - - jl convyuv422p - - add eax, edi - add ebx, Coded_Picture_Width - add ecx, Coded_Picture_Width - xor esi, esi - dec pheight - jnz convyuv422p - - mov edx, eax - sub edx, edi -convyuv422bottomp: - movd mm1, [eax+esi] - movd mm5, [edx+esi] - punpcklbw mm5, mm0 - movd [ecx+esi], mm1 - - punpcklbw mm1, mm0 - pmullw mm1, mm3 - paddusw mm5, mm1 - paddusw mm5, mm4 - psrlw mm5, 0x02 - packuswb mm5, mm0 - - add esi, 0x04 - cmp esi, edi - movd [ebx+esi-4], mm5 - jl convyuv422bottomp - - emms - } - } - else - { - __asm - { - mov eax, [src] // eax = src - mov ecx, [dst] // ecx = dst - xor esi, esi - pxor mm0, mm0 - movq mm3, [mmmask_0003] - movq mm4, [mmmask_0004] - movq mm5, [mmmask_0005] - mov edi, HALF_WIDTH - -convyuv422topi: - movd mm1, [eax+esi] - mov ebx, eax - add ebx, Coded_Picture_Width - movd mm2, [ebx+esi] - movd [ecx+esi], mm1 - sub ebx, edi - - punpcklbw mm1, mm0 - movq mm6, [ebx+esi] - pmullw mm1, mm5 - add ebx, Coded_Picture_Width - punpcklbw mm2, mm0 - movq mm7, [ebx+esi] - pmullw mm2, mm3 - paddusw mm2, mm1 - paddusw mm2, mm4 - psrlw mm2, 0x03 - packuswb mm2, mm0 - - mov edx, ecx - add edx, Coded_Picture_Width - movd [edx+esi], mm2 - sub edx, edi - - movd [edx+esi], mm6 - punpcklbw mm6, mm0 - pmullw mm6, [mmmask_0007] - punpcklbw mm7, mm0 - paddusw mm7, mm6 - paddusw mm7, mm4 - psrlw mm7, 0x03 - packuswb mm7, mm0 - - add edx, Coded_Picture_Width - add esi, 0x04 - cmp esi, edi - movd [edx+esi-4], mm7 - - jl convyuv422topi - - add eax, Coded_Picture_Width - add ecx, DOUBLE_WIDTH - xor esi, esi - -convyuv422i: - movd mm1, [eax+esi] - punpcklbw mm1, mm0 - movq mm6, mm1 - mov ebx, eax - sub ebx, Coded_Picture_Width - movd mm3, [ebx+esi] - pmullw mm1, [mmmask_0007] - punpcklbw mm3, mm0 - paddusw mm3, mm1 - paddusw mm3, mm4 - psrlw mm3, 0x03 - packuswb mm3, mm0 - - add ebx, edi - movq mm1, [ebx+esi] - add ebx, Coded_Picture_Width - movd [ecx+esi], mm3 - - movq mm3, [mmmask_0003] - movd mm2, [ebx+esi] - - punpcklbw mm1, mm0 - pmullw mm1, mm3 - punpcklbw mm2, mm0 - movq mm7, mm2 - pmullw mm2, mm5 - paddusw mm2, mm1 - paddusw mm2, mm4 - psrlw mm2, 0x03 - packuswb mm2, mm0 - - pmullw mm6, mm5 - mov edx, ecx - add edx, edi - movd [edx+esi], mm2 - - add ebx, edi - movd mm2, [ebx+esi] - punpcklbw mm2, mm0 - pmullw mm2, mm3 - paddusw mm2, mm6 - paddusw mm2, mm4 - psrlw mm2, 0x03 - packuswb mm2, mm0 - - pmullw mm7, [mmmask_0007] - add edx, edi - add ebx, edi - movd [edx+esi], mm2 - - movd mm2, [ebx+esi] - punpcklbw mm2, mm0 - paddusw mm2, mm7 - paddusw mm2, mm4 - psrlw mm2, 0x03 - packuswb mm2, mm0 - - add edx, edi - add esi, 0x04 - cmp esi, edi - movd [edx+esi-4], mm2 - - jl convyuv422i - add eax, Coded_Picture_Width - add ecx, DOUBLE_WIDTH - xor esi, esi - dec iheight - jnz convyuv422i - -convyuv422bottomi: - movd mm1, [eax+esi] - movq mm6, mm1 - punpcklbw mm1, mm0 - mov ebx, eax - sub ebx, Coded_Picture_Width - movd mm3, [ebx+esi] - punpcklbw mm3, mm0 - pmullw mm1, [mmmask_0007] - paddusw mm3, mm1 - paddusw mm3, mm4 - psrlw mm3, 0x03 - packuswb mm3, mm0 - - add ebx, edi - movq mm1, [ebx+esi] - punpcklbw mm1, mm0 - movd [ecx+esi], mm3 - - pmullw mm1, [mmmask_0003] - add ebx, Coded_Picture_Width - movd mm2, [ebx+esi] - movq mm7, mm2 - punpcklbw mm2, mm0 - pmullw mm2, mm5 - paddusw mm2, mm1 - paddusw mm2, mm4 - psrlw mm2, 0x03 - packuswb mm2, mm0 - - mov edx, ecx - add edx, edi - movd [edx+esi], mm2 - add edx, edi - movd [edx+esi], mm6 - - add edx, edi - add esi, 0x04 - cmp esi, edi - movd [edx+esi-4], mm7 - - jl convyuv422bottomi - - emms - } - } -} - -static void conv422toyuy2odd(unsigned char *py, unsigned char *pu, unsigned char *pv, unsigned char *dst) -{ - py += CLIP_STEP; - pu += CLIP_HALF_STEP; - pv += CLIP_HALF_STEP; - half_height = Clip_Height>>1; - - __asm - { - mov eax, [py] - mov ebx, [pu] - mov ecx, [pv] - mov edx, [dst] - xor esi, esi - mov edi, [Clip_Width] - -yuy2conv: - movd mm2, [ebx+esi] - movd mm3, [ecx+esi] - punpcklbw mm2, mm3 - movq mm1, [eax+esi*2] - movq mm4, mm1 - punpcklbw mm1, mm2 - punpckhbw mm4, mm2 - - add esi, 0x04 - cmp esi, edi - movq [edx+esi*4-16], mm1 - movq [edx+esi*4-8], mm4 - jl yuy2conv - - add eax, [DOUBLE_WIDTH] - add ebx, [Coded_Picture_Width] - add ecx, [Coded_Picture_Width] - add edx, [QUAD_CLIP_WIDTH] - xor esi, esi - dec half_height - jnz yuy2conv - - emms - } -} - -static void conv422toyuy2even(unsigned char *py, unsigned char *pu, unsigned char *pv, unsigned char *dst) -{ - py += Coded_Picture_Width + CLIP_STEP; - pu += HALF_WIDTH + CLIP_HALF_STEP; - pv += HALF_WIDTH + CLIP_HALF_STEP; - dst += DOUBLE_CLIP_WIDTH; - half_height = Clip_Height>>1; - - __asm - { - mov eax, [py] - mov ebx, [pu] - mov ecx, [pv] - mov edx, [dst] - xor esi, esi - mov edi, [Clip_Width] - -yuy2conv: - movd mm2, [ebx+esi] - movd mm3, [ecx+esi] - punpcklbw mm2, mm3 - movq mm1, [eax+esi*2] - movq mm4, mm1 - punpcklbw mm1, mm2 - punpckhbw mm4, mm2 - - add esi, 0x04 - cmp esi, edi - movq [edx+esi*4-16], mm1 - movq [edx+esi*4-8], mm4 - jl yuy2conv - - add eax, [DOUBLE_WIDTH] - add ebx, [Coded_Picture_Width] - add ecx, [Coded_Picture_Width] - add edx, [QUAD_CLIP_WIDTH] - xor esi, esi - dec half_height - jnz yuy2conv - - emms - } -} - -static void conv444toRGB24odd(unsigned char *py, unsigned char *pu, unsigned char *pv, unsigned char *dst) -{ - py += CLIP_STEP; - pu += CLIP_STEP; - pv += CLIP_STEP; - dst += RGB_DOWN1; - half_height = Clip_Height>>1; - - __asm - { - mov eax, [py] - mov ebx, [pu] - mov ecx, [pv] - mov edx, [dst] - mov edi, [Clip_Width] - xor esi, esi - pxor mm0, mm0 - -convRGB24: - movd mm1, [eax+esi] - movd mm3, [ebx+esi] - punpcklbw mm1, mm0 - punpcklbw mm3, mm0 - movd mm5, [ecx+esi] - punpcklbw mm5, mm0 - movq mm7, [mmmask_0128] - psubw mm3, mm7 - psubw mm5, mm7 - - psubw mm1, [RGB_Offset] - movq mm2, mm1 - movq mm7, [mmmask_0001] - punpcklwd mm1, mm7 - punpckhwd mm2, mm7 - movq mm7, [RGB_Scale] - pmaddwd mm1, mm7 - pmaddwd mm2, mm7 - - movq mm4, mm3 - punpcklwd mm3, mm0 - punpckhwd mm4, mm0 - movq mm7, [RGB_CBU] - pmaddwd mm3, mm7 - pmaddwd mm4, mm7 - paddd mm3, mm1 - paddd mm4, mm2 - psrad mm3, 13 - psrad mm4, 13 - packuswb mm3, mm0 - packuswb mm4, mm0 - - movq mm6, mm5 - punpcklwd mm5, mm0 - punpckhwd mm6, mm0 - movq mm7, [RGB_CRV] - pmaddwd mm5, mm7 - pmaddwd mm6, mm7 - paddd mm5, mm1 - paddd mm6, mm2 - - psrad mm5, 13 - psrad mm6, 13 - packuswb mm5, mm0 - packuswb mm6, mm0 - - punpcklbw mm3, mm5 - punpcklbw mm4, mm6 - movq mm5, mm3 - movq mm6, mm4 - psrlq mm5, 16 - psrlq mm6, 16 - por mm3, mm5 - por mm4, mm6 - - movd mm5, [ebx+esi] - movd mm6, [ecx+esi] - punpcklbw mm5, mm0 - punpcklbw mm6, mm0 - movq mm7, [mmmask_0128] - psubw mm5, mm7 - psubw mm6, mm7 - - movq mm7, mm6 - punpcklwd mm6, mm5 - punpckhwd mm7, mm5 - movq mm5, [RGB_CGX] - pmaddwd mm6, mm5 - pmaddwd mm7, mm5 - paddd mm6, mm1 - paddd mm7, mm2 - - psrad mm6, 13 - psrad mm7, 13 - packuswb mm6, mm0 - packuswb mm7, mm0 - - punpcklbw mm3, mm6 - punpcklbw mm4, mm7 - - movq mm1, mm3 - movq mm5, mm4 - movq mm6, mm4 - - psrlq mm1, 32 - psllq mm1, 24 - por mm1, mm3 - - psrlq mm3, 40 - psllq mm6, 16 - por mm3, mm6 - movd [edx], mm1 - - psrld mm4, 16 - psrlq mm5, 24 - por mm5, mm4 - movd [edx+4], mm3 - - add edx, 0x0c - add esi, 0x04 - cmp esi, edi - movd [edx-4], mm5 - - jl convRGB24 - - add eax, [DOUBLE_WIDTH] - add ebx, [DOUBLE_WIDTH] - add ecx, [DOUBLE_WIDTH] - sub edx, [NINE_CLIP_WIDTH] - xor esi, esi - dec half_height - jnz convRGB24 - - emms - } -} - -static void conv444toRGB24even(unsigned char *py, unsigned char *pu, unsigned char *pv, unsigned char *dst) -{ - py += Coded_Picture_Width + CLIP_STEP; - pu += Coded_Picture_Width + CLIP_STEP; - pv += Coded_Picture_Width + CLIP_STEP; - dst += RGB_DOWN2; - half_height = Clip_Height>>1; - - __asm - { - mov eax, [py] - mov ebx, [pu] - mov ecx, [pv] - mov edx, [dst] - mov edi, [Clip_Width] - xor esi, esi - pxor mm0, mm0 - -convRGB24: - movd mm1, [eax+esi] - movd mm3, [ebx+esi] - punpcklbw mm1, mm0 - punpcklbw mm3, mm0 - movd mm5, [ecx+esi] - punpcklbw mm5, mm0 - movq mm7, [mmmask_0128] - psubw mm3, mm7 - psubw mm5, mm7 - - psubw mm1, [RGB_Offset] - movq mm2, mm1 - movq mm7, [mmmask_0001] - punpcklwd mm1, mm7 - punpckhwd mm2, mm7 - movq mm7, [RGB_Scale] - pmaddwd mm1, mm7 - pmaddwd mm2, mm7 - - movq mm4, mm3 - punpcklwd mm3, mm0 - punpckhwd mm4, mm0 - movq mm7, [RGB_CBU] - pmaddwd mm3, mm7 - pmaddwd mm4, mm7 - paddd mm3, mm1 - paddd mm4, mm2 - psrad mm3, 13 - psrad mm4, 13 - packuswb mm3, mm0 - packuswb mm4, mm0 - - movq mm6, mm5 - punpcklwd mm5, mm0 - punpckhwd mm6, mm0 - movq mm7, [RGB_CRV] - pmaddwd mm5, mm7 - pmaddwd mm6, mm7 - paddd mm5, mm1 - paddd mm6, mm2 - psrad mm5, 13 - psrad mm6, 13 - packuswb mm5, mm0 - packuswb mm6, mm0 - - punpcklbw mm3, mm5 - punpcklbw mm4, mm6 - movq mm5, mm3 - movq mm6, mm4 - psrlq mm5, 16 - psrlq mm6, 16 - por mm3, mm5 - por mm4, mm6 - - movd mm5, [ebx+esi] - movd mm6, [ecx+esi] - punpcklbw mm5, mm0 - punpcklbw mm6, mm0 - movq mm7, [mmmask_0128] - psubw mm5, mm7 - psubw mm6, mm7 - - movq mm7, mm6 - punpcklwd mm6, mm5 - punpckhwd mm7, mm5 - movq mm5, [RGB_CGX] - pmaddwd mm6, mm5 - pmaddwd mm7, mm5 - paddd mm6, mm1 - paddd mm7, mm2 - - psrad mm6, 13 - psrad mm7, 13 - packuswb mm6, mm0 - packuswb mm7, mm0 - - punpcklbw mm3, mm6 - punpcklbw mm4, mm7 - - movq mm1, mm3 - movq mm5, mm4 - movq mm6, mm4 - - psrlq mm1, 32 - psllq mm1, 24 - por mm1, mm3 - - psrlq mm3, 40 - psllq mm6, 16 - por mm3, mm6 - movd [edx], mm1 - - psrld mm4, 16 - psrlq mm5, 24 - por mm5, mm4 - movd [edx+4], mm3 - - add edx, 0x0c - add esi, 0x04 - cmp esi, edi - movd [edx-4], mm5 - - jl convRGB24 - - add eax, [DOUBLE_WIDTH] - add ebx, [DOUBLE_WIDTH] - add ecx, [DOUBLE_WIDTH] - sub edx, [NINE_CLIP_WIDTH] - xor esi, esi - dec half_height - jnz convRGB24 - - emms - } -} diff --git a/src/dgindex/getbit.cpp b/src/dgindex/getbit.cpp deleted file mode 100644 index a6fb230..0000000 --- a/src/dgindex/getbit.cpp +++ /dev/null @@ -1,3099 +0,0 @@ -/* - * Mutated into DGIndex. Modifications Copyright (C) 2004-2008, Donald Graft - * - * Copyright (C) Chia-chen Kuo - April 2001 - * - * This file is part of DVD2AVI, a free MPEG-2 decoder - * - * DVD2AVI 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. - * - * DVD2AVI is distributed in the hope that 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. - * - */ - -#define GETBIT_GLOBAL -#include "global.h" -#include "getbit.h" -#include "AC3Dec\ac3.h" - -unsigned int start; - -int _donread(int fd, void *buffer, unsigned int count) -{ - int bytes; - bytes = _read(fd, buffer, count); - return bytes; -} - -#define MONO 3 -#define STEREO 0 -#define LAYER1 3 -#define LAYER2 2 -#define LAYER3 1 -#define LAYERRESERVED 0 -#define SAMPLE32K 2 -#define SAMPLE44K 0 -#define SAMPLERESERVED 3 -#define BITRATERESERVED 0xf - -static int check_adts_aac_header(int layer, int profile, int sample) -{ - if (layer) - return 1; - if (profile == 3) - return 1; - if (sample > 12) - return 1; - return 0; -} - -int check_audio_syncword(unsigned int audio_id, int layer, int bitrate, int sample, int mode, int emphasis) -{ - // Try to validate this syncword by validating semantics of the audio header. - // We're trying to filter out emulated syncwords. - if (layer == LAYERRESERVED) - return 1; - if (bitrate == BITRATERESERVED) - return 1; - if (sample == SAMPLERESERVED) - return 1; - if (layer == LAYER2) - { - if ((bitrate == 1 || bitrate == 2 || bitrate == 3 || bitrate == 5) && mode != MONO) - return 1; - if ((bitrate == 11 || bitrate == 12 || bitrate == 13 || bitrate == 14) && mode == MONO) - return 1; - } - // Emphasis is almost never used. It's less likely than hitting an emulated header. :-) -// if (emphasis != 0) -// return 1; - // The header appears to be valid. Store the audio characteristics. - audio[audio_id].layer = layer; - audio[audio_id].rate = bitrate; - audio[audio_id].sample = sample; - audio[audio_id].mode = mode; - return 0; -} - -int PTSDifference(__int64 apts, __int64 vpts, int *result) -{ - __int64 diff = 0; - - if (apts == vpts) - { - *result = 0; -#ifdef NO_NEED_AUDIO_DELAY_VALUE - return 1; -#else - return 0; -#endif - } - diff = apts - vpts; - WRAPAROUND_CORRECTION(diff); - diff /= 90; - *result = (int) diff; - if (_abs64(diff) > 1000 && (D2V_Flag || AudioOnly_Flag) && !CLIActive) - { - MessageBox(hWnd, - "The calculated audio delay is unusually large. This is sometimes\n" - "caused by an initial black video lead in that does not have valid\n" - "timestamps. You can try setting your project range to skip this\n" - "portion of the video. Use the > button to skip GOPS and then hit\n" - "the [ button to set the start of the project. This may give you a\n" - "valid delay value.", - "Audio Delay Warning", - MB_OK | MB_ICONWARNING); - // Reset data timeout. - start = timeGetTime(); - } - return 0; -} - - -FILE *OpenAudio(char *path, char *mode, unsigned int id) -{ - // Pick up the first audio file path for - // use in the AVS template. - if (id < LowestAudioId) - { - strcpy(AudioFilePath, path); - LowestAudioId = id; - } - return fopen(path, mode); -} - -#define LOCATE \ -while (Rdptr >= (Rdbfr + BUFFER_SIZE)) \ -{ \ - Read = _donread(Infile[CurrentFile], Rdbfr, BUFFER_SIZE); \ - if (Read < BUFFER_SIZE) Next_File(); \ - Rdptr -= BUFFER_SIZE; \ -} - -#define DECODE_AC3 \ -{ \ - if (SystemStream_Flag == TRANSPORT_STREAM && TransportPacketSize == 204) \ - Packet_Length -= 16; \ - size = 0; \ - while (Packet_Length > 0) \ - { \ - if (Packet_Length+Rdptr > BUFFER_SIZE+Rdbfr) \ - { \ - size = ac3_decode_data(Rdptr, BUFFER_SIZE+Rdbfr-Rdptr, size); \ - Packet_Length -= BUFFER_SIZE+Rdbfr-Rdptr; \ - Read = _donread(Infile[CurrentFile], Rdbfr, BUFFER_SIZE); \ - if (Read < BUFFER_SIZE) Next_File(); \ - Rdptr = Rdbfr; \ - } \ - else \ - { \ - size = ac3_decode_data(Rdptr, Packet_Length, size); \ - Rdptr += Packet_Length; \ - Packet_Length = 0; \ - } \ - } \ -} - -#define DEMUX_AC3 \ -{ \ - if (SystemStream_Flag == TRANSPORT_STREAM && TransportPacketSize == 204) \ - Packet_Length -= 16; \ - while (Packet_Length > 0) \ - { \ - if (Packet_Length+Rdptr > BUFFER_SIZE+Rdbfr) \ - { \ - fwrite(Rdptr, BUFFER_SIZE+Rdbfr-Rdptr, 1, audio[AUDIO_ID].file); \ - Packet_Length -= BUFFER_SIZE+Rdbfr-Rdptr; \ - Read = _donread(Infile[CurrentFile], Rdbfr, BUFFER_SIZE); \ - if (Read < BUFFER_SIZE) Next_File(); \ - Rdptr = Rdbfr; \ - } \ - else \ - { \ - fwrite(Rdptr, Packet_Length, 1, audio[AUDIO_ID].file); \ - Rdptr += Packet_Length; \ - Packet_Length = 0; \ - } \ - } \ -} - -void DemuxLPCM(int *size, int *Packet_Length, unsigned char PCM_Buffer[], unsigned char format) -{ - unsigned char tmp[12]; - int i; - - *size = 0; - while (*Packet_Length > 0) - { - if (*Packet_Length + Rdptr > BUFFER_SIZE + Rdbfr) - { - memcpy(PCM_Buffer + *size, Rdptr, BUFFER_SIZE + Rdbfr - Rdptr); - *size += (BUFFER_SIZE + Rdbfr - Rdptr); - *Packet_Length -= (BUFFER_SIZE + Rdbfr - Rdptr); - Read = _donread(Infile[CurrentFile], Rdbfr, BUFFER_SIZE); - if (Read < BUFFER_SIZE) - Next_File(); - Rdptr = Rdbfr; - } - else - { - memcpy(PCM_Buffer + *size, Rdptr, *Packet_Length); - Rdptr += *Packet_Length; - *size += *Packet_Length; - *Packet_Length = 0; - } - } - if ((format & 0xc0) == 0) - { - // 16-bit LPCM. - for (i = 0; i < *size; i += 2) - { - tmp[0] = PCM_Buffer[i]; - PCM_Buffer[i] = PCM_Buffer[i+1]; - PCM_Buffer[i+1] = tmp[0]; - } - } - else - { - // 24-bit LPCM. - if ((format & 0x07) + 1 == 1) - { - // Mono - for (i = 0; i < *size; i += 6) - { - tmp[0]=PCM_Buffer[i+4]; - tmp[1]=PCM_Buffer[i+1]; - tmp[2]=PCM_Buffer[i+0]; - tmp[3]=PCM_Buffer[i+5]; - tmp[4]=PCM_Buffer[i+3]; - tmp[5]=PCM_Buffer[i+2]; - memcpy(&PCM_Buffer[i], tmp, 6); - } - } - else - { - // Stereo - for (i = 0; i < *size; i += 12) - { - tmp[0] = PCM_Buffer[i+8]; - tmp[1] = PCM_Buffer[i+1]; - tmp[2] = PCM_Buffer[i+0]; - tmp[3] = PCM_Buffer[i+9]; - tmp[4] = PCM_Buffer[i+3]; - tmp[5] = PCM_Buffer[i+2]; - tmp[6] = PCM_Buffer[i+10]; - tmp[7] = PCM_Buffer[i+5]; - tmp[8] = PCM_Buffer[i+4]; - tmp[9] = PCM_Buffer[i+11]; - tmp[10] = PCM_Buffer[i+7]; - tmp[11] = PCM_Buffer[i+6]; - memcpy(&PCM_Buffer[i], tmp, 12); - } - } - } -} - -#define DEMUX_MPA_AAC(fp) \ -do { \ - if (SystemStream_Flag == TRANSPORT_STREAM && TransportPacketSize == 204) \ - Packet_Length -= 16; \ - while (Packet_Length > 0) \ - { \ - if (Packet_Length+Rdptr > BUFFER_SIZE+Rdbfr) \ - { \ - fwrite(Rdptr, BUFFER_SIZE+Rdbfr-Rdptr, 1, (fp)); \ - Packet_Length -= BUFFER_SIZE+Rdbfr-Rdptr; \ - Read = _donread(Infile[CurrentFile], Rdbfr, BUFFER_SIZE); \ - if (Read < BUFFER_SIZE) Next_File(); \ - Rdptr = Rdbfr; \ - } \ - else \ - { \ - fwrite(Rdptr, Packet_Length, 1, (fp)); \ - Rdptr += Packet_Length; \ - Packet_Length = 0; \ - } \ - } \ -} while( 0 ) - -#define DEMUX_DTS \ -{ \ - if (SystemStream_Flag == TRANSPORT_STREAM && TransportPacketSize == 204) \ - Packet_Length -= 16; \ - while (Packet_Length > 0) \ - { \ - if (Packet_Length+Rdptr > BUFFER_SIZE+Rdbfr) \ - { \ - fwrite(Rdptr, BUFFER_SIZE+Rdbfr-Rdptr, 1, audio[AUDIO_ID].file); \ - Packet_Length -= BUFFER_SIZE+Rdbfr-Rdptr; \ - Read = _donread(Infile[CurrentFile], Rdbfr, BUFFER_SIZE); \ - if (Read < BUFFER_SIZE) Next_File(); \ - Rdptr = Rdbfr; \ - } \ - else \ - { \ - fwrite(Rdptr, Packet_Length, 1, audio[AUDIO_ID].file); \ - Rdptr += Packet_Length; \ - Packet_Length = 0; \ - } \ - } \ -} - -static char *FTType[5] = { - "48KHz", "44.1KHz", "44.1KHz", "44.1KHz", "44.1KHz" -}; - -static char *AC3ModeDash[8] = { - "1+1", "1_0", "2_0", "3_0", "2_1", "3_1", "2_2", "3_2" -}; - -static char *AC3Mode[8] = { - "1+1", "1/0", "2/0", "3/0", "2/1", "3/1", "2/2", "3/2" -}; - -static int AC3Rate[32] = { - 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, - 192, 224, 256, 320, 384, 448, 512, 576, 640, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -static char *MPALayer[4] = { - "", "L3", "L2", "L1" -}; - -static char *MPAExtension[4] = { - "mpa", "mp3", "mp2", "mp1" -}; - -static char *MPAMode[4] = { - "2ch", "2ch", "2ch", "mono" -}; - -static char *MPASample[3] = { - "44.1", "48", "32" -}; - -static char *MPARate[4][15] = { - { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" }, // Layer reserved - { "free", "32", "40", "48", "56", "64", "80", "96", "112", "128", "160", "192", "224", "256", "320" }, // Layer 3 - { "free", "32", "48", "56", "64", "80", "96", "112", "128", "160", "192", "224", "256", "320", "384" }, // Layer 2 - { "free", "32", "64", "96", "128", "160", "192", "224", "256", "288", "320", "352", "384", "416", "448" } // Layer 1 -}; - -int check_audio_packet_continue = 0; -unsigned int num_pmt_pids = 0; - -__int64 VideoPTS, AudioPTS, LastVideoPTS; -static unsigned char PCM_Buffer[SECTOR_SIZE]; -static short *ptrPCM_Buffer = (short*)PCM_Buffer; - -unsigned char *buffer_invalid; - -void VideoDemux(void); - -void Initialize_Buffer() -{ - Rdptr = Rdbfr + BUFFER_SIZE; - Rdmax = Rdptr; - buffer_invalid = (unsigned char *) 0xffffffff; - - if (SystemStream_Flag != ELEMENTARY_STREAM && !AudioOnly_Flag) - { - if (Rdptr >= Rdmax) - Next_Packet(); - CurrentBfr = *Rdptr++ << 24; - - if (Rdptr >= Rdmax) - Next_Packet(); - CurrentBfr += *Rdptr++ << 16; - - if (Rdptr >= Rdmax) - Next_Packet(); - CurrentBfr += *Rdptr++ << 8; - - if (Rdptr >= Rdmax) - Next_Packet(); - CurrentBfr += *Rdptr++; - - Fill_Next(); - } - else - { - Fill_Buffer(); - - CurrentBfr = (*Rdptr << 24) + (*(Rdptr+1) << 16) + (*(Rdptr+2) << 8) + *(Rdptr+3); - Rdptr += 4; - - Fill_Next(); - } - - BitsLeft = 32; -} - -// Skips ahead in transport stream by specified number of bytes. -#define SKIP_TRANSPORT_PACKET_BYTES(bytes_to_skip) \ -do { \ - int temp = (bytes_to_skip); \ - while (temp > 0) \ - { \ - if (temp + Rdptr > BUFFER_SIZE + Rdbfr) \ - { \ - temp -= BUFFER_SIZE + Rdbfr - Rdptr; \ - Read = _donread(Infile[CurrentFile], Rdbfr, BUFFER_SIZE); \ - if (Read < BUFFER_SIZE) Next_File(); \ - Rdptr = Rdbfr; \ - } \ - else \ - { \ - Rdptr += temp; \ - temp = 0; \ - } \ - } \ - Packet_Length -= (bytes_to_skip); \ -} while (0) - -#define GET_PES_TIMESTAMP(ts, b1, b2, b3, b4, b5) \ -do { \ - ts = (__int64) (b1 & 0x0e) << 29 \ - | (b2 ) << 22 \ - | (b3 & 0xfe) << 14 \ - | (b4 ) << 7 \ - | (b5 ) >> 1; \ -} while (0) - -// Transport packet data structure. -typedef struct -{ - // 1 byte - unsigned char sync_byte; // 8 bits - - // 2 bytes - unsigned char transport_error_indicator; // 1 bit - unsigned char payload_unit_start_indicator; // 1 bit - unsigned char transport_priority; // 1 bit - unsigned short pid; // 13 bits - - // 1 byte - unsigned char transport_scrambling_control; // 2 bits - unsigned char adaptation_field_control; // 2 bits - unsigned char continuity_counter; // 4 bits - - // 1 byte - unsigned char adaptation_field_length; // 8 bits - - // 1 byte - unsigned char discontinuity_indicator; // 1 bit - unsigned char random_access_indicator; // 1 bit - unsigned char elementary_stream_priority_indicator; // 1 bit - unsigned char PCR_flag; // 1 bit - unsigned char OPCR_flag; // 1 bit - unsigned char splicing_point_flag; // 1 bit - unsigned char transport_private_data_flag; // 1 bit - unsigned char adaptation_field_extension_flag; // 1 bit -} transport_packet; - -transport_packet tp_zeroed = { 0 }; - -FILE *mpafp = NULL; -FILE *mpvfp = NULL; -FILE *pcmfp = NULL; - -// ATSC transport stream parser. -// We ignore the 'continuity counter' because with some DTV -// broadcasters, this isnt a reliable indicator. -void Next_Transport_Packet() -{ - static int i, Packet_Length, Packet_Header_Length, size; - static unsigned int code, flags, VOBCELL_Count, AUDIO_ID = 0; - __int64 PES_PTS, PES_DTS; - __int64 pts_stamp = 0, dts_stamp = 0; - int PTSDiff; - unsigned int bytes_left; - transport_packet tp; - unsigned int time; - double picture_period; - char ext[4], EXT[4]; - - static unsigned int prev_code; - bool pmt_check = false; - unsigned int check_num_pmt = 0; - unsigned int time_limit = 5000; -#ifdef _DEBUG - time_limit = 300000; /* Change 5 minutes. */ -#endif - - start = timeGetTime(); - for (;;) - { - PES_PTS = 0; - bytes_left = 0; - Packet_Length = TransportPacketSize; // total length of an MPEG-2 transport packet - tp = tp_zeroed; // to avoid warnings - - // If the packet size is 192, then assume it is an M2TS (blueray) file, which has 4 extra bytes - // in front of the sync byte. - if (TransportPacketSize == 192) - { - // Suck up the extra bytes. - Get_Byte(); - Get_Byte(); - Get_Byte(); - Get_Byte(); - Packet_Length -= 4; - } -retry_sync: - // Don't loop forever. If we don't get data - // in a reasonable time (5 secs) we exit. - time = timeGetTime(); - if (time - start > time_limit) - { - MessageBox(hWnd, "Cannot find audio or video data. Ensure that your PIDs\nare set correctly in the Stream menu. Refer to the\nUsers Manual for details.", - NULL, MB_OK | MB_ICONERROR); - ThreadKill(MISC_KILL); - } - else if ((Start_Flag || process.locate == LOCATE_SCROLL) && !pmt_check && time - start > 500) - { - pat_parser.InitializePMTCheckItems(); - pmt_check = true; - } - - // Search for a sync byte. Gives some protection against emulation. - if (Stop_Flag) - ThreadKill(MISC_KILL); - if (Get_Byte() != 0x47) - goto retry_sync; - if (Rdptr - Rdbfr > TransportPacketSize) - { - if (Rdptr[-(TransportPacketSize+1)] != 0x47) - goto retry_sync; - } - else if (Rdbfr + Read - Rdptr > TransportPacketSize - 1) - { - if (Rdptr[+(TransportPacketSize-1)] != 0x47) - goto retry_sync; - } - else - { - // We can't check so just accept this sync byte. - } - - // Record the location of the start of the packet. This will be used - // for indexing when an I frame is detected. - if (D2V_Flag) - { - PackHeaderPosition = _telli64(Infile[CurrentFile]) - - (__int64)BUFFER_SIZE + (__int64)Rdptr - (__int64)Rdbfr - 1; - } - // For M2TS (blueray) files, index the extra 4 bytes in front of the sync byte, - // because DGDecode will expect to see them. - if (TransportPacketSize == 192) - PackHeaderPosition -= 4; - --Packet_Length; // swallow the sync_byte - - code = Get_Short(); - Packet_Length = Packet_Length - 2; // swallow the two bytes we just got - tp.pid = (unsigned short) (code & 0x1FFF); - tp.transport_error_indicator = (unsigned char) ((code >> 15) & 0x01); - tp.payload_unit_start_indicator = (unsigned char) ((code >> 14) & 0x01); - tp.transport_priority = (unsigned char) ((code >> 13) & 0x01); - - if (tp.transport_error_indicator) - { - // Skip remaining bytes in current packet. - SKIP_TRANSPORT_PACKET_BYTES(Packet_Length); - // Try the next packet in the stream. - continue; - } - - code = Get_Byte(); - --Packet_Length; // decrement the 1 byte we just got; - tp.transport_scrambling_control = (unsigned char) ((code >> 6) & 0x03);// 2 bslbf - tp.adaptation_field_control = (unsigned char) ((code >> 4 ) & 0x03);// 2 bslbf - tp.continuity_counter = (unsigned char) (code & 0x0F);// 4 uimsbf - - // we don't care about the continuity counter - - if (tp.adaptation_field_control == 0) - { - // no payload - // skip remaining bytes in current packet - SKIP_TRANSPORT_PACKET_BYTES(Packet_Length); - continue; - } - - // 3) check the Adaptation-header, only so we can determine - // the exact #bytes to skip - if ( tp.adaptation_field_control == 2 || tp.adaptation_field_control == 3) - { - // adaptation field is present - tp.adaptation_field_length = (unsigned char) Get_Byte(); // 8-bits - --Packet_Length; // decrement the 1 byte we just got; - - if ( tp.adaptation_field_length != 0 ) // end of field already? - { - code = Get_Byte(); - --Packet_Length; // decrement the 1 byte we just got; - tp.discontinuity_indicator = (unsigned char) ((code >> 7) & 0x01); // 1 bslbf - tp.random_access_indicator = (unsigned char) ((code >> 6) & 0x01); // 1 bslbf - tp.elementary_stream_priority_indicator = (unsigned char) ((code >> 5) & 0x01); // 1 bslbf - tp.PCR_flag = (unsigned char) ((code >> 4) & 0x01); // 1 bslbf - tp.OPCR_flag = (unsigned char) ((code >> 3) & 0x01); // 1 bslbf - tp.splicing_point_flag = (unsigned char) ((code >> 2) & 0x01); // 1 bslbf - tp.transport_private_data_flag = (unsigned char) ((code >> 1) & 0x01); // 1 bslbf - tp.adaptation_field_extension_flag = (unsigned char) ((code >> 0) & 0x01); // 1 bslbf - bytes_left = tp.adaptation_field_length - 1; - if (LogTimestamps_Flag && D2V_Flag && tp.PCR_flag && tp.pid == MPEG2_Transport_PCRPID && StartLogging_Flag) - { - __int64 PCR, PCRbase, PCRext, tmp; - char pcr[64]; - - tmp = (__int64) Get_Byte(); - PCRbase = tmp << 25; - tmp = (__int64) Get_Byte(); - PCRbase |= tmp << 17; - tmp = (__int64) Get_Byte(); - PCRbase |= tmp << 9; - tmp = (__int64) Get_Byte(); - PCRbase |= tmp << 1; - tmp = (__int64) Get_Byte(); - PCRbase |= tmp >> 7; - PCRext = (tmp & 0x01) << 8; - tmp = (__int64) Get_Byte(); - PCRext |= tmp; - PCR = 300 * PCRbase + PCRext; - _i64toa(PCR, pcr, 10); - fprintf(Timestamps, "PCR %s ", pcr); - _i64toa(PCR/27000, pcr, 10); - bytes_left -= 6; - Packet_Length -= 6; - fprintf(Timestamps, "[%sms]\n", pcr); - } - - // skip the remainder of the adaptation_field - SKIP_TRANSPORT_PACKET_BYTES(bytes_left); - } // if ( tp.adaptation_field_length != 0 ) - } // if ( tp.adaptation_field_control != 1 ) - - // We've processed the MPEG-2 transport header. - // Any data left in the current transport packet? - if (Packet_Length == 0) - continue; - - if (tp.pid && tp.pid == MPEG2_Transport_VideoPID) - { - LOCATE - - if (tp.payload_unit_start_indicator) - { - Get_Short(); - Get_Short(); - Get_Short(); // MPEG2-PES total Packet_Length - Get_Byte(); // skip a byte - flags = Get_Byte(); - Packet_Header_Length = Get_Byte(); - Packet_Length = Packet_Length - 9; // compensate the bytes we extracted - - // Get timestamp, and skip rest of PES-header. - if ((flags & 0x80) && (Packet_Header_Length > 4)) - { - GET_PES_TIMESTAMP(PES_PTS, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - pts_stamp = PES_PTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, "V PTS %lld [%lldms]\n", pts_stamp, pts_stamp/90); - Packet_Length -= 5; - // DTS is not used. The code is here for analysis and debugging. - if ((flags & 0xc0) == 0xc0) - { - GET_PES_TIMESTAMP(PES_DTS, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - dts_stamp = PES_DTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, "V DTS %lld [%lldms]\n", dts_stamp, dts_stamp/90); - Packet_Length -= 5; - SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length - 10); - } - else - SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length - 5); - } - else - SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length); - if (!Start_Flag) - { - // Start_Flag becomes true after the first I frame. - // So VideoPTS will be left at the value corresponding to - // the first I frame. - VideoPTS = pts_stamp; - } - LastVideoPTS = pts_stamp; - } - - Rdmax = Rdptr + Packet_Length; - if (TransportPacketSize == 204) - Rdmax -= 16; - - Bitrate_Monitor += (Rdmax - Rdptr); - if (AudioOnly_Flag) - SKIP_TRANSPORT_PACKET_BYTES(Packet_Length); - return; - } - - else if ((Method_Flag == AUDIO_DEMUXALL || Method_Flag == AUDIO_DEMUX) && Start_Flag && - tp.pid && (tp.pid == MPEG2_Transport_AudioPID) && - (MPEG2_Transport_AudioType == 3 || MPEG2_Transport_AudioType == 4 || MPEG2_Transport_AudioType == 0xffffffff)) - { - // Both MPEG and AAC audio come here. The sync word will be checked to - // distinguish between them. - if (mpafp) - { - if (tp.payload_unit_start_indicator) - { - Get_Short(); // start code and stream id - Get_Short(); - Get_Short(); // packet length - Get_Byte(); // flags - code = Get_Byte(); // more flags - Packet_Header_Length = Get_Byte(); - Packet_Length -= 9; - if (code & 0x80) - { -// unsigned int dts_stamp; - code = Get_Byte(); - GET_PES_TIMESTAMP(PES_PTS, code, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - AudioPTS = PES_PTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, " A00 PTS %lld [%lldms]\n", AudioPTS, AudioPTS/90); - Packet_Length -= 5; -#if 0 - if ((code & 0xc0) == 0xc0) - { - GET_PES_TIMESTAMP(PES_DTS, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - dts_stamp = PES_DTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, "A DTS %lld [%lldms]\n", dts_stamp, dts_stamp/90); - Packet_Length -= 5; - SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length - 10); - } - else -#endif - SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length-5); - } - else - SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length); - } - DEMUX_MPA_AAC(mpafp); - } - else if (!(tp.payload_unit_start_indicator) && check_audio_packet_continue) - { - check_audio_packet_continue = 0; - code = prev_code; - goto emulated3; - } - else if (tp.payload_unit_start_indicator) - { - check_audio_packet_continue = 0; - Get_Short(); // start code - Get_Short(); // rest of start code and stream id - Get_Short(); // packet length - Get_Byte(); // flags - code = Get_Byte(); // more flags - Packet_Header_Length = Get_Byte(); - Packet_Length -= 9; - if (code & 0x80) - { -// unsigned int dts_stamp; - code = Get_Byte(); - GET_PES_TIMESTAMP(PES_PTS, code, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - AudioPTS = PES_PTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, " A00 PTS %lld [%lldms]\n", AudioPTS, AudioPTS/90); - Packet_Length = Packet_Length - 5; -#if 0 - if ((code & 0xc0) == 0xc0) - { - GET_PES_TIMESTAMP(PES_DTS, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - dts_stamp = PES_DTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, "A DTS %lld [%lldms]\n", dts_stamp, dts_stamp/90); - Packet_Length -= 5; - SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length - 10); - } - else -#endif - SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length-5); - - // Now we're at the start of the audio. - // Find the audio header. - code = (Get_Byte() << 24) | (Get_Byte() << 16) | (Get_Byte() << 8) | Get_Byte(); - Packet_Length -= 4; - while ((code & 0xfff80000) != 0xfff80000 && Packet_Length > 0) - { -emulated3: - code = (code << 8) | Get_Byte(); - Packet_Length--; - } - if ((code & 0xfff80000) != 0xfff80000) - { - SKIP_TRANSPORT_PACKET_BYTES(Packet_Length); - check_audio_packet_continue = 1; - prev_code = code; - continue; - } - if ((MPEG2_Transport_AudioType == 4) && ((code & 0xfffe0000) != 0xfff80000)) - { - goto emulated3; - } - // Found the audio header. Now check the layer field. - // For MPEG, layer is 1, 2, or 3. For AAC, it is 0. - // We demux the same for both; only the filename we create is different. - if (((code >> 17) & 3) == 0x00) - { - // AAC audio. - if (check_adts_aac_header((code >> 17) & 3, (code >> 14) & 3, (code >> 10) & 0xf)) - { - goto emulated3; - } - audio[0].type = FORMAT_AAC; - } - else - { - // MPEG audio. - // Try to detect emulated sync words by enforcing semantics. - if (check_audio_syncword(0, (code >> 17) & 3, (code >> 12) & 0xf, (code >> 10) & 3, (code >> 6) & 3, code & 3)) - { - goto emulated3; - } - audio[0].type = FORMAT_MPA; - } - if (AudioOnly_Flag) - { - char *p; - strcpy(szOutput, Infilename[0]); - p = &szOutput[sizeof(szOutput)]; - while (*p != '.') p--; - *p = 0; - if (audio[0].type == FORMAT_AAC) - sprintf(szBuffer, "%s PID %03x.aac", szOutput, MPEG2_Transport_AudioPID); - else - sprintf(szBuffer, "%s PID %03x %s %s %s %s.%s", szOutput, MPEG2_Transport_AudioPID, - MPALayer[audio[0].layer], MPAMode[audio[0].mode], MPASample[audio[0].sample], - MPARate[audio[0].layer][audio[0].rate], - UseMPAExtensions ? MPAExtension[0] : MPAExtension[audio[0].layer]); - } - else - { - // Adjust the VideoPTS to account for frame reordering. - if (!PTSAdjustDone) - { - PTSAdjustDone = 1; - picture_period = 1.0 / frame_rate; - VideoPTS -= (int) (LeadingBFrames * picture_period * 90000); - } - - if (PTSDifference(AudioPTS, VideoPTS, &PTSDiff)) - { - if (audio[0].type == FORMAT_AAC) - sprintf(szBuffer, "%s PID %03x.aac", szOutput, MPEG2_Transport_AudioPID); - else - sprintf(szBuffer, "%s PID %03x %s %s %s %s.%s", szOutput, MPEG2_Transport_AudioPID, - MPALayer[audio[0].layer], MPAMode[audio[0].mode], MPASample[audio[0].sample], - MPARate[audio[0].layer][audio[0].rate], - UseMPAExtensions ? MPAExtension[0] : MPAExtension[audio[0].layer]); - } - else - { - if (audio[0].type == FORMAT_AAC) - sprintf(szBuffer, "%s PID %03x DELAY %dms.aac", szOutput, MPEG2_Transport_AudioPID, PTSDiff); - else - sprintf(szBuffer, "%s PID %03x %s %s %s %s DELAY %dms.%s", szOutput, MPEG2_Transport_AudioPID, - MPALayer[audio[0].layer], MPAMode[audio[0].mode], MPASample[audio[0].sample], - MPARate[audio[0].layer][audio[0].rate], PTSDiff, - UseMPAExtensions ? MPAExtension[0] : MPAExtension[audio[0].layer]); - } - } - if (D2V_Flag || AudioOnly_Flag) - { - mpafp = OpenAudio(szBuffer, "wb", 0); - if (mpafp == NULL) - { - // Cannot open the output file, Disable further audio processing. - MPEG2_Transport_AudioType = 0xff; - SKIP_TRANSPORT_PACKET_BYTES(Packet_Length); - continue; - } - fputc((code >> 24) & 0xff, mpafp); - fputc((code >> 16) & 0xff, mpafp); - fputc((code >> 8) & 0xff, mpafp); - fputc((code ) & 0xff, mpafp); - DEMUX_MPA_AAC(mpafp); - } - } - } - if (AudioOnly_Flag && Info_Flag && !(AudioPktCount++ % 128)) - UpdateInfo(); - } - - else if ((Method_Flag == AUDIO_DEMUXALL || Method_Flag == AUDIO_DEMUX) && Start_Flag && - tp.pid && (tp.pid == MPEG2_Transport_AudioPID) && (MPEG2_Transport_AudioType == 0x80)) - { - if (pcmfp) - { - if (tp.payload_unit_start_indicator) - { - Get_Short(); // start code and stream id - Get_Short(); - Get_Short(); // packet length - Get_Byte(); // flags - code = Get_Byte(); // more flags - Packet_Header_Length = Get_Byte(); - Packet_Length -= 9; - if (code & 0x80) - { - code = Get_Byte(); - GET_PES_TIMESTAMP(PES_PTS, code, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - AudioPTS = PES_PTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, " A00 PTS %lld [%lldms]\n", AudioPTS, AudioPTS/90); - Packet_Length -= 5; - SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length-5); - } - else - SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length); - // Now we're at the start of the audio. - code = Get_Byte(); - code = Get_Byte(); - audio[0].format_m2ts = Get_Short(); - Packet_Length -= 4; - } - DEMUX_MPA_AAC(pcmfp); - } - else if (tp.payload_unit_start_indicator) - { - audio[0].type = FORMAT_LPCM_M2TS; - strcpy(ext, "pcm"); - strcpy(EXT, "pcm"); - _strupr(EXT); - Get_Short(); // start code - Get_Short(); // rest of start code and stream id - Get_Short(); // packet length - Get_Byte(); // flags - code = Get_Byte(); // more flags - Packet_Header_Length = Get_Byte(); - Packet_Length -= 9; - if (code & 0x80) - { - code = Get_Byte(); - GET_PES_TIMESTAMP(PES_PTS, code, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - AudioPTS = PES_PTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, " A00 PTS %lld [%lldms]\n", AudioPTS, AudioPTS/90); - Packet_Length = Packet_Length - 5; - SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length-5); - - // Now we're at the start of the audio. - code = Get_Byte(); - code = Get_Byte(); - audio[0].format_m2ts = Get_Short(); - Packet_Length -= 4; - - if (AudioOnly_Flag) - { - char *p; - strcpy(szOutput, Infilename[0]); - p = &szOutput[sizeof(szOutput)]; - while (*p != '.') p--; - *p = 0; - sprintf(szBuffer, "%s %s PID %03x.%s", szOutput, EXT, MPEG2_Transport_AudioPID, ext); - } - else - { - // Adjust the VideoPTS to account for frame reordering. - if (!PTSAdjustDone) - { - PTSAdjustDone = 1; - picture_period = 1.0 / frame_rate; - VideoPTS -= (int) (LeadingBFrames * picture_period * 90000); - } - - if (PTSDifference(AudioPTS, VideoPTS, &PTSDiff)) - sprintf(szBuffer, "%s %s PID %03x.%s", - szOutput, EXT, MPEG2_Transport_AudioPID, ext); - else - sprintf(szBuffer, "%s %s PID %03x DELAY %dms.%s", - szOutput, EXT, MPEG2_Transport_AudioPID, PTSDiff, ext); - } - if (D2V_Flag || AudioOnly_Flag) - { - pcmfp = OpenAudio(szBuffer, "wb", 0); - if (pcmfp == NULL) - { - // Cannot open the output file, Disable further audio processing. - MPEG2_Transport_AudioType = 0xff; - SKIP_TRANSPORT_PACKET_BYTES(Packet_Length); - continue; - } - DEMUX_MPA_AAC(pcmfp); - } - } - } - if (AudioOnly_Flag && Info_Flag && !(AudioPktCount++ % 128)) - UpdateInfo(); - } - - else if (tp.pid && tp.pid == MPEG2_Transport_AudioPID && (MPEG2_Transport_AudioType == 0x81)) - { - // We are demuxing AC3 audio. - // search for an MPEG-PES packet header - if (tp.random_access_indicator || tp.payload_unit_start_indicator ) - { - LOCATE - - code = Get_Short(); - code = (code & 0xffff)<<16 | Get_Short(); - Packet_Length = Packet_Length - 4; // remove these two bytes - - // Check for MPEG2-PES packet header. This may contains a PTS. - if ((TransportPacketSize != 192 && code != PRIVATE_STREAM_1) || - (TransportPacketSize == 192 && (code != BLURAY_STREAM_1 && code != PRIVATE_STREAM_1))) - { - // No, move the buffer-pointer back. - Rdptr -= 4; - Packet_Length = Packet_Length + 4; - } - else - { - // YES, pull out PTS - //Packet_Length = Get_Short(); - Get_Short(); // MPEG2-PES total Packet_Length - Get_Byte(); // skip a byte - - code = Get_Byte(); - Packet_Header_Length = Get_Byte(); - Packet_Length = Packet_Length - 5; // compensate the bytes we extracted - - // get PTS, and skip rest of PES-header - if (code >= 0x80 && Packet_Header_Length > 4 ) - { -// unsigned int dts_stamp; - code = Get_Byte(); - GET_PES_TIMESTAMP(PES_PTS, code, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - AudioPTS = PES_PTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, " A00 PTS %lld [%lldms]\n", AudioPTS, AudioPTS/90); - Packet_Length = Packet_Length - 5; -#if 0 - if ((code & 0xc0) == 0xc0) - { - GET_PES_TIMESTAMP(PES_DTS, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - dts_stamp = PES_DTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, "A DTS %lld [%lldms]\n", dts_stamp, dts_stamp/90); - Packet_Length -= 5; - SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length - 10); - } - else -#endif - SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length - 5); - } - else - SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length); - } - } - - // Done processing the MPEG-2 PES header, now for the *real* audio-data - - LOCATE - // if this is the *first* observation, we will seek to the - // first valid AC3-frame, then decode its header. - // We tried checking for tp.payload_unit_start_indicator, but this - // indicator isn't reliable on a lot of DTV-stations! - // Instead, we'll manually search for an AC3-sync word. - if (!audio[0].rip && Start_Flag && !audio[0].type && - (tp.random_access_indicator || tp.payload_unit_start_indicator) - && Packet_Length > 5 ) - { - code = Get_Byte(); - code = (code & 0xff)<<8 | Get_Byte(); - Packet_Length = Packet_Length - 2; // remove these two bytes - - // search for an AC3-sync word. We wouldn't have to do this if - // DTV-stations made proper use of tp.payload_unit_start_indicator; -#if 0 - if (tp.payload_unit_start_indicator) - { - MessageBox(hWnd, "This is a harmless condition but I want to know if it\n" - "ever occurs. Please email me at neuron2@comcast.net to inform\n" - "me that you saw this message box. Thank you.", - "Please tell me about this!", MB_OK | MB_ICONINFORMATION); - } -#endif - while (code != 0xb77 && Packet_Length > 0) - { - -oops2: - code = (code & 0xff)<<8 | Get_Byte(); - --Packet_Length; - } - - if ( code != 0xb77 ) // did we find the sync-header? - { - // no, we searched the *ENTIRE* transport-packet and came up empty! - SKIP_TRANSPORT_PACKET_BYTES(Packet_Length); - continue; - } - - // First time that we detected this particular channel? yes - audio[0].type = FORMAT_AC3; - - //Packet_Length = Packet_Length - 5; // remove five bytes - Get_Short(); - audio[0].rate = (Get_Byte()>>1) & 0x1f; - if (audio[0].rate > 0x12) - goto oops2; - Get_Byte(); - audio[0].mode = (Get_Byte()>>5) & 0x07; - //Packet_Length = Packet_Length + 5; // restore these five bytes - Rdptr -= 5; // restore these five bytes - - // ok, now move "backward" by two more bytes, so we're back at the - // start of the AC3-sync header - - Packet_Length += 2; - Rdptr -= 2; - - if (D2V_Flag || Decision_Flag || AudioOnly_Flag) - { - // For transport streams, the audio is always track 1. - if (Decision_Flag && audio[0].selected_for_demux == true) - { - InitialAC3(); - - DECODE_AC3 - - audio[0].rip = 1; - } - else if (Method_Flag==AUDIO_DECODE && audio[0].selected_for_demux == true) - { - InitialAC3(); - - sprintf(szBuffer, "%s PID %03x %sch %dKbps %s.wav", szOutput, MPEG2_Transport_AudioPID, - AC3ModeDash[audio[0].mode], AC3Rate[audio[0].rate], FTType[SRC_Flag]); - - strcpy(audio[0].filename, szBuffer); - audio[0].file = OpenAudio(szBuffer, "wb", 0); - if (audio[0].file == NULL) - { - // Cannot open the output file, Disable further audio processing. - MPEG2_Transport_AudioType = 0xff; - SKIP_TRANSPORT_PACKET_BYTES(Packet_Length); - continue; - } - - StartWAV(audio[0].file, 0x01); // 48K, 16bit, 2ch - - // Adjust the VideoPTS to account for frame reordering. - if (!PTSAdjustDone) - { - PTSAdjustDone = 1; - picture_period = 1.0 / frame_rate; - VideoPTS -= (int) (LeadingBFrames * picture_period * 90000); - } - - if (PTSDifference(AudioPTS, VideoPTS, &PTSDiff)) - audio[0].delay = 0; - else - audio[0].delay = PTSDiff * 192; - - if (SRC_Flag) - { - DownWAV(audio[0].file); - InitialSRC(); - } - - if (audio[0].delay > 0) - { - if (SRC_Flag) - audio[0].delay = ((int)(0.91875*audio[0].delay)>>2)<<2; - - for (i=0; i size) - audio[0].delay += size; - else - { - if (SRC_Flag) - Wavefs44(audio[0].file, size+audio[0].delay, AC3Dec_Buffer-audio[0].delay); - else - fwrite(AC3Dec_Buffer-audio[0].delay, size+audio[0].delay, 1, audio[0].file); - - audio[0].size += size+audio[0].delay; - audio[0].delay = 0; - } - - audio[0].rip = 1; - } - else if (Method_Flag == AUDIO_DEMUXALL || (Method_Flag==AUDIO_DEMUX && audio[0].selected_for_demux == true)) - { - if (AudioOnly_Flag) - { - char *p; - strcpy(szOutput, Infilename[0]); - p = &szOutput[sizeof(szOutput)]; - while (*p != '.') p--; - *p = 0; - sprintf(szBuffer, "%s PID %03x %sch %dKbps.ac3", szOutput, MPEG2_Transport_AudioPID, - AC3ModeDash[audio[0].mode], AC3Rate[audio[0].rate]); - } - else - { - // Adjust the VideoPTS to account for frame reordering. - if (!PTSAdjustDone) - { - PTSAdjustDone = 1; - picture_period = 1.0 / frame_rate; - VideoPTS -= (int) (LeadingBFrames * picture_period * 90000); - } - - if (PTSDifference(AudioPTS, VideoPTS, &PTSDiff)) - sprintf(szBuffer, "%s PID %03x %sch %dKbps.ac3", szOutput, MPEG2_Transport_AudioPID, - AC3ModeDash[audio[0].mode], AC3Rate[audio[0].rate]); - else - sprintf(szBuffer, "%s PID %03x %sch %dKbps DELAY %dms.ac3", szOutput, MPEG2_Transport_AudioPID, - AC3ModeDash[audio[0].mode], AC3Rate[audio[0].rate], PTSDiff); - } - - audio[0].file = OpenAudio(szBuffer, "wb", 0); - if (audio[0].file == NULL) - { - // Cannot open the output file, Disable further audio processing. - MPEG2_Transport_AudioType = 0xff; - SKIP_TRANSPORT_PACKET_BYTES(Packet_Length); - continue; - } - - DEMUX_AC3 - - audio[0].rip = 1; - } - } - } - else if (audio[0].rip) - { -// NOT WORKING YET -- DO NOT ENABLE THIS CODE! -//#define DETECT_AC3_MODE_CHANGE -#ifdef DETECT_AC3_MODE_CHANGE - if (tp.payload_unit_start_indicator && Rdptr < Rdbfr + BUFFER_SIZE - 20) - { - unsigned char *ptr = Rdptr; - code = Get_Byte(); - code = (code & 0xff)<<8 | Get_Byte(); - if (code == 0xb77) // did we find the sync-header? - { - unsigned char tmp1, tmp2; - Get_Short(); - tmp1 = (Get_Byte()>>1) & 0x1f; - Get_Byte(); - tmp2 = (Get_Byte()>>5) & 0x07; - if (audio[0].rate != tmp1 || audio[0].mode != tmp2) - { - sprintf(szBuffer, - "Audio format changed from AC3 %s %d to AC3 %s %d.\n" - "You should revise your project range so that it does\n" - "not include an audio format change.", - AC3Mode[ac3[0].mode], AC3Rate[ac3[0].rate], AC3Mode[tmp2], AC3Rate[tmp1]); - MessageBox(hWnd, szBuffer, "Warning: Audio format changed", MB_OK | MB_ICONWARNING); - } - audio[0].rate = tmp1; - audio[0].mode = tmp2; - Rdptr -= 5; // restore 5 bytes - } - Rdptr -= 2; // restore 2 bytes -#if 0 - if (Rdptr != ptr) - { - _lseek(Infile[CurrentFile], -BUFFER_SIZE, SEEK_CUR); - _donread(Infile[CurrentFile], Rdbfr, BUFFER_SIZE); - Rdptr = ptr; - } -#endif - } -#endif - if (Decision_Flag) - DECODE_AC3 - else if (Method_Flag==AUDIO_DECODE) - { - DECODE_AC3 - - if (-audio[0].delay > size) - audio[0].delay += size; - else - { - if (SRC_Flag) - Wavefs44(audio[0].file, size+audio[0].delay, AC3Dec_Buffer-audio[0].delay); - else - fwrite(AC3Dec_Buffer-audio[0].delay, size+audio[0].delay, 1, audio[0].file); - - audio[0].size += size+audio[0].delay; - audio[0].delay = 0; - } - } - else - { - DEMUX_AC3 - } - } - if (AudioOnly_Flag && Info_Flag && !(AudioPktCount++ % 128)) - UpdateInfo(); - } - else if ((Method_Flag == AUDIO_DEMUXALL || Method_Flag == AUDIO_DEMUX) && Start_Flag && - tp.pid && (tp.pid == MPEG2_Transport_AudioPID) && - (MPEG2_Transport_AudioType == 0xfe || MPEG2_Transport_AudioType == 0xffffffff)) - { - // We are demuxing DTS audio. - if (audio[0].file) - { - if (tp.payload_unit_start_indicator) - { - Get_Short(); // start code and stream id - Get_Short(); - Get_Short(); // packet length - Get_Byte(); // flags - code = Get_Byte(); // more flags - Packet_Header_Length = Get_Byte(); - Packet_Length -= 9; - if (code & 0x80) - { - code = Get_Byte(); - GET_PES_TIMESTAMP(PES_PTS, code, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - AudioPTS = PES_PTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, " A00 PTS %lld [%lldms]\n", AudioPTS, AudioPTS/90); - Packet_Length -= 5; - SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length-5); - } - } - DEMUX_DTS; - } - else if (tp.payload_unit_start_indicator) - { - Get_Short(); // start code - Get_Short(); // rest of start code and stream id - Get_Short(); // packet length - Get_Byte(); // flags - code = Get_Byte(); // more flags - Packet_Header_Length = Get_Byte(); - Packet_Length -= 9; - if (code & 0x80) - { - code = Get_Byte(); - GET_PES_TIMESTAMP(PES_PTS, code, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - AudioPTS = PES_PTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, " A00 PTS %lld [%lldms]\n", AudioPTS, AudioPTS/90); - Packet_Length = Packet_Length - 5; - SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length-5); - - // Now we're at the start of the audio. - audio[0].type = FORMAT_DTS; - - if (AudioOnly_Flag) - { - char *p; - strcpy(szOutput, Infilename[0]); - p = &szOutput[sizeof(szOutput)]; - while (*p != '.') p--; - *p = 0; - sprintf(szBuffer, "%s PID %03x.dts", szOutput, MPEG2_Transport_AudioPID); - } - else - { - // Adjust the VideoPTS to account for frame reordering. - if (!PTSAdjustDone) - { - PTSAdjustDone = 1; - picture_period = 1.0 / frame_rate; - VideoPTS -= (int) (LeadingBFrames * picture_period * 90000); - } - - if (PTSDifference(AudioPTS, VideoPTS, &PTSDiff)) - sprintf(szBuffer, "%s PID %03x.dts", szOutput, MPEG2_Transport_AudioPID); - else - sprintf(szBuffer, "%s PID %03x DELAY %dms.dts", szOutput, MPEG2_Transport_AudioPID, PTSDiff); - } - if (D2V_Flag || AudioOnly_Flag) - { - audio[0].file = OpenAudio(szBuffer, "wb", 0); - if (audio[0].file == NULL) - { - // Cannot open the output file, Disable further audio processing. - MPEG2_Transport_AudioType = 0xff; - SKIP_TRANSPORT_PACKET_BYTES(Packet_Length); - continue; - } - DEMUX_DTS; - } - } - } - if (AudioOnly_Flag && Info_Flag && !(AudioPktCount++ % 128)) - UpdateInfo(); - } - else if ((Start_Flag || process.locate == LOCATE_SCROLL) && pmt_check && num_pmt_pids) - { - if (!pat_parser.CheckPMTPid(tp.pid, check_num_pmt)) - { - static unsigned char pmt_packet_payload[192]; - int read_size = 0; - if (BUFFER_SIZE - (Rdptr - Rdbfr) < Packet_Length) - { - read_size = BUFFER_SIZE - (Rdptr - Rdbfr); - memcpy(pmt_packet_payload, Rdptr, read_size); - Rdptr += read_size; - LOCATE - } - memcpy(&(pmt_packet_payload[read_size]), Rdptr, Packet_Length - read_size); - Rdptr += Packet_Length - read_size; - read_size = Packet_Length; - Packet_Length = 0; - - int parse_pmt = pat_parser.CheckPMTSection(tp.pid, pmt_packet_payload, read_size, check_num_pmt); - if (parse_pmt > 0) - { - pat_parser.InitializePMTCheckItems(); - if (parse_pmt == 1) - { - pmt_check = false; - check_num_pmt = 0; - } - else - { - check_num_pmt++; - if (check_num_pmt >= num_pmt_pids) - { - ThreadKill(MISC_KILL); - } - } - } - } - } - // fallthrough case - // skip remaining bytes in current packet - SKIP_TRANSPORT_PACKET_BYTES(Packet_Length); - } -} - -// PVA packet data structure. -typedef struct -{ - unsigned short sync_byte; - unsigned char stream_id; - unsigned char counter; - unsigned char reserved; - unsigned char flags; - unsigned short length; -} pva_packet; - -// PVA transport stream parser. -void Next_PVA_Packet() -{ - unsigned int Packet_Length; - unsigned int time, start; - pva_packet pva; - unsigned int code, Packet_Header_Length; - __int64 PTS, PES_PTS; - int PTSDiff; - double picture_period; - - start = timeGetTime(); - for (;;) - { - // Don't loop forever. If we don't get data - // in a reasonable time (1 secs) we exit. - time = timeGetTime(); - if (time - start > 2000) - { - MessageBox(hWnd, "Cannot find video data.", NULL, MB_OK | MB_ICONERROR); - ThreadKill(MISC_KILL); - } - - // Search for a good sync. - for(;;) - { - if (Stop_Flag) - ThreadKill(MISC_KILL); - // Sync word is 0x4156. - if (Get_Byte() != 0x41) continue; - if (Get_Byte() != 0x56) - { - // This byte might be a 0x41, so back up by one. - Rdptr--; - continue; - } - // To protect against emulation of the sync word, - // also check that the stream says audio or video. - pva.stream_id = Get_Byte(); - if (pva.stream_id != 0x01 && pva.stream_id != 0x02) - { - // This byte might be a 0x41, so back up by one. - Rdptr--; - continue; - } - break; - } - - // Record the location of the start of the packet. This will be used - // for indexing when an I frame is detected. - if (D2V_Flag) - { - PackHeaderPosition = _telli64(Infile[CurrentFile]) - - (__int64)BUFFER_SIZE + (__int64)Rdptr - (__int64)Rdbfr - 3; - } - - // Pick up the remaining packet header fields. - pva.counter = Get_Byte(); - pva.reserved = Get_Byte(); - pva.flags = Get_Byte(); - pva.length = Get_Byte() << 8; - pva.length |= Get_Byte(); - Packet_Length = pva.length; - Rdmax = Rdptr + Packet_Length; - - // Any payload? - if (Packet_Length == 0 || pva.reserved != 0x55) - continue; // No, try the next packet. - - // Check stream id for video. - if (pva.stream_id == 1) - { - // This is a video packet. - // Extract the PTS if it exists. - if (pva.flags & 0x10) - { - PTS = (__int64) ((Get_Byte() << 24) | (Get_Byte() << 16) | (Get_Byte() << 8) | Get_Byte()); - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, "V PTS %lld [%lldms]\n", PTS, PTS/90); - Packet_Length -= 4; - if (pva.flags & 0x03) - { - // Suck up pre-bytes if any. - int i; - for (i = 0; i < (pva.flags & 0x03); i ++) - Get_Byte(); - Packet_Length -= i; - } - if (!Start_Flag) - { - VideoPTS = PTS; - } - LastVideoPTS = PTS; - } - - // Deliver the video to the ES parsing layer. - Bitrate_Monitor += (Rdmax - Rdptr); - if (AudioOnly_Flag) - SKIP_TRANSPORT_PACKET_BYTES(Packet_Length); - return; - } - - // Check stream id for audio. - else if ((Method_Flag == AUDIO_DEMUXALL || Method_Flag == AUDIO_DEMUX) && - Start_Flag && - pva.stream_id == 2) - { - // This is an audio packet. - if (mpafp) - { - // For audio, this flag bit means an embedded audio PES packet starts - // immediately in this PVA packet. - if (pva.flags & 0x10) - { - Get_Short(); // start code and stream id - Get_Short(); - Get_Short(); // packet length - Get_Byte(); // flags - code = Get_Byte(); // more flags - Packet_Header_Length = Get_Byte(); - Packet_Length -= 9; - if (code & 0x80) - { - code = Get_Byte(); - GET_PES_TIMESTAMP(PES_PTS, code, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - AudioPTS = PES_PTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, " A00 PTS %lld [%lldms]\n", AudioPTS, AudioPTS/90); - Packet_Length = Packet_Length - 5; - SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length-5); - } - } - DEMUX_MPA_AAC(mpafp); - } - else if (pva.flags & 0x10) - { - Get_Short(); // start code - Get_Short(); // rest of start code and stream id - Get_Short(); // packet length - Get_Byte(); // flags - code = Get_Byte(); // more flags - Packet_Header_Length = Get_Byte(); - Packet_Length -= 9; - if (code & 0x80) - { - code = Get_Byte(); - GET_PES_TIMESTAMP(PES_PTS, code, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - AudioPTS = PES_PTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, " A00 PTS %lld [%lldms]\n", AudioPTS, AudioPTS/90); - Packet_Length = Packet_Length - 5; - SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length-5); - // Now we're at the start of the audio. - // Find the audio header. - code = Get_Byte(); - code = ((code & 0xff) << 8) | Get_Byte(); - Packet_Length -= 2; - while ((code & 0xfff8) != 0xfff8 && Packet_Length > 0) - { -emulated0: - code = ((code & 0xff) << 8) | Get_Byte(); - Packet_Length--; - } - if ((code & 0xfff8) != 0xfff8) - { - SKIP_TRANSPORT_PACKET_BYTES(Packet_Length); - continue; - } - // Found the audio header. Now check the layer field. - // For MPEG, layer is 1, 2, or 3. For AAC, it is 0. - // We demux the same for both; only the file name we create is different. - if (((code & 6) >> 1) == 0x00) - { - // AAC audio. - audio[0].type = FORMAT_AAC; - } - else - { - // Try to detect emulated sync words by enforcing semantics. - if (check_audio_syncword(0, (code >> 1) & 3, (Rdptr[0] >> 4) & 0xf, (Rdptr[0] >> 2) & 3, (Rdptr[1] >> 6) & 3, Rdptr[1] & 3)) - { - goto emulated0; - } - - // MPEG audio. - audio[0].type = FORMAT_MPA; - } - - if (AudioOnly_Flag) - { - char *p; - strcpy(szOutput, Infilename[0]); - p = &szOutput[sizeof(szOutput)]; - while (*p != '.') p--; - *p = 0; - if (audio[0].type == FORMAT_AAC) - sprintf(szBuffer, "%s.aac", szOutput); - else - sprintf(szBuffer, "%s %s %s %s %s.%s", szOutput, - MPALayer[audio[0].layer], MPAMode[audio[0].mode], MPASample[audio[0].sample], - MPARate[audio[0].layer][audio[0].rate], - UseMPAExtensions ? MPAExtension[0] : MPAExtension[audio[0].layer]); - } - else - { - // Adjust the VideoPTS to account for frame reordering. && StartTemporalReference != -1 && StartTemporalReference < 18) - { - PTSAdjustDone = 1; - picture_period = 1.0 / frame_rate; - VideoPTS -= (int) (LeadingBFrames * picture_period * 90000); - } - - if (PTSDifference(AudioPTS, VideoPTS, &PTSDiff)) - { - if (audio[0].type == FORMAT_AAC) - sprintf(szBuffer, "%s.aac", szOutput); - else - sprintf(szBuffer, "%s %s %s %s %s.%s", szOutput, - MPALayer[audio[0].layer], MPAMode[audio[0].mode], MPASample[audio[0].sample], - MPARate[audio[0].layer][audio[0].rate], - UseMPAExtensions ? MPAExtension[0] : MPAExtension[audio[0].layer]); - } - else - { - if (audio[0].type == FORMAT_AAC) - sprintf(szBuffer, "%s DELAY %dms.aac", szOutput, PTSDiff); - else - sprintf(szBuffer, "%s %s %s %s %s DELAY %dms.%s", szOutput, - MPALayer[audio[0].layer], MPAMode[audio[0].mode], MPASample[audio[0].sample], - MPARate[audio[0].layer][audio[0].rate], PTSDiff, - UseMPAExtensions ? MPAExtension[0] : MPAExtension[audio[0].layer]); - } - } - - // Unread the audio header bytes. - Packet_Length += 2; - Rdptr -= 2; - if (D2V_Flag || AudioOnly_Flag) - { - mpafp = OpenAudio(szBuffer, "wb", 0); - if (mpafp == NULL) - { - // Cannot open the output file. - SKIP_TRANSPORT_PACKET_BYTES(Packet_Length); - continue; - } - DEMUX_MPA_AAC(mpafp); - } - } - } - if (AudioOnly_Flag && Info_Flag && !(AudioPktCount++ % 128)) - UpdateInfo(); - } - - // Not an video packet or an audio packet to be demultiplexed. Keep looking. - SKIP_TRANSPORT_PACKET_BYTES(Packet_Length); - } -} - -// MPEG2 program stream parser. -void Next_Packet() -{ - static int i, Packet_Length, Packet_Header_Length, size; - static unsigned int code, AUDIO_ID, VOBCELL_Count; - static int stream_type; - int PTSDiff; - double picture_period; - __int64 dts_stamp = 0; - __int64 tmp; - __int64 SCRbase, SCRext, SCR; - char buf[64]; - - if (SystemStream_Flag == TRANSPORT_STREAM) - { - Next_Transport_Packet(); - return; - } - else if (SystemStream_Flag == PVA_STREAM) - { - Next_PVA_Packet(); - return; - } - - for (;;) - { - code = Get_Short(); - code = (code << 16) | Get_Short(); - - while ((code & 0xffffff00) != 0x00000100) - { - if (Stop_Flag) - return; - code = (code<<8) + Get_Byte(); - } - - switch (code) - { - case PACK_START_CODE: - if (D2V_Flag) - { - PackHeaderPosition = _telli64(Infile[CurrentFile]); - PackHeaderPosition = PackHeaderPosition - (__int64)BUFFER_SIZE + (__int64)Rdptr - 4 - (__int64)Rdbfr; - } - if (((tmp = Get_Byte()) & 0xf0) == 0x20) - { - // MPEG1 program stream - stream_type = MPEG1_PROGRAM_STREAM; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - { - SCR = (tmp & 0x0e) << 29; - tmp = (__int64) Get_Byte(); - SCR |= tmp << 22; - tmp = (__int64) Get_Byte(); - SCR |= (tmp & 0xfe) << 14; - tmp = (__int64) Get_Byte(); - SCR |= tmp << 7; - tmp = (__int64) Get_Byte(); - SCR |= tmp >> 1; - tmp = (__int64) Get_Byte(); - tmp = (__int64) Get_Byte(); - tmp = (__int64) Get_Byte(); - SCR = 300 * SCR; - _i64toa(SCR, buf, 10); - fprintf(Timestamps, "SCR %s, ", buf); - _i64toa(SCR/27000, buf, 10); - fprintf(Timestamps, "[%sms]\n", buf); - } - else - Rdptr += 7; - } - else - { - // MPEG2 program stream - stream_type = MPEG2_PROGRAM_STREAM; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - { - SCRbase = (tmp & 0x38) << 27; - SCRbase |= (tmp & 0x03) << 28; - tmp = (__int64) Get_Byte(); - SCRbase |= tmp << 20; - tmp = (__int64) Get_Byte(); - SCRbase |= (tmp & 0xf8) << 12; - SCRbase |= (tmp & 0x03) << 13; - tmp = (__int64) Get_Byte(); - SCRbase |= tmp << 5; - tmp = (__int64) Get_Byte(); - SCRbase |= tmp >> 3; - SCRext = (tmp & 0x03) << 7; - tmp = (__int64) Get_Byte(); - SCRext |= tmp >> 1; - tmp = (__int64) Get_Byte(); - tmp = (__int64) Get_Byte(); - tmp = (__int64) Get_Byte(); - SCR = 300 * SCRbase + SCRext; - _i64toa(SCR, buf, 10); - fprintf(Timestamps, "SCR %s, ", buf); - _i64toa(SCR/27000, buf, 10); - fprintf(Timestamps, "[%sms]\n", buf); - } - else - Rdptr += 8; - } - VOBCELL_Count = 0; - break; - - case PRIVATE_STREAM_2: - Packet_Length = Get_Short(); - - if (++VOBCELL_Count==2) - { - Rdptr += 25; - VOB_ID = Get_Short(); - Get_Byte(); - CELL_ID = Get_Byte(); - Rdptr += Packet_Length - 29; - - sprintf(szBuffer, "%d", VOB_ID); - SetDlgItemText(hDlg, IDC_VOB_ID, szBuffer); - - sprintf(szBuffer, "%d", CELL_ID); - SetDlgItemText(hDlg, IDC_CELL_ID, szBuffer); - } - else - Rdptr += Packet_Length; - break; - - case PRIVATE_STREAM_1: - Packet_Length = Get_Short(); - - Rdptr ++; // +1 - code = Get_Byte(); // +1 - Packet_Header_Length = Get_Byte(); // +1 - - if (code>=0x80) - { - __int64 PES_PTS; - - GET_PES_TIMESTAMP(PES_PTS, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - AudioPTS = PES_PTS; - HadAudioPTS = true; - Rdptr += Packet_Header_Length - 5; - } - else - Rdptr += Packet_Header_Length; - - // Private stream 1 on a DVD has an audio substream number, - // but straight MPEG may not, in which case the audio sync word - // will appear where the substream number would be. We will have - // to parse differently for these two structures. For now, it's - // controlled by a GUI option. - if (FusionAudio) - { - // Determine the audio type from the audio sync word. - if (Rdptr[0] == 0x0b && Rdptr[1] == 0x77) - AUDIO_ID = SUB_AC3; - else if (Rdptr[0] == 0x7f && Rdptr[1] == 0xfe) - AUDIO_ID = SUB_DTS; - else - // Nothing else is supported. Force it to fail. - AUDIO_ID = 0; - Packet_Length -= Packet_Header_Length + 3; - } - else - { - AUDIO_ID = Get_Byte(); // +1 - Packet_Length -= Packet_Header_Length + 4; - } - - if (AUDIO_ID>=SUB_AC3 && AUDIO_ID= 0x80 && StartLogging_Flag) - fprintf(Timestamps, " A%2x PTS %lld [%lldms]\n", AUDIO_ID, AudioPTS, AudioPTS/90); - if (!FusionAudio) - { - Rdptr += 3; Packet_Length -= 3; - } - - LOCATE - - if (!audio[AUDIO_ID].rip && Start_Flag && !audio[AUDIO_ID].type && HadAudioPTS == true) - { - audio[AUDIO_ID].type = FORMAT_AC3; - - code = Get_Byte(); - code = (code & 0xff)<<8 | Get_Byte(); - i = 0; - - while (code!=0xb77) - { -oops: - code = (code & 0xff)<<8 | Get_Byte(); - i++; - } - - Get_Short(); - audio[AUDIO_ID].rate = (Get_Byte()>>1) & 0x1f; - if (audio[AUDIO_ID].rate > 0x12) - goto oops; - Get_Byte(); - audio[AUDIO_ID].mode = (Get_Byte()>>5) & 0x07; - - Rdptr -= 7; Packet_Length -= i; - - if (D2V_Flag || Decision_Flag || AudioOnly_Flag) - { - if (Decision_Flag && audio[AUDIO_ID].selected_for_demux == true) - { - InitialAC3(); - - DECODE_AC3 - - audio[AUDIO_ID].rip = true; - } - else if (Method_Flag==AUDIO_DECODE && audio[AUDIO_ID].selected_for_demux == true) - { - InitialAC3(); - - sprintf(szBuffer, "%s T%x %sch %dKbps %s.wav", szOutput, AUDIO_ID, - AC3ModeDash[audio[AUDIO_ID].mode], AC3Rate[audio[AUDIO_ID].rate], FTType[SRC_Flag]); - - strcpy(audio[AUDIO_ID].filename, szBuffer); - audio[AUDIO_ID].file = OpenAudio(szBuffer, "wb", AUDIO_ID); - if (audio[AUDIO_ID].file == NULL) - { - MessageBox(hWnd, "Cannot open file for audio demux output.\nAborting...", NULL, MB_OK | MB_ICONERROR); - ThreadKill(MISC_KILL); - } - - StartWAV(audio[AUDIO_ID].file, 0x01); // 48K, 16bit, 2ch - - // Adjust the VideoPTS to account for frame reordering. - if (!PTSAdjustDone) - { - PTSAdjustDone = 1; - picture_period = 1.0 / frame_rate; - VideoPTS -= (int) (LeadingBFrames * picture_period * 90000); - } - - if (PTSDifference(AudioPTS, VideoPTS, &PTSDiff)) - audio[AUDIO_ID].delay = 0; - else - audio[AUDIO_ID].delay = PTSDiff * 192; - - if (SRC_Flag) - { - DownWAV(audio[AUDIO_ID].file); - InitialSRC(); - } - - if (audio[AUDIO_ID].delay > 0) - { - if (SRC_Flag) - audio[AUDIO_ID].delay = ((int)(0.91875*audio[AUDIO_ID].delay)>>2)<<2; - - for (i=0; i size) - audio[AUDIO_ID].delay += size; - else - { - if (SRC_Flag) - Wavefs44(audio[AUDIO_ID].file, size+audio[AUDIO_ID].delay, AC3Dec_Buffer-audio[AUDIO_ID].delay); - else - fwrite(AC3Dec_Buffer-audio[AUDIO_ID].delay, size+audio[AUDIO_ID].delay, 1, audio[AUDIO_ID].file); - - audio[AUDIO_ID].size += size+audio[AUDIO_ID].delay; - audio[AUDIO_ID].delay = 0; - } - - audio[AUDIO_ID].rip = true; - } - else if (Method_Flag==AUDIO_DEMUXALL || (Method_Flag==AUDIO_DEMUX && audio[AUDIO_ID].selected_for_demux == true)) - { - if (AudioOnly_Flag) - { - char *p; - strcpy(szOutput, Infilename[0]); - p = &szOutput[sizeof(szOutput)]; - while (*p != '.') p--; - *p = 0; - sprintf(szBuffer, "%s T%x %sch %dKbps.ac3", szOutput, AUDIO_ID, - AC3ModeDash[audio[AUDIO_ID].mode], AC3Rate[audio[AUDIO_ID].rate]); - } - else - { - // Adjust the VideoPTS to account for frame reordering. - if (!PTSAdjustDone) - { - PTSAdjustDone = 1; - picture_period = 1.0 / frame_rate; - VideoPTS -= (int) (LeadingBFrames * picture_period * 90000); - } - - if (PTSDifference(AudioPTS, VideoPTS, &PTSDiff)) - sprintf(szBuffer, "%s T%x %sch %dKbps.ac3", szOutput, AUDIO_ID, - AC3ModeDash[audio[AUDIO_ID].mode], AC3Rate[audio[AUDIO_ID].rate]); - else - sprintf(szBuffer, "%s T%x %sch %dKbps DELAY %dms.ac3", szOutput, AUDIO_ID, - AC3ModeDash[audio[AUDIO_ID].mode], AC3Rate[audio[AUDIO_ID].rate], PTSDiff); - -// dprintf("DGIndex: Using Video PTS = %d, Audio PTS = %d [%d], reference = %d, rate = %f\n", -// VideoPTS/90, AudioPTS/90, PTSDiff, StartTemporalReference, frame_rate); - } - audio[AUDIO_ID].file = OpenAudio(szBuffer, "wb", AUDIO_ID); - if (audio[AUDIO_ID].file == NULL) - { - MessageBox(hWnd, "Cannot open file for audio demux output.\nAborting...", NULL, MB_OK | MB_ICONERROR); - ThreadKill(MISC_KILL); - } - - DEMUX_AC3 - - audio[AUDIO_ID].rip = true; - } - } - } - else if (audio[AUDIO_ID].rip) - { - if (Decision_Flag) - DECODE_AC3 - else if (Method_Flag==AUDIO_DECODE) - { - DECODE_AC3 - - if (-audio[AUDIO_ID].delay > size) - audio[AUDIO_ID].delay += size; - else - { - if (SRC_Flag) - Wavefs44(audio[AUDIO_ID].file, size+audio[AUDIO_ID].delay, AC3Dec_Buffer-audio[AUDIO_ID].delay); - else - fwrite(AC3Dec_Buffer-audio[AUDIO_ID].delay, size+audio[AUDIO_ID].delay, 1, audio[AUDIO_ID].file); - - audio[AUDIO_ID].size += size+audio[AUDIO_ID].delay; - audio[AUDIO_ID].delay = 0; - } - } - else - { - DEMUX_AC3 - } - } - } - else if (AUDIO_ID>=SUB_PCM && AUDIO_ID= 0x80 && StartLogging_Flag) - fprintf(Timestamps, " A%2x PTS %lld [%lldms]\n", AUDIO_ID, AudioPTS, AudioPTS/90); - Rdptr += 6; Packet_Length -= 6; - - LOCATE - - if (!audio[AUDIO_ID].rip && Start_Flag && !audio[AUDIO_ID].type) - { - audio[AUDIO_ID].type = FORMAT_LPCM; - - // Pick up the audio format byte. - audio[AUDIO_ID].format = Rdptr[-2]; - - if (D2V_Flag || AudioOnly_Flag) - { - if (Method_Flag==AUDIO_DEMUXALL || (Method_Flag == AUDIO_DEMUX && audio[AUDIO_ID].selected_for_demux == true)) - { - if (AudioOnly_Flag) - { - char *p; - strcpy(szOutput, Infilename[0]); - p = &szOutput[sizeof(szOutput)]; - while (*p != '.') p--; - *p = 0; - sprintf(szBuffer, "%s T%x %s %s %dch.wav", - szOutput, - AUDIO_ID, - (audio[AUDIO_ID].format & 0x30) == 0 ? "48K" : "96K", - (audio[AUDIO_ID].format & 0xc0) == 0 ? "16bit" : ((audio[AUDIO_ID].format & 0xc0) == 0x40 ? "20bit" : "24bit"), - (audio[AUDIO_ID].format & 0x07) + 1); - strcpy(audio[AUDIO_ID].filename, szBuffer); - } - else - { - // Adjust the VideoPTS to account for frame reordering. - if (!PTSAdjustDone) - { - PTSAdjustDone = 1; - picture_period = 1.0 / frame_rate; - VideoPTS -= (int) (LeadingBFrames * picture_period * 90000); - } - - if (PTSDifference(AudioPTS, VideoPTS, &PTSDiff)) - audio[AUDIO_ID].delay = 0; - else - audio[AUDIO_ID].delay = PTSDiff * 192; - - - sprintf(szBuffer, "%s T%x %s %s %dch.wav", - szOutput, - AUDIO_ID, - (audio[AUDIO_ID].format & 0x30) == 0 ? "48K" : "96K", - (audio[AUDIO_ID].format & 0xc0) == 0 ? "16bit" : ((audio[AUDIO_ID].format & 0xc0) == 0x40 ? "20bit" : "24bit"), - (audio[AUDIO_ID].format & 0x07) + 1); - strcpy(audio[AUDIO_ID].filename, szBuffer); - } - - audio[AUDIO_ID].file = OpenAudio(szBuffer, "wb", AUDIO_ID); - if (audio[AUDIO_ID].file == NULL) - { - MessageBox(hWnd, "Cannot open file for audio demux output.\nAborting...", NULL, MB_OK | MB_ICONERROR); - ThreadKill(MISC_KILL); - } - StartWAV(audio[AUDIO_ID].file, audio[AUDIO_ID].format); - - if (audio[AUDIO_ID].delay > 0) - { - for (i=0; i Packet_Length) - audio[AUDIO_ID].delay += Packet_Length; - else - { - DemuxLPCM(&size, &Packet_Length, PCM_Buffer, audio[AUDIO_ID].format); - fwrite(PCM_Buffer-audio[AUDIO_ID].delay, size+audio[AUDIO_ID].delay, 1, audio[AUDIO_ID].file); - - audio[AUDIO_ID].size += size+audio[AUDIO_ID].delay; - audio[AUDIO_ID].delay = 0; - } - - audio[AUDIO_ID].rip = true; - } - } - } - else if (audio[AUDIO_ID].rip) - { - if (-audio[AUDIO_ID].delay > Packet_Length) - audio[AUDIO_ID].delay += Packet_Length; - else - { - DemuxLPCM(&size, &Packet_Length, PCM_Buffer, audio[AUDIO_ID].format); - fwrite(PCM_Buffer-audio[AUDIO_ID].delay, size+audio[AUDIO_ID].delay, 1, audio[AUDIO_ID].file); - - audio[AUDIO_ID].size += size+audio[AUDIO_ID].delay; - audio[AUDIO_ID].delay = 0; - } - } - } - else if (AUDIO_ID>=SUB_DTS && AUDIO_ID= 0x80 && StartLogging_Flag) - fprintf(Timestamps, " A%2x PTS %lld [%lldms]\n", AUDIO_ID, AudioPTS, AudioPTS/90); - if (!FusionAudio) - { - Rdptr += 3; Packet_Length -= 3; - } - - LOCATE - - if (!audio[AUDIO_ID].rip && Start_Flag && !audio[AUDIO_ID].type) - { - audio[AUDIO_ID].type = FORMAT_DTS; - - if (D2V_Flag || AudioOnly_Flag) - { - if (Method_Flag==AUDIO_DEMUXALL || (Method_Flag==AUDIO_DEMUX && audio[AUDIO_ID].selected_for_demux == true)) - { - if (AudioOnly_Flag) - { - char *p; - strcpy(szOutput, Infilename[0]); - p = &szOutput[sizeof(szOutput)]; - while (*p != '.') p--; - *p = 0; - sprintf(szBuffer, "%s T%x.dts", szOutput, AUDIO_ID); - } - else - { - // Adjust the VideoPTS to account for frame reordering. - if (!PTSAdjustDone) - { - PTSAdjustDone = 1; - picture_period = 1.0 / frame_rate; - VideoPTS -= (int) (LeadingBFrames * picture_period * 90000); - } - - if (PTSDifference(AudioPTS, VideoPTS, &PTSDiff)) - sprintf(szBuffer, "%s T%x.dts", szOutput, AUDIO_ID); - else - sprintf(szBuffer, "%s T%x DELAY %dms.dts", szOutput, AUDIO_ID, PTSDiff); - } - - audio[AUDIO_ID].file = OpenAudio(szBuffer, "wb", AUDIO_ID); - if (audio[AUDIO_ID].file == NULL) - { - MessageBox(hWnd, "Cannot open file for audio demux output.\nAborting...", NULL, MB_OK | MB_ICONERROR); - ThreadKill(MISC_KILL); - } - - DEMUX_DTS - - audio[AUDIO_ID].rip = true; - } - } - } - else if (audio[AUDIO_ID].rip) - DEMUX_DTS - } - Rdptr += Packet_Length; - if (AudioOnly_Flag && Info_Flag && !(AudioPktCount++ % 128)) - UpdateInfo(); - break; - - case AUDIO_ELEMENTARY_STREAM_7: - case AUDIO_ELEMENTARY_STREAM_6: - case AUDIO_ELEMENTARY_STREAM_5: - case AUDIO_ELEMENTARY_STREAM_4: - case AUDIO_ELEMENTARY_STREAM_3: - case AUDIO_ELEMENTARY_STREAM_2: - case AUDIO_ELEMENTARY_STREAM_1: - case AUDIO_ELEMENTARY_STREAM_0: - AUDIO_ID = code & 0xff; - if (stream_type == MPEG1_PROGRAM_STREAM) - { - // MPEG1 program stream. - Packet_Length = Get_Short(); - - Packet_Header_Length = 0; - // Stuffing bytes. - do - { - code = Get_Byte(); - Packet_Header_Length += 1; - } while (code == 0xff); - if ((code & 0xc0) == 0x40) - { - // STD bytes. - Get_Byte(); - code = Get_Byte(); - Packet_Header_Length += 2; - } - if ((code & 0xf0) == 0x20) - { - // PTS bytes. - __int64 PES_PTS; - - GET_PES_TIMESTAMP(PES_PTS, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - AudioPTS = PES_PTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, " A%2x PTS %lld [%lldms]\n", AUDIO_ID, AudioPTS, AudioPTS/90); - Packet_Header_Length += 4; - } - else if ((code & 0xf0) == 0x30) - { - // PTS bytes. - __int64 PES_PTS, PES_DTS; - - GET_PES_TIMESTAMP(PES_PTS, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - AudioPTS = PES_PTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, " A%2x PTS %lld [%lldms]\n", AUDIO_ID, AudioPTS, AudioPTS/90); - GET_PES_TIMESTAMP(PES_DTS, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - dts_stamp = PES_DTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, " A%2x DTS %lld [%lldms]\n", AUDIO_ID, dts_stamp, dts_stamp/90); - Packet_Header_Length += 9; - } - Packet_Length -= Packet_Header_Length; - - LOCATE - - if (!audio[AUDIO_ID].rip && Start_Flag && !audio[AUDIO_ID].type) - { - audio[AUDIO_ID].type = FORMAT_MPA; - - code = Get_Byte(); - code = (code & 0xff)<<8 | Get_Byte(); - i = 0; - - while (code<0xfff0) - { -emulated1: - code = (code & 0xff)<<8 | Get_Byte(); - i++; - } - // Try to detect emulated sync words by enforcing semantics. - if (check_audio_syncword(AUDIO_ID, (code >> 1) & 3, (Rdptr[0] >> 4) & 0xf, (Rdptr[0] >> 2) & 3, (Rdptr[1] >> 6) & 3, Rdptr[1] & 3)) - { - goto emulated1; - } - - Rdptr -= 2; Packet_Length -= i; - - if (D2V_Flag || AudioOnly_Flag) - { - if (Method_Flag==AUDIO_DEMUXALL || (Method_Flag==AUDIO_DEMUX && audio[AUDIO_ID].selected_for_demux == true)) - { - if (AudioOnly_Flag) - { - char *p; - strcpy(szOutput, Infilename[0]); - p = &szOutput[sizeof(szOutput)]; - while (*p != '.') p--; - *p = 0; - sprintf(szBuffer, "%s T%x %s %s %s %s.%s", szOutput, AUDIO_ID, - MPALayer[audio[AUDIO_ID].layer], MPAMode[audio[AUDIO_ID].mode], MPASample[audio[AUDIO_ID].sample], - MPARate[audio[AUDIO_ID].layer][audio[AUDIO_ID].rate], - UseMPAExtensions ? MPAExtension[0] : MPAExtension[audio[AUDIO_ID].layer]); - } - else - { - // Adjust the VideoPTS to account for frame reordering. - if (!PTSAdjustDone) - { - PTSAdjustDone = 1; - picture_period = 1.0 / frame_rate; - VideoPTS -= (int) (LeadingBFrames * picture_period * 90000); - } - - if (PTSDifference(AudioPTS, VideoPTS, &PTSDiff)) - sprintf(szBuffer, "%s T%x %s %s %s %s.%s", szOutput, AUDIO_ID, - MPALayer[audio[AUDIO_ID].layer], MPAMode[audio[AUDIO_ID].mode], MPASample[audio[AUDIO_ID].sample], - MPARate[audio[AUDIO_ID].layer][audio[AUDIO_ID].rate], - UseMPAExtensions ? MPAExtension[0] : MPAExtension[audio[AUDIO_ID].layer]); - else - sprintf(szBuffer, "%s T%x %s %s %s %s DELAY %dms.%s", szOutput, AUDIO_ID, - MPALayer[audio[AUDIO_ID].layer], MPAMode[audio[AUDIO_ID].mode], MPASample[audio[AUDIO_ID].sample], - MPARate[audio[AUDIO_ID].layer][audio[AUDIO_ID].rate], PTSDiff, - UseMPAExtensions ? MPAExtension[0] : MPAExtension[audio[AUDIO_ID].layer]); - } - audio[AUDIO_ID].file = OpenAudio(szBuffer, "wb", AUDIO_ID); - if (audio[AUDIO_ID].file == NULL) - { - MessageBox(hWnd, "Cannot open file for audio demux output.\nAborting...", NULL, MB_OK | MB_ICONERROR); - ThreadKill(MISC_KILL); - } - - DEMUX_MPA_AAC(audio[AUDIO_ID].file); - - audio[AUDIO_ID].rip = true; - } - } - } - else if (audio[AUDIO_ID].rip) - DEMUX_MPA_AAC(audio[AUDIO_ID].file); - Rdptr += Packet_Length; - } - else - { - Packet_Length = Get_Short()-1; - code = Get_Byte(); - - if ((code & 0xc0)==0x80) - { - code = Get_Byte(); // +1 - Packet_Header_Length = Get_Byte(); // +1 - - if (code>=0x80) - { - __int64 PES_PTS, PES_DTS; - - GET_PES_TIMESTAMP(PES_PTS, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, " A%2x PTS %lld [%lldms]\n", AUDIO_ID, AudioPTS, AudioPTS/90); - AudioPTS = PES_PTS; - // DTS is not used. The code is here for analysis and debugging. - if ((code & 0xc0) == 0xc0) - { - GET_PES_TIMESTAMP(PES_DTS, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - dts_stamp = PES_DTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, "A%2x DTS %lld [%lldms]\n", AUDIO_ID, dts_stamp, dts_stamp/90); - Rdptr += Packet_Header_Length - 10; - } - else - Rdptr += Packet_Header_Length - 5; - } - else - Rdptr += Packet_Header_Length; - - Packet_Length -= Packet_Header_Length+2; - - LOCATE - - if (!audio[AUDIO_ID].rip && Start_Flag && !audio[AUDIO_ID].type) - { - audio[AUDIO_ID].type = FORMAT_MPA; - - code = Get_Byte(); - code = (code & 0xff)<<8 | Get_Byte(); - i = 0; - while (code < 0xfff0 && i < Packet_Length - 2) - { -emulated2: - code = (code & 0xff)<<8 | Get_Byte(); - i++; - } - if (i >= Packet_Length - 2) - { - break; - } - // Try to detect emulated sync words by enforcing semantics. - if (check_audio_syncword(AUDIO_ID, (code >> 1) & 3, (Rdptr[0] >> 4) & 0xf, (Rdptr[0] >> 2) & 3, (Rdptr[1] >> 6) & 3, Rdptr[1] & 3)) - { - goto emulated2; - } - - Rdptr -= 2; Packet_Length -= i; - - if (D2V_Flag || AudioOnly_Flag) - { - if (Method_Flag==AUDIO_DEMUXALL || (Method_Flag==AUDIO_DEMUX && audio[AUDIO_ID].selected_for_demux == true)) - { - if (AudioOnly_Flag) - { - char *p; - strcpy(szOutput, Infilename[0]); - p = &szOutput[sizeof(szOutput)]; - while (*p != '.') p--; - *p = 0; - sprintf(szBuffer, "%s T%x %s %s %s %s.%s", szOutput, AUDIO_ID, - MPALayer[audio[AUDIO_ID].layer], MPAMode[audio[AUDIO_ID].mode], MPASample[audio[AUDIO_ID].sample], - MPARate[audio[AUDIO_ID].layer][audio[AUDIO_ID].rate], - UseMPAExtensions ? MPAExtension[0] : MPAExtension[audio[AUDIO_ID].layer]); - } - else - { - // Adjust the VideoPTS to account for frame reordering. - if (!PTSAdjustDone) - { - PTSAdjustDone = 1; - picture_period = 1.0 / frame_rate; - VideoPTS -= (int) (LeadingBFrames * picture_period * 90000); - } - - if (PTSDifference(AudioPTS, VideoPTS, &PTSDiff)) - sprintf(szBuffer, "%s T%x %s %s %s %s.%s", szOutput, AUDIO_ID, - MPALayer[audio[AUDIO_ID].layer], MPAMode[audio[AUDIO_ID].mode], MPASample[audio[AUDIO_ID].sample], - MPARate[audio[AUDIO_ID].layer][audio[AUDIO_ID].rate], - UseMPAExtensions ? MPAExtension[0] : MPAExtension[audio[AUDIO_ID].layer]); - else - sprintf(szBuffer, "%s T%x %s %s %s %s DELAY %dms.%s", szOutput, AUDIO_ID, - MPALayer[audio[AUDIO_ID].layer], MPAMode[audio[AUDIO_ID].mode], MPASample[audio[AUDIO_ID].sample], - MPARate[audio[AUDIO_ID].layer][audio[AUDIO_ID].rate], PTSDiff, - UseMPAExtensions ? MPAExtension[0] : MPAExtension[audio[AUDIO_ID].layer]); - } - audio[AUDIO_ID].file = OpenAudio(szBuffer, "wb", AUDIO_ID); - if (audio[AUDIO_ID].file == NULL) - { - MessageBox(hWnd, "Cannot open file for audio demux output.\nAborting...", NULL, MB_OK | MB_ICONERROR); - ThreadKill(MISC_KILL); - } - - DEMUX_MPA_AAC(audio[AUDIO_ID].file); - - audio[AUDIO_ID].rip = true; - } - } - } - else if (audio[AUDIO_ID].rip) - DEMUX_MPA_AAC(audio[AUDIO_ID].file); - } - Rdptr += Packet_Length; - } - if (AudioOnly_Flag && Info_Flag && !(AudioPktCount++ % 128)) - UpdateInfo(); - - break; - - default: - if ((code & 0xfffffff0) == VIDEO_ELEMENTARY_STREAM) - { - Packet_Length = Get_Short(); - Rdmax = Rdptr + Packet_Length; - - if (stream_type == MPEG1_PROGRAM_STREAM) - { - __int64 PES_PTS, PES_DTS; - __int64 pts_stamp; - - // MPEG1 program stream. - Packet_Header_Length = 0; - // Stuffing bytes. - do - { - code = Get_Byte(); - Packet_Header_Length += 1; - } while (code == 0xff); - if ((code & 0xc0) == 0x40) - { - // STD bytes. - Get_Byte(); - code = Get_Byte(); - Packet_Header_Length += 2; - } - if ((code & 0xf0) == 0x20) - { - // PTS bytes. - GET_PES_TIMESTAMP(PES_PTS, code, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - pts_stamp = PES_PTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, "V PTS %lld [%lldms]\n", pts_stamp, pts_stamp/90); - Packet_Header_Length += 4; - } - else if ((code & 0xf0) == 0x30) - { - // PTS/DTS bytes. - GET_PES_TIMESTAMP(PES_PTS, code, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - pts_stamp = PES_PTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, "V PTS %lld [%lldms]\n", pts_stamp, pts_stamp/90); - GET_PES_TIMESTAMP(PES_DTS, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - dts_stamp = PES_DTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, "V DTS %lld [%lldms]\n", dts_stamp, dts_stamp/90); - Packet_Header_Length += 9; - } - else - { - // Just to kill a compiler warning. - pts_stamp = 0; - } - if (!Start_Flag) - { - // Start_Flag becomes true after the first I frame. - // So VideoPTS will be left at the value corresponding to - // the first I frame. - VideoPTS = pts_stamp; - } - LastVideoPTS = pts_stamp; - Bitrate_Monitor += Rdmax - Rdptr; - return; - } - else - { - // MPEG2 program stream. - code = Get_Byte(); - if ((code & 0xc0) == 0x80) - { - __int64 PES_PTS, PES_DTS; - __int64 pts_stamp, dts_stamp; - - code = Get_Byte(); - Packet_Header_Length = Get_Byte(); - - if (code >= 0x80) - { - GET_PES_TIMESTAMP(PES_PTS, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - pts_stamp = PES_PTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, "V PTS %lld [%lldms]\n", pts_stamp, pts_stamp/90); - // DTS is not used. The code is here for analysis and debugging. - if ((code & 0xc0) == 0xc0) - { - GET_PES_TIMESTAMP(PES_DTS, Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte(), Get_Byte()); - dts_stamp = PES_DTS; - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, "V DTS %lld [%lldms]\n", dts_stamp, dts_stamp/90); - Rdptr += Packet_Header_Length - 10; - } - else - Rdptr += Packet_Header_Length - 5; - - if (!Start_Flag) - { - // Start_Flag becomes true after the first I frame. - // So VideoPTS will be left at the value corresponding to - // the first I frame. - VideoPTS = pts_stamp; - } - LastVideoPTS = pts_stamp; - } - else - Rdptr += Packet_Header_Length; - - Bitrate_Monitor += Rdmax - Rdptr; - return; - } - else - { - Rdptr += Packet_Length-1; - } - } - } - else if (code>=SYSTEM_START_CODE) - { - Packet_Length = Get_Short(); - if (code == 0x1be && Packet_Length > 2048) - { - continue; - } - Rdptr += Packet_Length; - } - break; - } - } -} - -unsigned int Get_Bits_All(unsigned int N) -{ - N -= BitsLeft; - Val = (CurrentBfr << (32 - BitsLeft)) >> (32 - BitsLeft); - - if (N) - Val = (Val << N) + (NextBfr >> (32 - N)); - - VideoDemux(); - CurrentBfr = NextBfr; - BitsLeft = 32 - N; - Fill_Next(); - - return Val; -} - -void Flush_Buffer_All(unsigned int N) -{ - VideoDemux(); - CurrentBfr = NextBfr; - BitsLeft = BitsLeft + 32 - N; - Fill_Next(); -} - -void Fill_Buffer() -{ - Read = _donread(Infile[CurrentFile], Rdbfr, BUFFER_SIZE); - -// dprintf("DGIndex: Fill buffer\n"); - if (Read < BUFFER_SIZE) Next_File(); - - Rdptr = Rdbfr; - - if (SystemStream_Flag != ELEMENTARY_STREAM) - { - Rdmax -= BUFFER_SIZE; - } - else - Bitrate_Monitor += Read; -} - -void Next_File() -{ - int i, bytes; - unsigned char *p; - - if (CurrentFile < NumLoadedFiles-1) - { - CurrentFile++; - process.run = 0; - for (i=0; i> 4) & 0x7; - level = profile_and_level_indication & 0xf; - switch (profile) - { - case 1: // high - strcpy(szBuffer, "high@"); - break; - case 2: // spatial - strcpy(szBuffer, "spatial@"); - break; - case 3: // SNR - strcpy(szBuffer, "snr@"); - break; - case 4: // main - strcpy(szBuffer, "main@"); - break; - case 5: // simple - strcpy(szBuffer, "simple@"); - break; - default: - sprintf(szBuffer, "esc (%d@%d)", profile, level); - break; - } - switch (level) - { - case 4: - strcat(szBuffer, "high"); - break; - case 6: - strcat(szBuffer, "high1440"); - break; - case 8: - strcat(szBuffer, "main"); - break; - case 10: - strcat(szBuffer, "low"); - break; - default: - break; - } - SetDlgItemText(hDlg, IDC_PROFILE, szBuffer); - } - else - { - SetDlgItemText(hDlg, IDC_PROFILE, "[MPEG1]"); - } - - sprintf(szBuffer, "%.6f fps", Frame_Rate); - SetDlgItemText(hDlg, IDC_FRAME_RATE, szBuffer); - } - - while (SendDlgItemMessage(hDlg, IDC_AUDIO_LIST, LB_DELETESTRING, 0, 0) != LB_ERR); - for (i = 0; i < 0xc8; i++) - { - if (audio[i].type != 0) - { - switch (audio[i].type) - { - case FORMAT_AC3: - sprintf(szBuffer, "%x: AC3 %s %d", i, AC3Mode[audio[i].mode], AC3Rate[audio[i].rate]); - break; - - case FORMAT_MPA: - sprintf(szBuffer, "%x: MPA %s %s %s %s", i, - MPALayer[audio[i].layer], MPAMode[audio[i].mode], MPASample[audio[i].sample], - MPARate[audio[i].layer][audio[i].rate]); - break; - - case FORMAT_AAC: - sprintf(szBuffer, "%x: AAC Audio", i); - break; - - case FORMAT_LPCM: - sprintf(szBuffer, "%x: PCM %s %s %dch", i, - (audio[i].format & 0x30) == 0 ? "48K" : "96K", - (audio[i].format & 0xc0) == 0 ? "16bit" : ((audio[i].format & 0xc0) == 0x40 ? "20bit" : "24bit"), - (audio[i].format & 0x07) + 1); - break; - - case FORMAT_LPCM_M2TS: - { - char sample_rate[16]; - char bits_per_sample[16]; - char num_channels[16]; - switch ((audio[i].format_m2ts & 0xf00) >> 8) - { - case 1: - sprintf(sample_rate, "48K"); - break; - case 4: - sprintf(sample_rate, "96K"); - break; - case 5: - sprintf(sample_rate, "192K"); - break; - default: - sprintf(sample_rate, "RES"); - break; - } - switch ((audio[i].format_m2ts & 0xc0) >> 6) - { - case 1: - sprintf(bits_per_sample, "16bit"); - break; - case 2: - sprintf(bits_per_sample, "20bit"); - break; - case 3: - sprintf(bits_per_sample, "24bit"); - break; - default: - sprintf(bits_per_sample, "RES"); - break; - } - switch ((audio[i].format_m2ts & 0xf000) >> 12) - { - case 1: - sprintf(num_channels, "1/0"); - break; - case 3: - sprintf(num_channels, "2/0"); - break; - case 4: - sprintf(num_channels, "3/0"); - break; - case 5: - sprintf(num_channels, "2/1"); - break; - case 6: - sprintf(num_channels, "3/1"); - break; - case 7: - sprintf(num_channels, "2/2"); - break; - case 8: - sprintf(num_channels, "3/2"); - break; - case 9: - sprintf(num_channels, "3/2lfe"); - break; - case 10: - sprintf(num_channels, "3/4"); - break; - case 11: - sprintf(num_channels, "3/4lfe"); - break; - default: - printf("LPCM Audio Mode = reserved\n"); - break; - } - sprintf(szBuffer, "%x: PCM %s %s %s", i, sample_rate, bits_per_sample, num_channels); - break; - } - - case FORMAT_DTS: - sprintf(szBuffer, "%x: DTS Audio", i); - break; - - default: - sprintf(szBuffer, ""); - break; - } - SendDlgItemMessage(hDlg, IDC_AUDIO_LIST, LB_ADDSTRING, 0, (LPARAM)szBuffer); - if (SystemStream_Flag == TRANSPORT_STREAM) - break; - } - } - - if (AudioOnly_Flag || (SystemStream_Flag != ELEMENTARY_STREAM && process.locate != LOCATE_INIT)) - { - unsigned int hours, mins, secs; - __int64 processed; - int i, trackpos; - - pts = (unsigned int)(AudioPTS/90000); - hours = pts / 3600; - mins = (pts % 3600) / 60; - secs = pts % 60; - sprintf(szBuffer, "%d:%02d:%02d", hours, mins, secs); - SetDlgItemText(hDlg, IDC_TIMESTAMP, szBuffer); - for (i = 0, processed = 0; i < CurrentFile; i++) - { - processed += Infilelength[i]; - } - processed += _telli64(Infile[CurrentFile]); - processed *= TRACK_PITCH; - processed /= Infiletotal; - trackpos = (int) processed; - SendMessage(hTrack, TBM_SETPOS, (WPARAM)true, trackpos); - InvalidateRect(hwndSelect, NULL, TRUE); - } - else - SetDlgItemText(hDlg, IDC_TIMESTAMP, ""); - - if (process.locate==LOCATE_RIP) - { - if (VIDEO_Purity || FILM_Purity) - { - if (!FILM_Purity) - { - if (frame_rate==25 || frame_rate==50) - sprintf(szBuffer, "PAL"); - else - sprintf(szBuffer, "NTSC"); - } - else if (!VIDEO_Purity) - sprintf(szBuffer, "Film"); - else if (VIDEO_Purity > Old_VIDEO_Purity) - { - video_percent = 100.0 - (FILM_Purity*100.0)/(FILM_Purity+VIDEO_Purity); - if (video_percent > 50) - sprintf(szBuffer, "Video %.2f%%", video_percent); - else - sprintf(szBuffer, "Film %.2f%%", 100.0 - video_percent); - } - else - { - film_percent = (FILM_Purity*100.0)/(FILM_Purity+VIDEO_Purity); - if (film_percent > 50) - sprintf(szBuffer, "Film %.2f%%", film_percent); - else - sprintf(szBuffer, "Video %.2f%%", 100.0 - film_percent); - } - - Old_VIDEO_Purity = VIDEO_Purity; - SetDlgItemText(hDlg, IDC_VIDEO_TYPE, szBuffer); - } - } - else - { - SetDlgItemText(hDlg, IDC_VIDEO_TYPE, ""); - SetDlgItemText(hDlg, IDC_FRAME_TYPE, ""); - SetDlgItemText(hDlg, IDC_CODED_NUMBER, ""); - SetDlgItemText(hDlg, IDC_PLAYBACK_NUMBER, ""); - SetDlgItemText(hDlg, IDC_BITRATE,""); - SetDlgItemText(hDlg, IDC_BITRATE_AVG,""); - SetDlgItemText(hDlg, IDC_BITRATE_MAX,""); - SetDlgItemText(hDlg, IDC_ELAPSED, ""); - SetDlgItemText(hDlg, IDC_REMAIN, ""); - SetDlgItemText(hDlg, IDC_FPS, ""); - } -} - -// Video demuxing functions. -static int first_video_demux; - -void StartVideoDemux(void) -{ - char path[1024]; - char *p; - - strcpy(path, D2VFilePath); - p = path + strlen(path); - while (*p != '.' && p >= path) p--; - if (p < path) - { - // No extension in this name. WTF? - p = path; - strcat(path, "."); - } - else - p[1] = 0; - if (mpeg_type == IS_MPEG2) - strcat(p, "demuxed.m2v"); - else - strcat(p, "demuxed.m1v"); - MuxFile = fopen(path, "wb"); - if (MuxFile == (FILE *) 0) - { - MessageBox(hWnd, "Cannot open file for video demux output.", NULL, MB_OK | MB_ICONERROR); - MuxFile = (FILE *) 0xffffffff; - return; - } - first_video_demux = 1; -} - -void StopVideoDemux(void) -{ - unsigned char c; - - // Flush the last usable bytes in NextBfr. - c = NextBfr >> 24; - if (c != 0xff) - { - fwrite(&c, 1, 1, MuxFile); - c = (NextBfr >> 16) & 0xff; - if (c != 0xff) - { - fwrite(&c, 1, 1, MuxFile); - c = (NextBfr >> 8) & 0xff; - if (c != 0xff) - { - fwrite(&c, 1, 1, MuxFile); - c = NextBfr & 0xff; - if (c != 0xff) - { - fwrite(&c, 1, 1, MuxFile); - } - } - } - } -} - -void VideoDemux(void) -{ - unsigned char buf[8]; - - if (MuxFile == (FILE *) 0xffffffff || MuxFile <= 0) - return; - buf[0] = CurrentBfr >> 24; - buf[1] = (CurrentBfr >> 16) & 0xff; - buf[2] = (CurrentBfr >> 8) & 0xff; - buf[3] = CurrentBfr & 0xff; - if (first_video_demux == 1) - { - // Start demuxing at the first sequence header. - buf[4] = NextBfr >> 24; - buf[5] = (NextBfr >> 16) & 0xff; - buf[6] = (NextBfr >> 8) & 0xff; - buf[7] = NextBfr & 0xff; - first_video_demux = 0; - if (buf[0] == 0 && buf[1] == 0 && buf[2] == 1 && buf[3] == 0xb3) - fwrite(&buf[0], 1, 4, MuxFile); - else if (buf[1] == 0 && buf[2] == 0 && buf[3] == 1 && buf[4] == 0xb3) - fwrite(&buf[1], 1, 3, MuxFile); - else if (buf[2] == 0 && buf[3] == 0 && buf[4] == 1 && buf[5] == 0xb3) - fwrite(&buf[2], 1, 2, MuxFile); - else if (buf[3] == 0 && buf[4] == 0 && buf[5] == 1 && buf[6] == 0xb3) - fwrite(&buf[3], 1, 1, MuxFile); - else - first_video_demux = 1; - } - else - fwrite(&buf[0], 1, 4, MuxFile); -} diff --git a/src/dgindex/getbit.h b/src/dgindex/getbit.h deleted file mode 100644 index e795554..0000000 --- a/src/dgindex/getbit.h +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Mutated into DGIndex. Modifications Copyright (C) 2004, Donald Graft - * - * Copyright (C) Chia-chen Kuo - April 2001 - * - * This file is part of DVD2AVI, a free MPEG-2 decoder - * - * DVD2AVI 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. - * - * DVD2AVI is distributed in the hope that 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. - * - */ -#ifdef GETBIT_GLOBAL -#define GXTN -#else -#define GXTN extern -#endif - -void Initialize_Buffer(void); -void Fill_Buffer(void); -void Next_Packet(void); -void Flush_Buffer_All(unsigned int N); -unsigned int Get_Bits_All(unsigned int N); -void Next_File(void); - -GXTN unsigned char *Rdbfr, *Rdptr, *Rdmax; -GXTN unsigned int BitsLeft, CurrentBfr, NextBfr, Val, Read; -GXTN __int64 CurrentPackHeaderPosition; - -__forceinline static unsigned int Show_Bits(unsigned int N) -{ - if (N <= BitsLeft) - { - return (CurrentBfr << (32 - BitsLeft)) >> (32 - N); - } - else - { - N -= BitsLeft; - return (((CurrentBfr << (32 - BitsLeft)) >> (32 - BitsLeft)) << N) + (NextBfr >> (32 - N)); - } -} - -__forceinline static unsigned int Get_Bits(unsigned int N) -{ - if (N < BitsLeft) - { - Val = (CurrentBfr << (32 - BitsLeft)) >> (32 - N); - BitsLeft -= N; - return Val; - } - else - return Get_Bits_All(N); -} - -__forceinline static void Flush_Buffer(unsigned int N) -{ - if (N < BitsLeft) - BitsLeft -= N; - else - Flush_Buffer_All(N); -} - -int _donread(int fd, void *buffer, unsigned int count); - -__forceinline static unsigned int Get_Byte() -{ - extern unsigned char *buffer_invalid; - - if (Rdptr >= buffer_invalid) - { - // Ran out of good data. - if (LoopPlayback) - ThreadKill(END_OF_DATA_KILL); - Stop_Flag = 1; - return 0xff; - } - - while (Rdptr >= Rdbfr+BUFFER_SIZE) - { - Read = _donread(Infile[CurrentFile], Rdbfr, BUFFER_SIZE); - if (Read < BUFFER_SIZE) - Next_File(); - - Rdptr -= BUFFER_SIZE; - Rdmax -= BUFFER_SIZE; - } - - return *Rdptr++; -} - -__forceinline static void Fill_Next() -{ - extern unsigned char *buffer_invalid; - - if (Rdptr >= buffer_invalid) - { - // Ran out of good data. - if (LoopPlayback) - ThreadKill(END_OF_DATA_KILL); - Stop_Flag = 1; - NextBfr = 0xffffffff; - return; - } - - CurrentPackHeaderPosition = PackHeaderPosition; - if (SystemStream_Flag != ELEMENTARY_STREAM && Rdptr > Rdmax - 4 && !AudioOnly_Flag) - { - if (Rdptr >= Rdmax) - Next_Packet(); - NextBfr = Get_Byte() << 24; - - if (Rdptr >= Rdmax) - Next_Packet(); - NextBfr += Get_Byte() << 16; - - if (Rdptr >= Rdmax) - Next_Packet(); - NextBfr += Get_Byte() << 8; - - if (Rdptr >= Rdmax) - Next_Packet(); - NextBfr += Get_Byte(); - } - else if (Rdptr <= Rdbfr+BUFFER_SIZE - 4) - { -#if 1 - NextBfr = (*Rdptr << 24) + (*(Rdptr+1) << 16) + (*(Rdptr+2) << 8) + *(Rdptr+3); -#else - if (Rdptr < buffer_invalid) - { - NextBfr = (*Rdptr << 24); - if (Rdptr+1 < buffer_invalid) - { - NextBfr += (*(Rdptr+1) << 16); - if (Rdptr+2 < buffer_invalid) - { - NextBfr += (*(Rdptr+2) << 8); - if (Rdptr+3 < buffer_invalid) - { - NextBfr += (*(Rdptr+3)); - } - else - { - NextBfr += 0xff; - Stop_Flag = 1; - } - } - else - { - NextBfr += 0xffff; - Stop_Flag = 1; - } - } - else - { - NextBfr += 0xffffff; - Stop_Flag = 1; - } - } - else - { - NextBfr = 0xffffffff; - Stop_Flag = 1; - } -#endif - Rdptr += 4; - } - else - { - if (Rdptr >= Rdbfr+BUFFER_SIZE) - Fill_Buffer(); - NextBfr = *Rdptr++ << 24; - - if (Rdptr >= Rdbfr+BUFFER_SIZE) - Fill_Buffer(); - NextBfr += *Rdptr++ << 16; - - if (Rdptr >= Rdbfr+BUFFER_SIZE) - Fill_Buffer(); - NextBfr += *Rdptr++ << 8; - - if (Rdptr >= Rdbfr+BUFFER_SIZE) - Fill_Buffer(); - NextBfr += *Rdptr++; - } -} - -__forceinline static void next_start_code() -{ - unsigned int show; - - // This is contrary to the spec but is more resilient to some - // stream corruption scenarios. - BitsLeft = ((BitsLeft + 7) / 8) * 8; - - while (1) - { - show = Show_Bits(24); - if (Stop_Flag == true) - return; - if (show == 0x000001) - return; - Flush_Buffer(8); - } -} - -__forceinline static unsigned int Get_Short() -{ - unsigned int i, j; - - i = Get_Byte(); - j = Get_Byte(); - return ((i << 8) | j); -} diff --git a/src/dgindex/gethdr.cpp b/src/dgindex/gethdr.cpp deleted file mode 100644 index 183f4d5..0000000 --- a/src/dgindex/gethdr.cpp +++ /dev/null @@ -1,922 +0,0 @@ -/* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */ - -/* - * Disclaimer of Warranty - * - * These software programs are available to the user without any license fee or - * royalty on an "as is" basis. The MPEG Software Simulation Group disclaims - * any and all warranties, whether express, implied, or statuary, including any - * implied warranties or merchantability or of fitness for a particular - * purpose. In no event shall the copyright-holder be liable for any - * incidental, punitive, or consequential damages of any kind whatsoever - * arising from the use of these programs. - * - * This disclaimer of warranty extends to the user of these programs and user's - * customers, employees, agents, transferees, successors, and assigns. - * - * The MPEG Software Simulation Group does not represent or warrant that the - * programs furnished hereunder are free of infringement of any third-party - * patents. - * - * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware, - * are subject to royalty fees to patent holders. Many of these patents are - * general enough such that they are unavoidable regardless of implementation - * design. - * - */ - -#include "global.h" -#include "getbit.h" - -static int load_intra_quantizer_matrix; -static int load_non_intra_quantizer_matrix; -static int load_chroma_intra_quantizer_matrix; -static int load_chroma_non_intra_quantizer_matrix; -static int frame_rate_code; - -static double frame_rate_Table[16] = -{ - 0.0, - ((24.0*1000.0)/1001.0), - 24.0, - 25.0, - ((30.0*1000.0)/1001.0), - 30.0, - 50.0, - ((60.0*1000.0)/1001.0), - 60.0, - -1, // reserved - -1, - -1, - -1, - -1, - -1, - -1 -}; - -static unsigned int frame_rate_Table_Num[16] = -{ - 0, - 24000, - 24, - 25, - 30000, - 30, - 50, - 60000, - 60, - 0xFFFFFFFF, // reserved - 0xFFFFFFFF, - 0xFFFFFFFF, - 0xFFFFFFFF, - 0xFFFFFFFF, - 0xFFFFFFFF, - 0xFFFFFFFF -}; - -static unsigned int frame_rate_Table_Den[16] = -{ - 0, - 1001, - 1, - 1, - 1001, - 1, - 1, - 1001, - 1, - 0xFFFFFFFF, // reserved - 0xFFFFFFFF, - 0xFFFFFFFF, - 0xFFFFFFFF, - 0xFFFFFFFF, - 0xFFFFFFFF, - 0xFFFFFFFF -}; - -__forceinline static void group_of_pictures_header(void); -__forceinline static void picture_header(__int64, boolean, boolean); - -static void sequence_extension(void); -static void sequence_display_extension(void); -static void quant_matrix_extension(void); -static void picture_display_extension(void); -static void picture_coding_extension(void); -static void copyright_extension(void); -static int extra_bit_information(void); -static void extension_and_user_data(void); -void StartVideoDemux(void); - -////////// -// We index the on-disk file position for accessing each I picture. -// We prefer to index a sequence header immediately accompanying -// the GOP, because it might carry new quant matrices that we would need -// to read if we randomly access the picture. If no sequence header is -// there, we index the I picture header start code. For ES, we index -// directly each indexed location. For PES, we index the position of -// the previous packet start code for each indexed location. -// -// There are two different indexing strategies, one for ES and one for PES. -// The ES scheme directly calculates the required file offset. -// The PES scheme uses CurrentPackHeaderPosition for the on-disk file -// offset of the last pack start code. This variable is irrelevant for ES! -// The pack header position is double-buffered through PackHeaderPosition -// and CurrentPackHeaderPosition to avoid a vulnerability in which -// PackHeaderPosition can become invalid due to a Fill_Next() call -// triggering a Next_Packet() call, which would rewrite PackHeaderPosition. -// So we record PackHeaderPosition to CurrentPackHeaderPosition as the -// first thing we do in Fill_Next(). -////////// - -// Decode headers up to a picture header and then return. -// There are two modes of operation. Normally, we return only -// when we get a picture header and if we hit EOF file, we -// thread kill ourselves in here. But when checking for leading -// B frames we don't want to kill in order to properly handle -// files with only one I frame. So in the second mode, we detect -// the sequence end code and return with an indication. - -int Get_Hdr(int mode) -{ - int code; - __int64 position = 0; - boolean HadSequenceHeader = false; - boolean HadGopHeader = false; - - for (;;) - { - // Look for next_start_code. - if (Stop_Flag == true) - return 1; - next_start_code(); - - code = Show_Bits(32); - switch (code) - { - case 0x1be: - break; - - case SEQUENCE_HEADER_CODE: - // Index the location of the sequence header for the D2V file. - // We prefer to index the sequence header corresponding to this - // GOP, but if one doesn't exist, we index the picture header of the I frame. - if (SystemStream_Flag != ELEMENTARY_STREAM) - d2v_current.position = CurrentPackHeaderPosition; - else - { -// dprintf("DGIndex: Index sequence header at %d\n", Rdptr - 8 + (32 - BitsLeft)/8); - d2v_current.position = _telli64(Infile[CurrentFile]) - - (BUFFER_SIZE - (Rdptr - Rdbfr)) - - 8 - + (32 - BitsLeft)/8; - } - Get_Bits(32); - sequence_header(); - HadSequenceHeader = true; - break; - - case SEQUENCE_END_CODE: - Get_Bits(32); - if (mode == 1) - return 1; - break; - - case GROUP_START_CODE: - Get_Bits(32); - group_of_pictures_header(); - HadGopHeader = true; - GOPSeen = true; - break; - - case PICTURE_START_CODE: - if (SystemStream_Flag != ELEMENTARY_STREAM) - position = CurrentPackHeaderPosition; - else - position = _telli64(Infile[CurrentFile]) - - (BUFFER_SIZE - (Rdptr - Rdbfr)) - - 8 - + (32 - BitsLeft)/8; - Get_Bits(32); - picture_header(position, HadSequenceHeader, HadGopHeader); - return 0; - break; - - default: - Get_Bits(32); - break; - } - } -} - -/* decode sequence header */ -void sequence_header() -{ - int constrained_parameters_flag; - int bit_rate_value; - int vbv_buffer_size; - int i; - - // These will become nonzero if we receive a sequence display extension - display_horizontal_size = 0; - display_vertical_size = 0; - - horizontal_size = Get_Bits(12); - vertical_size = Get_Bits(12); - aspect_ratio_information = Get_Bits(4); - frame_rate_code = Get_Bits(4); - - // This is default MPEG1 handling. - // It may be overridden to MPEG2 if a - // sequence extension arrives. - frame_rate = frame_rate_Table[frame_rate_code]; - fr_num = frame_rate_Table_Num[frame_rate_code]; - fr_den = frame_rate_Table_Den[frame_rate_code]; - - bit_rate_value = Get_Bits(18); - Flush_Buffer(1); // marker bit - vbv_buffer_size = Get_Bits(10); - constrained_parameters_flag = Get_Bits(1); - - if (load_intra_quantizer_matrix = Get_Bits(1)) - { - for (i=0; i<64; i++) - intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8); - } - else - { - for (i=0; i<64; i++) - intra_quantizer_matrix[i] = default_intra_quantizer_matrix[i]; - } - - if (load_non_intra_quantizer_matrix = Get_Bits(1)) - { - for (i=0; i<64; i++) - non_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8); - } - else - { - for (i=0; i<64; i++) - non_intra_quantizer_matrix[i] = 16; - } - - /* copy luminance to chrominance matrices */ - for (i=0; i<64; i++) - { - chroma_intra_quantizer_matrix[i] = intra_quantizer_matrix[i]; - chroma_non_intra_quantizer_matrix[i] = non_intra_quantizer_matrix[i]; - } - - if (D2V_Flag && LogQuants_Flag) - { - // Log the quant matrix changes. - // Intra luma. - for (i=0; i<64; i++) - { - if (intra_quantizer_matrix[i] != intra_quantizer_matrix_log[i]) - break; - } - if (i < 64) - { - // The matrix changed, so log it. - fprintf(Quants, "Intra Luma and Chroma Matrix at encoded frame %d:\n", Frame_Number); - for (i=0; i<64; i++) - { - fprintf(Quants, "%d ", intra_quantizer_matrix[i]); - if ((i % 8) == 7) - fprintf(Quants, "\n"); - } - fprintf(Quants, "\n"); - // Record the new matrix for change detection. - memcpy(intra_quantizer_matrix_log, intra_quantizer_matrix, sizeof(intra_quantizer_matrix)); - memcpy(chroma_intra_quantizer_matrix_log, chroma_intra_quantizer_matrix, sizeof(chroma_intra_quantizer_matrix)); - } - // Non intra luma. - for (i=0; i<64; i++) - { - if (non_intra_quantizer_matrix[i] != non_intra_quantizer_matrix_log[i]) - break; - } - if (i < 64) - { - // The matrix changed, so log it. - fprintf(Quants, "NonIntra Luma and Chroma Matrix at encoded frame %d:\n", Frame_Number); - for (i=0; i<64; i++) - { - fprintf(Quants, "%d ", non_intra_quantizer_matrix[i]); - if ((i % 8) == 7) - fprintf(Quants, "\n"); - } - fprintf(Quants, "\n"); - // Record the new matrix for change detection. - memcpy(non_intra_quantizer_matrix_log, non_intra_quantizer_matrix, sizeof(non_intra_quantizer_matrix)); - memcpy(chroma_non_intra_quantizer_matrix_log, chroma_non_intra_quantizer_matrix, sizeof(chroma_non_intra_quantizer_matrix)); - } - } - - // This is default MPEG1 handling. - // It may be overridden to MPEG2 if a - // sequence extension arrives. - matrix_coefficients = 5; - default_matrix_coefficients = true; - - setRGBValues(); - // These are MPEG1 defaults. These will be overridden if we have MPEG2 - // when the sequence header extension is parsed. - progressive_sequence = 1; - chroma_format = CHROMA420; - - extension_and_user_data(); - - // Special case for 1080i video. - if (vertical_size == 1088) - { - if (CLIActive) - { - crop1088_warned = true; - crop1088 = true; - } - if (crop1088_warned == false) - { - char buf[255]; - sprintf(buf, "Your stream specifies a display height of 1088.\n" - "This is sometimes an encoding mistake and the last 8 lines are garbage.\n" - "Do you want to treat it as if it specified a height of 1080?"); - if (MessageBox(hWnd, buf, "Display Height 1088 Warning", MB_YESNO | MB_ICONINFORMATION) == IDYES) - crop1088 = true; - else - crop1088 = false; - crop1088_warned = true; - } - if (crop1088 == true) - vertical_size = 1080; - } -} - -/* decode group of pictures header */ -/* ISO/IEC 13818-2 section 6.2.2.6 */ -static void group_of_pictures_header() -{ - int gop_hour; - int gop_minute; - int gop_sec; - int gop_frame; - int drop_flag; - int broken_link; - - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - fprintf(Timestamps, "GOP start\n"); - drop_flag = Get_Bits(1); - gop_hour = Get_Bits(5); - gop_minute = Get_Bits(6); - Flush_Buffer(1); // marker bit - gop_sec = Get_Bits(6); - gop_frame = Get_Bits(6); - closed_gop = Get_Bits(1); - broken_link = Get_Bits(1); - -// extension_and_user_data(); -} - -/* decode picture header */ -/* ISO/IEC 13818-2 section 6.2.3 */ -static void picture_header(__int64 start, boolean HadSequenceHeader, boolean HadGopHeader) -{ - int vbv_delay; - int Extra_Information_Byte_Count; - int trackpos; - double track; - - temporal_reference = Get_Bits(10); - picture_coding_type = Get_Bits(3); - if (LogTimestamps_Flag && D2V_Flag && StartLogging_Flag) - { - fprintf(Timestamps, "Decode picture: temporal reference %d", temporal_reference); - switch (picture_coding_type) - { - case I_TYPE: - fprintf(Timestamps, "[I]\n"); - break; - case P_TYPE: - fprintf(Timestamps, "[P]\n"); - break; - case B_TYPE: - fprintf(Timestamps, "[B]\n"); - break; - } - } - - d2v_current.type = picture_coding_type; - - if (d2v_current.type == I_TYPE) - { - d2v_current.file = process.startfile = CurrentFile; - process.startloc = _telli64(Infile[CurrentFile]); - d2v_current.lba = process.startloc/SECTOR_SIZE - 1; - if (d2v_current.lba < 0) - { - d2v_current.lba = 0; - } - track = (double) d2v_current.lba; - track *= SECTOR_SIZE; - track += process.run; - track *= TRACK_PITCH; - track /= Infiletotal; - trackpos = (int) track; - SendMessage(hTrack, TBM_SETPOS, (WPARAM)true, trackpos); - InvalidateRect(hwndSelect, NULL, TRUE); -#if 0 - { - char buf[80]; - char total[80], run[80]; - _i64toa(Infiletotal, total, 10); - _i64toa(process.run, run, 10); - sprintf(buf, "DGIndex: d2v_current.lba = %x\n", d2v_current.lba); - OutputDebugString(buf); - sprintf(buf, "DGIndex: trackpos = %d\n", trackpos); - OutputDebugString(buf); - sprintf(buf, "DGIndex: process.run = %s\n", run); - OutputDebugString(buf); - sprintf(buf, "DGIndex: Infiletotal = %s\n", total); - OutputDebugString(buf); - } -#endif - - if (process.locate==LOCATE_RIP) - { - process.file = d2v_current.file; - process.lba = d2v_current.lba; - } - - // This triggers if we reach the right marker position. - if (CurrentFile==process.endfile && process.startloc>=process.endloc) // D2V END - { - ThreadKill(END_OF_DATA_KILL); - } - - if (Info_Flag) - UpdateInfo(); - UpdateWindowText(PICTURE_HEADER); - } - - vbv_delay = Get_Bits(16); - - if (picture_coding_type == P_TYPE || picture_coding_type == B_TYPE) - { - full_pel_forward_vector = Get_Bits(1); - forward_f_code = Get_Bits(3); - } - - if (picture_coding_type == B_TYPE) - { - full_pel_backward_vector = Get_Bits(1); - backward_f_code = Get_Bits(3); - } - - // MPEG1 defaults. May be overriden by picture coding extension. - intra_dc_precision = 0; - picture_structure = FRAME_PICTURE; - top_field_first = 1; - frame_pred_frame_dct = 1; - concealment_motion_vectors = 0; - q_scale_type = 0; - intra_vlc_format = 0; - alternate_scan = 0; - repeat_first_field = 0; - progressive_frame = 1; - - d2v_current.pf = progressive_frame; - d2v_current.trf = (top_field_first<<1) + repeat_first_field; - - Extra_Information_Byte_Count = extra_bit_information(); - extension_and_user_data(); - - // We prefer to index the sequence header, but if one doesn't exist, - // we index the picture header of the I frame. - if (HadSequenceHeader == false) - { - // Indexing for the D2V file. - if (picture_coding_type == I_TYPE && !Second_Field) - { -// dprintf("DGIndex: Index picture header at %d\n", Rdptr - Rdbfr); - d2v_current.position = start; - } - } -} - -/* decode slice header */ -/* ISO/IEC 13818-2 section 6.2.4 */ -int slice_header() -{ - int slice_vertical_position_extension; - int quantizer_scale_code; - - if (mpeg_type == IS_MPEG2) - slice_vertical_position_extension = vertical_size>2800 ? Get_Bits(3) : 0; - else - slice_vertical_position_extension = 0; - - quantizer_scale_code = Get_Bits(5); - if (mpeg_type == IS_MPEG2) - quantizer_scale = q_scale_type ? Non_Linear_quantizer_scale[quantizer_scale_code] : quantizer_scale_code<<1; - else - quantizer_scale = quantizer_scale_code; - - while (Get_Bits(1)) Flush_Buffer(8); - - return slice_vertical_position_extension; -} - -/* decode extension and user data */ -/* ISO/IEC 13818-2 section 6.2.2.2 */ -static void extension_and_user_data() -{ - int code, ext_ID; - - if (Stop_Flag == true) - return; - next_start_code(); - - while ((code = Show_Bits(32))==EXTENSION_START_CODE || code==USER_DATA_START_CODE) - { - if (code==EXTENSION_START_CODE) - { - Flush_Buffer(32); - ext_ID = Get_Bits(4); - - switch (ext_ID) - { - case SEQUENCE_EXTENSION_ID: - sequence_extension(); - break; - case SEQUENCE_DISPLAY_EXTENSION_ID: - sequence_display_extension(); - break; - case QUANT_MATRIX_EXTENSION_ID: - quant_matrix_extension(); - break; - case PICTURE_DISPLAY_EXTENSION_ID: - picture_display_extension(); - break; - case PICTURE_CODING_EXTENSION_ID: - picture_coding_extension(); - break; - case COPYRIGHT_EXTENSION_ID: - copyright_extension(); - break; - } - if (Stop_Flag == true) - return; - next_start_code(); - } - else - { - Flush_Buffer(32); // ISO/IEC 13818-2 sections 6.3.4.1 and 6.2.2.2.2 - if (Stop_Flag == true) - return; - next_start_code(); // skip user data - } - } -} - -/* decode sequence extension */ -/* ISO/IEC 13818-2 section 6.2.2.3 */ -int profile_and_level_indication; -static void sequence_extension() -{ - int low_delay; - int frame_rate_extension_n; - int frame_rate_extension_d; - int horizontal_size_extension; - int vertical_size_extension; - int bit_rate_extension; - int vbv_buffer_size_extension; - - // This extension means we must have MPEG2, so - // override the earlier assumption of MPEG1 for - // transport streams. - mpeg_type = IS_MPEG2; - setRGBValues(); - - profile_and_level_indication = Get_Bits(8); - progressive_sequence = Get_Bits(1); - chroma_format = Get_Bits(2); - horizontal_size_extension = Get_Bits(2); - vertical_size_extension = Get_Bits(2); - bit_rate_extension = Get_Bits(12); - Flush_Buffer(1); // marker bit - vbv_buffer_size_extension = Get_Bits(8); - low_delay = Get_Bits(1); - - frame_rate_extension_n = Get_Bits(2); - frame_rate_extension_d = Get_Bits(5); - frame_rate = frame_rate_Table[frame_rate_code] * (frame_rate_extension_n+1)/(frame_rate_extension_d+1); - fr_num = frame_rate_Table_Num[frame_rate_code] * (frame_rate_extension_n+1); - fr_den = frame_rate_Table_Den[frame_rate_code] * (frame_rate_extension_d+1); - - horizontal_size = (horizontal_size_extension<<12) | (horizontal_size&0x0fff); - vertical_size = (vertical_size_extension<<12) | (vertical_size&0x0fff); - // This is the default case and may be overridden by a sequence display extension. - if (horizontal_size > 720 || vertical_size > 576) - // HD - matrix_coefficients = 1; - else - // SD - matrix_coefficients = 5; -} - -/* decode sequence display extension */ -static void sequence_display_extension() -{ - int video_format; - int color_description; - int color_primaries; - int transfer_characteristics; - int matrix; - - video_format = Get_Bits(3); - color_description = Get_Bits(1); - - if (color_description) - { - color_primaries = Get_Bits(8); - transfer_characteristics = Get_Bits(8); - matrix = Get_Bits(8); - // If the stream specifies "reserved" or "unspecified" then leave things set to our default - // based on HD versus SD. - if (matrix == 1 || (matrix >= 4 && matrix <= 7)) - { - matrix_coefficients = matrix; - default_matrix_coefficients = false; - } - setRGBValues(); - } - - display_horizontal_size = Get_Bits(14); - Flush_Buffer(1); // marker bit - display_vertical_size = Get_Bits(14); -} - -/* decode quant matrix entension */ -/* ISO/IEC 13818-2 section 6.2.3.2 */ -static void quant_matrix_extension() -{ - int i; - - if (load_intra_quantizer_matrix = Get_Bits(1)) - for (i=0; i<64; i++) - chroma_intra_quantizer_matrix[scan[ZIG_ZAG][i]] - = intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8); - - if (load_non_intra_quantizer_matrix = Get_Bits(1)) - for (i=0; i<64; i++) - chroma_non_intra_quantizer_matrix[scan[ZIG_ZAG][i]] - = non_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8); - - if (load_chroma_intra_quantizer_matrix = Get_Bits(1)) - for (i=0; i<64; i++) - chroma_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8); - - if (load_chroma_non_intra_quantizer_matrix = Get_Bits(1)) - for (i=0; i<64; i++) - chroma_non_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8); - - if (D2V_Flag && LogQuants_Flag) - { - // Log the quant matrix changes. - // Intra luma. - for (i=0; i<64; i++) - { - if (intra_quantizer_matrix[i] != intra_quantizer_matrix_log[i]) - break; - } - if (i < 64) - { - // The matrix changed, so log it. - fprintf(Quants, "Intra Luma Matrix at encoded frame %d:\n", Frame_Number); - for (i=0; i<64; i++) - { - fprintf(Quants, "%d ", intra_quantizer_matrix[i]); - if ((i % 8) == 7) - fprintf(Quants, "\n"); - } - fprintf(Quants, "\n"); - // Record the new matrix for change detection. - memcpy(intra_quantizer_matrix_log, intra_quantizer_matrix, sizeof(intra_quantizer_matrix)); - } - // Non intra luma. - for (i=0; i<64; i++) - { - if (non_intra_quantizer_matrix[i] != non_intra_quantizer_matrix_log[i]) - break; - } - if (i < 64) - { - // The matrix changed, so log it. - fprintf(Quants, "NonIntra Luma Matrix at encoded frame %d:\n", Frame_Number); - for (i=0; i<64; i++) - { - fprintf(Quants, "%d ", non_intra_quantizer_matrix[i]); - if ((i % 8) == 7) - fprintf(Quants, "\n"); - } - fprintf(Quants, "\n"); - // Record the new matrix for change detection. - memcpy(non_intra_quantizer_matrix_log, non_intra_quantizer_matrix, sizeof(non_intra_quantizer_matrix)); - } - // Intra chroma. - for (i=0; i<64; i++) - { - if (chroma_intra_quantizer_matrix[i] != chroma_intra_quantizer_matrix_log[i]) - break; - } - if (i < 64) - { - // The matrix changed, so log it. - fprintf(Quants, "Intra Chroma Matrix at encoded frame %d:\n", Frame_Number); - for (i=0; i<64; i++) - { - fprintf(Quants, "%d ", chroma_intra_quantizer_matrix[i]); - if ((i % 8) == 7) - fprintf(Quants, "\n"); - } - fprintf(Quants, "\n"); - // Record the new matrix for change detection. - memcpy(chroma_intra_quantizer_matrix_log, chroma_intra_quantizer_matrix, sizeof(chroma_intra_quantizer_matrix)); - } - // Non intra chroma. - for (i=0; i<64; i++) - { - if (chroma_non_intra_quantizer_matrix[i] != chroma_non_intra_quantizer_matrix_log[i]) - break; - } - if (i < 64) - { - // The matrix changed, so log it. - fprintf(Quants, "NonIntra Chroma Matrix at encoded frame %d:\n", Frame_Number); - for (i=0; i<64; i++) - { - fprintf(Quants, "%d ", chroma_non_intra_quantizer_matrix[i]); - if ((i % 8) == 7) - fprintf(Quants, "\n"); - } - fprintf(Quants, "\n"); - // Record the new matrix for change detection. - memcpy(chroma_non_intra_quantizer_matrix_log, chroma_non_intra_quantizer_matrix, sizeof(chroma_non_intra_quantizer_matrix)); - } - } -} - -/* decode picture display extension */ -/* ISO/IEC 13818-2 section 6.2.3.3. */ -static void picture_display_extension() -{ - int frame_center_horizontal_offset[3]; - int frame_center_vertical_offset[3]; - - int i; - int number_of_frame_center_offsets; - - /* based on ISO/IEC 13818-2 section 6.3.12 - (November 1994) Picture display extensions */ - - /* derive number_of_frame_center_offsets */ - if (progressive_sequence) - { - if (repeat_first_field) - { - if (top_field_first) - number_of_frame_center_offsets = 3; - else - number_of_frame_center_offsets = 2; - } - else - number_of_frame_center_offsets = 1; - } - else - { - if (picture_structure!=FRAME_PICTURE) - number_of_frame_center_offsets = 1; - else - { - if (repeat_first_field) - number_of_frame_center_offsets = 3; - else - number_of_frame_center_offsets = 2; - } - } - - /* now parse */ - for (i=0; i 0) - { - WriteD2VLine(0); - } - if (GOPSeen == true && picture_coding_type == I_TYPE) - gop_entries[gop_entries_ndx].gop_start = true; - else - gop_entries[gop_entries_ndx].gop_start = false; - GOPSeen = false; - gop_entries[gop_entries_ndx].lba = (int) d2v_current.lba; - gop_entries[gop_entries_ndx].position = d2v_current.position; - gop_entries[gop_entries_ndx].pf = progressive_frame; - gop_entries[gop_entries_ndx].pct = picture_coding_type; - gop_entries[gop_entries_ndx].trf = d2v_current.trf; - gop_entries[gop_entries_ndx].closed = ForceOpenGops ? 0 : closed_gop; - gop_entries[gop_entries_ndx].pseq = progressive_sequence; - gop_entries[gop_entries_ndx].matrix = matrix_coefficients; - gop_entries[gop_entries_ndx].vob_id = VOB_ID; - gop_entries[gop_entries_ndx].cell_id = CELL_ID; - if (gop_entries_ndx < MAX_PICTURES_PER_GOP - 1) - gop_entries_ndx++; - else - { - MessageBox(hWnd, "Too many pictures per GOP (>= 500).\nDGIndex will terminate.", NULL, MB_OK | MB_ICONERROR); - exit(1); - } - } - if (D2V_Flag) - { - if (Frame_Number && picture_structure==FRAME_PICTURE || Second_Field) - { - if (d2v_current.type==B_TYPE) - { - DetectVideoType(Frame_Number-1, d2v_current.trf); - } - else - switch (d2v_forward.type) - { - case P_TYPE: - DetectVideoType(Frame_Number-1, d2v_forward.trf); - break; - - case I_TYPE: - DetectVideoType(Frame_Number-1, d2v_forward.trf); - break; - - default: - SetDlgItemText(hDlg, IDC_INFO, "picture error"); - break; - } - } - } - else if (!Decision_Flag) - { - /* update picture buffer pointers */ - Update_Picture_Buffers(); - - /* decode picture data ISO/IEC 13818-2 section 6.2.3.7 */ - picture_data(); - - /* write or display current or previously decoded reference frame */ - /* ISO/IEC 13818-2 section 6.1.1.11: Frame reordering */ - if (picture_structure == FRAME_PICTURE || Second_Field) - { - if (process.locate != LOCATE_RIP) - { - Write_Frame(backward_reference_frame, d2v_backward, 0); - ThreadKill(MISC_KILL); - } - else if (Frame_Number > 0) - { - if (picture_coding_type==B_TYPE) - Write_Frame(auxframe, d2v_current, Frame_Number-1); - else - Write_Frame(forward_reference_frame, d2v_forward, Frame_Number-1); - } - } - } - - if (picture_structure!=FRAME_PICTURE) - Second_Field = !Second_Field; - - if (!Second_Field) - Frame_Number++; - if (Info_Flag && process.locate==LOCATE_RIP && CLIPreview && Frame_Number >= 100) - { - CLIActive = 0; - SendMessage(hWnd, CLI_PREVIEW_DONE_MESSAGE, 0, 0); - ThreadKill(MISC_KILL); - } -} -__except (EXCEPTION_EXECUTE_HANDLER) -{ - if (MessageBox(hWnd, "Caught an exception during decoding! Continue?", "Exception!", MB_YESNO | MB_ICONERROR) == IDYES) - return; - else - ThreadKill(MISC_KILL); -} -} - -/* reuse old picture buffers as soon as they are no longer needed */ -static void Update_Picture_Buffers() -{ - int cc; - unsigned char *tmp; - - for (cc=0; cc<3; cc++) - { - /* B pictures do not need to be save for future reference */ - if (picture_coding_type==B_TYPE) - current_frame[cc] = auxframe[cc]; - else - { - if (!Second_Field) - { - /* only update at the beginning of the coded frame */ - tmp = forward_reference_frame[cc]; - - /* the previously decoded reference frame is stored coincident with the - location where the backward reference frame is stored (backwards - prediction is not needed in P pictures) */ - forward_reference_frame[cc] = backward_reference_frame[cc]; - - /* update pointer for potential future B pictures */ - backward_reference_frame[cc] = tmp; - } - - /* can erase over old backward reference frame since it is not used - in a P picture, and since any subsequent B pictures will use the - previously decoded I or P frame as the backward_reference_frame */ - current_frame[cc] = backward_reference_frame[cc]; - } - - if (picture_structure==BOTTOM_FIELD) - current_frame[cc] += (cc==0) ? Coded_Picture_Width : ((chroma_format==CHROMA444) ? Coded_Picture_Width : Coded_Picture_Width>>1); - } -} - -/* decode all macroblocks of the current picture */ -/* stages described in ISO/IEC 13818-2 section 7 */ -static void picture_data() -{ - int MBAmax; - unsigned int code; - - /* number of macroblocks per picture */ - MBAmax = mb_width*mb_height; - - if (picture_structure != FRAME_PICTURE) - MBAmax>>=1; - - for (;;) - { - if (Stop_Flag == true) - break; - next_start_code(); - code = Show_Bits(32); - if (code < SLICE_START_CODE_MIN || code > SLICE_START_CODE_MAX) - break; - Flush_Buffer(32); - slice(MBAmax, code); - } -} - -/* decode all macroblocks of the current picture */ -/* ISO/IEC 13818-2 section 6.3.16 */ -static void slice(int MBAmax, unsigned int code) -{ - int MBA, MBAinc; - int macroblock_type, motion_type, dct_type = 0; - int dc_dct_pred[3], PMV[2][2][2], motion_vertical_field_select[2][2], dmvector[2]; - int slice_vert_pos_ext; - - MBA = MBAinc = 0; - - /* decode slice header (may change quantizer_scale) */ - slice_vert_pos_ext = slice_header(); - - /* decode macroblock address increment */ - Fault_Flag = 0; - MBAinc = Get_macroblock_address_increment(); - if (MBAinc < 0) - { - // End of slice but we didn't process any macroblocks! - SetFaultFlag(4); - return; - } - - /* set current location */ - /* NOTE: the arithmetic used to derive macroblock_address below is - equivalent to ISO/IEC 13818-2 section 6.3.17: Macroblock */ - MBA = ((slice_vert_pos_ext << 7) + (code & 255) - 1) * mb_width + MBAinc - 1; - MBAinc = 1; // first macroblock in slice: not skipped - - /* reset all DC coefficient and motion vector predictors */ - /* ISO/IEC 13818-2 section 7.2.1: DC coefficients in intra blocks */ - dc_dct_pred[0]=dc_dct_pred[1] = dc_dct_pred[2]=0; - - /* ISO/IEC 13818-2 section 7.6.3.4: Resetting motion vector predictors */ - 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; - - // This while loop condition just prevents us from processing more than - // the maximum number of macroblocks possible in a picture. The loop is - // unlikely to ever terminate on this condition. Usually, it will - // terminate at the end of the slice. The end of a slice is indicated - // by 23 zeroes after a macroblock. To detect that, we use a trick in - // Get_macroblock_address_increment(). See that function for an - // explanation. - while (MBA < MBAmax) - { - if (MBAinc == 0) - { - /* decode macroblock address increment */ - MBAinc = Get_macroblock_address_increment(); - if (MBAinc < 0) - { - // End of slice. - break; - } - } - if (MBAinc==1) - { - decode_macroblock(¯oblock_type, &motion_type, &dct_type, PMV, - dc_dct_pred, motion_vertical_field_select, dmvector); - } - else - { - /* skipped macroblock */ - /* ISO/IEC 13818-2 section 7.6.6 */ - skipped_macroblock(dc_dct_pred, PMV, &motion_type, motion_vertical_field_select, ¯oblock_type); - } - if (Fault_Flag) - break; - - /* ISO/IEC 13818-2 section 7.6 */ - motion_compensation(MBA, macroblock_type, motion_type, PMV, - motion_vertical_field_select, dmvector, dct_type); - - /* advance to next macroblock */ - MBA++; - MBAinc--; - } -} - -/* ISO/IEC 13818-2 section 6.3.17.1: Macroblock modes */ -static void macroblock_modes(int *pmacroblock_type, int *pmotion_type, - int *pmotion_vector_count, int *pmv_format, - int *pdmv, int *pmvscale, int *pdct_type) -{ - int macroblock_type, motion_type, motion_vector_count; - int mv_format, dmv, mvscale, dct_type; - - /* get macroblock_type */ - macroblock_type = Get_macroblock_type(); - if (Fault_Flag) return; - - /* get frame/field motion type */ - if (macroblock_type & (MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD)) - { - if (picture_structure==FRAME_PICTURE) - motion_type = frame_pred_frame_dct ? MC_FRAME : Get_Bits(2); - else - motion_type = Get_Bits(2); - } - else - motion_type = (picture_structure==FRAME_PICTURE) ? MC_FRAME : MC_FIELD; - - /* derive motion_vector_count, mv_format and dmv, (table 6-17, 6-18) */ - if (picture_structure==FRAME_PICTURE) - { - motion_vector_count = (motion_type==MC_FIELD) ? 2 : 1; - mv_format = (motion_type==MC_FRAME) ? MV_FRAME : MV_FIELD; - } - else - { - motion_vector_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 - ISO/IEC 13818-2 section 7.6.3.1 Decoding the motion vectors - */ - mvscale = (mv_format==MV_FIELD && picture_structure==FRAME_PICTURE); - - /* get dct_type (frame DCT / field DCT) */ - dct_type = picture_structure==FRAME_PICTURE && !frame_pred_frame_dct - && (macroblock_type & (MACROBLOCK_PATTERN|MACROBLOCK_INTRA)) ? Get_Bits(1) : 0; - - /* return values */ - *pmacroblock_type = macroblock_type; - *pmotion_type = motion_type; - *pmotion_vector_count = motion_vector_count; - *pmv_format = mv_format; - *pdmv = dmv; - *pmvscale = mvscale; - *pdct_type = dct_type; -} - -/* move/add 8x8-Block from block[comp] to backward_reference_frame */ -/* copy reconstructed 8x8 block from block[comp] to current_frame[] - ISO/IEC 13818-2 section 7.6.8: Adding prediction and coefficient data - This stage also embodies some of the operations implied by: - - ISO/IEC 13818-2 section 7.6.7: Combining predictions - - ISO/IEC 13818-2 section 6.1.3: Macroblock -*/ -static void Add_Block(int count, int bx, int by, int dct_type, int addflag) -{ - static const __int64 mmmask_128 = 0x0080008000800080; - int Chroma_Width = (chroma_format==CHROMA444) ? Coded_Picture_Width : Coded_Picture_Width>>1; - - int comp, cc, iincr, bxh, byh; - unsigned char *rfp; - short *Block_Ptr; - - for (comp=0; comp>1)) + bx + ((comp&1)<<3); - iincr = Coded_Picture_Width<<1; - } - else - { - rfp = current_frame[0] + Coded_Picture_Width*(by+((comp&2)<<2)) + bx + ((comp&1)<<3); - iincr = Coded_Picture_Width; - } - } - else - { - rfp = current_frame[0] + (Coded_Picture_Width<<1)*(by+((comp&2)<<2)) + bx + ((comp&1)<<3); - iincr = Coded_Picture_Width<<1; - } - } - else - { - if (chroma_format!=CHROMA444) - bxh >>= 1; - if (chroma_format==CHROMA420) - byh >>= 1; - - if (picture_structure==FRAME_PICTURE) - { - if (dct_type && chroma_format!=CHROMA420) - { - // field DCT coding - rfp = current_frame[cc] + Chroma_Width*(byh+((comp&2)>>1)) + bxh + (comp&8); - iincr = Chroma_Width<<1; - } - else - { - // frame DCT coding - rfp = current_frame[cc] + Chroma_Width*(byh+((comp&2)<<2)) + bxh + (comp&8); - iincr = Chroma_Width; - } - } - else - { - // field picture - rfp = current_frame[cc] + (Chroma_Width<<1)*(byh+((comp&2)<<2)) + bxh + (comp&8); - iincr = Chroma_Width<<1; - } - } - - if (cpu.sse2) // SSE2 - { - if (addflag) - { - __asm - { - pxor xmm0, xmm0 - mov eax, [rfp] - mov ebx, [Block_Ptr] - mov ecx, [iincr] - mov edx, ecx - add edx, edx - mov edi, edx - add edx, ecx - add edi, edi - add edi, ecx - mov esi, edx - add esi, esi - add esi, ecx - - movq xmm1, qword ptr[eax] - punpcklbw xmm1, xmm0 - paddsw xmm1, [ebx+16*0] - packuswb xmm1, xmm0 - movq qword ptr[eax], xmm1 - - movq xmm2, qword ptr[eax+ecx] - punpcklbw xmm2, xmm0 - paddsw xmm2, [ebx+16*1] - packuswb xmm2, xmm0 - movq qword ptr[eax+ecx], xmm2 - - movq xmm3, qword ptr[eax+ecx*2] - punpcklbw xmm3, xmm0 - paddsw xmm3, [ebx+16*2] - packuswb xmm3, xmm0 - movq qword ptr[eax+ecx*2], xmm3 - - movq xmm4, qword ptr[eax+edx] - punpcklbw xmm4, xmm0 - paddsw xmm4, [ebx+16*3] - packuswb xmm4, xmm0 - movq qword ptr[eax+edx], xmm4 - - movq xmm5, qword ptr[eax+ecx*4] - punpcklbw xmm5, xmm0 - paddsw xmm5, [ebx+16*4] - packuswb xmm5, xmm0 - movq qword ptr[eax+ecx*4], xmm5 - - movq xmm6, qword ptr[eax+edi] - punpcklbw xmm6, xmm0 - paddsw xmm6, [ebx+16*5] - packuswb xmm6, xmm0 - movq qword ptr[eax+edi], xmm6 - - movq xmm7, qword ptr[eax+edx*2] - punpcklbw xmm7, xmm0 - paddsw xmm7, [ebx+16*6] - packuswb xmm7, xmm0 - movq qword ptr[eax+edx*2], xmm7 - - movq xmm1, qword ptr[eax+esi] - punpcklbw xmm1, xmm0 - paddsw xmm1, [ebx+16*7] - packuswb xmm1, xmm0 - movq qword ptr[eax+esi], xmm1 - } - } - else - { - __asm - { - mov eax, 0x00800080 - movd xmm7, eax - pshufd xmm7, xmm7, 0 - - mov eax, [rfp] - mov ebx, [Block_Ptr] - mov ecx, [iincr] - mov edx, ecx - add edx, edx - mov edi, edx - add edx, ecx - add edi, edi - add edi, ecx - mov esi, edx - add esi, esi - add esi, ecx - - movdqa xmm0, [ebx+16*0] - paddsw xmm0, xmm7 - packuswb xmm0, xmm0 - movq qword ptr[eax], xmm0 - - movdqa xmm1, [ebx+16*1] - paddsw xmm1, xmm7 - packuswb xmm1, xmm1 - movq qword ptr[eax+ecx],xmm1 - - movdqa xmm2, [ebx+16*2] - paddsw xmm2, xmm7 - packuswb xmm2, xmm2 - movq qword ptr [eax+ecx*2], xmm2 - - movdqa xmm3, [ebx+16*3] - paddsw xmm3, xmm7 - packuswb xmm3, xmm3 - movq qword ptr [eax+edx], xmm3 - - movdqa xmm4, [ebx+16*4] - paddsw xmm4, xmm7 - packuswb xmm4, xmm4 - movq qword ptr[eax+ecx*4], xmm4 - - movdqa xmm5, [ebx+16*5] - paddsw xmm5, xmm7 - packuswb xmm5, xmm5 - movq qword ptr [eax+edi], xmm5 - - movdqa xmm6, [ebx+16*6] - paddsw xmm6, xmm7 - packuswb xmm6, xmm6 - movq qword ptr [eax+edx*2], xmm6 - - paddsw xmm7, [ebx+16*7] - packuswb xmm7, xmm7 - movq qword ptr[eax+esi], xmm7 - } - } - } - else // MMX - { - if (addflag) - { - __asm - { - pxor mm0, mm0 - mov eax, [rfp] - mov ebx, [Block_Ptr] - mov edi, 8 - addon: - movq mm2, [ebx+8] - - movq mm3, [eax] - movq mm4, mm3 - - movq mm1, [ebx] - punpckhbw mm3, mm0 - - paddsw mm3, mm2 - packuswb mm3, mm0 - - punpcklbw mm4, mm0 - psllq mm3, 32 - - paddsw mm4, mm1 - packuswb mm4, mm0 - - por mm3, mm4 - add ebx, 16 - - dec edi - movq [eax], mm3 - - add eax, [iincr] - cmp edi, 0x00 - jg addon - } - } - else - { - __asm - { - mov eax, [rfp] - mov ebx, [Block_Ptr] - mov edi, 8 - - pxor mm0, mm0 - movq mm1, [mmmask_128] - addoff: - movq mm3, [ebx+8] - movq mm4, [ebx] - - paddsw mm3, mm1 - paddsw mm4, mm1 - - packuswb mm3, mm0 - packuswb mm4, mm0 - - psllq mm3, 32 - por mm3, mm4 - - add ebx, 16 - dec edi - - movq [eax], mm3 - - add eax, [iincr] - cmp edi, 0x00 - jg addoff - } - } - } - } - __asm emms; -} - -/* set scratch pad macroblock to zero */ -static void Clear_Block(int count) -{ - int comp; - short *Block_Ptr; - - for (comp=0; comp=16384) - tab = &DCTtabnext[(code>>12)-4]; - else if (code >= 1024) - tab = &DCTtab0[(code>>8)-4]; - else if (code >= 512) - tab = &DCTtab1[(code>>6)-8]; - else if (code >= 256) - tab = &DCTtab2[(code>>4)-16]; - else if (code >= 128) - tab = &DCTtab3[(code>>3)-16]; - else if (code >= 64) - tab = &DCTtab4[(code>>2)-16]; - else if (code >= 32) - tab = &DCTtab5[(code>>1)-16]; - else if (code >= 16) - tab = &DCTtab6[code-16]; - else - { - SetFaultFlag(1); - break; - } - - Flush_Buffer(tab->len); - val = tab->run; - - if (val == 65) - { - // escape - i+= Get_Bits(6); - val = Get_Bits(8); - if (val == 0) - val = Get_Bits(8); - else if (val == 128) - val = Get_Bits(8) - 256; - else if (val > 128) - val -= 256; - sign = (val < 0); - if (sign) - val = - val; - } - else - { - if (val == 64) - break; - i += val; - val = tab->level; - sign = Get_Bits(1); - } - if (i >= 64) - { - SetFaultFlag(1); - break; - } - - j = scan[0][i]; - val = (val * quantizer_scale * intra_quantizer_matrix[j]) >> 3; - if (val) - val = (val - 1) | 1; // mismatch - if (val >= 2048) val = 2047 + sign; // saturation - if (sign) - val = -val; - bp[j] = (short) val; - } -} - -/* decode one intra coded MPEG-2 block */ -static void Decode_MPEG2_Intra_Block(int comp, int dc_dct_pred[]) -{ - long code, val = 0, i, j, sign, sum; - const DCTtab *tab; - short *bp; - int *qmat; - - bp = block[comp]; - qmat = (comp<4 || chroma_format==CHROMA420) - ? intra_quantizer_matrix : chroma_intra_quantizer_matrix; - - /* ISO/IEC 13818-2 section 7.2.1: decode DC coefficients */ - switch (cc_table[comp]) - { - case 0: - val = (dc_dct_pred[0] += Get_Luma_DC_dct_diff()); - break; - - case 1: - val = (dc_dct_pred[1] += Get_Chroma_DC_dct_diff()); - break; - - case 2: - val = (dc_dct_pred[2] += Get_Chroma_DC_dct_diff()); - break; - } - - sum = val << (3 - intra_dc_precision); - bp[0] = (short) sum; - - /* decode AC coefficients */ - for (i=1; ; i++) - { - code = Show_Bits(16); - - if (code >= 16384) - { - if (intra_vlc_format) - tab = &DCTtab0a[(code>>8)-4]; - else - tab = &DCTtabnext[(code>>12)-4]; - } - else if (code >= 1024) - { - if (intra_vlc_format) - tab = &DCTtab0a[(code>>8)-4]; - else - tab = &DCTtab0[(code>>8)-4]; - } - else if (code >= 512) - { - if (intra_vlc_format) - tab = &DCTtab1a[(code>>6)-8]; - else - tab = &DCTtab1[(code>>6)-8]; - } - else if (code >= 256) - tab = &DCTtab2[(code>>4)-16]; - else if (code >= 128) - tab = &DCTtab3[(code>>3)-16]; - else if (code >= 64) - tab = &DCTtab4[(code>>2)-16]; - else if (code >= 32) - tab = &DCTtab5[(code>>1)-16]; - else if (code >= 16) - tab = &DCTtab6[code-16]; - else - { - SetFaultFlag(1); - break; - } - - Flush_Buffer(tab->len); - val = tab->run; - - if (val == 65) - { - // escape - i+= Get_Bits(6); - val = Get_Bits(12); - if (!(val & 2047)) - { - SetFaultFlag(1); - break; - } - sign = (val >= 2048); - if (sign) - val = 4096 - val; - } - else - { - if (val == 64) - break; - i+= val; - val = tab->level; - sign = Get_Bits(1); - } - if (i >= 64) - { - SetFaultFlag(1); - break; - } - j = scan[alternate_scan][i]; - val = (val * quantizer_scale * qmat[j]) >> 4; - if (val >= 2048) - val = 2047 + sign; // saturation - if (sign) - val = -val; - bp[j] = (short) val; - sum ^= val; // mismatch - } - - if (!Fault_Flag && !(sum & 1)) - bp[63] ^= 1; // mismatch control -} - -/* decode one non-intra coded MPEG-1 block */ -static void Decode_MPEG1_Non_Intra_Block(int comp) -{ - long code, val=0, i, j, sign; - const DCTtab *tab; - short *bp; - - bp = block[comp]; - - /* decode AC coefficients */ - for (i=0; ; i++) - { - code = Show_Bits(16); - - if (code >= 16384) - { - if (i) - tab = &DCTtabnext[(code>>12)-4]; - else - tab = &DCTtabfirst[(code>>12)-4]; - } - else if (code >= 1024) - tab = &DCTtab0[(code>>8)-4]; - else if (code >= 512) - tab = &DCTtab1[(code>>6)-8]; - else if (code >= 256) - tab = &DCTtab2[(code>>4)-16]; - else if (code >= 128) - tab = &DCTtab3[(code>>3)-16]; - else if (code >= 64) - tab = &DCTtab4[(code>>2)-16]; - else if (code >= 32) - tab = &DCTtab5[(code>>1)-16]; - else if (code >= 16) - tab = &DCTtab6[code-16]; - else - { - SetFaultFlag(1); - break; - } - - Flush_Buffer(tab->len); - val = tab->run; - - if (val == 65) - { - // escape - i+= Get_Bits(6); - val = Get_Bits(8); - if (val == 0) - val = Get_Bits(8); - else if (val == 128) - val = Get_Bits(8) - 256; - else if (val > 128) - val -= 256; - - sign = (val<0); - if (sign) - val = - val; - } - else - { - if (val == 64) - break; - i += val; - val = tab->level; - sign = Get_Bits(1); - } - if (i >= 64) - { - SetFaultFlag(1); - break; - } - - j = scan[0][i]; - val = (((val<<1)+1) * quantizer_scale * non_intra_quantizer_matrix[j]) >> 4; - if (val) - val = (val - 1) | 1; // mismatch - if (val >= 2048) - val = 2047 + sign; //saturation - if (sign) - val = -val; - bp[j] = (short) val; - } -} - -/* decode one non-intra coded MPEG-2 block */ -static void Decode_MPEG2_Non_Intra_Block(int comp) -{ - long code, val = 0, i, j, sign, sum; - const DCTtab *tab; - short *bp; - int *qmat; - - bp = block[comp]; - qmat = (comp<4 || chroma_format==CHROMA420) - ? non_intra_quantizer_matrix : chroma_non_intra_quantizer_matrix; - - /* decode AC coefficients */ - sum = 0; - for (i=0; ; i++) - { - code = Show_Bits(16); - - if (code >= 16384) - { - if (i) - tab = &DCTtabnext[(code>>12)-4]; - else - tab = &DCTtabfirst[(code>>12)-4]; - } - else if (code >= 1024) - tab = &DCTtab0[(code>>8)-4]; - else if (code >= 512) - tab = &DCTtab1[(code>>6)-8]; - else if (code >= 256) - tab = &DCTtab2[(code>>4)-16]; - else if (code >= 128) - tab = &DCTtab3[(code>>3)-16]; - else if (code >= 64) - tab = &DCTtab4[(code>>2)-16]; - else if (code >= 32) - tab = &DCTtab5[(code>>1)-16]; - else if (code >= 16) - tab = &DCTtab6[code-16]; - else - { - SetFaultFlag(1); - break; - } - - Flush_Buffer(tab->len); - val = tab->run; - - if (val == 65) - { - // escape - i+= Get_Bits(6); - val = Get_Bits(12); - if (!(val & 2047)) - { - SetFaultFlag(1); - break; - } - sign = (val >= 2048); - if (sign) - val = 4096 - val; - } - else - { - if (val == 64) - break; - i+= val; - val = tab->level; - sign = Get_Bits(1); - } - if (i >= 64) - { - SetFaultFlag(1); - break; - } - - j = scan[alternate_scan][i]; - val = (((val<<1)+1) * quantizer_scale * qmat[j]) >> 5; - if (val >= 2048) - val = 2047 + sign; // saturation - if (sign) - val = -val; - bp[j] = (short) val; - sum ^= val; // mismatch - } - - if (!Fault_Flag && !(sum & 1)) - bp[63] ^= 1; // mismatch control -} - -static int Get_macroblock_type() -{ - int macroblock_type = 0; - - switch (picture_coding_type) - { - case I_TYPE: - macroblock_type = Get_I_macroblock_type(); - break; - case P_TYPE: - macroblock_type = Get_P_macroblock_type(); - break; - case B_TYPE: - macroblock_type = Get_B_macroblock_type(); - break; - case D_TYPE: - macroblock_type = Get_D_macroblock_type(); - break; - default: - SetFaultFlag(2); - } - - return macroblock_type; -} - -static int Get_I_macroblock_type() -{ - int code = Show_Bits(2); - - // the only valid codes are 1, or 01 - if (code & 2) - { - Flush_Buffer(1); - return 1; - } - if (code & 1) - { - Flush_Buffer(2); - } - else - SetFaultFlag(2); - - return 17; -} - -static int Get_P_macroblock_type() -{ - int code = Show_Bits(6); - - if (code >= 8) - { - code >>= 3; - Flush_Buffer(PMBtab0[code].len); - code = PMBtab0[code].val; - } - else if (code) - { - Flush_Buffer(PMBtab1[code].len); - code = PMBtab1[code].val; - } - else - SetFaultFlag(2); - return code; -} - -static int Get_B_macroblock_type() -{ - int code = Show_Bits(6); - - if (code >= 8) - { - code >>= 2; - Flush_Buffer(BMBtab0[code].len); - code = BMBtab0[code].val; - } - else if (code) - { - Flush_Buffer(BMBtab1[code].len); - code = BMBtab1[code].val; - } - else - SetFaultFlag(2); - return code; -} - -static int Get_D_macroblock_type() -{ - if (Get_Bits(1)) - Flush_Buffer(1); - else - SetFaultFlag(2); - return 1; -} - -static int Get_coded_block_pattern() -{ - int code = Show_Bits(9); - if (code >= 128) - { - code >>= 4; - Flush_Buffer(CBPtab0[code].len); - code = CBPtab0[code].val; - } - else if (code >= 8) - { - code >>= 1; - Flush_Buffer(CBPtab1[code].len); - code = CBPtab1[code].val; - } - else if (code) - { - Flush_Buffer(CBPtab2[code].len); - code = CBPtab2[code].val; - } - else - SetFaultFlag(3); - return code; -} - -static int Get_macroblock_address_increment() -{ - int code, val; - - for (val = 0;;) - { - code = Show_Bits(11); - if (code >= 24) - break; - if (code != 15) /* if not macroblock_stuffing */ - { - if (code == 8) - { - /* macroblock_escape */ - val += 33; - } - else if (code == 0) - { - // The variable length code for the macroblock address - // increment cannot be all zeros. If we see all zeros here, - // then we must have run into the end of the slice, which is marked - // by 23 zeroes. We return a negative increment to signal end - // of slice. - return -1; - } - else - { - SetFaultFlag(5); - return -1; - } - } - Flush_Buffer(11); - } - - /* macroblock_address_increment == 1 */ - /* ('1' is in the MSB position of the lookahead) */ - if (code >= 1024) - { - Flush_Buffer(1); - val++; - } - - /* codes 00010 ... 011xx */ - else if (code >= 128) - { - /* remove leading zeros */ - code >>= 6; - Flush_Buffer(MBAtab1[code].len); - val += MBAtab1[code].val; - } - - /* codes 00000011000 ... 0000111xxxx */ - else - { - code -= 24; /* remove common base */ - Flush_Buffer(MBAtab2[code].len); - val += MBAtab2[code].val; - } - - return val; -} - -/* - parse VLC and perform dct_diff arithmetic. - MPEG-2: ISO/IEC 13818-2 section 7.2.1 - - Note: the arithmetic here is presented more elegantly than - the spec, yet the results, dct_diff, are the same. -*/ -static int Get_Luma_DC_dct_diff() -{ - int code, size, dct_diff; - - /* decode length */ - code = Show_Bits(5); - - if (code<31) - { - size = DClumtab0[code].val; - Flush_Buffer(DClumtab0[code].len); - } - else - { - code = Show_Bits(9) - 0x1f0; - size = DClumtab1[code].val; - Flush_Buffer(DClumtab1[code].len); - } - - if (size==0) - dct_diff = 0; - else - { - dct_diff = Get_Bits(size); - - if ((dct_diff & (1<<(size-1)))==0) - dct_diff-= (1<>1, PMV[0][0][0], PMV[0][0][1]>>1, stw); - - /* bottom field prediction */ - form_prediction(forward_reference_frame, motion_vertical_field_select[1][0], - current_frame, 1, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, - bx, by>>1, PMV[1][0][0], PMV[1][0][1]>>1, stw); - } - else if (motion_type==MC_DMV) /* dual prime prediction */ - { - /* calculate derived motion vectors */ - Dual_Prime_Arithmetic(DMV, dmvector, PMV[0][0][0], PMV[0][0][1]>>1); - - /* predict top field from top field */ - form_prediction(forward_reference_frame, 0, current_frame, 0, - Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, bx, by>>1, - PMV[0][0][0], PMV[0][0][1]>>1, 0); - - /* predict and add to top field from bottom field */ - form_prediction(forward_reference_frame, 1, current_frame, 0, - Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, bx, by>>1, - DMV[0][0], DMV[0][1], 1); - - /* predict bottom field from bottom field */ - form_prediction(forward_reference_frame, 1, current_frame, 1, - Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, bx, by>>1, - PMV[0][0][0], PMV[0][0][1]>>1, 0); - - /* predict and add to bottom field from top field */ - form_prediction(forward_reference_frame, 0, current_frame, 1, - Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, bx, by>>1, - DMV[1][0], DMV[1][1], 1); - } - } - else - { - /* field picture */ - currentfield = (picture_structure==BOTTOM_FIELD); - - /* determine which frame to use for prediction */ - if (picture_coding_type==P_TYPE && Second_Field && currentfield!=motion_vertical_field_select[0][0]) - predframe = backward_reference_frame; - else - predframe = forward_reference_frame; - - if (motion_type==MC_FIELD || !(macroblock_type & MACROBLOCK_MOTION_FORWARD)) - { - form_prediction(predframe, motion_vertical_field_select[0][0], current_frame, 0, - Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 16, bx, by, - PMV[0][0][0], PMV[0][0][1], stw); - } - else if (motion_type==MC_16X8) - { - form_prediction(predframe, motion_vertical_field_select[0][0], current_frame, 0, - Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, bx, by, - PMV[0][0][0], PMV[0][0][1], stw); - - if (picture_coding_type==P_TYPE && Second_Field && currentfield!=motion_vertical_field_select[1][0]) - predframe = backward_reference_frame; - else - predframe = forward_reference_frame; - - form_prediction(predframe, motion_vertical_field_select[1][0], current_frame, - 0, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, bx, by+8, - PMV[1][0][0], PMV[1][0][1], stw); - } - else if (motion_type==MC_DMV) - { - if (Second_Field) - predframe = backward_reference_frame; - else - predframe = forward_reference_frame; - - /* calculate derived motion vectors */ - Dual_Prime_Arithmetic(DMV, dmvector, PMV[0][0][0], PMV[0][0][1]); - - /* predict from field of same parity */ - form_prediction(forward_reference_frame, currentfield, current_frame, 0, - Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 16, bx, by, - PMV[0][0][0], PMV[0][0][1], 0); - - /* predict from field of opposite parity */ - form_prediction(predframe, !currentfield, current_frame, 0, - Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 16, bx, by, - DMV[0][0], DMV[0][1], 1); - } - } - - stw = 1; - } - - if (macroblock_type & MACROBLOCK_MOTION_BACKWARD) - { - if (picture_structure==FRAME_PICTURE) - { - if (motion_type==MC_FRAME) - { - /* frame-based prediction */ - form_prediction(backward_reference_frame, 0, current_frame, 0, - Coded_Picture_Width, Coded_Picture_Width<<1, 16, 8, bx, by, - PMV[0][1][0], PMV[0][1][1], stw); - - form_prediction(backward_reference_frame, 1, current_frame, 1, - Coded_Picture_Width, Coded_Picture_Width<<1, 16, 8, bx, by, - PMV[0][1][0], PMV[0][1][1], stw); - } - else /* field-based prediction */ - { - /* top field prediction */ - form_prediction(backward_reference_frame, motion_vertical_field_select[0][1], - current_frame, 0, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, - bx, by>>1, PMV[0][1][0], PMV[0][1][1]>>1, stw); - - /* bottom field prediction */ - form_prediction(backward_reference_frame, motion_vertical_field_select[1][1], - current_frame, 1, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, - bx, by>>1, PMV[1][1][0], PMV[1][1][1]>>1, stw); - } - } - else - { - /* field picture */ - if (motion_type==MC_FIELD) - { - /* field-based prediction */ - form_prediction(backward_reference_frame, motion_vertical_field_select[0][1], - current_frame, 0, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 16, - bx, by, PMV[0][1][0], PMV[0][1][1], stw); - } - else if (motion_type==MC_16X8) - { - form_prediction(backward_reference_frame, motion_vertical_field_select[0][1], - current_frame, 0, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, - bx, by, PMV[0][1][0], PMV[0][1][1], stw); - - form_prediction(backward_reference_frame, motion_vertical_field_select[1][1], - current_frame, 0, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, - bx, by+8, PMV[1][1][0], PMV[1][1][1], stw); - } - } - } - - __asm emms; -} - -static void form_prediction(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 average_flag) -{ - form_component_prediction(src[0]+(sfield?lx2>>1:0), dst[0]+(dfield?lx2>>1:0), - lx, lx2, w, h, x, y, dx, dy, average_flag); - - if (chroma_format!=CHROMA444) - { - lx>>=1; lx2>>=1; w>>=1; x>>=1; dx/=2; - } - - if (chroma_format==CHROMA420) - { - h>>=1; y>>=1; dy/=2; - } - - /* Cb */ - form_component_prediction(src[1]+(sfield?lx2>>1:0), dst[1]+(dfield?lx2>>1:0), - lx, lx2, w, h, x, y, dx, dy, average_flag); - - /* Cr */ - form_component_prediction(src[2]+(sfield?lx2>>1:0), dst[2]+(dfield?lx2>>1:0), - lx, lx2, w, h, x, y, dx, dy, average_flag); -} - -/* ISO/IEC 13818-2 section 7.6.4: Forming predictions */ -static void form_component_prediction(unsigned char *src, unsigned char *dst, - int lx, int lx2, int w, int h, int x, int y, - int dx, int dy, int average_flag) -{ - static const __int64 mmmask_0001 = 0x0001000100010001; - static const __int64 mmmask_0002 = 0x0002000200020002; - static const __int64 mmmask_0003 = 0x0003000300030003; - static const __int64 mmmask_0006 = 0x0006000600060006; - - unsigned char *s = src + lx * (y + (dy>>1)) + x + (dx>>1); - unsigned char *d = dst + lx * y + x; - int flag = (average_flag<<2) + ((dx & 1)<<1) + (dy & 1); - - switch (flag) - { - case 0: - // d[i] = s[i]; - __asm - { - mov eax, [s] - mov ebx, [d] - mov esi, 0x00 - mov edi, [h] - mc0: - movq mm1, [eax+esi] - add esi, 0x08 - cmp esi, [w] - movq [ebx+esi-8], mm1 - jl mc0 - - add eax, [lx2] - add ebx, [lx2] - dec edi - mov esi, 0x00 - cmp edi, 0x00 - jg mc0 - } - break; - - case 1: - // d[i] = (s[i]+s[i+lx]+1)>>1; - __asm - { - pxor mm0, mm0 - movq mm7, [mmmask_0001] - mov eax, [s] - mov ebx, [d] - mov ecx, eax - add ecx, [lx] - mov esi, 0x00 - mov edi, [h] - mc1: - movq mm1, [eax+esi] - movq mm2, [ecx+esi] - - movq mm3, mm1 - movq mm4, mm2 - - punpcklbw mm1, mm0 - punpckhbw mm3, mm0 - punpcklbw mm2, mm0 - punpckhbw mm4, mm0 - - paddsw mm1, mm2 - paddsw mm3, mm4 - - paddsw mm1, mm7 - paddsw mm3, mm7 - - psrlw mm1, 1 - psrlw mm3, 1 - - packuswb mm1, mm0 - packuswb mm3, mm0 - - psllq mm3, 32 - por mm1, mm3 - - add esi, 0x08 - cmp esi, [w] - movq [ebx+esi-8], mm1 - jl mc1 - - add eax, [lx2] - add ebx, [lx2] - add ecx, [lx2] - dec edi - mov esi, 0x00 - cmp edi, 0x00 - jg mc1 - } - break; - - case 2: - // d[i] = (s[i]+s[i+1]+1)>>1; - __asm - { - pxor mm0, mm0 - movq mm7, [mmmask_0001] - mov eax, [s] - mov ebx, [d] - mov esi, 0x00 - mov edi, [h] - mc2: - movq mm1, [eax+esi] - movq mm2, [eax+esi+1] - - movq mm3, mm1 - movq mm4, mm2 - - punpcklbw mm1, mm0 - punpckhbw mm3, mm0 - - punpcklbw mm2, mm0 - punpckhbw mm4, mm0 - - paddsw mm1, mm2 - paddsw mm3, mm4 - - paddsw mm1, mm7 - paddsw mm3, mm7 - - psrlw mm1, 1 - psrlw mm3, 1 - - packuswb mm1, mm0 - packuswb mm3, mm0 - - psllq mm3, 32 - por mm1, mm3 - - add esi, 0x08 - cmp esi, [w] - movq [ebx+esi-8], mm1 - jl mc2 - - add eax, [lx2] - add ebx, [lx2] - dec edi - mov esi, 0x00 - cmp edi, 0x00 - jg mc2 - } - break; - - case 3: - // d[i] = (s[i]+s[i+1]+s[i+lx]+s[i+lx+1]+2)>>2; - __asm - { - pxor mm0, mm0 - movq mm7, [mmmask_0002] - mov eax, [s] - mov ebx, [d] - mov ecx, eax - add ecx, [lx] - mov esi, 0x00 - mov edi, [h] - mc3: - movq mm1, [eax+esi] - movq mm2, [eax+esi+1] - movq mm3, mm1 - movq mm4, mm2 - - punpcklbw mm1, mm0 - punpckhbw mm3, mm0 - - punpcklbw mm2, mm0 - punpckhbw mm4, mm0 - - paddsw mm1, mm2 - paddsw mm3, mm4 - - movq mm5, [ecx+esi] - paddsw mm1, mm7 - - movq mm6, [ecx+esi+1] - paddsw mm3, mm7 - - movq mm2, mm5 - movq mm4, mm6 - - punpcklbw mm2, mm0 - punpckhbw mm5, mm0 - - punpcklbw mm4, mm0 - punpckhbw mm6, mm0 - - paddsw mm2, mm4 - paddsw mm5, mm6 - - paddsw mm1, mm2 - paddsw mm3, mm5 - - psrlw mm1, 2 - psrlw mm3, 2 - - packuswb mm1, mm0 - packuswb mm3, mm0 - - psllq mm3, 32 - por mm1, mm3 - - add esi, 0x08 - cmp esi, [w] - movq [ebx+esi-8], mm1 - jl mc3 - - add eax, [lx2] - add ebx, [lx2] - add ecx, [lx2] - dec edi - mov esi, 0x00 - cmp edi, 0x00 - jg mc3 - } - break; - - case 4: - // d[i] = (s[i]+d[i]+1)>>1; - __asm - { - pxor mm0, mm0 - movq mm7, [mmmask_0001] - mov eax, [s] - mov ebx, [d] - mov esi, 0x00 - mov edi, [h] - mc4: - movq mm1, [eax+esi] - movq mm2, [ebx+esi] - movq mm3, mm1 - movq mm4, mm2 - - punpcklbw mm1, mm0 - punpckhbw mm3, mm0 - - punpcklbw mm2, mm0 - punpckhbw mm4, mm0 - - paddsw mm1, mm2 - paddsw mm3, mm4 - - paddsw mm1, mm7 - paddsw mm3, mm7 - - psrlw mm1, 1 - psrlw mm3, 1 - - packuswb mm1, mm0 - packuswb mm3, mm0 - - psllq mm3, 32 - por mm1, mm3 - - add esi, 0x08 - cmp esi, [w] - movq [ebx+esi-8], mm1 - jl mc4 - - add eax, [lx2] - add ebx, [lx2] - dec edi - mov esi, 0x00 - cmp edi, 0x00 - jg mc4 - } - break; - - case 5: - // d[i] = ((d[i]<<1) + s[i]+s[i+lx] + 3)>>2; - __asm - { - pxor mm0, mm0 - movq mm7, [mmmask_0003] - mov eax, [s] - mov ebx, [d] - mov ecx, eax - add ecx, [lx] - mov esi, 0x00 - mov edi, [h] - mc5: - movq mm1, [eax+esi] - movq mm2, [ecx+esi] - movq mm3, mm1 - movq mm4, mm2 - - punpcklbw mm1, mm0 - punpckhbw mm3, mm0 - - punpcklbw mm2, mm0 - punpckhbw mm4, mm0 - - paddsw mm1, mm2 - paddsw mm3, mm4 - - movq mm5, [ebx+esi] - - paddsw mm1, mm7 - paddsw mm3, mm7 - - movq mm6, mm5 - punpcklbw mm5, mm0 - punpckhbw mm6, mm0 - - psllw mm5, 1 - psllw mm6, 1 - - paddsw mm1, mm5 - paddsw mm3, mm6 - - psrlw mm1, 2 - psrlw mm3, 2 - - packuswb mm1, mm0 - packuswb mm3, mm0 - - psllq mm3, 32 - por mm1, mm3 - - add esi, 0x08 - cmp esi, [w] - movq [ebx+esi-8], mm1 - jl mc5 - - add eax, [lx2] - add ebx, [lx2] - add ecx, [lx2] - dec edi - mov esi, 0x00 - cmp edi, 0x00 - jg mc5 - } - break; - - case 6: - // d[i] = ((d[i]<<1) + s[i]+s[i+1] + 3) >> 2; - __asm - { - pxor mm0, mm0 - movq mm7, [mmmask_0003] - mov eax, [s] - mov ebx, [d] - mov esi, 0x00 - mov edi, [h] - mc6: - movq mm1, [eax+esi] - movq mm2, [eax+esi+1] - movq mm3, mm1 - movq mm4, mm2 - - punpcklbw mm1, mm0 - punpckhbw mm3, mm0 - - punpcklbw mm2, mm0 - punpckhbw mm4, mm0 - - paddsw mm1, mm2 - paddsw mm3, mm4 - - movq mm5, [ebx+esi] - - paddsw mm1, mm7 - paddsw mm3, mm7 - - movq mm6, mm5 - punpcklbw mm5, mm0 - punpckhbw mm6, mm0 - - psllw mm5, 1 - psllw mm6, 1 - - paddsw mm1, mm5 - paddsw mm3, mm6 - - psrlw mm1, 2 - psrlw mm3, 2 - - packuswb mm1, mm0 - packuswb mm3, mm0 - - psllq mm3, 32 - por mm1, mm3 - - add esi, 0x08 - cmp esi, [w] - movq [ebx+esi-8], mm1 - jl mc6 - - add eax, [lx2] - add ebx, [lx2] - dec edi - mov esi, 0x00 - cmp edi, 0x00 - jg mc6 - } - break; - - case 7: - // d[i] = ((d[i]<<2) + s[i]+s[i+1]+s[i+lx]+s[i+lx+1] + 6)>>3; - __asm - { - pxor mm0, mm0 - movq mm7, [mmmask_0006] - mov eax, [s] - mov ebx, [d] - mov ecx, eax - add ecx, [lx] - mov esi, 0x00 - mov edi, [h] - mc7: - movq mm1, [eax+esi] - movq mm2, [eax+esi+1] - movq mm3, mm1 - movq mm4, mm2 - - punpcklbw mm1, mm0 - punpckhbw mm3, mm0 - - punpcklbw mm2, mm0 - punpckhbw mm4, mm0 - - paddsw mm1, mm2 - paddsw mm3, mm4 - - movq mm5, [ecx+esi] - paddsw mm1, mm7 - - movq mm6, [ecx+esi+1] - paddsw mm3, mm7 - - movq mm2, mm5 - movq mm4, mm6 - - punpcklbw mm2, mm0 - punpckhbw mm5, mm0 - - punpcklbw mm4, mm0 - punpckhbw mm6, mm0 - - paddsw mm2, mm4 - paddsw mm5, mm6 - - paddsw mm1, mm2 - paddsw mm3, mm5 - - movq mm6, [ebx+esi] - - movq mm4, mm6 - punpcklbw mm4, mm0 - punpckhbw mm6, mm0 - - psllw mm4, 2 - psllw mm6, 2 - - paddsw mm1, mm4 - paddsw mm3, mm6 - - psrlw mm1, 3 - psrlw mm3, 3 - - packuswb mm1, mm0 - packuswb mm3, mm0 - - psllq mm3, 32 - por mm1, mm3 - - add esi, 0x08 - cmp esi, [w] - movq [ebx+esi-8], mm1 - jl mc7 - - add eax, [lx2] - add ebx, [lx2] - add ecx, [lx2] - dec edi - mov esi, 0x00 - cmp edi, 0x00 - jg mc7 - } - break; - } - __asm emms; -} diff --git a/src/dgindex/global.h b/src/dgindex/global.h deleted file mode 100644 index 16942d9..0000000 --- a/src/dgindex/global.h +++ /dev/null @@ -1,1087 +0,0 @@ -/* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */ - -/* - * Disclaimer of Warranty - * - * These software programs are available to the user without any license fee or - * royalty on an "as is" basis. The MPEG Software Simulation Group disclaims - * any and all warranties, whether express, implied, or statuary, including any - * implied warranties or merchantability or of fitness for a particular - * purpose. In no event shall the copyright-holder be liable for any - * incidental, punitive, or consequential damages of any kind whatsoever - * arising from the use of these programs. - * - * This disclaimer of warranty extends to the user of these programs and user's - * customers, employees, agents, transferees, successors, and assigns. - * - * The MPEG Software Simulation Group does not represent or warrant that the - * programs furnished hereunder are free of infringement of any third-party - * patents. - * - * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware, - * are subject to royalty fees to patent holders. Many of these patents are - * general enough such that they are unavoidable regardless of implementation - * design. - * - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "misc.h" -#include "resource.h" -#include "pat.h" - -#ifdef GLOBAL -#define XTN -#else -#define XTN extern -#endif - -#define bool BOOL -#define true TRUE -#define false FALSE - -XTN bool bIsWindowsXPorLater; - -// Messages to the window procedure. -#define CLI_RIP_MESSAGE (WM_APP) -#define D2V_DONE_MESSAGE (WM_APP + 1) -#define CLI_PREVIEW_DONE_MESSAGE (WM_APP + 2) -#define PROGRESS_MESSAGE (WM_APP + 3) -#define CLI_PARSE_D2V_MESSAGE (WM_APP + 4) - -/* code definition */ -#define PICTURE_START_CODE 0x100 -#define SLICE_START_CODE_MIN 0x101 -#define SLICE_START_CODE_MAX 0x1AF -#define USER_DATA_START_CODE 0x1B2 -#define SEQUENCE_HEADER_CODE 0x1B3 -#define EXTENSION_START_CODE 0x1B5 -#define SEQUENCE_END_CODE 0x1B7 -#define GROUP_START_CODE 0x1B8 - -#define SYSTEM_END_CODE 0x1B9 -#define PACK_START_CODE 0x1BA -#define SYSTEM_START_CODE 0x1BB - -#define VIDEO_ELEMENTARY_STREAM 0x1E0 - -#define PRIVATE_STREAM_1 0x1BD -#define BLURAY_STREAM_1 0x1FD -#define PRIVATE_STREAM_2 0x1BF -#define AUDIO_ELEMENTARY_STREAM_0 0x1C0 -#define AUDIO_ELEMENTARY_STREAM_1 0x1C1 -#define AUDIO_ELEMENTARY_STREAM_2 0x1C2 -#define AUDIO_ELEMENTARY_STREAM_3 0x1C3 -#define AUDIO_ELEMENTARY_STREAM_4 0x1C4 -#define AUDIO_ELEMENTARY_STREAM_5 0x1C5 -#define AUDIO_ELEMENTARY_STREAM_6 0x1C6 -#define AUDIO_ELEMENTARY_STREAM_7 0x1C7 - -#define SUB_SUB 0x20 -#define SUB_AC3 0x80 -#define SUB_DTS 0x88 -#define SUB_PCM 0xA0 - -#define ELEMENTARY_STREAM 0 -#define MPEG1_PROGRAM_STREAM 1 -#define MPEG2_PROGRAM_STREAM 2 - -/* extension start code IDs */ -#define SEQUENCE_EXTENSION_ID 1 -#define SEQUENCE_DISPLAY_EXTENSION_ID 2 -#define QUANT_MATRIX_EXTENSION_ID 3 -#define COPYRIGHT_EXTENSION_ID 4 -#define PICTURE_DISPLAY_EXTENSION_ID 7 -#define PICTURE_CODING_EXTENSION_ID 8 - -#define ZIG_ZAG 0 -#define MB_WEIGHT 2 -#define MB_CLASS4 64 - -#define I_TYPE 1 -#define P_TYPE 2 -#define B_TYPE 3 -#define D_TYPE 4 - -#define MACROBLOCK_INTRA 1 -#define MACROBLOCK_PATTERN 2 -#define MACROBLOCK_MOTION_BACKWARD 4 -#define MACROBLOCK_MOTION_FORWARD 8 -#define MACROBLOCK_QUANT 16 - -#define TOP_FIELD 1 -#define BOTTOM_FIELD 2 -#define FRAME_PICTURE 3 - -#define MC_FIELD 1 -#define MC_FRAME 2 -#define MC_16X8 2 -#define MC_DMV 3 - -#define MV_FIELD 0 -#define MV_FRAME 1 - -#define CHROMA420 1 -#define CHROMA422 2 -#define CHROMA444 3 - -#define SECTOR_SIZE 2048 -#define BUFFER_SIZE 2048 -#define MAX_FILE_NUMBER 512 -#define MAX_PICTURES_PER_GOP 500 -#define MAX_GOPS 1000000 - -#define IDCT_MMX 1 -#define IDCT_SSEMMX 2 -#define IDCT_SSE2MMX 3 -#define IDCT_FPU 4 -#define IDCT_REF 5 -#define IDCT_SKAL 6 -#define IDCT_SIMPLE 7 - -#define LOCATE_INIT 0 -#define LOCATE_FORWARD 1 -#define LOCATE_BACKWARD -1 -#define LOCATE_SCROLL 2 -#define LOCATE_RIP 3 -#define LOCATE_PLAY 4 -#define LOCATE_DEMUX_AUDIO 5 - -#define CHANNEL 8 - -#define TRACK_1 0 -#define TRACK_2 1 -#define TRACK_3 2 -#define TRACK_4 3 -#define TRACK_5 4 -#define TRACK_6 5 -#define TRACK_7 6 -#define TRACK_8 7 - -#define FORMAT_AC3 1 -#define FORMAT_MPA 2 -#define FORMAT_LPCM 3 -#define FORMAT_LPCM_M2TS 4 -#define FORMAT_DTS 5 -#define FORMAT_AAC 6 - -#define AUDIO_NONE 0 -#define AUDIO_DEMUX 1 -#define AUDIO_DEMUXALL 2 -#define AUDIO_DECODE 3 - -#define DRC_NONE 0 -#define DRC_LIGHT 1 -#define DRC_NORMAL 2 -#define DRC_HEAVY 3 - -#define FO_NONE 0 -#define FO_FILM 1 -#define FO_RAW 2 - -#define SRC_NONE 0 -#define SRC_LOW 1 -#define SRC_MID 2 -#define SRC_HIGH 3 -#define SRC_UHIGH 4 - -#define PARSE_D2V_NONE 0x00 -#define PARSE_D2V_INPUT_FILE 0x01 -#define PARSE_D2V_AFTER_SAVING 0x02 - -#define MPEG_TIMESTAMP_MAX_VALUE (0x1FFFFFFFFLL) -#define MPEG_TIMESTAMP_WRAPAROUND_VALUE (0x200000000LL) -#define TIMESTAMP_WRAP_AROUND_CHECK_VALUE (0x0FFFFFFFFLL) - -#define WRAPAROUND_CORRECTION(v) \ -do { \ - if (_abs64(v) > TIMESTAMP_WRAP_AROUND_CHECK_VALUE) \ - v += MPEG_TIMESTAMP_WRAPAROUND_VALUE * ((v > 0) ? -1 : 1); \ -} while(0) - -#define TRACK_PITCH 30000 - -#define DG_MAX_PATH 2048 - -typedef struct { - int gop_start; - int type; - int file; - __int64 lba; - __int64 position; - bool pf; - bool trf; - int picture_structure; -} D2VData; -XTN D2VData d2v_backward, d2v_forward, d2v_current; - -XTN __int64 gop_positions[MAX_GOPS]; -XTN int gop_positions_ndx; - -typedef struct { - char filename[DG_MAX_PATH]; - FILE *file; - bool selected_for_demux; - bool rip; - int type; - // The different types use subsets of the following variables. - unsigned int layer; - unsigned int mode; - unsigned int sample; - unsigned int rate; - int size; - int delay; - unsigned char format; - unsigned short format_m2ts; -} AudioStream; -XTN AudioStream audio[256]; - -XTN int Sound_Max; - -typedef struct { - __int64 run; - __int64 start; - __int64 end; - __int64 trackleft; - __int64 trackright; - int locate; - int startfile; - __int64 startloc; - int endfile; - __int64 endloc; - int file; - __int64 lba; - int leftfile; - __int64 leftlba; - int rightfile; - __int64 rightlba; -} Process; -XTN Process process; - -typedef struct { - unsigned int op; - unsigned int mi; - unsigned int ed; -} Timing; -XTN Timing timing; - -typedef struct{ - bool mmx; - bool _3dnow; - bool ssemmx; - bool ssefpu; - bool sse2; -} Cpu; -XTN Cpu cpu; - -/* decoder operation control flags */ -XTN bool Check_Flag; -XTN bool D2V_Flag; -XTN bool AudioOnly_Flag; -XTN unsigned int AudioPktCount; -XTN bool Display_Flag; -XTN int Fault_Flag; -XTN int CurrentFile; -XTN int NumLoadedFiles; -XTN int FO_Flag; -XTN int iDCT_Flag; -XTN bool Info_Flag; -XTN bool Pause_Flag; -XTN bool Scale_Flag; -XTN bool Start_Flag; -XTN bool Stop_Flag; -XTN bool HadAudioPTS; -XTN int SystemStream_Flag; -#define ELEMENTARY_STREAM 0 -#define PROGRAM_STREAM 1 -#define TRANSPORT_STREAM 2 -#define PVA_STREAM 3 -XTN int program_stream_type; -XTN __int64 PackHeaderPosition; - -XTN int LeadingBFrames; -XTN int ForceOpenGops; -XTN char AVSTemplatePath[DG_MAX_PATH]; -XTN char BMPPathString[DG_MAX_PATH]; -XTN int FullPathInFiles; -XTN int LoopPlayback; -XTN int FusionAudio; -XTN int UseMPAExtensions; -XTN int NotifyWhenDone; -XTN int TsParseMargin; -XTN bool CorrectFieldOrderTrans; - -XTN bool Luminance_Flag; -XTN bool Cropping_Flag; -XTN int Clip_Width, Clip_Height; - -XTN int Method_Flag; -XTN char Track_List[255]; -XTN char Delay_Track[255]; -XTN int DRC_Flag; -XTN bool DSDown_Flag; -XTN bool Decision_Flag; -XTN int SRC_Flag; -XTN bool Norm_Flag; -XTN int Norm_Ratio; -XTN double PreScale_Ratio; - -/* DirectDraw & GDI resources */ -XTN HMENU hMenu; -XTN HDC hDC; - -/* Global Value */ -XTN unsigned int CLIParseD2V; -XTN int CLINoProgress; -XTN int CLIActive; -XTN char CLIPreview; -XTN char ExitOnEnd; -XTN char ExePath[DG_MAX_PATH]; -XTN FILE *D2VFile; -XTN char D2VFilePath[DG_MAX_PATH]; -XTN char AudioFilePath[DG_MAX_PATH]; -XTN unsigned int LowestAudioId; -XTN int VOB_ID, CELL_ID; -XTN FILE *MuxFile; -XTN int HadAddDialog; -XTN int hadRGoption; -#define D2V_FILE_VERSION 16 - -XTN int WindowMode; -XTN HWND hWnd, hDlg, hTrack; -XTN HWND hwndSelect; -XTN char szInput[MAX_FILE_NUMBER*DG_MAX_PATH], szOutput[DG_MAX_PATH], szBuffer[DG_MAX_PATH], szSave[DG_MAX_PATH]; - -XTN unsigned char *backward_reference_frame[3], *forward_reference_frame[3]; -XTN unsigned char *auxframe[3], *current_frame[3]; -XTN unsigned char *u422, *v422, *u444, *v444, *rgb24, *rgb24small, *yuy2, *lum; -XTN __int64 RGB_Scale, RGB_Offset, RGB_CRV, RGB_CBU, RGB_CGX; -XTN int LumGamma, LumOffset; - -XTN unsigned int elapsed, remain; -XTN int playback, frame_repeats, field_repeats, Old_Playback; -XTN int PlaybackSpeed, OldPlaybackSpeed; -XTN bool RightArrowHit; -#define SPEED_SINGLE_STEP 0 -#define SPEED_SUPER_SLOW 1 -#define SPEED_SLOW 2 -#define SPEED_NORMAL 3 -#define SPEED_FAST 4 -#define SPEED_MAXIMUM 5 - -XTN int HDDisplay; -#define HD_DISPLAY_FULL_SIZED 0 -#define HD_DISPLAY_SHRINK_BY_HALF 1 -#define HD_DISPLAY_TOP_LEFT 2 -#define HD_DISPLAY_TOP_RIGHT 3 -#define HD_DISPLAY_BOTTOM_LEFT 4 -#define HD_DISPLAY_BOTTOM_RIGHT 5 - -XTN unsigned int Frame_Number; -XTN int Coded_Picture_Width, Coded_Picture_Height; -XTN int block_count, Second_Field; -XTN int horizontal_size, vertical_size, mb_width, mb_height; - -XTN double frame_rate, Frame_Rate; -XTN unsigned int fr_num, fr_den; -XTN int FILM_Purity, VIDEO_Purity, Bitrate_Monitor; -XTN double Bitrate_Average; -XTN double max_rate; - -XTN int Clip_Left, Clip_Right, Clip_Top, Clip_Bottom; - -XTN int Infile[MAX_FILE_NUMBER]; -XTN char *Infilename[MAX_FILE_NUMBER]; -XTN __int64 Infilelength[MAX_FILE_NUMBER]; -XTN __int64 Infiletotal; - -XTN int intra_quantizer_matrix[64]; -XTN int intra_quantizer_matrix_log[64]; -XTN int non_intra_quantizer_matrix[64]; -XTN int non_intra_quantizer_matrix_log[64]; -XTN int chroma_intra_quantizer_matrix[64]; -XTN int chroma_intra_quantizer_matrix_log[64]; -XTN int chroma_non_intra_quantizer_matrix[64]; -XTN int chroma_non_intra_quantizer_matrix_log[64]; -XTN int full_pel_forward_vector; -XTN int full_pel_backward_vector; -XTN int forward_f_code; -XTN int backward_f_code; - -XTN int q_scale_type; -XTN int alternate_scan; -XTN int quantizer_scale; - -XTN short *block[8]; - -/* ISO/IEC 13818-2 section 6.2.2.1: sequence_header() */ -XTN int aspect_ratio_information; - -/* ISO/IEC 13818-2 section 6.2.2.3: sequence_extension() */ -XTN int progressive_sequence; -XTN int chroma_format; - -/* sequence_display_extension() */ -XTN int display_horizontal_size; -XTN int display_vertical_size; - -/* ISO/IEC 13818-2 section 6.2.2.6: group_of_pictures_header() */ -XTN int closed_gop; - -/* ISO/IEC 13818-2 section 6.2.3: picture_header() */ -XTN int temporal_reference; -XTN int picture_coding_type; -XTN int progressive_frame; -XTN int PTSAdjustDone; - -XTN int matrix_coefficients; -XTN bool default_matrix_coefficients; - -/* ISO/IEC 13818-2 section 6.2.3.1: picture_coding_extension() header */ -XTN int f_code[2][2]; -XTN int picture_structure; -XTN int frame_pred_frame_dct; -XTN int concealment_motion_vectors; -XTN int intra_dc_precision; -XTN int top_field_first; -XTN int repeat_first_field; -XTN int intra_vlc_format; - -XTN int strverscmp(const char *s1, const char *s2); - -/* getbit.c */ -XTN void UpdateInfo(void); - -/* gethdr.c */ -XTN int Get_Hdr(int); -XTN void sequence_header(void); -XTN int slice_header(void); -XTN bool GOPSeen; - -/* getpic.c */ -XTN void Decode_Picture(void); -XTN void WriteD2VLine(int); - -/* gui.cpp */ -#define PICTURE_HEADER 0 -#define THREAD_KILL 1 -XTN void UpdateWindowText(int); -XTN void UpdateMRUList(void); -XTN void AddMRUList(char *); -XTN void DeleteMRUList(int); -XTN char mMRUList[4][DG_MAX_PATH]; -#define MISC_KILL 0 -#define END_OF_DATA_KILL 1 -XTN void ThreadKill(int); -XTN void ResizeWindow(int width, int height); -XTN bool crop1088_warned, crop1088; -XTN int LogQuants_Flag; -XTN FILE *Quants; -XTN int LogTimestamps_Flag; -XTN int StartLogging_Flag; -XTN FILE *Timestamps; -XTN int InfoLog_Flag; - -/* gui */ -XTN void Recovery(void); -XTN void RefreshWindow(bool); -XTN void CheckFlag(void); -XTN int parse_cli(LPSTR lpCmdLine, LPSTR ucCmdLine); - -/* idct */ -extern "C" void __fastcall MMX_IDCT(short *block); -extern "C" void __fastcall SSEMMX_IDCT(short *block); -extern "C" void __fastcall SSE2MMX_IDCT(short *block); -XTN void Initialize_FPU_IDCT(void); -XTN void FPU_IDCT(short *block); -XTN void __fastcall REF_IDCT(short *block); -extern "C" void __fastcall Skl_IDct16_Sparse_SSE(short *block); -extern "C" void __fastcall simple_idct_mmx(short *block); - -/* motion.c */ -XTN void motion_vectors(int PMV[2][2][2], int dmvector[2], int motion_vertical_field_select[2][2], - int s, int motion_vector_count, int mv_format, int h_r_size, int v_r_size, int dmv, int mvscale); -XTN void Dual_Prime_Arithmetic(int DMV[][2], int *dmvector, int mvx, int mvy); - -/* mpeg2dec.c */ -XTN DWORD WINAPI MPEG2Dec(LPVOID n); -XTN int initial_parse(char *input_file, int *mpeg_type_p, int *is_pgrogram_stream_p); -XTN void setRGBValues(); -#define IS_NOT_MPEG 0 -#define IS_MPEG1 1 -#define IS_MPEG2 2 -XTN int mpeg_type; -XTN int is_program_stream; - -/* norm.c */ -XTN void Normalize(FILE *WaveIn, int WaveInPos, char *filename, FILE *WaveOut, int WaveOutPos, int size); - -/* store.c */ -XTN void Write_Frame(unsigned char *src[], D2VData d2v, DWORD frame); -XTN int DetectVideoType(int frame, int rff); -XTN void ShowFrame(bool move); - -/* wavefs44.c */ -XTN void InitialSRC(void); -XTN void Wavefs44(FILE *file, int size, unsigned char *buffer); -XTN void EndSRC(FILE *file); -XTN void StartWAV(FILE *file, unsigned char format); -XTN void CloseWAV(FILE *file, int size); -XTN void DownWAV(FILE *file); -XTN bool CheckWAV(void); - -static char *AspectRatio[] = { - "", "1:1", "4:3", "16:9", "2.21:1" -}; - -static char *AspectRatioMPEG1[] = { - "", "1:1", "0.6735", "16:9,625", "0.7615", "0.8055", "16:9,525", "0.8935", "4:3,625", "0.9815", "1.0255", - "1.0695", "4:3,525", "1.575", "1.2015" -}; - -XTN int TransportPacketSize; -XTN int MPEG2_Transport_VideoPID; -XTN int MPEG2_Transport_AudioPID; -XTN int MPEG2_Transport_PCRPID; -XTN int MPEG2_Transport_AudioType; -#define PID_DETECT_RAW 0 -#define PID_DETECT_PATPMT 1 -#define PID_DETECT_PSIP 2 -XTN int Pid_Detect_Method; -XTN PATParser pat_parser; - -/* default intra quantization matrix */ -XTN unsigned char default_intra_quantizer_matrix[64] -#ifdef GLOBAL -= -{ - 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 -} -#endif -; - -/* zig-zag and alternate scan patterns */ -XTN unsigned char scan[2][64] -#ifdef GLOBAL -= -{ - { // Zig-Zag scan pattern - 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 pattern - 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 - } -} -#endif -; - -/* non-linear quantization coefficient table */ -XTN unsigned char Non_Linear_quantizer_scale[32] -#ifdef GLOBAL -= -{ - 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 -} -#endif -; - -#define ERROR_VALUE (-1) - -typedef struct { - char run, level, len; -} DCTtab; - -typedef struct { - char val, len; -} VLCtab; - -/* Table B-10, motion_code, codes 0001 ... 01xx */ -XTN VLCtab MVtab0[8] -#ifdef GLOBAL -= -{ - {ERROR_VALUE,0}, {3,3}, {2,2}, {2,2}, {1,1}, {1,1}, {1,1}, {1,1} -} -#endif -; - -/* Table B-10, motion_code, codes 0000011 ... 000011x */ -XTN VLCtab MVtab1[8] -#ifdef GLOBAL -= -{ - {ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,0}, {7,6}, {6,6}, {5,6}, {4,5}, {4,5} -} -#endif -; - -/* Table B-10, motion_code, codes 0000001100 ... 000001011x */ -XTN VLCtab MVtab2[12] -#ifdef GLOBAL -= -{ - {16,9}, {15,9}, {14,9}, {13,9}, - {12,9}, {11,9}, {10,8}, {10,8}, - {9,8}, {9,8}, {8,8}, {8,8} -} -#endif -; - -/* Table B-9, coded_block_pattern, codes 01000 ... 111xx */ -XTN VLCtab CBPtab0[32] -#ifdef GLOBAL -= -{ - {ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,0}, - {ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,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} -} -#endif -; - -/* Table B-9, coded_block_pattern, codes 00000100 ... 001111xx */ -XTN VLCtab CBPtab1[64] -#ifdef GLOBAL -= -{ - {ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,0}, {ERROR_VALUE,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} -} -#endif -; - -/* Table B-9, coded_block_pattern, codes 000000001 ... 000000111 */ -XTN VLCtab CBPtab2[8] -#ifdef GLOBAL -= -{ - {ERROR_VALUE,0}, {0,9}, {39,9}, {27,9}, {59,9}, {55,9}, {47,9}, {31,9} -} -#endif -; - -/* Table B-1, macroblock_address_increment, codes 00010 ... 011xx */ -XTN VLCtab MBAtab1[16] -#ifdef GLOBAL -= -{ - {ERROR_VALUE,0}, {ERROR_VALUE,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} -} -#endif -; - -/* Table B-1, macroblock_address_increment, codes 00000011000 ... 0000111xxxx */ -XTN VLCtab MBAtab2[104] -#ifdef GLOBAL -= -{ - {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} -} -#endif -; - -/* Table B-12, dct_dc_size_luminance, codes 00xxx ... 11110 */ -XTN VLCtab DClumtab0[32] -#ifdef GLOBAL -= -{ - {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_VALUE, 0} -} -#endif -; - -/* Table B-12, dct_dc_size_luminance, codes 111110xxx ... 111111111 */ -XTN VLCtab DClumtab1[16] -#ifdef GLOBAL -= -{ - {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} -} -#endif -; - -/* Table B-13, dct_dc_size_chrominance, codes 00xxx ... 11110 */ -XTN VLCtab DCchromtab0[32] -#ifdef GLOBAL -= -{ - {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_VALUE, 0} -} -#endif -; - -/* Table B-13, dct_dc_size_chrominance, codes 111110xxxx ... 1111111111 */ -XTN VLCtab DCchromtab1[32] -#ifdef GLOBAL -= -{ - {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} -} -#endif -; - -/* Table B-14, DCT coefficients table zero, - * codes 0100 ... 1xxx (used for first (DC) coefficient) - */ -XTN DCTtab DCTtabfirst[12] -#ifdef GLOBAL -= -{ - {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} -} -#endif -; - -/* Table B-14, DCT coefficients table zero, - * codes 0100 ... 1xxx (used for all other coefficients) - */ -XTN DCTtab DCTtabnext[12] -#ifdef GLOBAL -= -{ - {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} -} -#endif -; - -/* Table B-14, DCT coefficients table zero, - * codes 000001xx ... 00111xxx - */ -XTN DCTtab DCTtab0[60] -#ifdef GLOBAL -= -{ - {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} -} -#endif -; - -/* Table B-15, DCT coefficients table one, - * codes 000001xx ... 11111111 -*/ -XTN DCTtab DCTtab0a[252] -#ifdef GLOBAL -= -{ - {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} -} -#endif -; - -/* Table B-14, DCT coefficients table zero, - * codes 0000001000 ... 0000001111 - */ -XTN DCTtab DCTtab1[8] -#ifdef GLOBAL -= -{ - {16,1,10}, {5,2,10}, {0,7,10}, {2,3,10}, - {1,4,10}, {15,1,10}, {14,1,10}, {4,2,10} -} -#endif -; - -/* Table B-15, DCT coefficients table one, - * codes 000000100x ... 000000111x - */ -XTN DCTtab DCTtab1a[8] -#ifdef GLOBAL -= -{ - {5,2,9}, {5,2,9}, {14,1,9}, {14,1,9}, - {2,4,10}, {16,1,10}, {15,1,9}, {15,1,9} -} -#endif -; - -/* Table B-14/15, DCT coefficients table zero / one, - * codes 000000010000 ... 000000011111 - */ -XTN DCTtab DCTtab2[16] -#ifdef GLOBAL -= -{ - {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} -} -#endif -; - -/* Table B-14/15, DCT coefficients table zero / one, - * codes 0000000010000 ... 0000000011111 - */ -XTN DCTtab DCTtab3[16] -#ifdef GLOBAL -= -{ - {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} -} -#endif -; - -/* Table B-14/15, DCT coefficients table zero / one, - * codes 00000000010000 ... 00000000011111 - */ -XTN DCTtab DCTtab4[16] -#ifdef GLOBAL -= -{ - {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} -} -#endif -; - -/* Table B-14/15, DCT coefficients table zero / one, - * codes 000000000010000 ... 000000000011111 - */ -XTN DCTtab DCTtab5[16] -#ifdef GLOBAL -= -{ - {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} -} -#endif -; - -/* Table B-14/15, DCT coefficients table zero / one, - * codes 0000000000010000 ... 0000000000011111 - */ -XTN DCTtab DCTtab6[16] -#ifdef GLOBAL -= -{ - {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} -} -#endif -; - -/* Table B-3, macroblock_type in P-pictures, codes 001..1xx */ -XTN VLCtab PMBtab0[8] -#ifdef GLOBAL -= -{ - {ERROR_VALUE,0}, - {MACROBLOCK_MOTION_FORWARD,3}, - {MACROBLOCK_PATTERN,2}, {MACROBLOCK_PATTERN,2}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,1}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,1}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,1}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,1} -} -#endif -; - -/* Table B-3, macroblock_type in P-pictures, codes 000001..00011x */ -XTN VLCtab PMBtab1[8] -#ifdef GLOBAL -= -{ - {ERROR_VALUE,0}, - {MACROBLOCK_QUANT|MACROBLOCK_INTRA,6}, - {MACROBLOCK_QUANT|MACROBLOCK_PATTERN,5}, {MACROBLOCK_QUANT|MACROBLOCK_PATTERN,5}, - {MACROBLOCK_QUANT|MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,5}, {MACROBLOCK_QUANT|MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,5}, - {MACROBLOCK_INTRA,5}, {MACROBLOCK_INTRA,5} -} -#endif -; - -/* Table B-4, macroblock_type in B-pictures, codes 0010..11xx */ -XTN VLCtab BMBtab0[16] -#ifdef GLOBAL -= -{ - {ERROR_VALUE,0}, - {ERROR_VALUE,0}, - {MACROBLOCK_MOTION_FORWARD,4}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,4}, - {MACROBLOCK_MOTION_BACKWARD,3}, - {MACROBLOCK_MOTION_BACKWARD,3}, - {MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,3}, - {MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,3}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD,2}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD,2}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD,2}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD,2}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,2}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,2}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,2}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,2} -} -#endif -; - -/* Table B-4, macroblock_type in B-pictures, codes 000001..00011x */ -XTN VLCtab BMBtab1[8] -#ifdef GLOBAL -= -{ - {ERROR_VALUE,0}, - {MACROBLOCK_QUANT|MACROBLOCK_INTRA,6}, - {MACROBLOCK_QUANT|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,6}, - {MACROBLOCK_QUANT|MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,6}, - {MACROBLOCK_QUANT|MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,5}, - {MACROBLOCK_QUANT|MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,5}, - {MACROBLOCK_INTRA,5}, - {MACROBLOCK_INTRA,5} -} -#endif -; diff --git a/src/dgindex/gui.cpp b/src/dgindex/gui.cpp deleted file mode 100644 index 0ea73a5..0000000 --- a/src/dgindex/gui.cpp +++ /dev/null @@ -1,4896 +0,0 @@ -/* - * Mutated into DGIndex. Modifications Copyright (C) 2004-2008, Donald Graft - * - * Copyright (C) Chia-chen Kuo - April 2001 - * - * This file is part of DVD2AVI, a free MPEG-2 decoder - * - * DVD2AVI 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. - * - * DVD2AVI is distributed in the hope that 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. - * - */ -#define _WIN32_WINNT 0x0501 // Needed for WM_MOUSEWHEEL - -#include -#include -#include "resource.h" -#include "Shlwapi.h" - -#define GLOBAL -#include "global.h" - -#include "..\config.h" - -#ifndef DGMPGDEC_GIT_VERSION -static char Version[] = "DGIndex 1.5.8"; -#else -static char Version[] = "DGIndex " DGMPGDEC_GIT_VERSION; -#endif - -#define TRACK_HEIGHT 32 -#define INIT_WIDTH 480 -#define INIT_HEIGHT 270 -#define MIN_WIDTH 160 -#define MIN_HEIGHT 32 - -#define MASKCOLOR RGB(0, 6, 0) - -#define SAVE_D2V 1 -#define SAVE_WAV 2 -#define OPEN_D2V 3 -#define OPEN_VOB 4 -#define OPEN_WAV 5 -#define SAVE_BMP 6 -#define OPEN_AVS 7 -#define OPEN_TXT 8 - -#define PRIORITY_HIGH 1 -#define PRIORITY_NORMAL 2 -#define PRIORITY_LOW 3 - -bool PopFileDlg(PTSTR, HWND, int); -ATOM MyRegisterClass(HINSTANCE); -LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK SelectProc(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK Info(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK VideoList(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK Cropping(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK Luminance(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK Speed(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK Normalization(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK SelectTracks(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK SelectDelayTrack(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK SetPids(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK SetMargin(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK AVSTemplate(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK BMPPath(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK DetectPids(HWND, UINT, WPARAM, LPARAM); -LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM); -static void ShowInfo(bool); -static void SaveBMP(void); -static void CopyBMP(void); -static void OpenVideoFile(HWND); -static void OpenAudioFile(HWND); -DWORD WINAPI ProcessWAV(LPVOID n); -void OutputProgress(int); - -static void StartupEnables(void); -static void FileLoadedEnables(void); -static void RunningEnables(void); - -enum { - DIALOG_INFORMATION, - DIALOG_ABOUT, - DIALOG_FILE_LIST, - DIALOG_LUMINANCE, - DIALOG_NORMALIZE, - DIALOG_SET_PIDS, - DIALOG_AVS_TEMPLATE, - DIALOG_BITMAP_PATH, - DIALOG_CROPPING, - DIALOG_DETECT_PIDS, - DIALOG_SELECT_TRACKS, - DIALOG_DELAY_TRACK, - DIALOG_MARGIN, - DIALOG_MAX -}; -static void LoadLanguageSettings(void); -static void *LoadDialogLanguageSettings(HWND, int); -static void DestroyDialogLanguageSettings(void *); - -static int INIT_X, INIT_Y, Priority_Flag, Edge_Width, Edge_Height; - -static FILE *INIFile; -static char szPath[DG_MAX_PATH], szTemp[DG_MAX_PATH], szWindowClass[DG_MAX_PATH]; - -static HINSTANCE hInst; -static HANDLE hProcess, hThread; -static HWND hLeftButton, hLeftArrow, hRightArrow, hRightButton; - -static DWORD threadId; -static RECT wrect, crect, info_wrect; -static int SoundDelay[MAX_FILE_NUMBER]; -static char Outfilename[MAX_FILE_NUMBER][DG_MAX_PATH]; - -static char windowTitle[DG_MAX_PATH] = ""; -static int stopWaitTime; - -extern int fix_d2v(HWND hWnd, char *path, int test_only); -extern int parse_d2v(HWND hWnd, char *path); -extern int analyze_sync(HWND hWnd, char *path, int track); -extern unsigned char *Rdbfr; -extern __int64 VideoPTS, LastVideoPTS; -static __int64 StartPTS, IframePTS; - -#undef DGMPGDEC_WIN9X_SUPPORTED -#if _MSC_VER < 1500 -#define DGMPGDEC_WIN9X_SUPPORTED -#endif - -#if !defined(DGMPGDEC_WIN9X_SUPPORTED) -static BOOL bIsWindowsVersionOK(DWORD dwMajor, DWORD dwMinor, WORD dwSPMajor) -{ - OSVERSIONINFOEX osvi; - DWORD dwTypeMask = VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR; - DWORDLONG dwlConditionMask = 0; - - ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); - - osvi.dwMajorVersion = dwMajor; - osvi.dwMinorVersion = dwMinor; - osvi.wServicePackMajor = dwSPMajor; - - VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION , VER_GREATER_EQUAL); - VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION , VER_GREATER_EQUAL); - VER_SET_CONDITION(dwlConditionMask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); - - return VerifyVersionInfo(&osvi, dwTypeMask, dwlConditionMask); -} -#endif - -int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) -{ - MSG msg; - HACCEL hAccel; - - int i; - char *ptr; - char ucCmdLine[4096]; - char prog[DG_MAX_PATH]; - char cwd[DG_MAX_PATH]; - - DWORD dwMajor = 5; - DWORD dwMinor = 1; - -#if !defined(DGMPGDEC_WIN9X_SUPPORTED) - bIsWindowsXPorLater = bIsWindowsVersionOK(dwMajor, dwMinor, 0); -#else - OSVERSIONINFO osvi; - - ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - - GetVersionEx(&osvi); - - bIsWindowsXPorLater = - ( (osvi.dwMajorVersion > dwMajor) || - ( (osvi.dwMajorVersion == dwMajor) && (osvi.dwMinorVersion >= dwMinor) )); -#endif - - if(bIsWindowsXPorLater) - { - // Prepare status output (console/file). - if (GetStdHandle(STD_OUTPUT_HANDLE) == (HANDLE)0) - { - // No output handle. We'll try to attach a console. - AttachConsole( ATTACH_PARENT_PROCESS ); - } - else - { - if (FlushFileBuffers(GetStdHandle(STD_OUTPUT_HANDLE))) - { - // Flush succeeded -> We are NOT writing to console (output redirected to file, etc.). No action required. - } - else - { - // Flush failed -> We are writing to console. AttachConsole to enable it. - AttachConsole( ATTACH_PARENT_PROCESS ); - } - } - } - - // Get the path to the DGIndex executable. - GetModuleFileName(NULL, ExePath, DG_MAX_PATH); - - // Find first char after last backslash. - if ((ptr = _tcsrchr(ExePath,'\\')) != 0) ptr++; - else ptr = ExePath; - *ptr = 0; - - // Load INI - strcpy(prog, ExePath); - strcat(prog, "DGIndex.ini"); - if ((INIFile = fopen(prog, "r")) == NULL) - { -NEW_VERSION: - INIT_X = INIT_Y = 100; - info_wrect.left = info_wrect.top = 100; - iDCT_Flag = IDCT_SKAL; - Scale_Flag = true; - setRGBValues(); - FO_Flag = FO_NONE; - Method_Flag = AUDIO_DEMUXALL; - strcpy(Track_List, ""); - DRC_Flag = DRC_NORMAL; - DSDown_Flag = false; - SRC_Flag = SRC_NONE; - Norm_Ratio = 100; - Priority_Flag = PRIORITY_NORMAL; - PlaybackSpeed = SPEED_NORMAL; - ForceOpenGops = 0; - // Default the AVS template path. - // Get the path to the DGIndex executable. - GetModuleFileName(NULL, AVSTemplatePath, 255); - // Find first char after last backslash. - if ((ptr = _tcsrchr(AVSTemplatePath,'\\')) != 0) ptr++; - else ptr = AVSTemplatePath; - *ptr = 0; - strcat(AVSTemplatePath, "template.avs"); - FullPathInFiles = 1; - LoopPlayback = 0; - FusionAudio = 0; - HDDisplay = HD_DISPLAY_SHRINK_BY_HALF; - for (i = 0; i < 4; i++) - mMRUList[i][0] = 0; - InfoLog_Flag = 1; - BMPPathString[0] = 0; - UseMPAExtensions = 0; - NotifyWhenDone = 0; - TsParseMargin = 0; - CorrectFieldOrderTrans = true; - } - else - { - char line[DG_MAX_PATH], *p; - unsigned int audio_id; - - fgets(line, DG_MAX_PATH - 1, INIFile); - line[strlen(line)-1] = 0; -//#ifdef DGMPGDEC_GIT_VERSION - p = strstr(line, "-"); - if (p) - *p = 0; -//#endif - p = strstr(line, "="); - if (p) - ++p; - if (!p || *p == 0 || strncmp(p, Version, strlen(p))) - { - fclose(INIFile); - goto NEW_VERSION; - } - - fscanf(INIFile, "Window_Position=%d,%d\n", &INIT_X, &INIT_Y); - fscanf(INIFile, "Info_Window_Position=%d,%d\n", &info_wrect.left, &info_wrect.top); - - fscanf(INIFile, "iDCT_Algorithm=%d\n", &iDCT_Flag); - fscanf(INIFile, "YUVRGB_Scale=%d\n", &Scale_Flag); - setRGBValues(); - fscanf(INIFile, "Field_Operation=%d\n", &FO_Flag); - fscanf(INIFile, "Output_Method=%d\n", &Method_Flag); - fgets(line, DG_MAX_PATH - 1, INIFile); - line[strlen(line)-1] = 0; - p = line; - while (*p++ != '='); - strcpy (Track_List, p); - for (i = 0; i < 0xc8; i++) - audio[i].selected_for_demux = false; - while ((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') || (*p >= 'A' && *p <= 'F')) - { - sscanf(p, "%x", &audio_id); - if (audio_id > 0xc7) - break; - audio[audio_id].selected_for_demux = true; - while (*p != ',' && *p != 0) p++; - if (*p == 0) - break; - p++; - } - fscanf(INIFile, "DR_Control=%d\n", &DRC_Flag); - fscanf(INIFile, "DS_Downmix=%d\n", &DSDown_Flag); - fscanf(INIFile, "SRC_Precision=%d\n", &SRC_Flag); - fscanf(INIFile, "Norm_Ratio=%d\n", &Norm_Ratio); - fscanf(INIFile, "Process_Priority=%d\n", &Priority_Flag); - fscanf(INIFile, "Playback_Speed=%d\n", &PlaybackSpeed); - fscanf(INIFile, "Force_Open_Gops=%d\n", &ForceOpenGops); - fgets(line, DG_MAX_PATH - 1, INIFile); - line[strlen(line)-1] = 0; - p = line; - while (*p++ != '='); - strcpy (AVSTemplatePath, p); - fscanf(INIFile, "Full_Path_In_Files=%d\n", &FullPathInFiles); - fscanf(INIFile, "Fusion_Audio=%d\n", &FusionAudio); - fscanf(INIFile, "Loop_Playback=%d\n", &LoopPlayback); - fscanf(INIFile, "HD_Display=%d\n", &HDDisplay); - for (i = 0; i < 4; i++) - { - fgets(line, DG_MAX_PATH - 1, INIFile); - line[strlen(line)-1] = 0; - p = line; - while (*p++ != '='); - strcpy(mMRUList[i], p); - } - fscanf(INIFile, "Enable_Info_Log=%d\n", &InfoLog_Flag); - fgets(line, DG_MAX_PATH - 1, INIFile); - line[strlen(line)-1] = 0; - p = line; - while (*p++ != '='); - strcpy(BMPPathString, p); - fscanf(INIFile, "Use_MPA_Extensions=%d\n", &UseMPAExtensions); - fscanf(INIFile, "Notify_When_Done=%d\n", &NotifyWhenDone); - TsParseMargin = 0; - fscanf(INIFile, "TS_Parse_Margin=%d\n", &TsParseMargin); - CorrectFieldOrderTrans = true; - fscanf(INIFile, "CorrectFieldOrderTrans=%d\n", &CorrectFieldOrderTrans); - fclose(INIFile); - } - - // Allocate stream buffer. - Rdbfr = (unsigned char *) malloc(BUFFER_SIZE); - if (Rdbfr == NULL) - { - MessageBox(hWnd, "Couldn't allocate stream buffer using configured size.\nTrying default size.", NULL, MB_OK | MB_ICONERROR); - Rdbfr = (unsigned char *) malloc(32 * SECTOR_SIZE); - if (Rdbfr == NULL) - { - MessageBox(hWnd, "Couldn't allocate stream buffer using default size.\nExiting.", NULL, MB_OK | MB_ICONERROR); - exit(0); - } - } - - // Perform application initialization - hInst = hInstance; - - // Load accelerators - hAccel = LoadAccelerators(hInst, (LPCTSTR)IDR_ACCELERATOR); - - // Initialize global strings - LoadString(hInst, IDC_GUI, szWindowClass, DG_MAX_PATH); - MyRegisterClass(hInst); - - hWnd = CreateWindow(szWindowClass, "DGIndex", WS_OVERLAPPEDWINDOW & ~(WS_THICKFRAME|WS_MAXIMIZEBOX), - CW_USEDEFAULT, 0, INIT_WIDTH, INIT_HEIGHT, NULL, NULL, hInst, NULL); - - // Test CPU - __asm - { - mov eax, 1 - cpuid - test edx, 0x00800000 // STD MMX - jz TEST_SSE - mov [cpu.mmx], 1 - TEST_SSE: - test edx, 0x02000000 // STD SSE - jz TEST_SSE2 - mov [cpu.ssemmx], 1 - mov [cpu.ssefpu], 1 - TEST_SSE2: - test edx, 0x04000000 // SSE2 - jz TEST_3DNOW - mov [cpu.sse2], 1 - TEST_3DNOW: - mov eax, 0x80000001 - cpuid - test edx, 0x80000000 // 3D NOW - jz TEST_SSEMMX - mov [cpu._3dnow], 1 - TEST_SSEMMX: - test edx, 0x00400000 // SSE MMX - jz TEST_END - mov [cpu.ssemmx], 1 - TEST_END: - } - - if (!cpu.sse2) - { - DeleteMenu(hMenu, IDM_IDCT_SSE2MMX, 0); - } - - if (!cpu.ssemmx) - { - DeleteMenu(hMenu, IDM_IDCT_SSEMMX, 0); - DeleteMenu(hMenu, IDM_IDCT_SKAL, 0); - } - - if (cpu.mmx) - CheckMenuItem(hMenu, IDM_MMX, MF_CHECKED); - else - DestroyWindow(hWnd); - - if (cpu.ssemmx) - CheckMenuItem(hMenu, IDM_SSEMMX, MF_CHECKED); - - if (cpu.sse2) - CheckMenuItem(hMenu, IDM_SSE2, MF_CHECKED); - - if (cpu._3dnow) - CheckMenuItem(hMenu, IDM_3DNOW, MF_CHECKED); - - if (cpu.ssefpu) - CheckMenuItem(hMenu, IDM_SSEFPU, MF_CHECKED); - - // Create control - hTrack = CreateWindow(TRACKBAR_CLASS, NULL, - WS_CHILD | WS_VISIBLE | WS_DISABLED | TBS_NOTICKS | TBS_TOP, - 0, INIT_HEIGHT, INIT_WIDTH-4*TRACK_HEIGHT, TRACK_HEIGHT, hWnd, (HMENU) ID_TRACKBAR, hInst, NULL); - SendMessage(hTrack, TBM_SETRANGE, (WPARAM) true, (LPARAM) MAKELONG(0, TRACK_PITCH)); - - hLeftButton = CreateWindow("BUTTON", "[", - WS_CHILD | WS_VISIBLE | WS_DLGFRAME | WS_DISABLED, - INIT_WIDTH-4*TRACK_HEIGHT, INIT_HEIGHT, - TRACK_HEIGHT, TRACK_HEIGHT, hWnd, (HMENU) ID_LEFT_BUTTON, hInst, NULL); - - hLeftArrow = CreateWindow("BUTTON", "<", - WS_CHILD | WS_VISIBLE | WS_DLGFRAME | WS_DISABLED, - INIT_WIDTH-3*TRACK_HEIGHT, INIT_HEIGHT, - TRACK_HEIGHT, TRACK_HEIGHT, hWnd, (HMENU) ID_LEFT_ARROW, hInst, NULL); - - hRightArrow = CreateWindow("BUTTON", ">", - WS_CHILD | WS_VISIBLE | WS_DLGFRAME | WS_DISABLED, - INIT_WIDTH-2*TRACK_HEIGHT, INIT_HEIGHT, - TRACK_HEIGHT, TRACK_HEIGHT, hWnd, (HMENU) ID_RIGHT_ARROW, hInst, NULL); - - hRightButton = CreateWindow("BUTTON", "]", - WS_CHILD | WS_VISIBLE | WS_DLGFRAME | WS_DISABLED, - INIT_WIDTH-TRACK_HEIGHT, INIT_HEIGHT, - TRACK_HEIGHT, TRACK_HEIGHT, hWnd, (HMENU) ID_RIGHT_BUTTON, hInst, NULL); - - ResizeWindow(INIT_WIDTH, INIT_HEIGHT); - MoveWindow(hWnd, INIT_X, INIT_Y, INIT_WIDTH+Edge_Width, INIT_HEIGHT+Edge_Height+TRACK_HEIGHT+TRACK_HEIGHT/3, true); - - LoadLanguageSettings(); - - MPEG2_Transport_VideoPID = 2; - MPEG2_Transport_AudioPID = 2; - MPEG2_Transport_PCRPID = 2; - - stopWaitTime = 5000; - - // Command line init. - strcpy(ucCmdLine, lpCmdLine); - _strupr(ucCmdLine); - - // Show window normal, minimized, or hidden as appropriate. - if (*lpCmdLine == 0) - WindowMode = SW_SHOW; - else - { - if (strstr(ucCmdLine,"-MINIMIZE")) - WindowMode = SW_MINIMIZE; - else if (strstr(ucCmdLine,"-HIDE")) - WindowMode = SW_HIDE; - else - WindowMode = SW_SHOW; - } - ShowWindow(hWnd, WindowMode); - - StartupEnables(); - CheckFlag(); - CLIActive = 0; - CLIParseD2V = PARSE_D2V_NONE; - CLINoProgress = 0; - - // First check whether we have "Open With" invocation. - if (*lpCmdLine != 0) - { - #define OUT_OF_FILE 0 - #define IN_FILE_QUOTED 1 - #define IN_FILE_BARE 2 - #define MAX_CMD 2048 - int tmp, n, i, j, k; - int state, ndx; - char *swp; - -// MessageBox(hWnd, lpCmdLine, NULL, MB_OK); - ptr = lpCmdLine; - // Look at the first non-white-space character. - // If it is a '-' we have CLI invocation, else - // we have "Open With" invocation. - while (*ptr == ' ' && *ptr == '\t') ptr++; - if (*ptr != '-') - { - // "Open With" invocation. - NumLoadedFiles = 0; - // Pick up all the filenames. - // The command line will look like this (with the quotes!): - // "c:\my dir\file1.vob" c:\dir\file2.vob ... - // The paths with spaces have quotes; those without do not. - // This is tricky to parse, so use a state machine. - state = OUT_OF_FILE; - for (k = 0; k < MAX_CMD; k++) - { - if (state == OUT_OF_FILE) - { - if (*ptr == 0) - { - break; - } - else if (*ptr == ' ') - { - } - else if (*ptr == '"') - { - state = IN_FILE_QUOTED; - ndx = 0; - } - else - { - state = IN_FILE_BARE; - ndx = 0; - cwd[ndx++] = *ptr; - } - } - else if (state == IN_FILE_QUOTED) - { - if (*ptr == '"') - { - cwd[ndx] = 0; - if ((tmp = _open(cwd, _O_RDONLY | _O_BINARY)) != -1) - { -// MessageBox(hWnd, "Open OK", NULL, MB_OK); - strcpy(Infilename[NumLoadedFiles], cwd); - Infile[NumLoadedFiles] = tmp; - NumLoadedFiles++; - } - state = OUT_OF_FILE; - } - else - { - cwd[ndx++] = *ptr; - } - } - else if (state == IN_FILE_BARE) - { - if (*ptr == 0) - { - cwd[ndx] = 0; - if ((tmp = _open(cwd, _O_RDONLY | _O_BINARY)) != -1) - { -// MessageBox(hWnd, "Open OK", NULL, MB_OK); - strcpy(Infilename[NumLoadedFiles], cwd); - Infile[NumLoadedFiles] = tmp; - NumLoadedFiles++; - } - break; - } - else if (*ptr == ' ') - { - cwd[ndx] = 0; - if ((tmp = _open(cwd, _O_RDONLY | _O_BINARY)) != -1) - { -// MessageBox(hWnd, "Open OK", NULL, MB_OK); - strcpy(Infilename[NumLoadedFiles], cwd); - Infile[NumLoadedFiles] = tmp; - NumLoadedFiles++; - } - state = OUT_OF_FILE; - } - else - { - cwd[ndx++] = *ptr; - } - } - ptr++; - } - // Sort the filenames. - n = NumLoadedFiles; - for (i = 0; i < n - 1; i++) - { - for (j = 0; j < n - 1 - i; j++) - { - if (strverscmp(Infilename[j+1], Infilename[j]) < 0) - { - swp = Infilename[j]; - Infilename[j] = Infilename[j+1]; - Infilename[j+1] = swp; - tmp = Infile[j]; - Infile[j] = Infile[j+1]; - Infile[j+1] = tmp; - } - } - } - // Start everything up with these files. - Recovery(); - RefreshWindow(true); - // Force the following CLI processing to be skipped. - *lpCmdLine = 0; - if (NumLoadedFiles) - { - // Start a LOCATE_INIT thread. When it kills itself, it will start a - // LOCATE_RIP thread by sending a WM_USER message to the main window. - process.rightfile = NumLoadedFiles-1; - process.rightlba = (int)(Infilelength[NumLoadedFiles-1]/SECTOR_SIZE); - process.end = Infiletotal - SECTOR_SIZE; - process.endfile = NumLoadedFiles - 1; - process.endloc = (Infilelength[NumLoadedFiles-1]/SECTOR_SIZE - 1)*SECTOR_SIZE; - process.locate = LOCATE_INIT; - if (!threadId || WaitForSingleObject(hThread, INFINITE)==WAIT_OBJECT_0) - hThread = CreateThread(NULL, 0, MPEG2Dec, 0, 0, &threadId); - } - } - } - - if (*lpCmdLine) - { - // CLI invocation. - if (parse_cli(lpCmdLine, ucCmdLine) != 0) - exit(0); - if (CLIParseD2V & PARSE_D2V_INPUT_FILE) - SendMessage(hWnd, CLI_PARSE_D2V_MESSAGE, 0, 0); - if (NumLoadedFiles) - { - // Start a LOCATE_INIT thread. When it kills itself, it will start a - // LOCATE_RIP thread by sending a WM_USER message to the main window. - PlaybackSpeed = SPEED_MAXIMUM; - // If the project range wasn't set with the RG option, set it to the entire timeline. - if (!hadRGoption) - { - process.rightfile = NumLoadedFiles-1; - process.rightlba = (int)(Infilelength[NumLoadedFiles-1]/SECTOR_SIZE); - process.end = Infiletotal - SECTOR_SIZE; - process.endfile = NumLoadedFiles - 1; - process.endloc = (Infilelength[NumLoadedFiles-1]/SECTOR_SIZE - 1)*SECTOR_SIZE; - } - process.locate = LOCATE_INIT; - if (!threadId || WaitForSingleObject(hThread, INFINITE)==WAIT_OBJECT_0) - hThread = CreateThread(NULL, 0, MPEG2Dec, 0, 0, &threadId); - } - } - - UpdateMRUList(); - - // Main message loop - while (GetMessage(&msg, NULL, 0, 0)) - { - if (!TranslateAccelerator(hWnd, hAccel, &msg)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } - - return msg.wParam; -} - -HBITMAP splash = NULL; - -// Processes messages for the main window -LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) -{ - DWORD wmId, wmEvent; - - HDC hdc; - PAINTSTRUCT ps; - char prog[DG_MAX_PATH]; - char path[DG_MAX_PATH]; - char avsfile[DG_MAX_PATH]; - LPTSTR path_p, prog_p; - FILE *tplate, *avs; - - int i, j; - - WNDCLASS rwc = {0}; - - switch (message) - { - case CLI_RIP_MESSAGE: - // The CLI-invoked LOCATE_INIT thread is finished. - // Kick off a LOCATE_RIP thread. - if (CLIPreview) - { - CLIParseD2V = PARSE_D2V_NONE; - goto preview; - } - else - goto proceed; - - case CLI_PREVIEW_DONE_MESSAGE: - // Destroy the Info dialog to generate the info log file. - DestroyWindow(hDlg); - if (ExitOnEnd) - exit(0); - break; - - case D2V_DONE_MESSAGE: - // Make an AVS file if it doesn't already exist and a template exists. - strcpy(avsfile, D2VFilePath); - path_p = strrchr(avsfile, '.'); - strcpy(++path_p, "avs"); - if (*AVSTemplatePath && !fopen(avsfile, "r") && (tplate = fopen(AVSTemplatePath, "r"))) - { - avs = fopen(avsfile, "w"); - if (avs) - { - while (fgets(path, 1023, tplate)) - { - path_p = path; - prog_p = prog; - while (1) - { - if (*path_p == 0) - { - *prog_p = 0; - break; - } - else if (path_p[0] == '_' && path_p[1] == '_' && path_p[2] == 'v' && - path_p[3] == 'i' && path_p[4] == 'd' && path_p[5] == '_' && path_p[6] == '_') - { - // Replace __vid__ macro. - *prog_p = 0; - if (FullPathInFiles) - { - strcat(prog_p, D2VFilePath); - prog_p = &prog[strlen(prog)]; - path_p += 7; - } - else - { - char *p; - if ((p = _tcsrchr(D2VFilePath,'\\')) != 0) p++; - else p = D2VFilePath; - strcat(prog_p, p); - prog_p = &prog[strlen(prog)]; - path_p += 7; - - } - } - else if (path_p[0] == '_' && path_p[1] == '_' && path_p[2] == 'a' && - path_p[3] == 'u' && path_p[4] == 'd' && path_p[5] == '_' && path_p[6] == '_') - { - // Replace __aud__ macro. - *prog_p = 0; - if (FullPathInFiles) - { - strcat(prog_p, AudioFilePath); - prog_p = &prog[strlen(prog)]; - path_p += 7; - } - else - { - char *p; - if ((p = _tcsrchr(AudioFilePath,'\\')) != 0) p++; - else p = AudioFilePath; - strcat(prog_p, p); - prog_p = &prog[strlen(prog)]; - path_p += 7; - } - } - else if (AudioFilePath && path_p[0] == '_' && path_p[1] == '_' && path_p[2] == 'd' && - path_p[3] == 'e' && path_p[4] == 'l' && path_p[5] == '_' && path_p[6] == '_') - { - // Replace __del__ macro. - char *d = &AudioFilePath[strlen(AudioFilePath)-3]; - int delay; - float fdelay; - char fdelay_str[32]; - while (d > AudioFilePath) - { - if (d[0] == 'm' && d[1] == 's' && d[2] == '.') - break; - d--; - } - if (d > AudioFilePath) - { - while ((d > AudioFilePath) && d[0] != ' ') d--; - if (d[0] == ' ') - { - sscanf(d, "%d", &delay); - fdelay = (float) 0.001 * delay; - sprintf(fdelay_str, "%.3f", fdelay); - *prog_p = 0; - strcat(prog_p, fdelay_str); - prog_p = &prog[strlen(prog)]; - path_p += 7; - } - else - *prog_p++ = *path_p++; - } - else - *prog_p++ = *path_p++; - } - else - { - *prog_p++ = *path_p++; - } - } - fputs(prog, avs); - } - fclose(tplate); - fclose(avs); - } - } - if (CLIParseD2V & PARSE_D2V_AFTER_SAVING) - { - strcpy(szInput, D2VFilePath); - goto cli_parse_d2v; - } - if (ExitOnEnd) - { - if (Info_Flag) - DestroyWindow(hDlg); - exit(0); - } - else - { - CLIActive = 0; - CLIParseD2V = PARSE_D2V_NONE; - } - break; - - case CLI_PARSE_D2V_MESSAGE: -cli_parse_d2v: - parse_d2v(hWnd, szInput); - if (CLIParseD2V == PARSE_D2V_AFTER_SAVING) - CLIActive = 0; - if (ExitOnEnd && !CLIActive) - exit(0); - if (CLIParseD2V & PARSE_D2V_INPUT_FILE) - CLIParseD2V &= ~PARSE_D2V_INPUT_FILE; - else - CLIParseD2V = PARSE_D2V_NONE; - break; - - case PROGRESS_MESSAGE: - if (CLINoProgress == 0) - OutputProgress(wParam); - break; - - case WM_CREATE: - PreScale_Ratio = 1.0; - - process.trackleft = 0; - process.trackright = TRACK_PITCH; - - rwc.lpszClassName = TEXT("SelectControl"); - rwc.hbrBackground = GetSysColorBrush(COLOR_BTNFACE); - rwc.style = CS_HREDRAW; - rwc.lpfnWndProc = SelectProc; - RegisterClass(&rwc); - - hwndSelect = CreateWindowEx(0, TEXT("SelectControl"), NULL, - WS_CHILD | WS_VISIBLE, 12, 108, 370, TRACK_HEIGHT/3, hWnd, NULL, NULL, NULL); - - hDC = GetDC(hWnd); - hMenu = GetMenu(hWnd); - hProcess = GetCurrentProcess(); - - // Load the splash screen from the file dgindex.bmp if it exists. - strcpy(prog, ExePath); - strcat(prog, "dgindex.bmp"); - splash = (HBITMAP) ::LoadImage (0, prog, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); -// if (splash == 0) -// { -// // No splash file. Use the built-in default splash screen. -// splash = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_SPLASH)); -// } - - for (i=0; iprocess.leftfile) || (process.file==process.leftfile && process.lba>process.leftlba)) - { - process.rightfile = process.file; - process.rightlba = process.lba; - - process.run = 0; - for (i=0; i Infilelength[process.startfile]) - { - process.startloc -= Infilelength[process.startfile]; - process.run += Infilelength[process.startfile]; - process.startfile++; - } - - process.end = Infiletotal - SECTOR_SIZE; - process.endfile = NumLoadedFiles - 1; - process.endloc = (Infilelength[NumLoadedFiles-1]/SECTOR_SIZE-1)*SECTOR_SIZE; - - process.locate = LOCATE_SCROLL; - - hThread = CreateThread(NULL, 0, MPEG2Dec, 0, 0, &threadId); - } - break; - - case WM_KEYDOWN: - switch (wParam) - { - case VK_HOME: - if (IsWindowEnabled(hTrack)) - { - if (Info_Flag) - { - DestroyWindow(hDlg); - Info_Flag = false; - } - SendMessage(hWnd, WM_COMMAND, MAKEWPARAM(ID_LEFT_BUTTON, 0), (LPARAM) 0); - } - break; - - case VK_END: - if (IsWindowEnabled(hTrack)) - { - if (Info_Flag) - { - DestroyWindow(hDlg); - Info_Flag = false; - } - SendMessage(hWnd, WM_COMMAND, MAKEWPARAM(ID_RIGHT_BUTTON, 0), (LPARAM) 0); - } - break; - - case VK_LEFT: - if (IsWindowEnabled(hTrack)) - { - if (Info_Flag) - { - DestroyWindow(hDlg); - Info_Flag = false; - } - if (WaitForSingleObject(hThread, 0)==WAIT_OBJECT_0) - { - Display_Flag = true; - - process.locate = LOCATE_BACKWARD; - hThread = CreateThread(NULL, 0, MPEG2Dec, 0, 0, &threadId); - } - } - break; - - case VK_RIGHT: - if (process.locate == LOCATE_RIP) - { - // We are in play/preview mode. Signal the - // display process to step forward one frame. - if (PlaybackSpeed == SPEED_SINGLE_STEP) - RightArrowHit = true; - break; - } - if (IsWindowEnabled(hTrack)) - { - if (Info_Flag) - { - DestroyWindow(hDlg); - Info_Flag = false; - } - if (WaitForSingleObject(hThread, 0)==WAIT_OBJECT_0) - { - Display_Flag = true; - - process.locate = LOCATE_FORWARD; - hThread = CreateThread(NULL, 0, MPEG2Dec, 0, 0, &threadId); - } - } - break; - } - break; - - case WM_SIZE: - if (!IsIconic(hWnd)) - { - ShowInfo(false); - RefreshWindow(true); - } - break; - - case WM_MOVE: - if (!IsIconic(hWnd)) - { - GetWindowRect(hWnd, &wrect); - RefreshWindow(false); - } - break; - - case WM_PAINT: - { - BITMAP bm; - HDC hdcMem; - HBITMAP hbmOld; - - hdc = BeginPaint(hWnd, &ps); - // Paint the splash screen if no files are loaded. - if (splash && NumLoadedFiles == 0) - { - hdcMem = CreateCompatibleDC(hdc); - hbmOld = (HBITMAP) SelectObject(hdcMem, splash); - GetObject(splash, sizeof(bm), &bm); - BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY); - SelectObject(hdcMem, hbmOld); - DeleteDC(hdcMem); - } - EndPaint(hWnd, &ps); - ReleaseDC(hWnd, hdc); - RefreshWindow(false); - break; - } - - case WM_DROPFILES: - char *ext, *tmp; - int drop_count, drop_index; - int n; - - if (Info_Flag) - { - DestroyWindow(hDlg); - Info_Flag = false; - } - - DragQueryFile((HDROP)wParam, 0, szInput, sizeof(szInput)); - SetForegroundWindow(hWnd); - - // Set the output directory for a Save D2V operation to the - // same path as these input files. - tmp = _tcsrchr(szInput, '\\'); - if( tmp ) - { - size_t num = (size_t)(tmp - szInput) + 1; - strncpy(szSave, szInput, num); - szSave[num] = 0; - } - else - szSave[0] = 0; - - ext = strrchr(szInput, '.'); - if (ext!=NULL) - { - if (!_strnicmp(ext, ".d2v", 4)) - { - DragFinish((HDROP)wParam); - goto D2V_PROCESS; - } - } - - if (threadId) - { - Stop_Flag = true; - if (WaitForSingleObject(hThread, stopWaitTime) != WAIT_OBJECT_0) - exit(EXIT_FAILURE); - } - while (NumLoadedFiles) - { - NumLoadedFiles--; - _close(Infile[NumLoadedFiles]); - Infile[NumLoadedFiles] = NULL; - } - - drop_count = DragQueryFile((HDROP)wParam, 0xffffffff, szInput, sizeof(szInput)); - for (drop_index = 0; drop_index < drop_count; drop_index++) - { - DragQueryFile((HDROP)wParam, drop_index, szInput, sizeof(szInput)); - if (strchr(szInput, '?') != NULL) // Exclude the filename that contains Unicode. - continue; - struct _finddata_t seqfile; - if (_findfirst(szInput, &seqfile) != -1L) - { - strcpy(Infilename[NumLoadedFiles], szInput); - NumLoadedFiles++; - SystemStream_Flag = ELEMENTARY_STREAM; - } - } - DragFinish((HDROP)wParam); - // Sort the filenames. - // This is a special sort designed to do things intelligently - // for typical sequentially numbered filenames. - // Sorry, just a bubble sort. No need for performance here. KISS. - n = NumLoadedFiles; - for (i = 0; i < n - 1; i++) - { - for (j = 0; j < n - 1 - i; j++) - { - if (strverscmp(Infilename[j+1], Infilename[j]) < 0) - { - tmp = Infilename[j]; - Infilename[j] = Infilename[j+1]; - Infilename[j+1] = tmp; - } - } - } - // Open the files. - for (i = 0; i < NumLoadedFiles; i++) - { - Infile[i] = _open(Infilename[i], _O_RDONLY | _O_BINARY | _O_SEQUENTIAL); - } - DialogBox(hInst, (LPCTSTR)IDD_FILELIST, hWnd, (DLGPROC)VideoList); - break; - - case WM_DESTROY: - Stop_Flag = true; - WaitForSingleObject(hThread, 2000); - strcpy(prog, ExePath); - strcat(prog, "DGIndex.ini"); - if ((INIFile = fopen(prog, "w")) != NULL) - { - fprintf(INIFile, "DGIndex_Version=%s\n", Version); - fprintf(INIFile, "Window_Position=%d,%d\n", wrect.left, wrect.top); - fprintf(INIFile, "Info_Window_Position=%d,%d\n", info_wrect.left, info_wrect.top); - fprintf(INIFile, "iDCT_Algorithm=%d\n", iDCT_Flag); - fprintf(INIFile, "YUVRGB_Scale=%d\n", Scale_Flag); - fprintf(INIFile, "Field_Operation=%d\n", FO_Flag); - fprintf(INIFile, "Output_Method=%d\n", Method_Flag); - fprintf(INIFile, "Track_List=%s\n", Track_List); - fprintf(INIFile, "DR_Control=%d\n", DRC_Flag); - fprintf(INIFile, "DS_Downmix=%d\n", DSDown_Flag); - fprintf(INIFile, "SRC_Precision=%d\n", SRC_Flag); - fprintf(INIFile, "Norm_Ratio=%d\n", 100 * Norm_Flag + Norm_Ratio); - fprintf(INIFile, "Process_Priority=%d\n", Priority_Flag); - fprintf(INIFile, "Playback_Speed=%d\n", PlaybackSpeed); - fprintf(INIFile, "Force_Open_Gops=%d\n", ForceOpenGops); - fprintf(INIFile, "AVS_Template_Path=%s\n", AVSTemplatePath); - fprintf(INIFile, "Full_Path_In_Files=%d\n", FullPathInFiles); - fprintf(INIFile, "Fusion_Audio=%d\n", FusionAudio); - fprintf(INIFile, "Loop_Playback=%d\n", LoopPlayback); - fprintf(INIFile, "HD_Display=%d\n", HDDisplay); - for (i = 0; i < 4; i++) - { - fprintf(INIFile, "MRUList[%d]=%s\n", i, mMRUList[i]); - } - fprintf(INIFile, "Enable_Info_Log=%d\n", InfoLog_Flag); - fprintf(INIFile, "BMP_Path=%s\n", BMPPathString); - fprintf(INIFile, "Use_MPA_Extensions=%d\n", UseMPAExtensions); - fprintf(INIFile, "Notify_When_Done=%d\n", NotifyWhenDone); - fprintf(INIFile, "TS_Parse_Margin=%d\n", TsParseMargin); - fprintf(INIFile, "CorrectFieldOrderTrans=%d\n", CorrectFieldOrderTrans); - fclose(INIFile); - } - - while (NumLoadedFiles) - { - NumLoadedFiles--; - _close(Infile[NumLoadedFiles]); - Infile[NumLoadedFiles] = NULL; - } - - Recovery(); - - for (i=0; i<8; i++) - _aligned_free(block[i]); - - for (i=0; i rect.right) - { - right = rect.right; - } - right = left + 2; - SelectObject(hdc, hLine); - SelectObject(hdc, hPenLine); - Rectangle(hdc, left, 0, (int) right, TRACK_HEIGHT/3); - DeleteObject(hPenBrush); - DeleteObject(hBrush); - DeleteObject(hPenLine); - DeleteObject(hLine); - EndPaint(hwnd, &ps); - break; - } - return DefWindowProc(hwnd, msg, wParam, lParam); -} - -LRESULT CALLBACK DetectPids(HWND hDialog, UINT message, WPARAM wParam, LPARAM lParam) -{ - char msg[255]; - static void *lang = NULL; - - switch (message) - { - case WM_INITDIALOG: - if (SystemStream_Flag != TRANSPORT_STREAM) - { - sprintf(msg, "Not a transport stream!"); - SendDlgItemMessage(hDialog, IDC_PID_LISTBOX, LB_ADDSTRING, 0, (LPARAM)msg); - } - else if (Pid_Detect_Method == PID_DETECT_RAW) - { - pat_parser.DumpRaw(hDialog, Infilename[0]); - } - else if (Pid_Detect_Method == PID_DETECT_PSIP && pat_parser.DumpPSIP(hDialog, Infilename[0]) == 1) - { - sprintf(msg, "Could not find PSIP tables!"); - SendDlgItemMessage(hDialog, IDC_PID_LISTBOX, LB_ADDSTRING, 0, (LPARAM)msg); - } - else if (Pid_Detect_Method == PID_DETECT_PATPMT && pat_parser.DumpPAT(hDialog, Infilename[0]) == 1) - { - sprintf(msg, "Could not find PAT/PMT tables!"); - SendDlgItemMessage(hDialog, IDC_PID_LISTBOX, LB_ADDSTRING, 0, (LPARAM)msg); - } - { - char pid_string[16]; - if (MPEG2_Transport_VideoPID != 2) - { - sprintf(pid_string, "0x%X", MPEG2_Transport_VideoPID); - SetDlgItemText(hDialog, IDC_SELECT_VIDEO_PID, pid_string); - } - if (MPEG2_Transport_AudioPID != 2) - { - sprintf(pid_string, "0x%X", MPEG2_Transport_AudioPID); - SetDlgItemText(hDialog, IDC_SELECT_AUDIO_PID, pid_string); - } - if (MPEG2_Transport_PCRPID != 2) - { - sprintf(pid_string, "0x%X", MPEG2_Transport_PCRPID); - SetDlgItemText(hDialog, IDC_SELECT_PCR_PID, pid_string); - } - } - lang = LoadDialogLanguageSettings(hDialog, DIALOG_DETECT_PIDS); - return true; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - int item; - char text[80], *ptr; - - case IDC_SET_AUDIO: - case IDC_SET_VIDEO: - case IDC_SET_PCR: - item = SendDlgItemMessage(hDialog, IDC_PID_LISTBOX, (UINT) LB_GETCURSEL, 0, 0); - if (item != LB_ERR) - { - SendDlgItemMessage(hDialog, IDC_PID_LISTBOX, (UINT) LB_GETTEXT, item, (LPARAM) text); - if ((ptr = strstr(text, "0x")) != NULL) - { - int id = -1; - int pid = 2; - if (LOWORD(wParam) == IDC_SET_AUDIO) - { - if (sscanf(ptr, "%x", &MPEG2_Transport_AudioPID) == 1) - { - pid = MPEG2_Transport_AudioPID; - id = IDC_SELECT_AUDIO_PID; - } - } - else if (LOWORD(wParam) == IDC_SET_VIDEO) - { - if (sscanf(ptr, "%x", &MPEG2_Transport_VideoPID) == 1) - { - pid = MPEG2_Transport_VideoPID; - id = IDC_SELECT_VIDEO_PID; - } - } - else - { - if (sscanf(ptr, "%x", &MPEG2_Transport_PCRPID) == 1) - { - pid = MPEG2_Transport_PCRPID; - id = IDC_SELECT_PCR_PID; - } - } - if (pid != 2) - { - char pid_string[16]; - sprintf(pid_string, "0x%X", pid); - SetDlgItemText(hDialog, id, pid_string); - } - } - } - if (LOWORD(wParam) == IDC_SET_AUDIO || LOWORD(wParam) == IDC_SET_PCR) break; - Recovery(); - if (NumLoadedFiles) - { - FileLoadedEnables(); - process.rightfile = NumLoadedFiles-1; - process.rightlba = (int)(Infilelength[NumLoadedFiles-1]/SECTOR_SIZE); - - process.end = Infiletotal - SECTOR_SIZE; - process.endfile = NumLoadedFiles - 1; - process.endloc = (Infilelength[NumLoadedFiles-1]/SECTOR_SIZE - 1)*SECTOR_SIZE; - - process.locate = LOCATE_INIT; - - if (!threadId || WaitForSingleObject(hThread, INFINITE)==WAIT_OBJECT_0) - hThread = CreateThread(NULL, 0, MPEG2Dec, 0, 0, &threadId); - } - break; - - case IDC_SET_DONE: - case IDCANCEL: - EndDialog(hDialog, 0); - DestroyDialogLanguageSettings(lang); - } - return true; - } - return false; -} - -LRESULT CALLBACK VideoList(HWND hVideoListDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - int i, j; - char updown[DG_MAX_PATH]; - char *name; - int handle; - static void *lang = NULL; - - switch (message) - { - case WM_INITDIALOG: - HadAddDialog = 0; - SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_SETHORIZONTALEXTENT, (WPARAM) 1024, 0); - if (NumLoadedFiles) - for (i=0; i 0) - { - name = Infilename[i]; - Infilename[i] = Infilename[i-1]; - Infilename[i-1] = name; - handle = Infile[i]; - Infile[i] = Infile[i-1]; - Infile[i-1] = handle; - SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_GETTEXT, i - 1, (LPARAM) updown); - SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_DELETESTRING, i - 1, 0); - SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_INSERTSTRING, i, (LPARAM) updown); - SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_SETCURSEL, i - 1, 0); - } - break; - - case ID_DOWN: - i = SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_GETCURSEL, 0, 0); - j = SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_GETCOUNT, 0, 0); - if (i < j - 1) - { - name = Infilename[i]; - Infilename[i] = Infilename[i+1]; - Infilename[i+1] = name; - handle = Infile[i]; - Infile[i] = Infile[i+1]; - Infile[i+1] = handle; - SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_GETTEXT, i, (LPARAM) updown); - SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_DELETESTRING, i, 0); - SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_INSERTSTRING, i + 1, (LPARAM) updown); - SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_SETCURSEL, i + 1, 0); - } - break; - - case ID_DEL: - if (NumLoadedFiles) - { - if (threadId) - { - Stop_Flag = true; - if (WaitForSingleObject(hThread, stopWaitTime) != WAIT_OBJECT_0) - exit(EXIT_FAILURE); - } - i= SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_GETCURSEL, 0, 0); - SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_DELETESTRING, i, 0); - NumLoadedFiles--; - _close(Infile[i]); - Infile[i] = NULL; - for (j=i; j=NumLoadedFiles ? NumLoadedFiles-1 : i, 0); - } - if (!NumLoadedFiles) - { - Recovery(); - MPEG2_Transport_VideoPID = 2; - MPEG2_Transport_AudioPID = 2; - MPEG2_Transport_PCRPID = 2; - } - break; - - case ID_DELALL: - if (threadId) - { - Stop_Flag = true; - if (WaitForSingleObject(hThread, stopWaitTime) != WAIT_OBJECT_0) - exit(EXIT_FAILURE); - } - while (NumLoadedFiles) - { - NumLoadedFiles--; - i= SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_GETCURSEL, 0, 0); - SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_DELETESTRING, i, 0); - _close(Infile[i]); - Infile[i] = NULL; - SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_SETCURSEL, i>=NumLoadedFiles ? NumLoadedFiles-1 : i, 0); - } - Recovery(); - break; - - case IDOK: - case IDCANCEL: - EndDialog(hVideoListDlg, 0); - DestroyDialogLanguageSettings(lang); - if (threadId) - { - Stop_Flag = true; - if (WaitForSingleObject(hThread, stopWaitTime) != WAIT_OBJECT_0) - exit(EXIT_FAILURE); - } - Recovery(); - MPEG2_Transport_VideoPID = 2; - MPEG2_Transport_AudioPID = 2; - MPEG2_Transport_PCRPID = 2; - - if (!HadAddDialog) - { - for (i = 0; i < NumLoadedFiles; i++) - { - if (Infile[i] != NULL) - _close(Infile[i]); - Infile[i] = _open(Infilename[i], _O_RDONLY | _O_BINARY | _O_SEQUENTIAL); - } - } - if (NumLoadedFiles) - { - FileLoadedEnables(); - process.rightfile = NumLoadedFiles-1; - process.rightlba = (int)(Infilelength[NumLoadedFiles-1]/SECTOR_SIZE); - - process.end = Infiletotal - SECTOR_SIZE; - process.endfile = NumLoadedFiles - 1; - process.endloc = (Infilelength[NumLoadedFiles-1]/SECTOR_SIZE - 1)*SECTOR_SIZE; - - process.locate = LOCATE_INIT; - - if (!threadId || WaitForSingleObject(hThread, INFINITE)==WAIT_OBJECT_0) - hThread = CreateThread(NULL, 0, MPEG2Dec, 0, 0, &threadId); - } - else - { - StartupEnables(); - } - return true; - } - break; - } - return false; -} - -static void OpenVideoFile(HWND hVideoListDlg) -{ - if (PopFileDlg(szInput, hVideoListDlg, OPEN_VOB)) - { - char *p; - char path[DG_MAX_PATH]; - char filename[DG_MAX_PATH]; - char curPath[DG_MAX_PATH]; - struct _finddata_t seqfile; - int i, j, n; - char *tmp; - - SystemStream_Flag = ELEMENTARY_STREAM; - _getcwd(curPath, DG_MAX_PATH); - if (strlen(curPath) != strlen(szInput)) - { - // Only one file specified. - if (strchr(szInput, '?') != NULL) // Exclude the filename that contains Unicode. - return; - if (_findfirst(szInput, &seqfile) == -1L) return; - SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_ADDSTRING, 0, (LPARAM) szInput); - strcpy(Infilename[NumLoadedFiles], szInput); - Infile[NumLoadedFiles] = _open(szInput, _O_RDONLY | _O_BINARY | _O_SEQUENTIAL); - NumLoadedFiles++; - // Set the output directory for a Save D2V operation to the - // same path as this input files. - p = _tcsrchr(szInput, '\\'); - if( p ) - { - size_t num = (size_t)(p - szInput) + 1; - strncpy(szSave, szInput, num); - szSave[num] = 0; - } - else - szSave[0] = 0; - return; - } - // Multi-select handling. - // First clear existing file list box. - n = NumLoadedFiles; - while (n) - { - n--; - i = SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_GETCURSEL, 0, 0); - SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_DELETESTRING, i, 0); - SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_SETCURSEL, i >= n ? n - 1 : i, 0); - } - // Save the path prefix (path without the filename). - strcpy(path, szInput); - // Also set that path as the default for a Save D2V operation. - strcpy(szSave, szInput); - // Add a trailing backslash if needed. - p = szInput; - while (*p != 0) p++; - p--; - if (*p != '\\') - strcat(path, "\\"); - // Skip the path prefix. - p = szInput; - while (*p++ != 0); - // Load the filenames. - for (;;) - { - // Build full path plus filename. - strcpy(filename, path); - strcat(filename, p); - if (strchr(filename, '?') != NULL) // Exclude the filename that contains Unicode. - goto next_filename; - if (_findfirst(filename, &seqfile) == -1L) break; - strcpy(Infilename[NumLoadedFiles], filename); - NumLoadedFiles++; -next_filename: - // Skip to next filename. - while (*p++ != 0); - // A double zero is the end of the file list. - if (*p == 0) break; - } - // Sort the filenames. - // This is a special sort designed to do things intelligently - // for typical sequentially numbered filenames. - // Sorry, just a bubble sort. No need for performance here. KISS. - n = NumLoadedFiles; - for (i = 0; i < n - 1; i++) - { - for (j = 0; j < n - 1 - i; j++) - { - if (strverscmp(Infilename[j+1], Infilename[j]) < 0) - { - tmp = Infilename[j]; - Infilename[j] = Infilename[j+1]; - Infilename[j+1] = tmp; - } - } - } - // Load up the file open dialog list box and open the files. - for (i = 0; i < NumLoadedFiles; i++) - { - SendDlgItemMessage(hVideoListDlg, IDC_LIST, LB_ADDSTRING, 0, (LPARAM) Infilename[i]); - if (Infile[i] == NULL) - Infile[i] = _open(Infilename[i], _O_RDONLY | _O_BINARY | _O_SEQUENTIAL); - } - HadAddDialog = 1; - } -} - -void ThreadKill(int mode) -{ - int i; - double film_percent; - - // Get rid of the % completion string in the window title. - remain = 0; - UpdateWindowText(THREAD_KILL); - - // Close the quants log if necessary. - if (Quants) - fclose(Quants); - - for (i = 0; i < 0xc8; i++) - { - if ((D2V_Flag || AudioOnly_Flag) && - ((audio[i].rip && audio[i].type == FORMAT_AC3 && Method_Flag==AUDIO_DECODE) - || (audio[i].rip && audio[i].type == FORMAT_LPCM))) - { - if (SRC_Flag) - { - EndSRC(audio[i].file); - audio[i].size = ((int)(0.91875*audio[i].size)>>2)<<2; - } - - Normalize(NULL, 44, audio[i].filename, audio[i].file, 44, audio[i].size); - CloseWAV(audio[i].file, audio[i].size); - } - } - - if (AudioOnly_Flag) - { - _fcloseall(); - FileLoadedEnables(); -// SendMessage(hTrack, TBM_SETSEL, (WPARAM) true, (LPARAM) MAKELONG(process.trackleft, process.trackright)); - if (NotifyWhenDone & 1) - SetForegroundWindow(hWnd); - if (NotifyWhenDone & 2) - MessageBeep(MB_OK); - SetDlgItemText(hDlg, IDC_REMAIN, "FINISH"); - AudioOnly_Flag = false; - ExitThread(0); - } - - if (process.locate==LOCATE_INIT || process.locate==LOCATE_RIP) - { - if (D2V_Flag) - { - // Revised by Donald Graft to support IBBPIBBP... - WriteD2VLine(1); - fprintf(D2VFile, "\nFINISHED"); - // Prevent divide by 0. - if (FILM_Purity+VIDEO_Purity == 0) VIDEO_Purity = 1; - film_percent = (FILM_Purity*100.0)/(FILM_Purity+VIDEO_Purity); - if (film_percent >= 50.0) - fprintf(D2VFile, " %.2f%% FILM\n", film_percent); - else - fprintf(D2VFile, " %.2f%% VIDEO\n", 100.0 - film_percent); - } - - if (MuxFile > 0 && MuxFile != (FILE *) 0xffffffff) - { - void StopVideoDemux(void); - - StopVideoDemux(); - } - - _fcloseall(); - - if (D2V_Flag) - { - if (fix_d2v(hWnd, D2VFilePath, 1)) - { - // User wants to correct the field order transition. - fix_d2v(hWnd, D2VFilePath, 0); - } - } - - if (Decision_Flag) - { - if (Sound_Max > 1) - { - PreScale_Ratio = 327.68 * Norm_Ratio / Sound_Max; - - if (PreScale_Ratio > 1.0 && PreScale_Ratio < 1.01) - PreScale_Ratio = 1.0; - - sprintf(szBuffer, "%.2f", PreScale_Ratio); - SetDlgItemText(hDlg, IDC_INFO, szBuffer); - - CheckMenuItem(hMenu, IDM_PRESCALE, MF_CHECKED); - CheckMenuItem(hMenu, IDM_NORM, MF_UNCHECKED); - Norm_Flag = false; - } - else - { - SetDlgItemText(hDlg, IDC_INFO, "n/a"); - CheckMenuItem(hMenu, IDM_PRESCALE, MF_UNCHECKED); - } - } - - FileLoadedEnables(); -// SendMessage(hTrack, TBM_SETSEL, (WPARAM) true, (LPARAM) MAKELONG(process.trackleft, process.trackright)); - } - - if (process.locate == LOCATE_RIP) - { - if (NotifyWhenDone & 1) - SetForegroundWindow(hWnd); - if (NotifyWhenDone & 2) - MessageBeep(MB_OK); - SetDlgItemText(hDlg, IDC_REMAIN, "FINISH"); - if (D2V_Flag) - SendMessage(hWnd, D2V_DONE_MESSAGE, 0, 0); - } - if (LoopPlayback && mode == END_OF_DATA_KILL && process.locate == LOCATE_RIP && !D2V_Flag) - { - PostMessage(hWnd, WM_COMMAND, MAKEWPARAM(IDM_PREVIEW_NO_INFO, 0), (LPARAM) 0); - ExitThread(0); - } - - if (process.locate==LOCATE_INIT || process.locate==LOCATE_RIP) - { - D2V_Flag = false; - Decision_Flag = false; - Display_Flag = false; - } - // This restores the normal operation of the right arrow button - // if we were in single-step playback. - process.locate = LOCATE_INIT; - - if (CLIActive) - { - SendMessage(hWnd, CLI_RIP_MESSAGE, 0, 0); - } - - ExitThread(0); -} - -LRESULT CALLBACK Info(HWND hInfoDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - static void *lang = NULL; - switch (message) - { - case WM_INITDIALOG: - lang = LoadDialogLanguageSettings(hInfoDlg, DIALOG_INFORMATION); - return true; - - case WM_MOVE: - GetWindowRect(hInfoDlg, &info_wrect); - break; - - case WM_COMMAND: - if (LOWORD(wParam)==IDCANCEL) - { - DestroyWindow(hInfoDlg); - Info_Flag = false; - return true; - } - case WM_DESTROY: - { - char logfile[DG_MAX_PATH], *p; - FILE *lfp; - int i, count; - - if (InfoLog_Flag) - { - strcpy(logfile, Infilename[0]); - p = strrchr(logfile, '.'); - strcpy(++p, "log"); - if (lfp = fopen(logfile, "w")) - { - GetDlgItemText(hDlg, IDC_STREAM_TYPE, logfile, 255); - fprintf(lfp, "Stream Type: %s\n", logfile); - GetDlgItemText(hDlg, IDC_PROFILE, logfile, 255); - fprintf(lfp, "Profile: %s\n", logfile); - GetDlgItemText(hDlg, IDC_FRAME_SIZE, logfile, 255); - fprintf(lfp, "Frame Size: %s\n", logfile); - GetDlgItemText(hDlg, IDC_DISPLAY_SIZE, logfile, 255); - fprintf(lfp, "Display Size: %s\n", logfile); - GetDlgItemText(hDlg, IDC_ASPECT_RATIO, logfile, 255); - fprintf(lfp, "Aspect Ratio: %s\n", logfile); - GetDlgItemText(hDlg, IDC_FRAME_RATE, logfile, 255); - fprintf(lfp, "Frame Rate: %s\n", logfile); - GetDlgItemText(hDlg, IDC_VIDEO_TYPE, logfile, 255); - fprintf(lfp, "Video Type: %s\n", logfile); - GetDlgItemText(hDlg, IDC_FRAME_TYPE, logfile, 255); - fprintf(lfp, "Frame Type: %s\n", logfile); - GetDlgItemText(hDlg, IDC_CODING_TYPE, logfile, 255); - fprintf(lfp, "Coding Type: %s\n", logfile); - GetDlgItemText(hDlg, IDC_COLORIMETRY, logfile, 255); - fprintf(lfp, "Colorimetry: %s\n", logfile); - GetDlgItemText(hDlg, IDC_FRAME_STRUCTURE, logfile, 255); - fprintf(lfp, "Frame Structure: %s\n", logfile); - GetDlgItemText(hDlg, IDC_FIELD_ORDER, logfile, 255); - fprintf(lfp, "Field Order: %s\n", logfile); - GetDlgItemText(hDlg, IDC_CODED_NUMBER, logfile, 255); - fprintf(lfp, "Coded Number: %s\n", logfile); - GetDlgItemText(hDlg, IDC_PLAYBACK_NUMBER, logfile, 255); - fprintf(lfp, "Playback Number: %s\n", logfile); - GetDlgItemText(hDlg, IDC_FRAME_REPEATS, logfile, 255); - fprintf(lfp, "Frame Repeats: %s\n", logfile); - GetDlgItemText(hDlg, IDC_FIELD_REPEATS, logfile, 255); - fprintf(lfp, "Field Repeats: %s\n", logfile); - GetDlgItemText(hDlg, IDC_VOB_ID, logfile, 255); - fprintf(lfp, "VOB ID: %s\n", logfile); - GetDlgItemText(hDlg, IDC_CELL_ID, logfile, 255); - fprintf(lfp, "Cell ID: %s\n", logfile); - GetDlgItemText(hDlg, IDC_BITRATE, logfile, 255); - fprintf(lfp, "Bitrate: %s\n", logfile); - GetDlgItemText(hDlg, IDC_BITRATE_AVG, logfile, 255); - fprintf(lfp, "Bitrate (Avg): %s\n", logfile); - GetDlgItemText(hDlg, IDC_BITRATE_MAX, logfile, 255); - fprintf(lfp, "Bitrate (Max): %s\n", logfile); - if ((count = SendDlgItemMessage(hDlg, IDC_AUDIO_LIST, LB_GETCOUNT, 0, 0)) != LB_ERR) - { - for (i = 0; i < count; i++) - { - SendDlgItemMessage(hDlg, IDC_AUDIO_LIST, LB_GETTEXT, i, (LPARAM)logfile); - fprintf(lfp, "Audio Stream: %s\n", logfile); - } - } - GetDlgItemText(hDlg, IDC_TIMESTAMP, logfile, 255); - fprintf(lfp, "Timestamp: %s\n", logfile); - GetDlgItemText(hDlg, IDC_ELAPSED, logfile, 255); - fprintf(lfp, "Elapsed: %s\n", logfile); - GetDlgItemText(hDlg, IDC_REMAIN, logfile, 255); - fprintf(lfp, "Remain: %s\n", logfile); - GetDlgItemText(hDlg, IDC_FPS, logfile, 255); - fprintf(lfp, "FPS: %s\n", logfile); - GetDlgItemText(hDlg, IDC_INFO, logfile, 255); - fprintf(lfp, "Info: %s\n", logfile); - fclose(lfp); - } - } - DestroyDialogLanguageSettings(lang); - } - break; - } - return false; -} - -LRESULT CALLBACK About(HWND hAboutDlg, UINT message, WPARAM wParam, LPARAM lParam) -{ - static void *lang = NULL; - switch (message) - { - case WM_INITDIALOG: - sprintf(szBuffer, "%s", Version); - SetDlgItemText(hAboutDlg, IDC_VERSION, szBuffer); - lang = LoadDialogLanguageSettings(hAboutDlg, DIALOG_ABOUT); - return true; - - case WM_COMMAND: - if (LOWORD(wParam)==IDOK || LOWORD(wParam)==IDCANCEL) - { - EndDialog(hAboutDlg, 0); - DestroyDialogLanguageSettings(lang); - return true; - } - } - return false; -} - -LRESULT CALLBACK Cropping(HWND hDialog, UINT message, WPARAM wParam, LPARAM lParam) -{ - int i; - static void *lang = NULL; - - switch (message) - { - case WM_INITDIALOG: - SendDlgItemMessage(hDialog, IDC_LEFT_SLIDER, TBM_SETRANGE, 0, MAKELPARAM(0, 256)); - SendDlgItemMessage(hDialog, IDC_LEFT_SLIDER, TBM_SETPOS, 1, Clip_Left/4); - SetDlgItemInt(hDialog, IDC_LEFT, Clip_Left, 0); - - SendDlgItemMessage(hDialog, IDC_RIGHT_SLIDER, TBM_SETRANGE, 0, MAKELPARAM(0, 256)); - SendDlgItemMessage(hDialog, IDC_RIGHT_SLIDER, TBM_SETPOS, 1, Clip_Right/4); - SetDlgItemInt(hDialog, IDC_RIGHT, Clip_Right, 0); - - SendDlgItemMessage(hDialog, IDC_TOP_SLIDER, TBM_SETRANGE, 0, MAKELPARAM(0, 256)); - SendDlgItemMessage(hDialog, IDC_TOP_SLIDER, TBM_SETPOS, 1, Clip_Top/4); - SetDlgItemInt(hDialog, IDC_TOP, Clip_Top, 0); - - SendDlgItemMessage(hDialog, IDC_BOTTOM_SLIDER, TBM_SETRANGE, 0, MAKELPARAM(0, 256)); - SendDlgItemMessage(hDialog, IDC_BOTTOM_SLIDER, TBM_SETPOS, 1, Clip_Bottom/4); - SetDlgItemInt(hDialog, IDC_BOTTOM, Clip_Bottom, 0); - - SetDlgItemInt(hDialog, IDC_WIDTH, horizontal_size-Clip_Left-Clip_Right, 0); - SetDlgItemInt(hDialog, IDC_HEIGHT, vertical_size-Clip_Top-Clip_Bottom, 0); - - lang = LoadDialogLanguageSettings(hDialog, DIALOG_CROPPING); - ShowWindow(hDialog, SW_SHOW); - - if (Cropping_Flag) - SendDlgItemMessage(hDialog, IDC_CROPPING_CHECK, BM_SETCHECK, BST_CHECKED, 0); - return true; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDC_CROPPING_CHECK: - if (SendDlgItemMessage(hDialog, IDC_CROPPING_CHECK, BM_GETCHECK, 1, 0)==BST_CHECKED) - { - CheckMenuItem(hMenu, IDM_CROPPING, MF_CHECKED); - Cropping_Flag = true; - } - else - { - CheckMenuItem(hMenu, IDM_CROPPING, MF_UNCHECKED); - Cropping_Flag = false; - } - - RefreshWindow(true); - ShowInfo(false); - break; - - case IDCANCEL: - EndDialog(hDialog, 0); - DestroyDialogLanguageSettings(lang); - return true; - } - break; - - case WM_HSCROLL: - switch (GetWindowLong((HWND)lParam, GWL_ID)) - { - case IDC_LEFT_SLIDER: - i = SendDlgItemMessage(hDialog, IDC_LEFT_SLIDER, TBM_GETPOS, 0, 0)*4; - if (i+Clip_Right+MIN_WIDTH <= horizontal_size) - Clip_Left = i; - else - Clip_Left = horizontal_size - (Clip_Right+MIN_WIDTH); - SetDlgItemInt(hDialog, IDC_LEFT, Clip_Left, 0); - SetDlgItemInt(hDialog, IDC_WIDTH, horizontal_size-Clip_Left-Clip_Right, 0); - break; - - case IDC_RIGHT_SLIDER: - i = SendDlgItemMessage(hDialog, IDC_RIGHT_SLIDER, TBM_GETPOS, 0, 0)*4; - if (i+Clip_Left+MIN_WIDTH <= horizontal_size) - Clip_Right = i; - else - Clip_Right = horizontal_size - (Clip_Left+MIN_WIDTH); - SetDlgItemInt(hDialog, IDC_RIGHT, Clip_Right, 0); - SetDlgItemInt(hDialog, IDC_WIDTH, horizontal_size-Clip_Left-Clip_Right, 0); - break; - - case IDC_TOP_SLIDER: - i = SendDlgItemMessage(hDialog, IDC_TOP_SLIDER, TBM_GETPOS, 0, 0)*4; - if (i+Clip_Bottom+MIN_HEIGHT <= vertical_size) - Clip_Top = i; - else - Clip_Top = vertical_size - (Clip_Bottom+MIN_HEIGHT); - SetDlgItemInt(hDialog, IDC_TOP, Clip_Top, 0); - SetDlgItemInt(hDialog, IDC_HEIGHT, vertical_size-Clip_Top-Clip_Bottom, 0); - break; - - case IDC_BOTTOM_SLIDER: - i = SendDlgItemMessage(hDialog, IDC_BOTTOM_SLIDER, TBM_GETPOS, 0, 0)*4; - if (i+Clip_Top+MIN_HEIGHT <= vertical_size) - Clip_Bottom = i; - else - Clip_Bottom = vertical_size - (Clip_Top+MIN_HEIGHT); - SetDlgItemInt(hDialog, IDC_BOTTOM, Clip_Bottom, 0); - SetDlgItemInt(hDialog, IDC_HEIGHT, vertical_size-Clip_Top-Clip_Bottom, 0); - break; - } - - RefreshWindow(true); - ShowInfo(false); - break; - } - return false; -} - -LRESULT CALLBACK Luminance(HWND hDialog, UINT message, WPARAM wParam, LPARAM lParam) -{ - static void *lang = NULL; - switch (message) - { - case WM_INITDIALOG: - SendDlgItemMessage(hDialog, IDC_GAMMA_SPIN, UDM_SETRANGE, 0, MAKELPARAM(511, 1)); - SendDlgItemMessage(hDialog, IDC_GAMMA_SPIN, UDM_SETPOS, 1, LumGamma + 256); - sprintf(szTemp, "%d", LumGamma); - SetDlgItemText(hDialog, IDC_GAMMA_BOX, szTemp); - - SendDlgItemMessage(hDialog, IDC_OFFSET_SPIN, UDM_SETRANGE, 0, MAKELPARAM(511, 1)); - SendDlgItemMessage(hDialog, IDC_OFFSET_SPIN, UDM_SETPOS, 1, LumOffset + 256); - sprintf(szTemp, "%d", LumOffset); - SetDlgItemText(hDialog, IDC_OFFSET_BOX, szTemp); - - lang = LoadDialogLanguageSettings(hDialog, DIALOG_LUMINANCE); - ShowWindow(hDialog, SW_SHOW); - - if (Luminance_Flag) - SendDlgItemMessage(hDialog, IDC_LUM_CHECK, BM_SETCHECK, BST_CHECKED, 0); - return true; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDC_LUM_CHECK: - if (SendDlgItemMessage(hDialog, IDC_LUM_CHECK, BM_GETCHECK, 1, 0)==BST_CHECKED) - { - CheckMenuItem(hMenu, IDM_LUMINANCE, MF_CHECKED); - Luminance_Flag = true; - } - else - { - CheckMenuItem(hMenu, IDM_LUMINANCE, MF_UNCHECKED); - Luminance_Flag = false; - } - - RefreshWindow(true); - break; - - case IDCANCEL: - EndDialog(hDialog, 0); - DestroyDialogLanguageSettings(lang); - return true; - } - break; - - case WM_VSCROLL: - switch (GetWindowLong((HWND)lParam, GWL_ID)) - { - case IDC_GAMMA_SPIN: - LumGamma = LOWORD(SendDlgItemMessage(hDialog, IDC_GAMMA_SPIN, UDM_GETPOS, 0,0)) - 256; - sprintf(szTemp, "%d", LumGamma); - SetDlgItemText(hDialog, IDC_GAMMA_BOX, szTemp); - break; - case IDC_OFFSET_SPIN: - LumOffset = LOWORD(SendDlgItemMessage(hDialog, IDC_OFFSET_SPIN, UDM_GETPOS, 0,0)) - 256; - sprintf(szTemp, "%d", LumOffset); - SetDlgItemText(hDialog, IDC_OFFSET_BOX, szTemp); - break; - } - - RefreshWindow(true); - break; - } - return false; -} - -LRESULT CALLBACK AVSTemplate(HWND hDialog, UINT message, WPARAM wParam, LPARAM lParam) -{ - static void *lang = NULL; - switch (message) - { - case WM_INITDIALOG: - sprintf(szTemp, "%s", AVSTemplatePath); - SetDlgItemText(hDialog, IDC_AVS_TEMPLATE, szTemp); - lang = LoadDialogLanguageSettings(hDialog, DIALOG_AVS_TEMPLATE); - ShowWindow(hDialog, SW_SHOW); - return true; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDC_NO_TEMPLATE: - AVSTemplatePath[0] = 0; - sprintf(szTemp, "%s", ""); - SetDlgItemText(hDialog, IDC_AVS_TEMPLATE, szTemp); - ShowWindow(hDialog, SW_SHOW); - EndDialog(hDialog, 0); - DestroyDialogLanguageSettings(lang); - return true; - case IDC_CHANGE_TEMPLATE: - if (PopFileDlg(AVSTemplatePath, hWnd, OPEN_AVS)) - { - sprintf(szTemp, "%s", AVSTemplatePath); - SetDlgItemText(hDialog, IDC_AVS_TEMPLATE, szTemp); - } - else - { - AVSTemplatePath[0] = 0; - sprintf(szTemp, "%s", ""); - SetDlgItemText(hDialog, IDC_AVS_TEMPLATE, szTemp); - } - ShowWindow(hDialog, SW_SHOW); - EndDialog(hDialog, 0); - DestroyDialogLanguageSettings(lang); - return true; - case IDC_KEEP_TEMPLATE: - case IDCANCEL: - EndDialog(hDialog, 0); - DestroyDialogLanguageSettings(lang); - return true; - } - break; - } - return false; -} - -LRESULT CALLBACK BMPPath(HWND hDialog, UINT message, WPARAM wParam, LPARAM lParam) -{ - static void *lang = NULL; - switch (message) - { - case WM_INITDIALOG: - sprintf(szTemp, "%s", BMPPathString); - SetDlgItemText(hDialog, IDC_BMP_PATH, szTemp); - lang = LoadDialogLanguageSettings(hDialog, DIALOG_BITMAP_PATH); - ShowWindow(hDialog, SW_SHOW); - return true; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDC_BMP_PATH_OK: - GetDlgItemText(hDialog, IDC_BMP_PATH, BMPPathString, DG_MAX_PATH - 1); - ShowWindow(hDialog, SW_SHOW); - EndDialog(hDialog, 0); - DestroyDialogLanguageSettings(lang); - return true; - case IDC_BMP_PATH_CANCEL: - case IDCANCEL: - EndDialog(hDialog, 0); - DestroyDialogLanguageSettings(lang); - return true; - } - break; - } - return false; -} - -LRESULT CALLBACK SetPids(HWND hDialog, UINT message, WPARAM wParam, LPARAM lParam) -{ - char buf[80]; - static void *lang = NULL; - - switch (message) - { - case WM_INITDIALOG: - sprintf(szTemp, "%x", MPEG2_Transport_VideoPID); - SetDlgItemText(hDialog, IDC_VIDEO_PID, szTemp); - sprintf(szTemp, "%x", MPEG2_Transport_AudioPID); - SetDlgItemText(hDialog, IDC_AUDIO_PID, szTemp); - sprintf(szTemp, "%x", MPEG2_Transport_PCRPID); - SetDlgItemText(hDialog, IDC_PCR_PID, szTemp); - lang = LoadDialogLanguageSettings(hDialog, DIALOG_SET_PIDS); - ShowWindow(hDialog, SW_SHOW); - return true; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDC_PIDS_OK: - GetDlgItemText(hDialog, IDC_VIDEO_PID, buf, 10); - sscanf(buf, "%x", &MPEG2_Transport_VideoPID); - GetDlgItemText(hDialog, IDC_AUDIO_PID, buf, 10); - sscanf(buf, "%x", &MPEG2_Transport_AudioPID); - GetDlgItemText(hDialog, IDC_PCR_PID, buf, 10); - sscanf(buf, "%x", &MPEG2_Transport_PCRPID); - EndDialog(hDialog, 0); - DestroyDialogLanguageSettings(lang); - Recovery(); - if (NumLoadedFiles) - { - FileLoadedEnables(); - process.rightfile = NumLoadedFiles-1; - process.rightlba = (int)(Infilelength[NumLoadedFiles-1]/SECTOR_SIZE); - - process.end = Infiletotal - SECTOR_SIZE; - process.endfile = NumLoadedFiles - 1; - process.endloc = (Infilelength[NumLoadedFiles-1]/SECTOR_SIZE - 1)*SECTOR_SIZE; - - process.locate = LOCATE_INIT; - - if (!threadId || WaitForSingleObject(hThread, INFINITE)==WAIT_OBJECT_0) - hThread = CreateThread(NULL, 0, MPEG2Dec, 0, 0, &threadId); - } - return true; - - case IDCANCEL: - case IDC_PIDS_CANCEL: - EndDialog(hDialog, 0); - DestroyDialogLanguageSettings(lang); - return true; - } - break; - } - return false; -} - -LRESULT CALLBACK SetMargin(HWND hDialog, UINT message, WPARAM wParam, LPARAM lParam) -{ - char buf[80]; - static void *lang = NULL; - - switch (message) - { - case WM_INITDIALOG: - sprintf(szTemp, "%d", TsParseMargin); - SetDlgItemText(hDialog, IDC_MARGIN, szTemp); - lang = LoadDialogLanguageSettings(hDialog, DIALOG_MARGIN); - ShowWindow(hDialog, SW_SHOW); - return true; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDC_MARGIN_OK: - GetDlgItemText(hDialog, IDC_MARGIN, buf, 10); - sscanf(buf, "%d", &TsParseMargin); - EndDialog(hDialog, 0); - DestroyDialogLanguageSettings(lang); - Recovery(); - MPEG2_Transport_VideoPID = MPEG2_Transport_AudioPID = MPEG2_Transport_PCRPID = 0x02; - if (NumLoadedFiles) - { - FileLoadedEnables(); - process.rightfile = NumLoadedFiles-1; - process.rightlba = (int)(Infilelength[NumLoadedFiles-1]/SECTOR_SIZE); - - process.end = Infiletotal - SECTOR_SIZE; - process.endfile = NumLoadedFiles - 1; - process.endloc = (Infilelength[NumLoadedFiles-1]/SECTOR_SIZE - 1)*SECTOR_SIZE; - - process.locate = LOCATE_INIT; - - if (!threadId || WaitForSingleObject(hThread, INFINITE)==WAIT_OBJECT_0) - hThread = CreateThread(NULL, 0, MPEG2Dec, 0, 0, &threadId); - } - return true; - - case IDCANCEL: - case IDC_MARGIN_CANCEL: - EndDialog(hDialog, 0); - DestroyDialogLanguageSettings(lang); - return true; - } - break; - } - return false; -} - -LRESULT CALLBACK Normalization(HWND hDialog, UINT message, WPARAM wParam, LPARAM lParam) -{ - static void *lang = NULL; - switch (message) - { - case WM_INITDIALOG: - SendDlgItemMessage(hDialog, IDC_NORM_SLIDER, TBM_SETRANGE, 0, MAKELPARAM(0, 100)); - SendDlgItemMessage(hDialog, IDC_NORM_SLIDER, TBM_SETTICFREQ, 50, 0); - SendDlgItemMessage(hDialog, IDC_NORM_SLIDER, TBM_SETPOS, 1, Norm_Ratio); - sprintf(szTemp, "%d", Norm_Ratio); - SetDlgItemText(hDialog, IDC_NORM, szTemp); - - lang = LoadDialogLanguageSettings(hDialog, DIALOG_NORMALIZE); - ShowWindow(hDialog, SW_SHOW); - - if (Norm_Flag) - SendDlgItemMessage(hDialog, IDC_NORM_CHECK, BM_SETCHECK, BST_CHECKED, 0); - return true; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDC_NORM_CHECK: - if (SendDlgItemMessage(hDialog, IDC_NORM_CHECK, BM_GETCHECK, 1, 0)==BST_CHECKED) - { - CheckMenuItem(hMenu, IDM_NORM, MF_CHECKED); - Norm_Flag = true; - } - else - { - CheckMenuItem(hMenu, IDM_NORM, MF_UNCHECKED); - Norm_Flag = false; - } - break; - - case IDCANCEL: - EndDialog(hDialog, 0); - DestroyDialogLanguageSettings(lang); - return true; - } - break; - - case WM_HSCROLL: - if (GetWindowLong((HWND)lParam, GWL_ID)==IDC_NORM_SLIDER) - { - Norm_Ratio = SendDlgItemMessage(hDialog, IDC_NORM_SLIDER, TBM_GETPOS, 0, 0); - sprintf(szTemp, "%d", Norm_Ratio); - SetDlgItemText(hDialog, IDC_NORM, szTemp); - } - break; - } - return false; -} - -LRESULT CALLBACK SelectTracks(HWND hDialog, UINT message, WPARAM wParam, LPARAM lParam) -{ - unsigned int i; - static char track_list[255]; - char *p; - unsigned int audio_id; - static void *lang = NULL; - - switch (message) - { - case WM_INITDIALOG: - SetDlgItemText(hDialog, IDC_TRACK_LIST, Track_List); - strcpy(track_list, Track_List); - for (i = 0; i < 0xc8; i++) - audio[i].selected_for_demux = false; - p = Track_List; - while ((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') || (*p >= 'A' && *p <= 'F')) - { - sscanf(p, "%x", &audio_id); - if (audio_id > 0xc7) - break; - audio[audio_id].selected_for_demux = true; - while (*p != ',' && *p != 0) p++; - if (*p == 0) - break; - p++; - } - lang = LoadDialogLanguageSettings(hDialog, DIALOG_SELECT_TRACKS); - ShowWindow(hDialog, SW_SHOW); - - return true; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDC_TRACK_OK: - GetDlgItemText(hDialog, IDC_TRACK_LIST, track_list, 255); - if (strcmp(Track_List, track_list)) - { - strcpy(Track_List, track_list); - for (i = 0; i < 0xc8; i++) - audio[i].selected_for_demux = false; - p = Track_List; - while ((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') || (*p >= 'A' && *p <= 'F')) - { - sscanf(p, "%x", &audio_id); - if (audio_id > 0xc7) - break; - audio[audio_id].selected_for_demux = true; - while (*p != ',' && *p != 0) p++; - if (*p == 0) - break; - p++; - } - CheckMenuItem(hMenu, IDM_PRESCALE, MF_UNCHECKED); - PreScale_Ratio = 1.0; - } - EndDialog(hDialog, 0); - DestroyDialogLanguageSettings(lang); - return false; - case IDCANCEL: - case IDC_TRACK_CANCEL: - EndDialog(hDialog, 0); - DestroyDialogLanguageSettings(lang); - return true; - } - break; - } - return false; -} - -LRESULT CALLBACK SelectDelayTrack(HWND hDialog, UINT message, WPARAM wParam, LPARAM lParam) -{ - static char delay_track[255]; - char *p; - unsigned int audio_id; - static void *lang = NULL; - - switch (message) - { - case WM_INITDIALOG: - SetDlgItemText(hDialog, IDC_DELAY_LIST, Delay_Track); - strcpy(delay_track, Delay_Track); - lang = LoadDialogLanguageSettings(hDialog, DIALOG_DELAY_TRACK); - ShowWindow(hDialog, SW_SHOW); - return true; - - case WM_COMMAND: - switch (LOWORD(wParam)) - { - case IDC_DELAY_OK: - GetDlgItemText(hDialog, IDC_DELAY_LIST, delay_track, 255); - strcpy(Delay_Track, delay_track); - p = delay_track; - sscanf(p, "%x", &audio_id); - if (PopFileDlg(szInput, hWnd, OPEN_TXT)) - { - if (analyze_sync(hWnd, szInput, audio_id)) - { - ShellExecute(hDlg, "open", szInput, NULL, NULL, SW_SHOWNORMAL); - } - } - EndDialog(hDialog, 0); - DestroyDialogLanguageSettings(lang); - return false; - case IDCANCEL: - case IDC_DELAY_CANCEL: - EndDialog(hDialog, 0); - DestroyDialogLanguageSettings(lang); - return true; - } - break; - } - return false; -} - -/* register the window class */ -ATOM MyRegisterClass(HINSTANCE hInstance) -{ - WNDCLASSEX wcex; - - wcex.cbSize = sizeof(WNDCLASSEX); - wcex.style = CS_HREDRAW | CS_VREDRAW; - wcex.lpfnWndProc = (WNDPROC)WndProc; - wcex.cbClsExtra = false; - wcex.cbWndExtra = false; - wcex.hInstance = hInstance; - wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_MOVIE); - wcex.hCursor = LoadCursor(NULL, IDC_ARROW); - wcex.hbrBackground = CreateSolidBrush(MASKCOLOR); - - wcex.lpszMenuName = (LPCSTR)IDC_GUI; - wcex.lpszMenuName = (LPCSTR)IDC_GUI; - wcex.lpszClassName = szWindowClass; - wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); - - return RegisterClassEx(&wcex); -} - -bool PopFileDlg(PTSTR pstrFileName, HWND hOwner, int Status) -{ - static OPENFILENAME ofn; - static char *szFilter, *ext; - - switch (Status) - { - case OPEN_VOB: - ofn.nFilterIndex = 4; - szFilter = \ - TEXT ("vob\0*.vob\0") \ - TEXT ("mpg, mpeg, m1v, m2v, mpv\0*.mpg;*.mpeg;*.m1v;*.m2v;*.mpv\0") \ - TEXT ("tp, ts, trp, m2t, m2ts, pva, vro\0*.tp;*.ts;*.trp;*.m2t;*.m2ts;*.pva;*.vro\0") \ - TEXT ("All MPEG Files\0*.vob;*.mpg;*.mpeg;*.m1v;*.m2v;*.mpv;*.tp;*.ts;*.trp;*.m2t;*.m2ts;*.pva;*.vro\0") \ - TEXT ("All Files (*.*)\0*.*\0"); - break; - - case OPEN_D2V: - szFilter = TEXT ("DGIndex Project File (*.d2v)\0*.d2v\0") \ - TEXT ("All Files (*.*)\0*.*\0"); - break; - - case OPEN_TXT: - szFilter = TEXT ("DGIndex Timestamps File (*.txt)\0*.txt\0") \ - TEXT ("All Files (*.*)\0*.*\0"); - break; - - case OPEN_AVS: - szFilter = TEXT ("AVS File (*.avs)\0*.avs\0") \ - TEXT ("All Files (*.*)\0*.*\0"); - break; - - case SAVE_D2V: - szFilter = TEXT ("DGIndex Project File (*.d2v)\0*.d2v\0") \ - TEXT ("All Files (*.*)\0*.*\0"); - break; - - case SAVE_BMP: - szFilter = TEXT ("BMP File (*.bmp)\0*.bmp\0") \ - TEXT ("All Files (*.*)\0*.*\0"); - break; - - case OPEN_WAV: - case SAVE_WAV: - szFilter = TEXT ("WAV File (*.wav)\0*.wav\0") \ - TEXT ("All Files (*.*)\0*.*\0"); - break; - } - - ofn.lStructSize = sizeof (OPENFILENAME) ; - ofn.hwndOwner = hOwner ; - ofn.hInstance = hInst ; - ofn.lpstrFilter = szFilter ; - ofn.nMaxFile = MAX_FILE_NUMBER * DG_MAX_PATH - 1 ; - ofn.lpstrFileTitle = 0 ; - ofn.lpstrFile = pstrFileName ; - ofn.lpstrInitialDir = szSave; - - switch (Status) - { - case OPEN_VOB: - case OPEN_D2V: - case OPEN_WAV: - crop1088_warned = false; - *ofn.lpstrFile = 0; - ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER; - return GetOpenFileName(&ofn); - - case OPEN_AVS: - case OPEN_TXT: - *ofn.lpstrFile = 0; - ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER; - return GetOpenFileName(&ofn); - - case SAVE_BMP: - *ofn.lpstrFile = 0; - ofn.lpstrInitialDir = BMPPathString; - ofn.Flags = OFN_HIDEREADONLY | OFN_EXPLORER; - if (GetSaveFileName(&ofn)) - { - ext = strrchr(pstrFileName, '.'); - if (ext!=NULL && !_strnicmp(ext, ".bmp", 4)) - *ext = 0; - return true; - } - break; - - case SAVE_WAV: - *ofn.lpstrFile = 0; - ofn.Flags = OFN_HIDEREADONLY | OFN_EXPLORER; - if (GetSaveFileName(&ofn)) - { - ext = strrchr(pstrFileName, '.'); - if (ext!=NULL && !_strnicmp(ext, ".wav", 4)) - *ext = 0; - return true; - } - break; - - case SAVE_D2V: - { - char *p; - - ofn.Flags = OFN_HIDEREADONLY | OFN_EXPLORER; - // Load a default filename based on the name of the first input file. - if (szOutput[0] == NULL) - { - strcpy(ofn.lpstrFile, Infilename[0]); - p = &ofn.lpstrFile[strlen(ofn.lpstrFile)]; - while (*p != '.' && p >= ofn.lpstrFile) p--; - if (p != ofn.lpstrFile) - { - *p = 0; - } - } - if (GetSaveFileName(&ofn)) - { - ext = strrchr(pstrFileName, '.'); - if (ext!=NULL && !_strnicmp(ext, ".d2v", 4)) - *ext = 0; - return true; - } - break; - } - } - return false; -} - -static void ShowInfo(bool update) -{ - RECT rect; - - if (update) - { - if (Info_Flag) - { - DestroyWindow(hDlg); - } - - Info_Flag = true; - hDlg = CreateDialog(hInst, (LPCTSTR)IDD_INFO, hWnd, (DLGPROC)Info); - } - - if (Info_Flag) - { - GetWindowRect(hDlg, &rect); - MoveWindow(hDlg, info_wrect.left, info_wrect.top, rect.right-rect.left, rect.bottom-rect.top, true); - ShowWindow(hDlg, WindowMode); - } - SetFocus(hWnd); -} - -void CheckFlag() -{ - CheckMenuItem(hMenu, IDM_IDCT_MMX, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_IDCT_SSEMMX, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_IDCT_SSE2MMX, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_IDCT_FPU, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_IDCT_REF, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_IDCT_SKAL, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_IDCT_SIMPLE, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_PCSCALE, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_TVSCALE, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_FO_FILM, MF_UNCHECKED); - - //Downgrade the iDCT if the processor does not support it. - if (iDCT_Flag == IDCT_SSE2MMX && !cpu.sse2) - iDCT_Flag = IDCT_SKAL; - if (iDCT_Flag == IDCT_SKAL && !cpu.ssemmx) - iDCT_Flag = IDCT_SSEMMX; - if (iDCT_Flag == IDCT_SSEMMX && !cpu.ssemmx) - iDCT_Flag = IDCT_MMX; - - switch (iDCT_Flag) - { - case IDCT_MMX: - CheckMenuItem(hMenu, IDM_IDCT_MMX, MF_CHECKED); - break; - - case IDCT_SSEMMX: - CheckMenuItem(hMenu, IDM_IDCT_SSEMMX, MF_CHECKED); - break; - - case IDCT_SSE2MMX: - CheckMenuItem(hMenu, IDM_IDCT_SSE2MMX, MF_CHECKED); - break; - - case IDCT_FPU: - CheckMenuItem(hMenu, IDM_IDCT_FPU, MF_CHECKED); - break; - - case IDCT_REF: - CheckMenuItem(hMenu, IDM_IDCT_REF, MF_CHECKED); - break; - - case IDCT_SKAL: - CheckMenuItem(hMenu, IDM_IDCT_SKAL, MF_CHECKED); - break; - - case IDCT_SIMPLE: - CheckMenuItem(hMenu, IDM_IDCT_SIMPLE, MF_CHECKED); - break; - } - - setRGBValues(); - if (Scale_Flag) CheckMenuItem(hMenu, IDM_PCSCALE, MF_CHECKED); - else CheckMenuItem(hMenu, IDM_TVSCALE, MF_CHECKED); - - switch (FO_Flag) - { - case FO_NONE: - CheckMenuItem(hMenu, IDM_FO_NONE, MF_CHECKED); - CheckMenuItem(hMenu, IDM_FO_FILM, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_FO_RAW, MF_UNCHECKED); - break; - - case FO_FILM: - CheckMenuItem(hMenu, IDM_FO_NONE, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_FO_FILM, MF_CHECKED); - CheckMenuItem(hMenu, IDM_FO_RAW, MF_UNCHECKED); - break; - - case FO_RAW: - CheckMenuItem(hMenu, IDM_FO_NONE, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_FO_FILM, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_FO_RAW, MF_CHECKED); - break; - } - - switch (Method_Flag) - { - case AUDIO_NONE: - CheckMenuItem(hMenu, IDM_AUDIO_NONE, MF_CHECKED); - break; - - case AUDIO_DEMUX: - CheckMenuItem(hMenu, IDM_DEMUX, MF_CHECKED); - break; - - case AUDIO_DEMUXALL: - CheckMenuItem(hMenu, IDM_DEMUXALL, MF_CHECKED); - break; - - case AUDIO_DECODE: - CheckMenuItem(hMenu, IDM_DECODE, MF_CHECKED); - break; - } - - if (Method_Flag == AUDIO_DECODE) switch (DRC_Flag) - { - case DRC_NONE: - CheckMenuItem(hMenu, IDM_DRC_NONE, MF_CHECKED); - break; - - case DRC_LIGHT: - CheckMenuItem(hMenu, IDM_DRC_LIGHT, MF_CHECKED); - break; - - case DRC_NORMAL: - CheckMenuItem(hMenu, IDM_DRC_NORMAL, MF_CHECKED); - break; - - case DRC_HEAVY: - CheckMenuItem(hMenu, IDM_DRC_HEAVY, MF_CHECKED); - break; - } - - if (Method_Flag == AUDIO_DECODE && DSDown_Flag) - CheckMenuItem(hMenu, IDM_DSDOWN, MF_CHECKED); - - if (Method_Flag == AUDIO_DECODE) switch (SRC_Flag) - { - case SRC_NONE: - CheckMenuItem(hMenu, IDM_SRC_NONE, MF_CHECKED); - break; - - case SRC_LOW: - CheckMenuItem(hMenu, IDM_SRC_LOW, MF_CHECKED); - break; - - case SRC_MID: - CheckMenuItem(hMenu, IDM_SRC_MID, MF_CHECKED); - break; - - case SRC_HIGH: - CheckMenuItem(hMenu, IDM_SRC_HIGH, MF_CHECKED); - break; - - case SRC_UHIGH: - CheckMenuItem(hMenu, IDM_SRC_UHIGH, MF_CHECKED); - break; - } - - if (Method_Flag == AUDIO_DECODE && Norm_Ratio > 100) - { - CheckMenuItem(hMenu, IDM_NORM, MF_CHECKED); - Norm_Flag = true; - Norm_Ratio -= 100; - } - - switch (Priority_Flag) - { - case PRIORITY_HIGH: - CheckMenuItem(hMenu, IDM_PP_HIGH, MF_CHECKED); - SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS); - break; - - case PRIORITY_NORMAL: - CheckMenuItem(hMenu, IDM_PP_NORMAL, MF_CHECKED); - SetPriorityClass(hProcess, NORMAL_PRIORITY_CLASS); - break; - - case PRIORITY_LOW: - CheckMenuItem(hMenu, IDM_PP_LOW, MF_CHECKED); - SetPriorityClass(hProcess, IDLE_PRIORITY_CLASS); - break; - } - - switch (PlaybackSpeed) - { - case SPEED_SINGLE_STEP: - CheckMenuItem(hMenu, IDM_SPEED_SINGLE_STEP, MF_CHECKED); - break; - - case SPEED_SUPER_SLOW: - CheckMenuItem(hMenu, IDM_SPEED_SUPER_SLOW, MF_CHECKED); - break; - - case SPEED_SLOW: - CheckMenuItem(hMenu, IDM_SPEED_SLOW, MF_CHECKED); - break; - - case SPEED_NORMAL: - CheckMenuItem(hMenu, IDM_SPEED_NORMAL, MF_CHECKED); - break; - - case SPEED_FAST: - CheckMenuItem(hMenu, IDM_SPEED_FAST, MF_CHECKED); - break; - - case SPEED_MAXIMUM: - CheckMenuItem(hMenu, IDM_SPEED_MAXIMUM, MF_CHECKED); - break; - } - - switch (HDDisplay) - { - case HD_DISPLAY_FULL_SIZED: - CheckMenuItem(hMenu, IDM_FULL_SIZED, MF_CHECKED); - break; - - case HD_DISPLAY_SHRINK_BY_HALF: - CheckMenuItem(hMenu, IDM_SHRINK_BY_HALF, MF_CHECKED); - break; - - case HD_DISPLAY_TOP_LEFT: - CheckMenuItem(hMenu, IDM_TOP_LEFT, MF_CHECKED); - break; - - case HD_DISPLAY_TOP_RIGHT: - CheckMenuItem(hMenu, IDM_TOP_RIGHT, MF_CHECKED); - break; - - case HD_DISPLAY_BOTTOM_LEFT: - CheckMenuItem(hMenu, IDM_BOTTOM_LEFT, MF_CHECKED); - break; - - case HD_DISPLAY_BOTTOM_RIGHT: - CheckMenuItem(hMenu, IDM_BOTTOM_RIGHT, MF_CHECKED); - break; - } - - if (ForceOpenGops) - CheckMenuItem(hMenu, IDM_FORCE_OPEN, MF_CHECKED); - - if (FullPathInFiles) - CheckMenuItem(hMenu, IDM_FULL_PATH, MF_CHECKED); - - if (LoopPlayback) - CheckMenuItem(hMenu, IDM_LOOP_PLAYBACK, MF_CHECKED); - - if (FusionAudio) - CheckMenuItem(hMenu, IDM_FUSION_AUDIO, MF_CHECKED); - - if (InfoLog_Flag) - CheckMenuItem(hMenu, IDM_INFO_LOG, MF_CHECKED); - - CheckMenuItem(hMenu, IDM_CFOT_DISABLE, (CorrectFieldOrderTrans) ? MF_UNCHECKED : MF_CHECKED); - CheckMenuItem(hMenu, IDM_CFOT_ENABLE , (CorrectFieldOrderTrans) ? MF_CHECKED : MF_UNCHECKED); -} - -void Recovery() -{ - int i; - - hThread = NULL; - threadId = 0; - StartPTS = IframePTS = 0; - - if (Check_Flag) - { - for (i=0; i<3; i++) - { - _aligned_free(backward_reference_frame[i]); - _aligned_free(forward_reference_frame[i]); - _aligned_free(auxframe[i]); - } - - _aligned_free(u422); - _aligned_free(v422); - _aligned_free(u444); - _aligned_free(v444); - _aligned_free(rgb24); - _aligned_free(rgb24small); - _aligned_free(yuy2); - _aligned_free(lum); - } - - Check_Flag = false; - MuxFile = (FILE *) 0xffffffff; - - SendMessage(hTrack, TBM_SETPOS, (WPARAM) true, 0); - InvalidateRect(hwndSelect, NULL, TRUE); -// SendMessage(hTrack, TBM_SETSEL, (WPARAM) true, (LPARAM) MAKELONG(0, 0)); - - LumGamma = LumOffset = 0; - Luminance_Flag = false; - CheckMenuItem(hMenu, IDM_LUMINANCE, MF_UNCHECKED); - - Clip_Width = Clip_Height = 0; - Clip_Left = Clip_Right = Clip_Top = Clip_Bottom = 0; - Cropping_Flag = false; - CheckMenuItem(hMenu, IDM_CROPPING, MF_UNCHECKED); - - PreScale_Ratio = 1.0; - CheckMenuItem(hMenu, IDM_PRESCALE, MF_UNCHECKED); - - strcpy(windowTitle, "DGIndex"); - SetWindowText(hWnd, windowTitle); - - if (NumLoadedFiles) - { - ZeroMemory(&process, sizeof(process)); - process.trackright = TRACK_PITCH; - - Display_Flag = true; - - for (i=0, Infiletotal = 0; i= 100 && bIsWindowsXPorLater) - PostMessage(hWnd, PROGRESS_MESSAGE, 10000, 0); - } - else - remain = 0; - - if (remain && process.locate == LOCATE_RIP || process.locate == LOCATE_PLAY || process.locate == LOCATE_DEMUX_AUDIO) - { - if (elapsed + remain) - { - if (interrupted) - sprintf(szBuffer, "DGIndex[%d%%] - ", (elapsed * 100) / (elapsed + remain)); - else - sprintf(szBuffer, "DGIndex[%d%%] eta %d:%02d:%02d - ", (elapsed * 100) / (elapsed + remain) - , remain/3600, (remain%3600)/60, remain%60); - if(bIsWindowsXPorLater) - PostMessage(hWnd, PROGRESS_MESSAGE, (elapsed * 10000) / (elapsed + remain), 0); - } - else - { - sprintf(szBuffer, "DGIndex[0%%] - "); - if(bIsWindowsXPorLater) - PostMessage(hWnd, PROGRESS_MESSAGE, 0, 0); - } - if (interrupted && bIsWindowsXPorLater) - { - PostMessage(hWnd, PROGRESS_MESSAGE, -1, 0); - } - } - else - sprintf(szBuffer, "DGIndex - "); - ext = _tcsrchr(Infilename[CurrentFile], '\\'); - if (ext) - strncat(szBuffer, ext+1, strlen(Infilename[CurrentFile])-(int)(ext-Infilename[CurrentFile])); - else - strcat(szBuffer, Infilename[CurrentFile]); - sprintf(szTemp, " [%dx%d] [File %d/%d]", Clip_Width, Clip_Height, CurrentFile+1, NumLoadedFiles); - strcat(szBuffer, szTemp); - if (VOB_ID && CELL_ID) - { - sprintf(szTemp, " [Vob %d] [Cell %d]", VOB_ID, CELL_ID); - strcat(szBuffer, szTemp); - } - if (remain == 0 || interrupted) - { - if (StartPTS == 0) - StartPTS = VideoPTS; - if (!Start_Flag && mode == PICTURE_HEADER) - IframePTS = VideoPTS; - else if (process.locate == LOCATE_RIP || process.locate == LOCATE_PLAY || process.locate == LOCATE_DEMUX_AUDIO) - { - if (mode == THREAD_KILL) - IframePTS = LastVideoPTS; - else - IframePTS = 0; - } - if (IframePTS > 0) - { - __int64 time = IframePTS - StartPTS; - WRAPAROUND_CORRECTION(time); - time /= 90; - sprintf(szTemp, " [%02lld:%02lld:%02lld.%03lld]", time/3600000, ((time/1000)%3600)/60, (time/1000)%60, time%1000); - strcat(szBuffer, szTemp); - } - } - if (strcmp(szBuffer, windowTitle)) - { - strcpy(windowTitle, szBuffer); - SetWindowText(hWnd, szBuffer); - } -} - -void OutputProgress(int progr) -{ - static int lastprogress = -1; - - if (progr != lastprogress) - { - char percent[50]; - DWORD written; - - if (progr == 10000) - sprintf(percent, "DGIndex: [100%%] - FINISHED \n"); - else if(progr == -1) - sprintf(percent, "DGIndex: [%.2f%%] - Interrupted \n", lastprogress / 100.0); - else - sprintf(percent, "DGIndex: [%.2f%%] elapsed, eta %d:%02d:%02d\r", progr / 100.0 - , remain/3600, (remain%3600)/60, remain%60); - WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), percent, strlen(percent), &written, NULL); - lastprogress = progr; - } -} - -void DeleteMRUList(int index) -{ - for (; index < 3; index++) - { - strcpy(mMRUList[index], mMRUList[index+1]); - } - mMRUList[3][0] = 0; - UpdateMRUList(); -} - -void AddMRUList(char *name) -{ - int i; - - // Is the name in the list? - for (i = 0; i < 4; i++) - { - if (!strcmp(mMRUList[i], name)) - break; - } - if (i == 4) - { - // New name, add it to the list. - for (i = 3; i > 0; i--) - strcpy(mMRUList[i], mMRUList[i-1]); - strcpy(mMRUList[0], name); - } - else - { - // Name exists, move it to the top. - strcpy(name, mMRUList[i]); - for (; i > 0; i--) - strcpy(mMRUList[i], mMRUList[i-1]); - strcpy(mMRUList[0], name); - } -} - -void UpdateMRUList(void) -{ - HMENU hmenuFile = GetSubMenu(GetMenu((HWND)hWnd), 0); - MENUITEMINFO m; - char name[DG_MAX_PATH]; - int index = 0; -#define MRU_LIST_POSITION 14 - - memset(&m, 0, sizeof m); - m.cbSize = sizeof(MENUITEMINFO); - for(;;) { - m.fMask = MIIM_TYPE; - m.dwTypeData = name; - m.cch = sizeof name; - - if (!GetMenuItemInfo(hmenuFile, MRU_LIST_POSITION, TRUE, &m)) break; - - if (m.fType & MFT_SEPARATOR) break; - - RemoveMenu(hmenuFile, MRU_LIST_POSITION, MF_BYPOSITION); - } - - for (;;) - { - char path[DG_MAX_PATH]; - - if (!mMRUList[index][0]) - break; - - strcpy(path, mMRUList[index]); - PathCompactPath(GetDC(hWnd), (LPSTR) path, 320); - - m.fMask = MIIM_TYPE | MIIM_STATE | MIIM_ID; - m.fType = MFT_STRING; - m.fState = MFS_ENABLED; - m.dwTypeData = path; - m.cch = DG_MAX_PATH; - m.wID = ID_MRU_FILE0 + index; - - if (!InsertMenuItem(hmenuFile, MRU_LIST_POSITION+index, TRUE, &m)) - break; - if (++index >= 4) - break; - } - - if (!index) { - m.fMask = MIIM_TYPE | MIIM_STATE | MIIM_ID; - m.fType = MFT_STRING; - m.fState = MFS_GRAYED; - m.wID = ID_MRU_FILE0; - m.dwTypeData = "Recent file list"; - m.cch = DG_MAX_PATH; - - InsertMenuItem(hmenuFile, MRU_LIST_POSITION+index, TRUE, &m); - } - - DrawMenuBar((HWND)hWnd); -} - -static void LoadLanguageSettings(void) -{ - char ini[DG_MAX_PATH]; - strcpy(ini, ExePath); - strcat(ini, "DGIndex.lang.ini"); - - FILE* lang_ini = fopen(ini, "r"); - if (lang_ini == NULL) - return; - - char lang_string[255]; - MENUITEMINFO lpmii; - lpmii.cbSize = sizeof(lpmii); - lpmii.fMask = MIIM_TYPE; - lpmii.fType = MFT_STRING; - lpmii.fState = MFS_DEFAULT; - lpmii.dwTypeData = lang_string; - - // Parse language settings. - HMENU menu = NULL; - while (fgets(lang_string, 255, lang_ini)) - { - if (lang_string[0] == '[') - { - char *c = strstr(lang_string, "]"); - if (c) - *c = '\0'; - char *menu_name = &lang_string[1]; - if (strcmp(menu_name, "MainMenu") == 0) - menu = hMenu; - else if (strncmp(menu_name, "SubMenu", 7) == 0) - { - int no1, no2, no3; - int num = sscanf(menu_name, "SubMenu%d-%d-%d", &no1, &no2, &no3); - if (num == 3) - { - menu = GetSubMenu(hMenu, no1); - menu = GetSubMenu(menu, no2); - menu = GetSubMenu(menu, no3); - } - else if (num == 2) - { - menu = GetSubMenu(hMenu, no1); - menu = GetSubMenu(menu, no2); - } - else if (num == 1) - menu = GetSubMenu(hMenu, no1); - else - menu = NULL; - } - else if (menu != NULL) - break; - continue; - } - else if (menu == NULL) - continue; - int item_no = -1; - if (sscanf(lang_string, "%d=%[^\n]", &item_no, lang_string) == 2) - SetMenuItemInfo(menu, item_no, TRUE, &lpmii); - } - - fclose(lang_ini); -} - -typedef struct { - DWORD fSize; - HFONT hFont; -} lang_settings_t; - -static void *LoadDialogLanguageSettings(HWND hInfoDlg, int dialog_id) -{ - char ini[DG_MAX_PATH]; - strcpy(ini, ExePath); - strcat(ini, "DGIndex.lang.ini"); - - FILE* lang_ini = fopen(ini, "r"); - if (lang_ini == NULL) - return NULL; - - lang_settings_t *lang = (lang_settings_t *)(malloc(sizeof(lang_settings_t))); - if (lang == NULL) - return NULL; - lang->fSize = 10; - lang->hFont = NULL; - - static const DWORD res_information[] = { 0 }; - static const DWORD res_about[] = { IDOK, IDC_STATIC_ABOUT, IDC_STATIC_THANK }; - static const DWORD res_file_list[] = { ID_ADD, ID_UP, ID_DOWN, ID_DEL, ID_DELALL, IDOK }; - static const DWORD res_luminance[] = { IDC_LUM_CHECK, IDC_STATIC_OFFSET, IDC_STATIC_GAMMA }; - static const DWORD res_normalize[] = { IDC_NORM_CHECK, IDC_STATIC_VOLUME }; - static const DWORD res_set_pids[] = { IDC_PIDS_OK, IDC_PIDS_CANCEL, IDC_STATIC_VIDEO_PID, IDC_STATIC_AUDIO_PID, IDC_STATIC_PCR_PID, IDC_STATIC_SET_PIDS }; - static const DWORD res_avs_template[] = { IDC_NO_TEMPLATE, IDC_CHANGE_TEMPLATE, IDC_KEEP_TEMPLATE, IDC_STATIC_AVS_TEMPLATE }; - static const DWORD res_bitmap_path[] = { IDC_BMP_PATH_OK, IDC_BMP_PATH_CANCEL, IDC_STATIC_BMP_PATH }; - static const DWORD res_cropping[] = { IDC_CROPPING_CHECK, IDC_STATIC_FLEFT, IDC_STATIC_FRIGHT, IDC_STATIC_FTOP, IDC_STATIC_FBOTTOM, IDC_FWIDTH, IDC_FHEIGHT }; - static const DWORD res_detect_pids[] = { IDC_SET_VIDEO, IDC_SET_AUDIO, IDC_SET_PCR, IDC_SET_DONE, IDC_STATIC_DETECT_PIDS }; - static const DWORD res_select_tracks[] = { IDC_TRACK_OK, IDC_TRACK_CANCEL, IDC_STATIC_SELECT_TRACKS, IDC_TRACK_LIST }; - static const DWORD res_delay_track[] = { IDC_DELAY_OK, IDC_DELAY_CANCEL, IDC_STATIC_SELECT_DELAY_TRACK, IDC_DELAY_LIST }; - static const DWORD res_margin[] = { IDC_MARGIN_OK, IDC_MARGIN_CANCEL, IDC_STATIC_SET_MARGIN, IDC_STATIC_MSEC, IDC_MARGIN }; - static const DWORD *res_ids[DIALOG_MAX] = { - res_information, res_about, res_file_list, res_luminance, res_normalize, res_set_pids, - res_avs_template, res_bitmap_path, res_cropping, res_detect_pids, res_select_tracks, res_delay_track, - res_margin - }; -#define GET_NUMS(a) (sizeof(a)/sizeof(a[0])) - static const int ids_nums[DIALOG_MAX] = { - //GET_NUMS(res_information), - 0, - GET_NUMS(res_about), GET_NUMS(res_file_list), GET_NUMS(res_luminance), - GET_NUMS(res_normalize), GET_NUMS(res_set_pids), GET_NUMS(res_avs_template), GET_NUMS(res_bitmap_path), - GET_NUMS(res_cropping), GET_NUMS(res_detect_pids), GET_NUMS(res_select_tracks), GET_NUMS(res_delay_track), - GET_NUMS(res_margin) - }; -#undef GET_NUMS - static const DWORD res_information_txts[] = { 0 }; - static const DWORD res_about_txts[] = { IDOK, IDC_STATIC_ABOUT, IDC_STATIC_THANK, IDC_VERSION, 0 }; - static const DWORD res_file_list_txts[] = { ID_ADD, ID_UP, ID_DOWN, ID_DEL, ID_DELALL, IDOK, IDC_LIST, 0 }; - static const DWORD res_luminance_txts[] = { IDC_LUM_CHECK, IDC_STATIC_OFFSET, IDC_STATIC_GAMMA, IDC_GAMMA_BOX, IDC_OFFSET_BOX, 0 }; - static const DWORD res_normalize_txts[] = { IDC_NORM_CHECK, IDC_STATIC_VOLUME, IDC_NORM, 0 }; - static const DWORD res_set_pids_txts[] = { IDC_PIDS_OK, IDC_PIDS_CANCEL, IDC_STATIC_VIDEO_PID, IDC_STATIC_AUDIO_PID, IDC_STATIC_PCR_PID, IDC_STATIC_SET_PIDS, - IDC_VIDEO_PID, IDC_AUDIO_PID, IDC_PCR_PID, 0 }; - static const DWORD res_avs_template_txts[] = { IDC_NO_TEMPLATE, IDC_CHANGE_TEMPLATE, IDC_KEEP_TEMPLATE, IDC_STATIC_AVS_TEMPLATE, IDC_AVS_TEMPLATE, 0 }; - static const DWORD res_bitmap_path_txts[] = { IDC_BMP_PATH_OK, IDC_BMP_PATH_CANCEL, IDC_STATIC_BMP_PATH, IDC_BMP_PATH, 0 }; - static const DWORD res_cropping_txts[] = { IDC_CROPPING_CHECK, IDC_STATIC_FLEFT, IDC_STATIC_FRIGHT, IDC_STATIC_FTOP, IDC_STATIC_FBOTTOM, IDC_FWIDTH, IDC_FHEIGHT, - IDC_WIDTH, IDC_HEIGHT, IDC_LEFT, IDC_RIGHT, IDC_TOP, IDC_BOTTOM, 0 }; - static const DWORD res_detect_pids_txts[] = { IDC_SET_VIDEO, IDC_SET_AUDIO, IDC_SET_PCR, IDC_SET_DONE, IDC_STATIC_DETECT_PIDS, - IDC_PID_LISTBOX, IDC_SELECT_VIDEO_PID, IDC_SELECT_AUDIO_PID, IDC_SELECT_PCR_PID, 0 }; - static const DWORD res_select_tracks_txts[] = { IDC_TRACK_OK, IDC_TRACK_CANCEL, IDC_STATIC_SELECT_TRACKS, IDC_TRACK_LIST, IDC_TRACK_LIST, 0 }; - static const DWORD res_delay_track_txts[] = { IDC_DELAY_OK, IDC_DELAY_CANCEL, IDC_STATIC_SELECT_DELAY_TRACK, IDC_DELAY_LIST, IDC_DELAY_LIST, 0 }; - static const DWORD res_margin_txts[] = { IDC_MARGIN_OK, IDC_MARGIN_CANCEL, IDC_STATIC_SET_MARGIN, IDC_STATIC_MSEC, IDC_MARGIN, IDC_MARGIN, 0 }; - static const DWORD *res_txts[DIALOG_MAX] = { - res_information_txts, res_about_txts, res_file_list_txts, res_luminance_txts, res_normalize_txts, - res_set_pids_txts, res_avs_template_txts, res_bitmap_path_txts, res_cropping_txts, res_detect_pids_txts, - res_select_tracks_txts, res_delay_track_txts, res_margin_txts - }; - - const int ids_max = ids_nums[dialog_id]; - const DWORD *ids = res_ids[dialog_id]; - const DWORD *txts = res_txts[dialog_id]; - - // Parse language settings. - char lang_string[255]; - HWND dialog = NULL; - while (fgets(lang_string, 255, lang_ini)) - { - if (lang_string[0] == '[') - { - char *c = strstr(lang_string, "]"); - if (c) - *c = '\0'; - char *dlg_name = &lang_string[1]; - if (strncmp(dlg_name, "Dialog", 6) == 0) - { - if (dialog != NULL) - break; - int no; - if (sscanf(dlg_name, "Dialog%d", &no) == 1) - { - if (no == dialog_id) - dialog = hInfoDlg; - } - } - continue; - } - else if (dialog == NULL) - continue; - int item_no = -1; - int nums = sscanf(lang_string, "%d=%[^\n]", &item_no, lang_string); - if (nums == 0) - { - // Check the Caption & Font settings. - if (sscanf(lang_string, "caption=%[^\n]", lang_string) == 1) - SetWindowText(dialog, lang_string); - else if (sscanf(lang_string, "font_size=%[^\n]", lang_string) == 1) - lang->fSize = atoi(lang_string); - else if (sscanf(lang_string, "font_name=%[^\n]", lang_string) == 1) - { - if (lang->hFont != NULL) - DeleteObject(lang->hFont); - lang->hFont = CreateFont(-MulDiv(lang->fSize, GetDeviceCaps(hDC, LOGPIXELSY), 72), - 0, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, - DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, - DEFAULT_QUALITY, (DEFAULT_PITCH | FF_DONTCARE), lang_string); - for( int i = 0; txts[i] != 0; i++ ) - SendMessage(GetDlgItem(dialog, txts[i]), WM_SETFONT, (WPARAM)lang->hFont, MAKELPARAM(TRUE, 0)); - } - continue; - } - if (item_no < 0 || ids_max <= item_no) - continue; - DWORD id = ids[item_no]; - if (id != 0 && nums == 2) - { - // Apply the user-specified settings. - SetDlgItemText(dialog, id, lang_string); - } - } - - fclose(lang_ini); - return lang; -} - -static void DestroyDialogLanguageSettings(void *lh) -{ - if (lh == NULL) - return; - lang_settings_t *lang = (lang_settings_t*)lh; - - if (lang->hFont) - DeleteObject(lang->hFont); - free(lang); -} diff --git a/src/dgindex/gui.rc b/src/dgindex/gui.rc deleted file mode 100644 index fad3fbd..0000000 --- a/src/dgindex/gui.rc +++ /dev/null @@ -1,653 +0,0 @@ -//Microsoft Developer Studio generated resource script. -// -#include "resource.h" -#include "..\config.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "resource.h" -#define APSTUDIO_HIDDEN_SYMBOLS -#include "windows.h" -#undef APSTUDIO_HIDDEN_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (U.S.) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) -#endif //_WIN32 - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_INFO DIALOG DISCARDABLE 0, 0, 125, 406 -STYLE DS_MODALFRAME | DS_NOIDLEMSG | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Information" -FONT 8, "Tahoma" -BEGIN - GROUPBOX "Video",IDC_STATIC,3,5,119,226,BS_LEFT - RTEXT "Frame Type",IDC_STATIC,13,105,40,9,SS_CENTERIMAGE | NOT - WS_GROUP - RTEXT "Aspect Ratio",IDC_STATIC,9,55,44,9,SS_CENTERIMAGE | NOT - WS_GROUP - RTEXT "Coded #",IDC_STATIC,24,145,29,9,SS_CENTERIMAGE | NOT - WS_GROUP - RTEXT "Playback #",IDC_STATIC,13,155,40,9,SS_CENTERIMAGE | NOT - WS_GROUP - RTEXT "Frame Rate",IDC_STATIC,14,65,39,9,SS_CENTERIMAGE | NOT - WS_GROUP - RTEXT "Video Type",IDC_STATIC,13,75,40,9,SS_CENTERIMAGE | NOT - WS_GROUP - CTEXT "",IDC_CODED_NUMBER,56,145,59,9,SS_CENTERIMAGE | - SS_SUNKEN | NOT WS_GROUP - GROUPBOX "Audio",IDC_STATIC,3,236,119,105 - RTEXT "Elapsed",IDC_STATIC,16,356,27,9,SS_CENTERIMAGE | NOT - WS_GROUP - RTEXT "Remain",IDC_STATIC,18,366,27,9,SS_CENTERIMAGE | NOT - WS_GROUP - CTEXT "",IDC_PLAYBACK_NUMBER,56,155,59,9,SS_CENTERIMAGE | - SS_SUNKEN | NOT WS_GROUP - CTEXT "",IDC_FRAME_RATE,56,65,59,9,SS_CENTERIMAGE | SS_SUNKEN | - NOT WS_GROUP - CTEXT "",IDC_VIDEO_TYPE,56,75,59,9,SS_CENTERIMAGE | SS_SUNKEN | - NOT WS_GROUP - CTEXT "",IDC_FRAME_TYPE,56,105,59,9,SS_CENTERIMAGE | SS_SUNKEN | - NOT WS_GROUP - CTEXT "",IDC_ASPECT_RATIO,56,55,59,9,SS_CENTERIMAGE | - SS_SUNKEN | NOT WS_GROUP - CTEXT "",IDC_REMAIN,46,366,69,9,SS_CENTERIMAGE | SS_SUNKEN | - NOT WS_GROUP - CTEXT "",IDC_ELAPSED,46,356,69,9,SS_CENTERIMAGE | SS_SUNKEN | - NOT WS_GROUP - CTEXT "",IDC_FPS,46,376,69,9,SS_CENTERIMAGE | SS_SUNKEN | NOT - WS_GROUP - RTEXT "FPS",IDC_STATIC,27,376,16,9,SS_CENTERIMAGE | NOT - WS_GROUP - CTEXT "",IDC_INFO,46,386,69,9,SS_SUNKEN | NOT WS_GROUP - RTEXT "Info",IDC_STATIC,27,386,16,8,NOT WS_GROUP - RTEXT "Timestamp",IDC_STATIC,6,326,39,9,SS_CENTERIMAGE | NOT - WS_GROUP - CTEXT "",IDC_TIMESTAMP,47,326,68,9,SS_CENTERIMAGE | SS_SUNKEN | - NOT WS_GROUP - GROUPBOX "Status",IDC_STATIC,3,347,119,55,BS_LEFT - RTEXT "Vob Cell ID",IDC_STATIC,10,185,43,9,SS_CENTERIMAGE | - NOT WS_GROUP - CTEXT "",IDC_VOB_ID,56,185,29,9,SS_CENTERIMAGE | SS_SUNKEN | - NOT WS_GROUP - CTEXT "",IDC_CELL_ID,87,185,28,9,SS_CENTERIMAGE | SS_SUNKEN | - NOT WS_GROUP - RTEXT "Bitrate",IDC_STATIC,10,194,43,9,SS_CENTERIMAGE | NOT - WS_GROUP - CTEXT "",IDC_BITRATE,56,195,59,9,SS_CENTERIMAGE | SS_SUNKEN | - NOT WS_GROUP - RTEXT "Frame Size",IDC_STATIC,9,35,44,9,SS_CENTERIMAGE | NOT - WS_GROUP - CTEXT "",IDC_FRAME_SIZE,56,35,59,9,SS_CENTERIMAGE | SS_SUNKEN | - NOT WS_GROUP - RTEXT "Profile",IDC_STATIC,9,25,44,9,SS_CENTERIMAGE | NOT - WS_GROUP - CTEXT "",IDC_PROFILE,56,25,59,9,SS_CENTERIMAGE | SS_SUNKEN | - NOT WS_GROUP - RTEXT "Frame Struct",IDC_STATIC,7,95,46,9,SS_CENTERIMAGE | NOT - WS_GROUP - CTEXT "",IDC_FRAME_STRUCTURE,56,95,59,9,SS_CENTERIMAGE | - SS_SUNKEN | NOT WS_GROUP - RTEXT "Field Order",IDC_STATIC,7,135,46,9,SS_CENTERIMAGE | NOT - WS_GROUP - CTEXT "",IDC_FIELD_ORDER,56,135,59,9,SS_CENTERIMAGE | - SS_SUNKEN | NOT WS_GROUP - RTEXT "Colorimetry",IDC_STATIC,13,125,40,9,SS_CENTERIMAGE | - NOT WS_GROUP - CTEXT "",IDC_COLORIMETRY,56,125,59,9,SS_CENTERIMAGE | - SS_SUNKEN | NOT WS_GROUP - RTEXT "Bitrate (Avg)",IDC_STATIC,10,204,43,9,SS_CENTERIMAGE | - NOT WS_GROUP - CTEXT "",IDC_BITRATE_AVG,56,205,59,9,SS_CENTERIMAGE | - SS_SUNKEN | NOT WS_GROUP - RTEXT "Stream Type",IDC_STATIC,9,15,44,9,SS_CENTERIMAGE | NOT - WS_GROUP - CTEXT "",IDC_STREAM_TYPE,56,15,59,9,SS_CENTERIMAGE | SS_SUNKEN | - NOT WS_GROUP - RTEXT "Frame Rpts",IDC_STATIC,9,164,44,9,SS_CENTERIMAGE | NOT - WS_GROUP - CTEXT "",IDC_FRAME_REPEATS,56,165,59,9,SS_CENTERIMAGE | - SS_SUNKEN | NOT WS_GROUP - RTEXT "Field Rpts",IDC_STATIC,9,175,44,9,SS_CENTERIMAGE | NOT - WS_GROUP - CTEXT "",IDC_FIELD_REPEATS,56,175,59,9,SS_CENTERIMAGE | - SS_SUNKEN | NOT WS_GROUP - LISTBOX IDC_AUDIO_LIST,9,247,106,74,NOT LBS_NOTIFY | - LBS_NOINTEGRALHEIGHT | LBS_DISABLENOSCROLL - RTEXT "Coding Type",IDC_STATIC,13,115,40,9,SS_CENTERIMAGE | - NOT WS_GROUP - CTEXT "",IDC_CODING_TYPE,56,115,59,9,SS_CENTERIMAGE | - SS_SUNKEN | NOT WS_GROUP - RTEXT "Bitrate (Max)",IDC_STATIC,10,214,43,9,SS_CENTERIMAGE | - NOT WS_GROUP - CTEXT "",IDC_BITRATE_MAX,56,215,59,9,SS_CENTERIMAGE | - SS_SUNKEN | NOT WS_GROUP - RTEXT "Display Size",IDC_STATIC,10,45,44,9,SS_CENTERIMAGE | - NOT WS_GROUP - CTEXT "",IDC_DISPLAY_SIZE,56,45,59,9,SS_CENTERIMAGE | - SS_SUNKEN | NOT WS_GROUP - RTEXT "Sequence",IDC_STATIC,13,85,40,9,SS_CENTERIMAGE | NOT - WS_GROUP - CTEXT "",IDC_SEQUENCE,56,85,59,9,SS_CENTERIMAGE | SS_SUNKEN | - NOT WS_GROUP -END - -IDD_ABOUT DIALOG DISCARDABLE 0, 0, 171, 123 -STYLE DS_MODALFRAME | DS_NOIDLEMSG | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Version" -FONT 10, "System" -BEGIN - PUSHBUTTON "OK",IDOK,143,8,22,15 - CTEXT "",IDC_VERSION,31,7,104,17,SS_CENTERIMAGE | WS_BORDER | - NOT WS_GROUP - ICON IDI_MOVIE,IDC_STATIC,5,6,20,20 - LTEXT "DGIndex is an evolution of jackei's original work called DVD2AVI. The name was changed to prevent versioning nightmares and to reflect the significant divergence of functionality.", - IDC_STATIC_ABOUT,9,35,153,36,NOT WS_GROUP - LTEXT "I am using this About box to permanently record the origins of DGIndex and to acknowledge the original work of jackei, as well as my personal gratitude for his wonderful contribution to our community!", - IDC_STATIC_THANK,9,74,153,44,NOT WS_GROUP -END - -IDD_FILELIST DIALOG DISCARDABLE 0, 0, 270, 151 -STYLE DS_MODALFRAME | DS_NOIDLEMSG | WS_POPUP | WS_CAPTION -CAPTION "File List" -FONT 10, "System" -BEGIN - PUSHBUTTON "ADD",ID_ADD,223,7,39,14 - PUSHBUTTON "UP",ID_UP,223,26,39,14 - PUSHBUTTON "DOWN",ID_DOWN,223,45,39,14 - PUSHBUTTON "DEL",ID_DEL,223,64,39,14 - PUSHBUTTON "DEL ALL",ID_DELALL,223,83,39,14 - PUSHBUTTON "OK",IDOK,223,132,39,14 - LISTBOX IDC_LIST,7,7,207,141,NOT LBS_NOTIFY | - LBS_DISABLENOSCROLL | WS_VSCROLL | WS_HSCROLL -END - -IDD_LUMINANCE DIALOG DISCARDABLE 0, 0, 113, 67 -STYLE DS_MODALFRAME | DS_NOIDLEMSG | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Luminance Filter" -FONT 10, "System" -BEGIN - CONTROL "Enable Luminance Filter",IDC_LUM_CHECK,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,5,5,108,11 - CONTROL "",IDC_GAMMA_SPIN,"msctls_updown32",WS_TABSTOP,86,23,8, - 14 - CONTROL "",IDC_OFFSET_SPIN,"msctls_updown32",WS_TABSTOP,86,45,8, - 14 - RTEXT "0",IDC_GAMMA_BOX,64,22,18,15,SS_CENTERIMAGE - RTEXT "Offset:",IDC_STATIC_OFFSET,30,47,29,11,NOT WS_GROUP - RTEXT "Gamma:",IDC_STATIC_GAMMA,28,25,30,8,NOT WS_GROUP - RTEXT "0",IDC_OFFSET_BOX,63,44,19,15,SS_CENTERIMAGE -END - -IDD_NORM DIALOG DISCARDABLE 0, 0, 124, 40 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Normalization" -FONT 10, "System" -BEGIN - CONTROL "Enable Normalization",IDC_NORM_CHECK,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,6,5,93,8 - CONTROL "",IDC_NORM_SLIDER,"msctls_trackbar32",TBS_NOTICKS | - WS_TABSTOP,33,22,72,10 - LTEXT "Volume",IDC_STATIC_VOLUME,7,22,25,8,NOT WS_GROUP - CTEXT "0",IDC_NORM,106,22,16,8,NOT WS_GROUP -END - -IDD_SET_PIDS DIALOG DISCARDABLE 0, 0, 116, 118 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Set PIDs" -FONT 10, "System" -BEGIN - EDITTEXT IDC_VIDEO_PID,62,7,22,12,ES_RIGHT | ES_AUTOHSCROLL - EDITTEXT IDC_AUDIO_PID,62,30,22,12,ES_RIGHT | ES_AUTOHSCROLL - EDITTEXT IDC_PCR_PID,62,53,22,12,ES_RIGHT | ES_AUTOHSCROLL - PUSHBUTTON "OK",IDC_PIDS_OK,7,99,44,12 - PUSHBUTTON "Cancel",IDC_PIDS_CANCEL,64,99,45,12 - RTEXT "Video PID",IDC_STATIC_VIDEO_PID,17,9,39,11 - RTEXT "Audio PID",IDC_STATIC_AUDIO_PID,17,32,39,11 - RTEXT "PCR PID",IDC_STATIC_PCR_PID,17,55,39,11 - CTEXT "[Please use hexadecimal values with no leading 0x.]", - IDC_STATIC_SET_PIDS,11,73,92,19 -END - -IDD_AVS_TEMPLATE DIALOG DISCARDABLE 0, 0, 362, 78 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "AVS Template" -FONT 10, "System" -BEGIN - PUSHBUTTON "Don't Use Template",IDC_NO_TEMPLATE,7,51,114,14 - PUSHBUTTON "Change Template File",IDC_CHANGE_TEMPLATE,124,51,114,14 - PUSHBUTTON "Keep Current Template File",IDC_KEEP_TEMPLATE,241,51, - 114,14 - LTEXT "Your current AVS template file is:", - IDC_STATIC_AVS_TEMPLATE,10,9,129,11 - EDITTEXT IDC_AVS_TEMPLATE,10,27,340,12,ES_AUTOHSCROLL | - WS_DISABLED | NOT WS_BORDER | NOT WS_TABSTOP -END - -IDD_BMP_PATH DIALOG DISCARDABLE 0, 0, 362, 78 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "BMP Save Path" -FONT 10, "System" -BEGIN - PUSHBUTTON "OK",IDC_BMP_PATH_OK,258,51,47,14 - PUSHBUTTON "Cancel",IDC_BMP_PATH_CANCEL,308,51,47,14 - LTEXT "Your current BMP save path is:",IDC_STATIC_BMP_PATH,10,9, - 129,11 - EDITTEXT IDC_BMP_PATH,10,27,340,12,ES_AUTOHSCROLL | NOT - WS_TABSTOP -END - -IDD_CROPPING DIALOG DISCARDABLE 0, 0, 241, 97 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Cropping" -FONT 10, "System" -BEGIN - CONTROL "Enable Cropping Filter",IDC_CROPPING_CHECK,"Button", - BS_AUTOCHECKBOX | WS_TABSTOP,8,8,106,8 - CONTROL "",IDC_LEFT_SLIDER,"msctls_trackbar32",TBS_NOTICKS | - WS_TABSTOP,33,38,188,10 - CONTROL "",IDC_RIGHT_SLIDER,"msctls_trackbar32",TBS_NOTICKS | - WS_TABSTOP,33,52,188,10 - CONTROL "",IDC_TOP_SLIDER,"msctls_trackbar32",TBS_NOTICKS | - WS_TABSTOP,33,66,188,10 - CONTROL "",IDC_BOTTOM_SLIDER,"msctls_trackbar32",TBS_NOTICKS | - WS_TABSTOP,33,80,188,10 - LTEXT "Left",IDC_STATIC_FLEFT,7,38,13,8,NOT WS_GROUP - LTEXT "Right",IDC_STATIC_FRIGHT,7,52,18,8,NOT WS_GROUP - LTEXT "Top",IDC_STATIC_FTOP,7,66,13,8,NOT WS_GROUP - LTEXT "Bottom",IDC_STATIC_FBOTTOM,7,80,24,8,NOT WS_GROUP - LTEXT "Width",IDC_FWIDTH,183,10,24,8,NOT WS_GROUP - LTEXT "Height",IDC_FHEIGHT,183,22,26,8,NOT WS_GROUP - RTEXT "0",IDC_WIDTH,217,10,16,8,NOT WS_GROUP - RTEXT "0",IDC_HEIGHT,217,22,16,8,NOT WS_GROUP - CTEXT "0",IDC_LEFT,223,38,16,8,NOT WS_GROUP - CTEXT "0",IDC_RIGHT,223,52,16,8,NOT WS_GROUP - CTEXT "0",IDC_TOP,223,66,16,8,NOT WS_GROUP - CTEXT "0",IDC_BOTTOM,223,80,16,8,NOT WS_GROUP -END - -IDD_DETECT_PIDS DIALOG DISCARDABLE 0, 0, 170, 244 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Detect PIDs" -FONT 10, "System" -BEGIN - LISTBOX IDC_PID_LISTBOX,6,7,157,169,WS_VSCROLL - PUSHBUTTON "Set Video",IDC_SET_VIDEO,12,170,60,14 - PUSHBUTTON "Set Audio",IDC_SET_AUDIO,12,186,60,14 - PUSHBUTTON "Set PCR",IDC_SET_PCR,12,202,60,14 - PUSHBUTTON "Done",IDC_SET_DONE,123,202,36,14 - CTEXT "", IDC_SELECT_VIDEO_PID,74,170,40,14,SS_CENTERIMAGE | SS_SUNKEN - CTEXT "", IDC_SELECT_AUDIO_PID,74,186,40,14,SS_CENTERIMAGE | SS_SUNKEN - CTEXT "", IDC_SELECT_PCR_PID,74,202,40,14,SS_CENTERIMAGE | SS_SUNKEN - CTEXT "Select a line and use these buttons to set that PID as the audio or video PID.", - IDC_STATIC_DETECT_PIDS,6,220,157,17 -END - -IDD_SELECT_TRACKS DIALOG DISCARDABLE 0, 0, 215, 75 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Select Track(s)" -FONT 10, "System" -BEGIN - EDITTEXT IDC_TRACK_LIST,7,23,187,15,ES_AUTOHSCROLL - PUSHBUTTON "OK",IDC_TRACK_OK,7,54,50,14 - PUSHBUTTON "Cancel",IDC_TRACK_CANCEL,63,54,50,14 - LTEXT "List desired audio id's separated by commas", - IDC_STATIC_SELECT_TRACKS,7,2,202,16,SS_CENTERIMAGE -END - -IDD_SELECT_DELAY_TRACK DIALOG DISCARDABLE 0, 0, 215, 75 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Select Track to Analyze" -FONT 10, "System" -BEGIN - EDITTEXT IDC_DELAY_LIST,7,23,34,15,ES_AUTOHSCROLL - PUSHBUTTON "OK",IDC_DELAY_OK,7,54,50,14 - PUSHBUTTON "Cancel",IDC_DELAY_CANCEL,63,54,50,14 - LTEXT "Enter audio id to analyze in hex without the leading 0x", - IDC_STATIC_SELECT_DELAY_TRACK,7,2,202,16,SS_CENTERIMAGE -END - -IDD_SET_MARGIN DIALOG DISCARDABLE 0, 0, 127, 51 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Set Margin" -FONT 10, "System" -BEGIN - EDITTEXT IDC_MARGIN,49,8,40,12,ES_RIGHT | ES_AUTOHSCROLL - PUSHBUTTON "OK",IDC_MARGIN_OK,11,32,48,12 - PUSHBUTTON "Cancel",IDC_MARGIN_CANCEL,68,32,48,12 - RTEXT "Margin:",IDC_STATIC_SET_MARGIN,7,9,38,11 - CTEXT "msec",IDC_STATIC_MSEC,91,9,29,11 -END - - -///////////////////////////////////////////////////////////////////////////// -// -// Menu -// - -IDC_GUI MENU DISCARDABLE -BEGIN - POPUP "&File" - BEGIN - MENUITEM "&Open\t[F2]", IDM_OPEN - MENUITEM "Load Project", IDM_LOAD_D2V - MENUITEM "&Close\t[F3]", IDM_CLOSE - MENUITEM SEPARATOR - MENUITEM "&Save Project\t[F4]", IDM_SAVE_D2V - MENUITEM "Save Project and Demux Video", IDM_SAVE_D2V_AND_DEMUX - MENUITEM "Save BMP\t[F7]", IDM_BMP - MENUITEM "Demux Audio-Only Stream", IDM_DEMUX_AUDIO - MENUITEM SEPARATOR - MENUITEM "Preview\t[F5]", IDM_PREVIEW - MENUITEM "Play\t[F6]", IDM_PLAY - MENUITEM "Stop\t[Esc]", IDM_STOP - MENUITEM "Pause/Resume\t[Space]", IDM_PAUSE - MENUITEM SEPARATOR - MENUITEM SEPARATOR - MENUITEM "Exit", IDM_EXIT - END - POPUP "&Stream" - BEGIN - MENUITEM "Detect PIDs: PAT/PMT", IDM_DETECT_PIDS - MENUITEM "Detect PIDs: PSIP", IDM_DETECT_PIDS_PSIP - MENUITEM "Detect PIDs: Raw", IDM_DETECT_PIDS_RAW - MENUITEM "Set PIDs", IDM_SET_PIDS - MENUITEM "Set Margin", IDM_SET_MARGIN - END - POPUP "&Video" - BEGIN - POPUP "iDCT Algorithm" - BEGIN - MENUITEM "32-bit MMX", IDM_IDCT_MMX - MENUITEM "32-bit SSE MMX", IDM_IDCT_SSEMMX - MENUITEM "32-bit SSE2 MMX", IDM_IDCT_SSE2MMX - MENUITEM "64-bit Floating Point", IDM_IDCT_FPU - MENUITEM "IEEE-1180 Reference", IDM_IDCT_REF - MENUITEM "Skal SSE MMX", IDM_IDCT_SKAL - MENUITEM "Simple MMX", IDM_IDCT_SIMPLE - END - POPUP "Field Operation" - BEGIN - MENUITEM "Honor Pulldown Flags", IDM_FO_NONE - MENUITEM "Ignore Pulldown Flags", IDM_FO_RAW - MENUITEM "Forced Film", IDM_FO_FILM - END - POPUP "YUV -> RGB" - BEGIN - MENUITEM "PC\tScale", IDM_PCSCALE - MENUITEM "TV\tScale", IDM_TVSCALE - END - POPUP "HD Display" - BEGIN - MENUITEM "Full Sized", IDM_FULL_SIZED - MENUITEM "Shrink by Half", IDM_SHRINK_BY_HALF - MENUITEM "Top Left", IDM_TOP_LEFT - MENUITEM "Top Right", IDM_TOP_RIGHT - MENUITEM "Bottom Left", IDM_BOTTOM_LEFT - MENUITEM "Bottom Right", IDM_BOTTOM_RIGHT - END - MENUITEM SEPARATOR - MENUITEM "Luminance Filter", IDM_LUMINANCE - MENUITEM "Cropping Filter", IDM_CROPPING - MENUITEM SEPARATOR - MENUITEM "Copy frame to clipboard\t[F8]", IDM_COPYFRAMETOCLIPBOARD - END - POPUP "&Audio" - BEGIN - POPUP "Output Method" - BEGIN - MENUITEM "Disable", IDM_AUDIO_NONE - MENUITEM "Demux Tracks", IDM_DEMUX - MENUITEM "Demux All Tracks", IDM_DEMUXALL - MENUITEM "Decode AC3 Track to WAV", IDM_DECODE - END - MENUITEM "Select Track(s)", IDM_TRACK_NUMBER - MENUITEM SEPARATOR - POPUP "Dolby Digital Decode" - BEGIN - POPUP "Dynamic Range Control" - BEGIN - MENUITEM "Off", IDM_DRC_NONE - MENUITEM SEPARATOR - MENUITEM "Light", IDM_DRC_LIGHT - MENUITEM "Normal", IDM_DRC_NORMAL - MENUITEM "Heavy", IDM_DRC_HEAVY - END - MENUITEM "Dolby Surround Downmix", IDM_DSDOWN - MENUITEM "Pre-Scale Decision\t[F9]", IDM_PRESCALE - END - POPUP "48 -> 44.1KHz" - BEGIN - MENUITEM "Off", IDM_SRC_NONE - MENUITEM SEPARATOR - MENUITEM "Low", IDM_SRC_LOW - MENUITEM "Mid", IDM_SRC_MID - MENUITEM "High", IDM_SRC_HIGH - MENUITEM "UltraHigh", IDM_SRC_UHIGH - END - MENUITEM "Normalization", IDM_NORM - END - POPUP "&Options" - BEGIN - MENUITEM "Loop Playback", IDM_LOOP_PLAYBACK - POPUP "Playback Speed" - BEGIN - MENUITEM "Single Step", IDM_SPEED_SINGLE_STEP - MENUITEM "Super Slow", IDM_SPEED_SUPER_SLOW - MENUITEM "Slow", IDM_SPEED_SLOW - MENUITEM "Normal", IDM_SPEED_NORMAL - MENUITEM "Fast", IDM_SPEED_FAST - MENUITEM "Maximum", IDM_SPEED_MAXIMUM - END - POPUP "Process Priority" - BEGIN - MENUITEM "High", IDM_PP_HIGH - MENUITEM "Normal", IDM_PP_NORMAL - MENUITEM "Low", IDM_PP_LOW - END - MENUITEM "Use Full Paths", IDM_FULL_PATH - MENUITEM "Force Fusion-Style Audio", IDM_FUSION_AUDIO - MENUITEM "Force Open GOPs in D2V File", IDM_FORCE_OPEN - MENUITEM "Log Quant Matrices", IDM_LOG_QUANTS - MENUITEM "Log Timestamps", IDM_LOG_TIMESTAMPS - MENUITEM "AVS Template", IDM_AVS_TEMPLATE - MENUITEM "BMP Save Path", IDM_BMP_PATH - MENUITEM "Enable Info Log", IDM_INFO_LOG - POPUP "Correct D2V" - BEGIN - MENUITEM "Disable", IDM_CFOT_DISABLE - MENUITEM "Enable", IDM_CFOT_ENABLE - END - END - POPUP "&Tools" - BEGIN - MENUITEM "Analyze Sync", IDM_ANALYZESYNC - MENUITEM "Fix D2V", IDM_FIX_D2V - MENUITEM "Parse D2V", IDM_PARSE_D2V - END - POPUP "&Help" - BEGIN - POPUP "Detected SIMD" - BEGIN - MENUITEM "MMX", IDM_MMX, INACTIVE - MENUITEM "SSE MMX", IDM_SSEMMX, INACTIVE - MENUITEM "SSE2", IDM_SSE2, INACTIVE - MENUITEM "SSE FPU", IDM_SSEFPU - MENUITEM "3D Now!", IDM_3DNOW - END - MENUITEM "VFAPI Plug-In", IDM_VFAPI, INACTIVE - MENUITEM SEPARATOR - MENUITEM "About DGIndex", IDM_ABOUT - MENUITEM "DGMPGDec Quick Start Guide", IDM_QUICK_START - MENUITEM "DGIndex User Manual", IDM_DGINDEX_MANUAL - MENUITEM "DGDecode User Manual", IDM_DGDECODE_MANUAL - MENUITEM SEPARATOR - MENUITEM "jackei's Web Site", IDM_JACKEI - MENUITEM "neuron2's Web Site", IDM_NEURON2 - END -END - - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_MOVIE ICON DISCARDABLE "movie.ico" -IDI_SMALL ICON DISCARDABLE "movie.ico" - -#ifndef _MAC -///////////////////////////////////////////////////////////////////////////// -// -// Version -// - -1 VERSIONINFO - FILEVERSION 1,5,8,0 - PRODUCTVERSION 1,5,8,0 - FILEFLAGSMASK 0x0L -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x0L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "040904b0" - BEGIN - VALUE "Comments", "DGIndex is the indexing component of DGMPGDec, an MPEG decoding and frame serving utility.\0" - VALUE "CompanyName", "Freeware licensed under GPL\0" - VALUE "LegalCopyright", "Copyright (C) 2001-2010 Donald A. Graft\0" - VALUE "OriginalFilename", "DGIndex.exe\0" -#ifdef DGMPGDEC_GIT_VERSION - VALUE "FileVersion", DGMPGDEC_GIT_VERSION "\0" -#else - VALUE "FileVersion", "1.5.8\0" -#endif - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x409, 1200 - END -END - -#endif // !_MAC - - -///////////////////////////////////////////////////////////////////////////// -// -// Accelerator -// - -IDR_ACCELERATOR ACCELERATORS MOVEABLE PURE -BEGIN - "<", ID_LEFT_ARROW, ASCII, NOINVERT - ">", ID_RIGHT_ARROW, ASCII, NOINVERT - "@", ID_TRACKBAR, ASCII, NOINVERT - "O", IDM_OPEN, VIRTKEY, CONTROL, NOINVERT - "S", IDM_SAVE_D2V, VIRTKEY, CONTROL, NOINVERT - VK_ESCAPE, IDM_STOP, VIRTKEY, NOINVERT - VK_F2, IDM_OPEN, VIRTKEY, NOINVERT - VK_F3, IDM_CLOSE, VIRTKEY, NOINVERT - VK_F4, IDM_SAVE_D2V, VIRTKEY, NOINVERT - VK_F5, IDM_PREVIEW, VIRTKEY, NOINVERT - VK_F6, IDM_PLAY, VIRTKEY, NOINVERT - VK_F7, IDM_BMP, VIRTKEY, NOINVERT - VK_F8, IDM_COPYFRAMETOCLIPBOARD, VIRTKEY, NOINVERT - VK_F9, IDM_PRESCALE, VIRTKEY, NOINVERT - VK_SPACE, IDM_PAUSE, VIRTKEY, NOINVERT - "[", ID_LEFT_BUTTON, ASCII, NOINVERT - "]", ID_RIGHT_BUTTON, ASCII, NOINVERT -END - - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE DISCARDABLE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE DISCARDABLE -BEGIN - "#include ""resource.h""\r\n" - "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" - "#include ""windows.h""\r\n" - "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" - "\0" -END - -3 TEXTINCLUDE DISCARDABLE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO DISCARDABLE -BEGIN - IDD_SELECT_TRACKS, DIALOG - BEGIN - RIGHTMARGIN, 209 - END -END -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// String Table -// - -STRINGTABLE DISCARDABLE -BEGIN - IDC_GUI "DGIndex" -END - -#endif // English (U.S.) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED diff --git a/src/dgindex/idctfpu.cpp b/src/dgindex/idctfpu.cpp deleted file mode 100644 index a1d50a4..0000000 --- a/src/dgindex/idctfpu.cpp +++ /dev/null @@ -1,450 +0,0 @@ -/* idct.c, inverse fast discrete cosine transform */ - - -/*************************************************************/ -/* inverse two dimensional DCT, Chen-Wang algorithm */ -/* (cf. IEEE ASSP-32, pp. 803-816, Aug. 1984) */ -/* */ -/* floating point conversion by Miha Peternel */ -/* x87 hand-optimized assembly by Miha Peternel */ -/* 27.11. - 11.12.2000 */ -/* */ -/* You are free to use this code in your project if: */ -/* - no changes are made to this message */ -/* - any changes to this code are publicly available */ -/* - your project documentation contains the following text: */ -/* "This software contains fast high-quality IDCT decoder */ -/* by Miha Peternel." */ -/* */ -/*************************************************************/ - - -///////////////////////////////////////////////////// -// -// TODO: -// - loops can be easily vectorized for SIMD -// -///////////////////////////////////////////////////// - -#include -#define PI 3.1415926535897932384626433832795 - -#define FLOAT double - -const static double RC = 1.0*1024*1024*1024*1024*256*16 + 1024; // magic + clip center - -static FLOAT W1; // /* sqrt(2)*cos(1*pi/16) */ -static FLOAT W2; // /* sqrt(2)*cos(2*pi/16) */ -static FLOAT W5; // /* sqrt(2)*cos(5*pi/16) */ - -static FLOAT W1_8; -static FLOAT W2_8; -static FLOAT W5_8; - -static FLOAT W7; // /* sqrt(2)*cos(7*pi/16) */ -static FLOAT W1mW7; // W1-W7 -static FLOAT W1pW7; // W1+W7 - -static FLOAT W3; // /* sqrt(2)*cos(3*pi/16) */ -static FLOAT W3mW5; // W3-W5 -static FLOAT W3pW5; // W3+W5 - -static FLOAT W6; // /* sqrt(2)*cos(6*pi/16) */ -static FLOAT W2mW6; // W2-W6 -static FLOAT W2pW6; // W2+W6 - -static FLOAT S2; // 1/sqrt(2) -static FLOAT D8 = 1.0/8; - -static FLOAT W7_8; -static FLOAT W1mW7_8; -static FLOAT W1pW7_8; - -static FLOAT W3_8; -static FLOAT W3mW5_8; -static FLOAT W3pW5_8; - -static FLOAT W6_8; -static FLOAT W2mW6_8; -static FLOAT W2pW6_8; - -/* private data */ -static short iclip[1024+1024]; /* clipping table */ - -void Initialize_FPU_IDCT() -{ - int i; - - S2 = sqrt(0.5); // 1.0/sqrt(2); - - W1 = sqrt(2.0)*cos(PI*(1.0/16)); - W1_8 = W1/8; - W2 = sqrt(2.0)*cos(PI*(2.0/16)); - W2_8 = W2/8; - W3 = sqrt(2.0)*cos(PI*(3.0/16)); - W3_8 = W3/8; - W5 = sqrt(2.0)*cos(PI*(5.0/16)); - W5_8 = W5/8; - W6 = sqrt(2.0)*cos(PI*(6.0/16)); - W6_8 = W6/8; - W7 = sqrt(2.0)*cos(PI*(7.0/16)); - W7_8 = W7/8; - - W1mW7 = W1-W7; W1mW7_8 = W1mW7/8; - W1pW7 = W1+W7; W1pW7_8 = W1pW7/8; - W3mW5 = W3-W5; W3mW5_8 = W3mW5/8; - W3pW5 = W3+W5; W3pW5_8 = W3pW5/8; - W2mW6 = W2-W6; W2mW6_8 = W2mW6/8; - W2pW6 = W2+W6; W2pW6_8 = W2pW6/8; - - for (i= -1024; i<1024; i++) - iclip[i+1024] = (i<-256) ? -256 : ((i>255) ? 255 : i); -} - -void FPU_IDCT(short *block) -{ - int *b = (int *) block; - if( b[0]==0 && (b[31]==0x10000 || b[31]==0) ) - { - if( b[ 1]|b[ 2]|b[ 3]|b[ 4]|b[ 5] ) - goto normal; - if( b[ 6]|b[ 7]|b[ 8]|b[ 9]|b[10] ) - goto normal; - if( b[11]|b[12]|b[13]|b[14]|b[15] ) - goto normal; - if( b[16]|b[17]|b[18]|b[19]|b[20] ) - goto normal; - if( b[21]|b[22]|b[23]|b[24]|b[25] ) - goto normal; - if( b[26]|b[27]|b[28]|b[29]|b[30] ) - goto normal; - b[31]=0; - ////empty++; - return; - } -normal: - -#define tmp ebx -#define tmp1 ebx-1*8 -#define tmp2 ebx-2*8 -#define tmp3 ebx-3*8 -#define int0 ebx-3*8-1*4 -#define int1 ebx-3*8-2*4 -#define int2 ebx-3*8-3*4 -#define int3 ebx-3*8-4*4 -#define int4 ebx-3*8-5*4 -#define int5 ebx-3*8-6*4 -#define int6 ebx-3*8-7*4 -#define int7 ebx-3*8-8*4 -#define SIZE 8*8*8+3*8+8*4+16 // locals + 16-byte alignment area - __asm - { - lea ebx,[esp-8*8*8] - sub esp,SIZE - and ebx,-16 // force 16-byte alignment of locals - -// rows - mov esi,[block] - lea edi,[tmp] - mov ecx,8 - - align 16 -Lrows: - movsx eax,word ptr [esi+2] - or eax, [esi+4] - or eax, [esi+8] - or eax, [esi+12] - jnz L1 - - fild word ptr [esi+0*2] - fst qword ptr [edi+7*8] - fst qword ptr [edi+6*8] - fst qword ptr [edi+5*8] - fst qword ptr [edi+4*8] - fst qword ptr [edi+3*8] - fst qword ptr [edi+2*8] - fst qword ptr [edi+1*8] - fstp qword ptr [edi+0*8] - jmp L2 - - align 16 - L1: - - fild word ptr [esi+7*2] - fld st(0) - fild word ptr [esi+1*2] - fadd st(1),st(0) - fld qword ptr [W7] - fxch st(1) - fmul qword ptr [W1mW7] - fxch st(1) - fmulp st(2),st(0) - fadd st(0),st(1) - fstp qword ptr [tmp1] - fild word ptr [esi+3*2] - fld st(0) - fxch st(3) - fmul qword ptr [W1pW7] - fild word ptr [esi+5*2] - fadd st(4),st(0) - fmul qword ptr [W3mW5] - fxch st(1) - fsubp st(3),st(0)//fsubrp - fld qword ptr [W3] - fmulp st(4),st(0) - fsubr st(0),st(3) - fstp qword ptr [tmp2] - fmul qword ptr [W3pW5] - fsubp st(2),st(0)//fsubrp - fxch st(1) - fstp qword ptr [tmp3] - fild word ptr [esi+0*2] - fild word ptr [esi+4*2] - fild word ptr [esi+2*2] - fld st(0) - fmul qword ptr [W2mW6] - fld st(3) - fild word ptr [esi+6*2] - fxch st(5) - fsub st(0),st(4) - fxch st(3) - fadd st(0),st(5) - fxch st(1) - faddp st(4),st(0) - fld qword ptr [W6] - fmulp st(1),st(0) - fxch st(4) - fmul qword ptr [W2pW6] - fld qword ptr [tmp1] - fsub qword ptr [tmp2] - fld st(5) - fxch st(3) - faddp st(6),st(0) - fld qword ptr [tmp1] - fxch st(1) - fstp qword ptr [tmp1] - fld st(6) - fadd qword ptr [tmp3] - fxch st(1) - fadd qword ptr [tmp2] - fxch st(7) - fsub qword ptr [tmp3] - fxch st(1) - fstp qword ptr [tmp2] - fld st(4) - fxch st(3) - fsubrp st(2),st(0)//fsubp - fxch st(4) - fsub st(0),st(5) - fxch st(2) - faddp st(5),st(0) - fld st(2) - fsub st(0),st(1) - fxch st(5) - fstp qword ptr [tmp3] - fld qword ptr [tmp1] - fld qword ptr [S2] - fxch st(4) - faddp st(2),st(0) - fld st(3) - fxch st(1) - fadd st(0),st(5) - fmulp st(1),st(0) - - fld qword ptr [tmp3] - fadd st(0),st(7) - fxch st(5) - fsubr qword ptr [tmp1] - fxch st(5) - fstp qword ptr [edi+0*8] - fxch st(6) - fsubr qword ptr [tmp3] - fld st(2) - fxch st(1) - fstp qword ptr [edi+7*8] - fadd qword ptr [tmp2] - fxch st(3) - fmulp st(4),st(0) - fxch st(2) - fstp qword ptr [edi+3*8] - fld st(1) - fadd st(0),st(5) - fxch st(1) - fsub qword ptr [tmp2] - fxch st(2) - fsubrp st(5),st(0)//fsubp - fstp qword ptr [edi+1*8] - fld st(2) - fxch st(1) - fstp qword ptr [edi+4*8] - fxch st(2) - fsub st(0),st(1) - fxch st(2) - faddp st(1),st(0) - fxch st(2) - fstp qword ptr [edi+6*8] - fstp qword ptr [edi+5*8] - fstp qword ptr [edi+2*8] - L2: - add esi,8*2 - add edi,8*8 - dec ecx - jnz Lrows - -// columns - lea esi,[tmp] - mov edi,[block] - lea edx,[iclip+1024*2] - mov ecx,8 - - align 16 -Lcols: - fld qword ptr [esi+7*8*8] - fld st(0) - fld qword ptr [esi+1*8*8] - fadd st(1),st(0) - fld qword ptr [W7_8] - fxch st(1) - fmul qword ptr [W1mW7_8] - fxch st(1) - fmulp st(2),st(0) - fadd st(0),st(1) - fstp qword ptr [tmp2] - fld qword ptr [esi+3*8*8] - fld st(0) - fxch st(3) - fmul qword ptr [W1pW7_8] - fld qword ptr [esi+5*8*8] - fadd st(4),st(0) - fmul qword ptr [W3mW5_8] - fxch st(1) - fsubp st(3),st(0)//fsubrp - fld qword ptr [W3_8] - fmulp st(4),st(0) - fsubr st(0),st(3) - fstp qword ptr [tmp3] - fld qword ptr [D8] - fld qword ptr [esi+0*8*8] - fmul st(0),st(1) - fxch st(2) - fmul qword ptr [W3pW5_8] - fld qword ptr [esi+4*8*8] - fmulp st(2),st(0) - fld qword ptr [esi+6*8*8] - fld st(3) - fxch st(6) - fsubrp st(2),st(0)//fsubp - fld qword ptr [esi+2*8*8] - fld st(0) - fxch st(5) - fsub st(0),st(4) - fxch st(7) - faddp st(4),st(0) - fxch st(4) - fadd st(0),st(1) - fld qword ptr [W6_8] - fxch st(2) - fmul qword ptr [W2pW6_8] - fxch st(2) - fmulp st(1),st(0) - fxch st(4) - fmul qword ptr [W2mW6_8] - fld qword ptr [tmp2] - fsub qword ptr [tmp3] - fxch st(2) - fsubr st(0),st(5) - fxch st(1) - faddp st(5),st(0) - fld qword ptr [tmp2] - fxch st(2) - fstp qword ptr [tmp2] - fld st(5) - fxch st(2) - fadd qword ptr [tmp3] - fxch st(6) - fsub st(0),st(3) - fxch st(2) - faddp st(3),st(0) - fld st(3) - fsub st(0),st(5) - fxch st(3) - fstp qword ptr [tmp3] - fxch st(3) - faddp st(4),st(0) - fld st(5) - fld qword ptr [tmp2] - fxch st(7) - fsub st(0),st(4) - fxch st(7) - fadd st(0),st(2) - fxch st(1) - faddp st(4),st(0) - fld qword ptr [S2] - fmul st(1),st(0) - fxch st(1) - fstp qword ptr [tmp1] - fld st(4) - fadd st(0),st(6) - fxch st(2) - fsubr qword ptr [tmp2] - fxch st(5) - fsubrp st(6),st(0)//fsubp - fxch st(1) - fistp dword ptr [int0] - fxch st(4) - mov eax,[int0] - movsx eax,word ptr [edx+2*eax] - mov [edi+0*8*2],ax - fistp dword ptr [int7] - mov eax,[int7] - fld st(0) - movsx eax,word ptr [edx+2*eax] - mov [edi+7*8*2],ax - fadd qword ptr [tmp3] - fistp dword ptr [int3] - mov eax,[int3] - movsx eax,word ptr [edx+2*eax] - mov [edi+3*8*2],ax - fsub qword ptr [tmp3] - fld st(1) - fxch st(1) - fistp dword ptr [int4] - mov eax,[int4] - movsx eax,word ptr [edx+2*eax] - mov [edi+4*8*2],ax - fadd qword ptr [tmp1] - fxch st(3) - fmulp st(2),st(0) - fxch st(2) - fistp dword ptr [int1] - fxch st(1) - mov eax,[int1] - movsx eax,word ptr [edx+2*eax] - mov [edi+1*8*2],ax - fsub qword ptr [tmp1] - fld st(2) - fsub st(0),st(2) - fxch st(1) - fistp dword ptr [int6] - fxch st(2) - mov eax,[int6] - faddp st(1),st(0) - movsx eax,word ptr [edx+2*eax] - mov [edi+6*8*2],ax - fistp dword ptr [int2] - mov eax,[int2] - movsx eax,word ptr [edx+2*eax] - mov [edi+2*8*2],ax - fistp dword ptr [int5] - mov eax,[int5] - movsx eax,word ptr [edx+2*eax] - mov [edi+5*8*2],ax - - add esi,8 - add edi,2 - dec ecx - jnz Lcols - - add esp,SIZE - } -} diff --git a/src/dgindex/idctmmx.asm b/src/dgindex/idctmmx.asm deleted file mode 100644 index 174fa0f..0000000 --- a/src/dgindex/idctmmx.asm +++ /dev/null @@ -1,1164 +0,0 @@ -; -; idct8x8_xmm.asm -; -; Originally provided by Intel at AP-922 -; http://developer.intel.com/vtune/cbts/strmsimd/922down.htm -; (See more app notes at http://developer.intel.com/vtune/cbts/strmsimd/appnotes.htm) -; but in a limited edition. -; New macro implements a column part for precise iDCT -; The routine precision now satisfies IEEE standard 1180-1990. -; -; Copyright (c) 2000-2001 Peter Gubanov -; Rounding trick Copyright (c) 2000 Michel Lespinasse -; -; http://www.elecard.com/peter/idct.html -; http://www.linuxvideo.org/mpeg2dec/ -; - -; -; SSE2 code by Dmitry Rozhdestvensky -; -;============================================================================= -; -; These examples contain code fragments for first stage iDCT 8x8 -; (for rows) and first stage DCT 8x8 (for columns) -; -;============================================================================= -; - -mword typedef qword -mptr equ mword ptr - -BITS_INV_ACC = 5 ; 4 or 5 for IEEE -SHIFT_INV_ROW = 16 - BITS_INV_ACC -SHIFT_INV_COL = 1 + BITS_INV_ACC -RND_INV_ROW = 1024 * (6 - BITS_INV_ACC) ; 1 << (SHIFT_INV_ROW-1) -RND_INV_COL = 16 * (BITS_INV_ACC - 3) ; 1 << (SHIFT_INV_COL-1) -RND_INV_CORR = RND_INV_COL - 1 ; correction -1.0 and round - -BITS_FRW_ACC = 3 ; 2 or 3 for accuracy -SHIFT_FRW_COL = BITS_FRW_ACC -SHIFT_FRW_ROW = BITS_FRW_ACC + 17 -RND_FRW_ROW = 262144 * (BITS_FRW_ACC - 1) ; 1 << (SHIFT_FRW_ROW-1) - -_MMX = 1 - -.nolist - -.586 - -if @version GE 612 -.mmx -mmword TEXTEQU -else -include IAMMX.INC -endif - -if @version GE 614 -.xmm -mm2word TEXTEQU ; needed for Streaming SIMD Extensions macros -else -include iaxmm.inc ; Streaming SIMD Extensions Emulator Macros -endif - - .list - .model flat - -_DATA SEGMENT PARA PUBLIC USE32 'DATA' - -one_corr sword 1, 1, 1, 1 -round_inv_row dword RND_INV_ROW, RND_INV_ROW -round_inv_col sword RND_INV_COL, RND_INV_COL, RND_INV_COL, RND_INV_COL -round_inv_corr sword RND_INV_CORR, RND_INV_CORR, RND_INV_CORR, RND_INV_CORR -round_frw_row dword RND_FRW_ROW, RND_FRW_ROW - tg_1_16 sword 13036, 13036, 13036, 13036 ; tg * (2<<16) + 0.5 - tg_2_16 sword 27146, 27146, 27146, 27146 ; tg * (2<<16) + 0.5 - tg_3_16 sword -21746, -21746, -21746, -21746 ; tg * (2<<16) + 0.5 - cos_4_16 sword -19195, -19195, -19195, -19195 ; cos * (2<<16) + 0.5 -ocos_4_16 sword 23170, 23170, 23170, 23170 ; cos * (2<<15) + 0.5 - - otg_3_16 sword 21895, 21895, 21895, 21895 ; tg * (2<<16) + 0.5 - -; assume SHIFT_INV_ROW == 12 -;rounder_0 dword 65536, 65536 -;rounder_4 dword 0, 0 -;rounder_1 dword 7195, 7195 -;rounder_7 dword 1024, 1024 -;rounder_2 dword 4520, 4520 -;rounder_6 dword 1024, 1024 -;rounder_3 dword 2407, 2407 -;rounder_5 dword 240, 240 - -; assume SHIFT_INV_ROW == 11 -rounder_0 dword 65536, 65536 -rounder_4 dword 0, 0 -rounder_1 dword 3597, 3597 -rounder_7 dword 512, 512 -rounder_2 dword 2260, 2260 -rounder_6 dword 512, 512 -rounder_3 dword 1203, 1203 -rounder_5 dword 120, 120 - -;============================================================================= -; -; The first stage iDCT 8x8 - inverse DCTs of rows -; -;----------------------------------------------------------------------------- -; The 8-point inverse DCT direct algorithm -;----------------------------------------------------------------------------- -; -; static const short w[32] = { -; FIX(cos_4_16), FIX(cos_2_16), FIX(cos_4_16), FIX(cos_6_16), -; FIX(cos_4_16), FIX(cos_6_16), -FIX(cos_4_16), -FIX(cos_2_16), -; FIX(cos_4_16), -FIX(cos_6_16), -FIX(cos_4_16), FIX(cos_2_16), -; FIX(cos_4_16), -FIX(cos_2_16), FIX(cos_4_16), -FIX(cos_6_16), -; FIX(cos_1_16), FIX(cos_3_16), FIX(cos_5_16), FIX(cos_7_16), -; FIX(cos_3_16), -FIX(cos_7_16), -FIX(cos_1_16), -FIX(cos_5_16), -; FIX(cos_5_16), -FIX(cos_1_16), FIX(cos_7_16), FIX(cos_3_16), -; FIX(cos_7_16), -FIX(cos_5_16), FIX(cos_3_16), -FIX(cos_1_16) }; -; -; #define DCT_8_INV_ROW(x, y) -; { -; int a0, a1, a2, a3, b0, b1, b2, b3; -; -; a0 =x[0]*w[0]+x[2]*w[1]+x[4]*w[2]+x[6]*w[3]; -; a1 =x[0]*w[4]+x[2]*w[5]+x[4]*w[6]+x[6]*w[7]; -; a2 = x[0] * w[ 8] + x[2] * w[ 9] + x[4] * w[10] + x[6] * w[11]; -; a3 = x[0] * w[12] + x[2] * w[13] + x[4] * w[14] + x[6] * w[15]; -; b0 = x[1] * w[16] + x[3] * w[17] + x[5] * w[18] + x[7] * w[19]; -; b1 = x[1] * w[20] + x[3] * w[21] + x[5] * w[22] + x[7] * w[23]; -; b2 = x[1] * w[24] + x[3] * w[25] + x[5] * w[26] + x[7] * w[27]; -; b3 = x[1] * w[28] + x[3] * w[29] + x[5] * w[30] + x[7] * w[31]; -; -; y[0] = SHIFT_ROUND ( a0 + b0 ); -; y[1] = SHIFT_ROUND ( a1 + b1 ); -; y[2] = SHIFT_ROUND ( a2 + b2 ); -; y[3] = SHIFT_ROUND ( a3 + b3 ); -; y[4] = SHIFT_ROUND ( a3 - b3 ); -; y[5] = SHIFT_ROUND ( a2 - b2 ); -; y[6] = SHIFT_ROUND ( a1 - b1 ); -; y[7] = SHIFT_ROUND ( a0 - b0 ); -; } -; -;----------------------------------------------------------------------------- -; -; In this implementation the outputs of the iDCT-1D are multiplied -; for rows 0,4 - by cos_4_16, -; for rows 1,7 - by cos_1_16, -; for rows 2,6 - by cos_2_16, -; for rows 3,5 - by cos_3_16 -; and are shifted to the left for better accuracy -; -; For the constants used, -; FIX(float_const) = (short) (float_const * (1<<15) + 0.5) -; -;============================================================================= - -;============================================================================= -; MMX code -;============================================================================= - -; Table for rows 0,4 - constants are multiplied by cos_4_16 - align 16 -tab_i_04 sword 16384, 16384, 16384, -16384 ; movq-> w06 w04 w02 w00 - sword 21407, 8867, 8867, -21407 ; w07 w05 w03 w01 - sword 16384, -16384, 16384, 16384 ; w14 w12 w10 w08 - sword -8867, 21407, -21407, -8867 ; w15 w13 w11 w09 - sword 22725, 12873, 19266, -22725 ; w22 w20 w18 w16 - sword 19266, 4520, -4520, -12873 ; w23 w21 w19 w17 - sword 12873, 4520, 4520, 19266 ; w30 w28 w26 w24 - sword -22725, 19266, -12873, -22725 ; w31 w29 w27 w25 - -; Table for rows 1,7 - constants are multiplied by cos_1_16 - -tab_i_17 sword 22725, 22725, 22725, -22725 ; movq-> w06 w04 w02 w00 - sword 29692, 12299, 12299, -29692 ; w07 w05 w03 w01 - sword 22725, -22725, 22725, 22725 ; w14 w12 w10 w08 - sword -12299, 29692, -29692, -12299 ; w15 w13 w11 w09 - sword 31521, 17855, 26722, -31521 ; w22 w20 w18 w16 - sword 26722, 6270, -6270, -17855 ; w23 w21 w19 w17 - sword 17855, 6270, 6270, 26722 ; w30 w28 w26 w24 - sword -31521, 26722, -17855, -31521 ; w31 w29 w27 w25 - -; Table for rows 2,6 - constants are multiplied by cos_2_16 - -tab_i_26 sword 21407, 21407, 21407, -21407 ; movq-> w06 w04 w02 w00 - sword 27969, 11585, 11585, -27969 ; w07 w05 w03 w01 - sword 21407, -21407, 21407, 21407 ; w14 w12 w10 w08 - sword -11585, 27969, -27969, -11585 ; w15 w13 w11 w09 - sword 29692, 16819, 25172, -29692 ; w22 w20 w18 w16 - sword 25172, 5906, -5906, -16819 ; w23 w21 w19 w17 - sword 16819, 5906, 5906, 25172 ; w30 w28 w26 w24 - sword -29692, 25172, -16819, -29692 ; w31 w29 w27 w25 - -; Table for rows 3,5 - constants are multiplied by cos_3_16 - -tab_i_35 sword 19266, 19266, 19266, -19266 ; movq-> w06 w04 w02 w00 - sword 25172, 10426, 10426, -25172 ; w07 w05 w03 w01 - sword 19266, -19266, 19266, 19266 ; w14 w12 w10 w08 - sword -10426, 25172, -25172, -10426 ; w15 w13 w11 w09 - sword 26722, 15137, 22654, -26722 ; w22 w20 w18 w16 - sword 22654, 5315, -5315, -15137 ; w23 w21 w19 w17 - sword 15137, 5315, 5315, 22654 ; w30 w28 w26 w24 - sword -26722, 22654, -15137, -26722 ; w31 w29 w27 w25 - -;----------------------------------------------------------------------------- - -DCT_8_INV_ROW_1 MACRO INP:REQ, OUT:REQ, TABLE:REQ, ROUNDER:REQ - - movq mm0, mptr [INP] ; 0 ; x3 x2 x1 x0 - - movq mm1, mptr [INP+8] ; 1 ; x7 x6 x5 x4 - movq mm2, mm0 ; 2 ; x3 x2 x1 x0 - - movq mm3, mptr [TABLE] ; 3 ; w06 w04 w02 w00 - punpcklwd mm0, mm1 ; x5 x1 x4 x0 - - movq mm5, mm0 ; 5 ; x5 x1 x4 x0 - punpckldq mm0, mm0 ; x4 x0 x4 x0 - - movq mm4, mptr [TABLE+8] ; 4 ; w07 w05 w03 w01 - punpckhwd mm2, mm1 ; 1 ; x7 x3 x6 x2 - - pmaddwd mm3, mm0 ; x4*w06+x0*w04 x4*w02+x0*w00 - movq mm6, mm2 ; 6 ; x7 x3 x6 x2 - - movq mm1, mptr [TABLE+32] ; 1 ; w22 w20 w18 w16 - punpckldq mm2, mm2 ; x6 x2 x6 x2 - - pmaddwd mm4, mm2 ; x6*w07+x2*w05 x6*w03+x2*w01 - punpckhdq mm5, mm5 ; x5 x1 x5 x1 - - pmaddwd mm0, mptr [TABLE+16] ; x4*w14+x0*w12 x4*w10+x0*w08 - punpckhdq mm6, mm6 ; x7 x3 x7 x3 - - movq mm7, mptr [TABLE+40] ; 7 ; w23 w21 w19 w17 - pmaddwd mm1, mm5 ; x5*w22+x1*w20 x5*w18+x1*w16 - - paddd mm3, mptr [ROUNDER] ; +rounder - pmaddwd mm7, mm6 ; x7*w23+x3*w21 x7*w19+x3*w17 - - pmaddwd mm2, mptr [TABLE+24] ; x6*w15+x2*w13 x6*w11+x2*w09 - paddd mm3, mm4 ; 4 ; a1=sum(even1) a0=sum(even0) - - pmaddwd mm5, mptr [TABLE+48] ; x5*w30+x1*w28 x5*w26+x1*w24 - movq mm4, mm3 ; 4 ; a1 a0 - - pmaddwd mm6, mptr [TABLE+56] ; x7*w31+x3*w29 x7*w27+x3*w25 - paddd mm1, mm7 ; 7 ; b1=sum(odd1) b0=sum(odd0) - - paddd mm0, mptr [ROUNDER] ; +rounder - psubd mm3, mm1 ; a1-b1 a0-b0 - - psrad mm3, SHIFT_INV_ROW ; y6=a1-b1 y7=a0-b0 - paddd mm1, mm4 ; 4 ; a1+b1 a0+b0 - - paddd mm0, mm2 ; 2 ; a3=sum(even3) a2=sum(even2) - psrad mm1, SHIFT_INV_ROW ; y1=a1+b1 y0=a0+b0 - - paddd mm5, mm6 ; 6 ; b3=sum(odd3) b2=sum(odd2) - movq mm4, mm0 ; 4 ; a3 a2 - - paddd mm0, mm5 ; a3+b3 a2+b2 - psubd mm4, mm5 ; 5 ; a3-b3 a2-b2 - - psrad mm0, SHIFT_INV_ROW ; y3=a3+b3 y2=a2+b2 - psrad mm4, SHIFT_INV_ROW ; y4=a3-b3 y5=a2-b2 - - packssdw mm1, mm0 ; 0 ; y3 y2 y1 y0 - packssdw mm4, mm3 ; 3 ; y6 y7 y4 y5 - - movq mm7, mm4 ; 7 ; y6 y7 y4 y5 - psrld mm4, 16 ; 0 y6 0 y4 - - pslld mm7, 16 ; y7 0 y5 0 - movq mptr [OUT], mm1 ; 1 ; save y3 y2 y1 y0 - - por mm7, mm4 ; 4 ; y7 y6 y5 y4 - movq mptr [OUT+8], mm7 ; 7 ; save y7 y6 y5 y4 -ENDM - -;============================================================================= -; code for Pentium III -;============================================================================= - -; Table for rows 0,4 - constants are multiplied by cos_4_16 - -tab_i_04_s sword 16384, 21407, 16384, 8867 ; movq-> w05 w04 w01 w00 - sword 16384, 8867, -16384, -21407 ; w07 w06 w03 w02 - sword 16384, -8867, 16384, -21407 ; w13 w12 w09 w08 - sword -16384, 21407, 16384, -8867 ; w15 w14 w11 w10 - sword 22725, 19266, 19266, -4520 ; w21 w20 w17 w16 - sword 12873, 4520, -22725, -12873 ; w23 w22 w19 w18 - sword 12873, -22725, 4520, -12873 ; w29 w28 w25 w24 - sword 4520, 19266, 19266, -22725 ; w31 w30 w27 w26 - -; Table for rows 1,7 - constants are multiplied by cos_1_16 - -tab_i_17_s sword 22725, 29692, 22725, 12299 ; movq-> w05 w04 w01 w00 - sword 22725, 12299, -22725, -29692 ; w07 w06 w03 w02 - sword 22725, -12299, 22725, -29692 ; w13 w12 w09 w08 - sword -22725, 29692, 22725, -12299 ; w15 w14 w11 w10 - sword 31521, 26722, 26722, -6270 ; w21 w20 w17 w16 - sword 17855, 6270, -31521, -17855 ; w23 w22 w19 w18 - sword 17855, -31521, 6270, -17855 ; w29 w28 w25 w24 - sword 6270, 26722, 26722, -31521 ; w31 w30 w27 w26 - -; Table for rows 2,6 - constants are multiplied by cos_2_16 - -tab_i_26_s sword 21407, 27969, 21407, 11585 ; movq-> w05 w04 w01 w00 - sword 21407, 11585, -21407, -27969 ; w07 w06 w03 w02 - sword 21407, -11585, 21407, -27969 ; w13 w12 w09 w08 - sword -21407, 27969, 21407, -11585 ; w15 w14 w11 w10 - sword 29692, 25172, 25172, -5906 ; w21 w20 w17 w16 - sword 16819, 5906, -29692, -16819 ; w23 w22 w19 w18 - sword 16819, -29692, 5906, -16819 ; w29 w28 w25 w24 - sword 5906, 25172, 25172, -29692 ; w31 w30 w27 w26 - -; Table for rows 3,5 - constants are multiplied by cos_3_16 - -tab_i_35_s sword 19266, 25172, 19266, 10426 ; movq-> w05 w04 w01 w00 - sword 19266, 10426, -19266, -25172 ; w07 w06 w03 w02 - sword 19266, -10426, 19266, -25172 ; w13 w12 w09 w08 - sword -19266, 25172, 19266, -10426 ; w15 w14 w11 w10 - sword 26722, 22654, 22654, -5315 ; w21 w20 w17 w16 - sword 15137, 5315, -26722, -15137 ; w23 w22 w19 w18 - sword 15137, -26722, 5315, -15137 ; w29 w28 w25 w24 - sword 5315, 22654, 22654, -26722 ; w31 w30 w27 w26 - -;----------------------------------------------------------------------------- - -DCT_8_INV_ROW_1_s MACRO INP:REQ, OUT:REQ, TABLE:REQ, ROUNDER:REQ - - movq mm0, mptr [INP] ; 0 ; x3 x2 x1 x0 - - movq mm1, mptr [INP+8] ; 1 ; x7 x6 x5 x4 - movq mm2, mm0 ; 2 ; x3 x2 x1 x0 - - movq mm3, mptr [TABLE] ; 3 ; w05 w04 w01 w00 - pshufw mm0, mm0, 10001000b ; x2 x0 x2 x0 - - movq mm4, mptr [TABLE+8] ; 4 ; w07 w06 w03 w02 - movq mm5, mm1 ; 5 ; x7 x6 x5 x4 - pmaddwd mm3, mm0 ; x2*w05+x0*w04 x2*w01+x0*w00 - - movq mm6, mptr [TABLE+32] ; 6 ; w21 w20 w17 w16 - pshufw mm1, mm1, 10001000b ; x6 x4 x6 x4 - pmaddwd mm4, mm1 ; x6*w07+x4*w06 x6*w03+x4*w02 - - movq mm7, mptr [TABLE+40] ; 7 ; w23 w22 w19 w18 - pshufw mm2, mm2, 11011101b ; x3 x1 x3 x1 - pmaddwd mm6, mm2 ; x3*w21+x1*w20 x3*w17+x1*w16 - - pshufw mm5, mm5, 11011101b ; x7 x5 x7 x5 - pmaddwd mm7, mm5 ; x7*w23+x5*w22 x7*w19+x5*w18 - - paddd mm3, mptr [ROUNDER] ; +rounder - - pmaddwd mm0, mptr [TABLE+16] ; x2*w13+x0*w12 x2*w09+x0*w08 - paddd mm3, mm4 ; 4 ; a1=sum(even1) a0=sum(even0) - - pmaddwd mm1, mptr [TABLE+24] ; x6*w15+x4*w14 x6*w11+x4*w10 - movq mm4, mm3 ; 4 ; a1 a0 - - pmaddwd mm2, mptr [TABLE+48] ; x3*w29+x1*w28 x3*w25+x1*w24 - paddd mm6, mm7 ; 7 ; b1=sum(odd1) b0=sum(odd0) - - pmaddwd mm5, mptr [TABLE+56] ; x7*w31+x5*w30 x7*w27+x5*w26 - paddd mm3, mm6 ; a1+b1 a0+b0 - - paddd mm0, mptr [ROUNDER] ; +rounder - psrad mm3, SHIFT_INV_ROW ; y1=a1+b1 y0=a0+b0 - - paddd mm0, mm1 ; 1 ; a3=sum(even3) a2=sum(even2) - psubd mm4, mm6 ; 6 ; a1-b1 a0-b0 - - movq mm7, mm0 ; 7 ; a3 a2 - paddd mm2, mm5 ; 5 ; b3=sum(odd3) b2=sum(odd2) - - paddd mm0, mm2 ; a3+b3 a2+b2 - psrad mm4, SHIFT_INV_ROW ; y6=a1-b1 y7=a0-b0 - - psubd mm7, mm2 ; 2 ; a3-b3 a2-b2 - psrad mm0, SHIFT_INV_ROW ; y3=a3+b3 y2=a2+b2 - - psrad mm7, SHIFT_INV_ROW ; y4=a3-b3 y5=a2-b2 - - packssdw mm3, mm0 ; 0 ; y3 y2 y1 y0 - - packssdw mm7, mm4 ; 4 ; y6 y7 y4 y5 - - movq mptr [OUT], mm3 ; 3 ; save y3 y2 y1 y0 - pshufw mm7, mm7, 10110001b ; y7 y6 y5 y4 - - movq mptr [OUT+8], mm7 ; 7 ; save y7 y6 y5 y4 -ENDM - -;============================================================================= -; -;============================================================================= - -;============================================================================= -; -; The first stage DCT 8x8 - forward DCTs of columns -; -; The outputs are multiplied -; for rows 0,4 - on cos_4_16, -; for rows 1,7 - on cos_1_16, -; for rows 2,6 - on cos_2_16, -; for rows 3,5 - on cos_3_16 -; and are shifted to the left for rise of accuracy -; -;----------------------------------------------------------------------------- -; -; The 8-point scaled forward DCT algorithm (26a8m) -; -;----------------------------------------------------------------------------- -; -; #define DCT_8_FRW_COL(x, y) -;{ -; short t0, t1, t2, t3, t4, t5, t6, t7; -; short tp03, tm03, tp12, tm12, tp65, tm65; -; short tp465, tm465, tp765, tm765; -; -; t0 = LEFT_SHIFT ( x[0] + x[7] ); -; t1 = LEFT_SHIFT ( x[1] + x[6] ); -; t2 = LEFT_SHIFT ( x[2] + x[5] ); -; t3 = LEFT_SHIFT ( x[3] + x[4] ); -; t4 = LEFT_SHIFT ( x[3] - x[4] ); -; t5 = LEFT_SHIFT ( x[2] - x[5] ); -; t6 = LEFT_SHIFT ( x[1] - x[6] ); -; t7 = LEFT_SHIFT ( x[0] - x[7] ); -; -; tp03 = t0 + t3; -; tm03 = t0 - t3; -; tp12 = t1 + t2; -; tm12 = t1 - t2; -; -; y[0] = tp03 + tp12; -; y[4] = tp03 - tp12; -; -; y[2] = tm03 + tm12 * tg_2_16; -; y[6] = tm03 * tg_2_16 - tm12; -; -; tp65 =(t6 +t5 )*cos_4_16; -; tm65 =(t6 -t5 )*cos_4_16; -; -; tp765 = t7 + tp65; -; tm765 = t7 - tp65; -; tp465 = t4 + tm65; -; tm465 = t4 - tm65; -; -; y[1] = tp765 + tp465 * tg_1_16; -; y[7] = tp765 * tg_1_16 - tp465; -; y[5] = tm765 * tg_3_16 + tm465; -; y[3] = tm765 - tm465 * tg_3_16; -;} -; -;============================================================================= -DCT_8_FRW_COL_4 MACRO INP:REQ, OUT:REQ -LOCAL x0, x1, x2, x3, x4, x5, x6, x7 -LOCAL y0, y1, y2, y3, y4, y5, y6, y7 -x0 equ [INP + 0*16] -x1 equ [INP + 1*16] -x2 equ [INP + 2*16] -x3 equ [INP + 3*16] -x4 equ [INP + 4*16] -x5 equ [INP + 5*16] -x6 equ [INP + 6*16] -x7 equ [INP + 7*16] -y0 equ [OUT + 0*16] -y1 equ [OUT + 1*16] -y2 equ [OUT + 2*16] -y3 equ [OUT + 3*16] -y4 equ [OUT + 4*16] -y5 equ [OUT + 5*16] -y6 equ [OUT + 6*16] -y7 equ [OUT + 7*16] -movq mm0, x1 ; 0 ; x1 -movq mm1, x6 ; 1 ; x6 -movq mm2, mm0 ; 2 ; x1 -movq mm3, x2 ; 3 ; x2 -paddsw mm0, mm1 ; t1 = x[1] + x[6] -movq mm4, x5 ; 4 ; x5 -psllw mm0, SHIFT_FRW_COL ; t1 -movq mm5, x0 ; 5 ; x0 -paddsw mm4, mm3 ; t2 = x[2] + x[5] -paddsw mm5, x7 ; t0 = x[0] + x[7] -psllw mm4, SHIFT_FRW_COL ; t2 -movq mm6, mm0 ; 6 ; t1 -psubsw mm2, mm1 ; 1 ; t6 = x[1] - x[6] -movq mm1, mptr tg_2_16 ; 1 ; tg_2_16 -psubsw mm0, mm4 ; tm12 = t1 - t2 -movq mm7, x3 ; 7 ; x3 -pmulhw mm1, mm0 ; tm12*tg_2_16 -paddsw mm7, x4 ; t3 = x[3] + x[4] -psllw mm5, SHIFT_FRW_COL ; t0 -paddsw mm6, mm4 ; 4 ; tp12 = t1 + t2 -psllw mm7, SHIFT_FRW_COL ; t3 -movq mm4, mm5 ; 4 ; t0 -psubsw mm5, mm7 ; tm03 = t0 - t3 -paddsw mm1, mm5 ; y2 = tm03 + tm12*tg_2_16 -paddsw mm4, mm7 ; 7 ; tp03 = t0 + t3 -por mm1, mptr one_corr ; correction y2 +0.5 -psllw mm2, SHIFT_FRW_COL+1 ; t6 -pmulhw mm5, mptr tg_2_16 ; tm03*tg_2_16 -movq mm7, mm4 ; 7 ; tp03 -psubsw mm3, x5 ; t5 = x[2] - x[5] -psubsw mm4, mm6 ; y4 = tp03 - tp12 -movq y2, mm1 ; 1 ; save y2 -paddsw mm7, mm6 ; 6 ; y0 = tp03 + tp12 -movq mm1, x3 ; 1 ; x3 -psllw mm3, SHIFT_FRW_COL+1 ; t5 -psubsw mm1, x4 ; t4 = x[3] - x[4] -movq mm6, mm2 ; 6 ; t6 -movq y4, mm4 ; 4 ; save y4 -paddsw mm2, mm3 ; t6 + t5 -pmulhw mm2, mptr ocos_4_16 ; tp65 = (t6 + t5)*cos_4_16 -psubsw mm6, mm3 ; 3 ; t6 - t5 -pmulhw mm6, mptr ocos_4_16 ; tm65 = (t6 - t5)*cos_4_16 -psubsw mm5, mm0 ; 0 ; y6 = tm03*tg_2_16 - tm12 -por mm5, mptr one_corr ; correction y6 +0.5 -psllw mm1, SHIFT_FRW_COL ; t4 -por mm2, mptr one_corr ; correction tp65 +0.5 -movq mm4, mm1 ; 4 ; t4 -movq mm3, x0 ; 3 ; x0 -paddsw mm1, mm6 ; tp465 = t4 + tm65 -psubsw mm3, x7 ; t7 = x[0] - x[7] -psubsw mm4, mm6 ; 6 ; tm465 = t4 - tm65 -movq mm0, mptr tg_1_16 ; 0 ; tg_1_16 -psllw mm3, SHIFT_FRW_COL ; t7 -movq mm6, mptr tg_3_16 ; 6 ; tg_3_16 -pmulhw mm0, mm1 ; tp465*tg_1_16 -movq y0, mm7 ; 7 ; save y0 -pmulhw mm6, mm4 ; tm465*tg_3_16 -movq y6, mm5 ; 5 ; save y6 -movq mm7, mm3 ; 7 ; t7 -movq mm5, mptr tg_3_16 ; 5 ; tg_3_16 -psubsw mm7, mm2 ; tm765 = t7 - tp65 -paddsw mm3, mm2 ; 2 ; tp765 = t7 + tp65 -pmulhw mm5, mm7 ; tm765*tg_3_16 -paddsw mm0, mm3 ; y1 = tp765 + tp465*tg_1_16 -paddsw mm6, mm4 ; tm465*tg_3_16 -pmulhw mm3, mptr tg_1_16 ; tp765*tg_1_16 -por mm0, mptr one_corr ; correction y1 +0.5 -paddsw mm5, mm7 ; tm765*tg_3_16 -psubsw mm7, mm6 ; 6 ; y3 = tm765 - tm465*tg_3_16 -movq y1, mm0 ; 0 ; save y1 -paddsw mm5, mm4 ; 4 ; y5 = tm765*tg_3_16 + tm465 -movq y3, mm7 ; 7 ; save y3 -psubsw mm3, mm1 ; 1 ; y7 = tp765*tg_1_16 - tp465 -movq y5, mm5 ; 5 ; save y5 -movq y7, mm3 ; 3 ; save y7 -ENDM - -DCT_8_INV_COL_4 MACRO INP:REQ, OUT:REQ - movq mm0, mmword ptr tg_3_16 - - movq mm3, mmword ptr [INP+16*3] - movq mm1, mm0 ; tg_3_16 - - movq mm5, mmword ptr [INP+16*5] - pmulhw mm0, mm3 ; x3*(tg_3_16-1) - - movq mm4, mmword ptr tg_1_16 - pmulhw mm1, mm5 ; x5*(tg_3_16-1) - - movq mm7, mmword ptr [INP+16*7] - movq mm2, mm4 ; tg_1_16 - - movq mm6, mmword ptr [INP+16*1] - pmulhw mm4, mm7 ; x7*tg_1_16 - - paddsw mm0, mm3 ; x3*tg_3_16 - pmulhw mm2, mm6 ; x1*tg_1_16 - - paddsw mm1, mm3 ; x3+x5*(tg_3_16-1) - psubsw mm0, mm5 ; x3*tg_3_16-x5 = tm35 - - movq mm3, mmword ptr ocos_4_16 - paddsw mm1, mm5 ; x3+x5*tg_3_16 = tp35 - - paddsw mm4, mm6 ; x1+tg_1_16*x7 = tp17 - psubsw mm2, mm7 ; x1*tg_1_16-x7 = tm17 - - movq mm5, mm4 ; tp17 - movq mm6, mm2 ; tm17 - - paddsw mm5, mm1 ; tp17+tp35 = b0 - psubsw mm6, mm0 ; tm17-tm35 = b3 - - psubsw mm4, mm1 ; tp17-tp35 = t1 - paddsw mm2, mm0 ; tm17+tm35 = t2 - - movq mm7, mmword ptr tg_2_16 - movq mm1, mm4 ; t1 - -; movq mmword ptr [SCRATCH+0], mm5 ; save b0 - movq mmword ptr [OUT+3*16], mm5 ; save b0 - paddsw mm1, mm2 ; t1+t2 - -; movq mmword ptr [SCRATCH+8], mm6 ; save b3 - movq mmword ptr [OUT+5*16], mm6 ; save b3 - psubsw mm4, mm2 ; t1-t2 - - movq mm5, mmword ptr [INP+2*16] - movq mm0, mm7 ; tg_2_16 - - movq mm6, mmword ptr [INP+6*16] - pmulhw mm0, mm5 ; x2*tg_2_16 - - pmulhw mm7, mm6 ; x6*tg_2_16 -; slot - pmulhw mm1, mm3 ; ocos_4_16*(t1+t2) = b1/2 -; slot - movq mm2, mmword ptr [INP+0*16] - pmulhw mm4, mm3 ; ocos_4_16*(t1-t2) = b2/2 - - psubsw mm0, mm6 ; t2*tg_2_16-x6 = tm26 - movq mm3, mm2 ; x0 - - movq mm6, mmword ptr [INP+4*16] - paddsw mm7, mm5 ; x2+x6*tg_2_16 = tp26 - - paddsw mm2, mm6 ; x0+x4 = tp04 - psubsw mm3, mm6 ; x0-x4 = tm04 - - movq mm5, mm2 ; tp04 - movq mm6, mm3 ; tm04 - - psubsw mm2, mm7 ; tp04-tp26 = a3 - paddsw mm3, mm0 ; tm04+tm26 = a1 - - paddsw mm1, mm1 ; b1 - paddsw mm4, mm4 ; b2 - - paddsw mm5, mm7 ; tp04+tp26 = a0 - psubsw mm6, mm0 ; tm04-tm26 = a2 - - movq mm7, mm3 ; a1 - movq mm0, mm6 ; a2 - - paddsw mm3, mm1 ; a1+b1 - paddsw mm6, mm4 ; a2+b2 - - psraw mm3, SHIFT_INV_COL ; dst1 - psubsw mm7, mm1 ; a1-b1 - - psraw mm6, SHIFT_INV_COL ; dst2 - psubsw mm0, mm4 ; a2-b2 - -; movq mm1, mmword ptr [SCRATCH+0] ; load b0 - movq mm1, mmword ptr [OUT+3*16] ; load b0 - psraw mm7, SHIFT_INV_COL ; dst6 - - movq mm4, mm5 ; a0 - psraw mm0, SHIFT_INV_COL ; dst5 - - movq mmword ptr [OUT+1*16], mm3 - paddsw mm5, mm1 ; a0+b0 - - movq mmword ptr [OUT+2*16], mm6 - psubsw mm4, mm1 ; a0-b0 - -; movq mm3, mmword ptr [SCRATCH+8] ; load b3 - movq mm3, mmword ptr [OUT+5*16] ; load b3 - psraw mm5, SHIFT_INV_COL ; dst0 - - movq mm6, mm2 ; a3 - psraw mm4, SHIFT_INV_COL ; dst7 - - movq mmword ptr [OUT+5*16], mm0 - paddsw mm2, mm3 ; a3+b3 - - movq mmword ptr [OUT+6*16], mm7 - psubsw mm6, mm3 ; a3-b3 - - movq mmword ptr [OUT+0*16], mm5 - psraw mm2, SHIFT_INV_COL ; dst3 - - movq mmword ptr [OUT+7*16], mm4 - psraw mm6, SHIFT_INV_COL ; dst4 - - movq mmword ptr [OUT+3*16], mm2 - - movq mmword ptr [OUT+4*16], mm6 -ENDM - -;_DATA SEGMENT PARA PUBLIC USE32 'DATA' - -; Table for rows 0,4 - constants are multiplied by cos_4_16 - -tab_i_04_s2 sword 16384, 21407, 16384, 8867 ; movq-> w05 w04 w01 w00 - sword 16384, -8867, 16384, -21407 ; w13 w12 w09 w08 - sword 16384, 8867, -16384, -21407 ; w07 w06 w03 w02 - sword -16384, 21407, 16384, -8867 ; w15 w14 w11 w10 - sword 22725, 19266, 19266, -4520 ; w21 w20 w17 w16 - sword 12873, -22725, 4520, -12873 ; w29 w28 w25 w24 - sword 12873, 4520, -22725, -12873 ; w23 w22 w19 w18 - sword 4520, 19266, 19266, -22725 ; w31 w30 w27 w26 - -; Table for rows 1,7 - constants are multiplied by cos_1_16 - -tab_i_17_s2 sword 22725, 29692, 22725, 12299 ; movq-> w05 w04 w01 w00 - sword 22725, -12299, 22725, -29692 ; w13 w12 w09 w08 - sword 22725, 12299, -22725, -29692 ; w07 w06 w03 w02 - sword -22725, 29692, 22725, -12299 ; w15 w14 w11 w10 - sword 31521, 26722, 26722, -6270 ; w21 w20 w17 w16 - sword 17855, -31521, 6270, -17855 ; w29 w28 w25 w24 - sword 17855, 6270, -31521, -17855 ; w23 w22 w19 w18 - sword 6270, 26722, 26722, -31521 ; w31 w30 w27 w26 - -; Table for rows 2,6 - constants are multiplied by cos_2_16 - -tab_i_26_s2 sword 21407, 27969, 21407, 11585 ; movq-> w05 w04 w01 w00 - sword 21407, -11585, 21407, -27969 ; w13 w12 w09 w08 - sword 21407, 11585, -21407, -27969 ; w07 w06 w03 w02 - sword -21407, 27969, 21407, -11585 ; w15 w14 w11 w10 - sword 29692, 25172, 25172, -5906 ; w21 w20 w17 w16 - sword 16819, -29692, 5906, -16819 ; w29 w28 w25 w24 - sword 16819, 5906, -29692, -16819 ; w23 w22 w19 w18 - sword 5906, 25172, 25172, -29692 ; w31 w30 w27 w26 - -; Table for rows 3,5 - constants are multiplied by cos_3_16 - -tab_i_35_s2 sword 19266, 25172, 19266, 10426 ; movq-> w05 w04 w01 w00 - sword 19266, -10426, 19266, -25172 ; w13 w12 w09 w08 - sword 19266, 10426, -19266, -25172 ; w07 w06 w03 w02 - sword -19266, 25172, 19266, -10426 ; w15 w14 w11 w10 - sword 26722, 22654, 22654, -5315 ; w21 w20 w17 w16 - sword 15137, -26722, 5315, -15137 ; w29 w28 w25 w24 - sword 15137, 5315, -26722, -15137 ; w23 w22 w19 w18 - sword 5315, 22654, 22654, -26722 ; w31 w30 w27 w26 - -;----------------------------------------------------------------------------- - -; assume SHIFT_INV_ROW == 12 -;rounder_2_0 dword 65536, 65536 -; dword 65536, 65536 -;rounder_2_4 dword 0, 0 -; dword 0, 0 -;rounder_2_1 dword 7195, 7195 -; dword 7195, 7195 -;rounder_2_7 dword 1024, 1024 -; dword 1024, 1024 -;rounder_2_2 dword 4520, 4520 -; dword 4520, 4520 -;rounder_2_6 dword 1024, 1024 -; dword 1024, 1024 -;rounder_2_3 dword 2407, 2407 -; dword 2407, 2407 -;rounder_2_5 dword 240, 240 -; dword 240, 240 - -; assume SHIFT_INV_ROW == 11 -rounder_2_0 dword 65536, 65536 - dword 65536, 65536 -rounder_2_4 dword 0, 0 - dword 0, 0 -rounder_2_1 dword 3597, 3597 - dword 3597, 3597 -rounder_2_7 dword 512, 512 - dword 512, 512 -rounder_2_2 dword 2260, 2260 - dword 2260, 2260 -rounder_2_6 dword 512, 512 - dword 512, 512 -rounder_2_3 dword 1203, 1203 - dword 1203, 1203 -rounder_2_5 dword 120, 120 - dword 120, 120 - -;----------------------------------------------------------------------------- - - tg_1_16_2 sword 13036, 13036, 13036, 13036 ; tg * (2<<16) + 0.5 - sword 13036, 13036, 13036, 13036 - tg_2_16_2 sword 27146, 27146, 27146, 27146 ; tg * (2<<16) + 0.5 - sword 27146, 27146, 27146, 27146 - tg_3_16_2 sword -21746, -21746, -21746, -21746 ; tg * (2<<16) + 0.5 - sword -21746, -21746, -21746, -21746 -ocos_4_16_2 sword 23170, 23170, 23170, 23170 ; cos * (2<<15) + 0.5 - sword 23170, 23170, 23170, 23170 - -_DATA ENDS -_TEXT SEGMENT PARA PUBLIC USE32 'CODE' - -; -; extern "C" __fastcall void idct8x8_mmx (short *src_result); -; -public @MMX_IDCT@4 - -@MMX_IDCT@4 proc near - - mov eax, ecx ; source - - DCT_8_INV_ROW_1 [eax+0], [eax+0], tab_i_04, rounder_0 - DCT_8_INV_ROW_1 [eax+16], [eax+16], tab_i_17, rounder_1 - DCT_8_INV_ROW_1 [eax+32], [eax+32], tab_i_26, rounder_2 - DCT_8_INV_ROW_1 [eax+48], [eax+48], tab_i_35, rounder_3 - DCT_8_INV_ROW_1 [eax+64], [eax+64], tab_i_04, rounder_4 - DCT_8_INV_ROW_1 [eax+80], [eax+80], tab_i_35, rounder_5 - DCT_8_INV_ROW_1 [eax+96], [eax+96], tab_i_26, rounder_6 - DCT_8_INV_ROW_1 [eax+112], [eax+112], tab_i_17, rounder_7 - - DCT_8_INV_COL_4 [eax+0],[eax+0] - DCT_8_INV_COL_4 [eax+8],[eax+8] - - ret - -@MMX_IDCT@4 ENDP - -_TEXT ENDS - -_TEXT SEGMENT PARA PUBLIC USE32 'CODE' - -; -; extern "C" __fastcall void idct8x8_sse (short *src_result); -; -public @SSEMMX_IDCT@4 - -@SSEMMX_IDCT@4 proc near - mov eax, ecx ; source - - DCT_8_INV_ROW_1_s [eax+0], [eax+0], tab_i_04_s, rounder_0 - DCT_8_INV_ROW_1_s [eax+16], [eax+16], tab_i_17_s, rounder_1 - DCT_8_INV_ROW_1_s [eax+32], [eax+32], tab_i_26_s, rounder_2 - DCT_8_INV_ROW_1_s [eax+48], [eax+48], tab_i_35_s, rounder_3 - DCT_8_INV_ROW_1_s [eax+64], [eax+64], tab_i_04_s, rounder_4 - DCT_8_INV_ROW_1_s [eax+80], [eax+80], tab_i_35_s, rounder_5 - DCT_8_INV_ROW_1_s [eax+96], [eax+96], tab_i_26_s, rounder_6 - DCT_8_INV_ROW_1_s [eax+112], [eax+112], tab_i_17_s, rounder_7 - - DCT_8_INV_COL_4 [eax+0],[eax+0] - DCT_8_INV_COL_4 [eax+8],[eax+8] - - ret - -@SSEMMX_IDCT@4 ENDP - -_TEXT ENDS - -;END - -;============================================================================= -; code for Pentium IV -;============================================================================= - -DCT_8_INV_ROW_1_s2 MACRO INP:REQ, OUT:REQ, TABLE:REQ, ROUNDER:REQ - -pshufhw xmm1,[INP],11011000b ;x 75643210 -pshuflw xmm1,xmm1,11011000b ;x 75643120 -pshufd xmm0,xmm1,00000000b ;x 20202020 -pmaddwd xmm0,[TABLE] ;w 13 12 9 8 5410 - ;a 3210 first part - -pshufd xmm2,xmm1,10101010b ;x 64646464 -pmaddwd xmm2,[TABLE+16] ;w 15 14 11 10 7632 - ;a 3210 second part - -paddd xmm2,xmm0 ;a 3210 ready -paddd xmm2,[ROUNDER] ;must be 4 dwords long, not 2 as for sse1 -movdqa xmm5,xmm2 - -pshufd xmm3,xmm1,01010101b ;x 31313131 -pmaddwd xmm3,[TABLE+32] ;w 29 28 25 24 21 20 17 16 - ;b 3210 first part - -pshufd xmm4,xmm1,11111111b ;x 75757575 -pmaddwd xmm4,[TABLE+48] ;w 31 30 27 26 23 22 19 18 - ;b 3210 second part -paddd xmm3,xmm4 ;b 3210 ready - -paddd xmm2,xmm3 ;will be y 3210 -psubd xmm5,xmm3 ;will be y 4567 - -psrad xmm2,SHIFT_INV_ROW -psrad xmm5,SHIFT_INV_ROW - -packssdw xmm2,xmm5; ;y 45673210 -pshufhw xmm6,xmm2,00011011b ;y 76543210 - -movdqa [OUT],xmm6 - -ENDM - -; %macro DCT_8_INV_COL_4_sse2 2 -DCT_8_INV_COL_4_s2 MACRO INP:REQ, OUT:REQ - - movdqa xmm0,[INP+16*0] ;x0 (all columns) - movdqa xmm2,[INP+16*4] ;x4 - movdqa xmm1,xmm0 - - movdqa xmm4,[INP+16*2] ;x2 - movdqa xmm5,[INP+16*6] ;x6 - movdqa xmm6,[tg_2_16_2] - movdqa xmm7,xmm6 - - paddsw xmm0,xmm2 ;u04=x0+x4 - psubsw xmm1,xmm2 ;v04=x0-x4 - movdqa xmm3,xmm0 - movdqa xmm2,xmm1 - - pmulhw xmm6,xmm4 - pmulhw xmm7,xmm5 - psubsw xmm6,xmm5 ;v26=x2*T2-x6 - paddsw xmm7,xmm4 ;u26=x6*T2+x2 - - paddsw xmm1,xmm6 ;a1=v04+v26 - paddsw xmm0,xmm7 ;a0=u04+u26 - psubsw xmm2,xmm6 ;a2=v04-v26 - psubsw xmm3,xmm7 ;a3=u04-u26 - - movdqa [OUT+16*0],xmm0 ;store a3-a0 to - movdqa [OUT+16*6],xmm1 ;free registers - movdqa [OUT+16*2],xmm2 - movdqa [OUT+16*4],xmm3 - - movdqa xmm0,[INP+16*1] ;x1 - movdqa xmm1,[INP+16*7] ;x7 - movdqa xmm2,[tg_1_16_2] - movdqa xmm3,xmm2 - - movdqa xmm4,[INP+16*3] ;x3 - movdqa xmm5,[INP+16*5] ;x5 - movdqa xmm6,[tg_3_16_2] - movdqa xmm7,xmm6 - - pmulhw xmm2,xmm0 - pmulhw xmm3,xmm1 - psubsw xmm2,xmm1 ;v17=x1*T1-x7 - paddsw xmm3,xmm0 ;u17=x7*T1+x1 - movdqa xmm0,xmm3 ;u17 - movdqa xmm1,xmm2 ;v17 - - pmulhw xmm6,xmm4 ;x3*(t3-1) - pmulhw xmm7,xmm5 ;x5*(t3-1) - paddsw xmm6,xmm4 ; >>> - paddsw xmm7,xmm5 ; >>> - psubsw xmm6,xmm5 ;v35=x3*T3-x5 - paddsw xmm7,xmm4 ;u35=x5*T3+x3 - - movdqa xmm4,[ocos_4_16_2] - - paddsw xmm0,xmm7 ;b0=u17+u35 - psubsw xmm1,xmm6 ;b3=v17-v35 - psubsw xmm3,xmm7 ;u12=u17-v35 - paddsw xmm2,xmm6 ;v12=v17+v35 - - movdqa xmm5,xmm3 - paddsw xmm3,xmm2 ;tb1 - psubsw xmm5,xmm2 ;tb2 - pmulhw xmm5,xmm4 - pmulhw xmm4,xmm3 - paddsw xmm5,xmm5 - paddsw xmm4,xmm4 - - movdqa xmm6,[OUT+16*0] ;a0 - movdqa xmm7,xmm6 - paddsw xmm6,xmm0 - psubsw xmm7,xmm0 - psraw xmm6,SHIFT_INV_COL ;y0=a0+b0 - psraw xmm7,SHIFT_INV_COL ;y7=a0-b0 - movdqa [OUT+16*0],xmm6 - movdqa [OUT+16*7],xmm7 - - movdqa xmm2,[OUT+16*4] ;a3 - movdqa xmm3,xmm2 - paddsw xmm2,xmm1 - psubsw xmm3,xmm1 - psraw xmm2,SHIFT_INV_COL ;y3=a3+b3 - psraw xmm3,SHIFT_INV_COL ;y4=a3-b3 - movdqa [OUT+16*3],xmm2 - movdqa [OUT+16*4],xmm3 - - movdqa xmm0,[OUT+16*6] ;a1 - movdqa xmm1,xmm0 - paddsw xmm0,xmm4 - psubsw xmm1,xmm4 - psraw xmm0,SHIFT_INV_COL ;y1=a1+b1 - psraw xmm1,SHIFT_INV_COL ;y6=a1-b1 - movdqa [OUT+16*1],xmm0 - movdqa [OUT+16*6],xmm1 - - movdqa xmm6,[OUT+16*2] ;a2 - movdqa xmm7,xmm6 - paddsw xmm6,xmm5 - psubsw xmm7,xmm5 - psraw xmm6,SHIFT_INV_COL ;y2=a2+b2 - psraw xmm7,SHIFT_INV_COL ;y5=a2-b2 - movdqa [OUT+16*2],xmm6 - movdqa [OUT+16*5],xmm7 - -ENDM -;%endmacro - -; Dmitry - the previous macro, now unused - -DCT_8_INV_COL_4_s2x MACRO INP:REQ, OUT:REQ - -;Original algorythm makes 4 colums at once - -;We will make 8 with 128-bit registers of SSE2 :) - -movdqa xmm0,[INP+16*0] ;x0 (all columns) -movdqa xmm1,xmm0 -movdqa xmm2,[INP+16*4] ;x4 - -paddsw xmm0,xmm2 ;u04=x0+x4 -psubsw xmm1,xmm2 ;v04=x0-x4 -movdqa xmm3,xmm0 -movdqa xmm2,xmm1 - -movdqa xmm4,[INP+16*2] ;x2 -movdqa xmm5,[INP+16*6] ;x6 -movdqa xmm6,[tg_2_16_2] -movdqa xmm7,xmm6 -pmulhw xmm6,xmm4 -psubsw xmm6,xmm5 ;v26=x2*T2-x6 -pmulhw xmm7,xmm5 -paddsw xmm7,xmm4 ;u26=x6*T2+x2 - -paddsw xmm0,xmm7 ;a0=u04+u26 -paddsw xmm1,xmm6 ;a1=v04+v26 -psubsw xmm2,xmm6 ;a2=v04-v26 -psubsw xmm3,xmm7 ;a3=u04-u26 - -movdqa [OUT+16*0],xmm0 ;store a3-a0 to -movdqa [OUT+16*6],xmm1 ;free registers -movdqa [OUT+16*2],xmm2 -movdqa [OUT+16*4],xmm3 - -movdqa xmm0,[INP+16*1] ;x1 -movdqa xmm1,[INP+16*7] ;x7 -movdqa xmm2,[tg_1_16_2] -movdqa xmm3,xmm2 -pmulhw xmm2,xmm0 -psubsw xmm2,xmm1 ;v17=x1*T1-x7 -pmulhw xmm3,xmm1 -paddsw xmm3,xmm0 ;u17=x7*T1+x1 -movdqa xmm0,xmm3 ;u17 -movdqa xmm1,xmm2 ;v17 - -movdqa xmm4,[INP+16*3] ;x3 -movdqa xmm5,[INP+16*5] ;x5 -movdqa xmm6,[tg_3_16_2] -movdqa xmm7,xmm6 -pmulhw xmm6,xmm4 -psubsw xmm6,xmm5 ;v35=x3*T3-x5 -pmulhw xmm7,xmm5 -paddsw xmm7,xmm4 ;u35=x5*T3+x3 - -movdqa xmm4,[ocos_4_16_2] - -paddsw xmm0,xmm7 ;b0=u17+u35 -psubsw xmm1,xmm6 ;b3=v17-v35 -psubsw xmm3,xmm7 ;u12=u17-v35 -paddsw xmm2,xmm6 ;v12=v17+v35 - -pmulhw xmm2,xmm4 -paddsw xmm2,xmm2 ;u12=2*C4*u12 - -pmulhw xmm4,xmm3 -paddsw xmm4,xmm4 ;v12=2*C4*v12 -movdqa xmm5,xmm4 - -paddsw xmm4,xmm2 ;b1=u12+v12 -psubsw xmm5,xmm2 ;b2=u12-v12 - -movdqa xmm6,[OUT+16*0] ;a0 -movdqa xmm7,xmm6 -paddsw xmm6,xmm0 -psraw xmm6,SHIFT_INV_COL ;y0=a0+b0 -psubsw xmm7,xmm0 -psraw xmm7,SHIFT_INV_COL ;y7=a0-b0 -movdqa [OUT+16*0],xmm6 -movdqa [OUT+16*7],xmm7 - -movdqa xmm2,[OUT+16*4] ;a3 -movdqa xmm3,xmm2 -paddsw xmm2,xmm1 -psraw xmm2,SHIFT_INV_COL ;y3=a3+b3 -psubsw xmm3,xmm1 - -psraw xmm3,SHIFT_INV_COL ;y4=a3-b3 -movdqa [OUT+16*3],xmm2 -movdqa [OUT+16*4],xmm3 - -movdqa xmm0,[OUT+16*6] ;a1 -movdqa xmm1,xmm0 -paddsw xmm0,xmm4 -psraw xmm0,SHIFT_INV_COL ;y1=a1+b1 -psubsw xmm1,xmm4 -psraw xmm1,SHIFT_INV_COL ;y6=a1-b1 -movdqa [OUT+16*1],xmm0 -movdqa [OUT+16*6],xmm1 - -movdqa xmm6,[OUT+16*2] ;a2 -movdqa xmm7,xmm6 -paddsw xmm6,xmm5 -psraw xmm6,SHIFT_INV_COL ;y2=a2+B2 - -psubsw xmm7,xmm5 -psraw xmm7,SHIFT_INV_COL ;y5=a2-b2 -movdqa [OUT+16*2],xmm6 -movdqa [OUT+16*5],xmm7 - -ENDM - -_TEXT SEGMENT PARA PUBLIC USE32 'CODE' - -; -; extern "C" __fastcall void idct8x8_sse2 (short *src_result); -; - -public @SSE2MMX_IDCT@4 - -@SSE2MMX_IDCT@4 proc near - - mov eax, ecx ; source - - DCT_8_INV_ROW_1_s2 [eax+0], [eax+0], tab_i_04_s2, rounder_2_0 - DCT_8_INV_ROW_1_s2 [eax+16], [eax+16], tab_i_17_s2, rounder_2_1 - DCT_8_INV_ROW_1_s2 [eax+32], [eax+32], tab_i_26_s2, rounder_2_2 - DCT_8_INV_ROW_1_s2 [eax+48], [eax+48], tab_i_35_s2, rounder_2_3 - DCT_8_INV_ROW_1_s2 [eax+64], [eax+64], tab_i_04_s2, rounder_2_4 - DCT_8_INV_ROW_1_s2 [eax+80], [eax+80], tab_i_35_s2, rounder_2_5 - DCT_8_INV_ROW_1_s2 [eax+96], [eax+96], tab_i_26_s2, rounder_2_6 - DCT_8_INV_ROW_1_s2 [eax+112], [eax+112], tab_i_17_s2, rounder_2_7 - - DCT_8_INV_COL_4_s2 [eax+0],[eax+0] - - ret - -@SSE2MMX_IDCT@4 ENDP - -; public @IDCT_CONST_PREFETCH@4 -public @IDCT_CONST_PREFETCH@0 - -@IDCT_CONST_PREFETCH@0 proc near - -; mov eax, tab_i_04_s2 - lea eax, tab_i_04_s2 - - prefetchnta [eax] - - prefetchnta [eax+64] ;tab_i_17_s2 - prefetchnta [eax+128] ;tab_i_26_s2 - prefetchnta [eax+192] ;tab_i_35_s2 - -; mov eax,rounder_2_0 - lea eax,rounder_2_0 - - prefetchnta [eax] - -; mov eax,tg_1_16_2 - lea eax,tg_1_16_2 - - prefetchnta [eax] - ret - -@IDCT_CONST_PREFETCH@0 ENDP - -_TEXT ENDS - -END diff --git a/src/dgindex/idctmmx.obj b/src/dgindex/idctmmx.obj deleted file mode 100644 index 33e16c2..0000000 Binary files a/src/dgindex/idctmmx.obj and /dev/null differ diff --git a/src/dgindex/idctref.cpp b/src/dgindex/idctref.cpp deleted file mode 100644 index cbd7890..0000000 --- a/src/dgindex/idctref.cpp +++ /dev/null @@ -1,281 +0,0 @@ -/* idctref_miha.c, Inverse Discrete Fourier Transform, double precision */ - -/*************************************************************/ -/* */ -/* x87 hand-optimized assembly by Miha Peternel */ -/* 27.11. - 20.1.2001 */ -/* */ -/* You are free to use this code in your project if: */ -/* - no changes are made to this message */ -/* - any changes to this code are publicly available */ -/* - your project documentation contains the following text: */ -/* "This software contains fast high-quality IDCT decoder */ -/* by Miha Peternel." */ -/* */ -/*************************************************************/ - -// revised by Loli.J: bug fix together with rounding mode optimization -// clipping is unnecessary since motion compensation will saturate thereafter - -// Perform IEEE 1180 reference (64-bit floating point, separable 8x1 -// direct matrix multiply) Inverse Discrete Cosine Transform - -static const double r[8][8] = { - { - 3.5355339059327379e-001, 3.5355339059327379e-001, - 3.5355339059327379e-001, 3.5355339059327379e-001, - 3.5355339059327379e-001, 3.5355339059327379e-001, - 3.5355339059327379e-001, 3.5355339059327379e-001, - }, { - 4.9039264020161522e-001, 4.1573480615127262e-001, - 2.7778511650980114e-001, 9.7545161008064166e-002, - -9.7545161008064096e-002, -2.7778511650980098e-001, - -4.1573480615127267e-001, -4.9039264020161522e-001, - }, { - 4.6193976625564337e-001, 1.9134171618254492e-001, - -1.9134171618254486e-001, -4.6193976625564337e-001, - -4.6193976625564342e-001, -1.9134171618254517e-001, - 1.9134171618254500e-001, 4.6193976625564326e-001, - }, { - 4.1573480615127262e-001, -9.7545161008064096e-002, - -4.9039264020161522e-001, -2.7778511650980109e-001, - 2.7778511650980092e-001, 4.9039264020161522e-001, - 9.7545161008064388e-002, -4.1573480615127256e-001, - }, { - 3.5355339059327379e-001, -3.5355339059327373e-001, - -3.5355339059327384e-001, 3.5355339059327368e-001, - 3.5355339059327384e-001, -3.5355339059327334e-001, - -3.5355339059327356e-001, 3.5355339059327329e-001, - }, { - 2.7778511650980114e-001, -4.9039264020161522e-001, - 9.7545161008064152e-002, 4.1573480615127273e-001, - -4.1573480615127256e-001, -9.7545161008064013e-002, - 4.9039264020161533e-001, -2.7778511650980076e-001, - }, { - 1.9134171618254492e-001, -4.6193976625564342e-001, - 4.6193976625564326e-001, -1.9134171618254495e-001, - -1.9134171618254528e-001, 4.6193976625564337e-001, - -4.6193976625564320e-001, 1.9134171618254478e-001, - }, { - 9.7545161008064166e-002, -2.7778511650980109e-001, - 4.1573480615127273e-001, -4.9039264020161533e-001, - 4.9039264020161522e-001, -4.1573480615127251e-001, - 2.7778511650980076e-001, -9.7545161008064291e-002, - }, -}; - -void __fastcall REF_IDCT(short *block) -{ - int *b = (int *)block; - double tmp[64], rnd[64]; - - if ( !(b[0]|(b[31]&~0x10000)) ) - { - if( b[ 1]|b[ 2]|b[ 3]|b[ 4]|b[ 5]|b[ 6] ) - goto __normal; - if( b[ 7]|b[ 8]|b[ 9]|b[10]|b[11]|b[12] ) - goto __normal; - if( b[13]|b[14]|b[15]|b[16]|b[17]|b[18] ) - goto __normal; - if( b[19]|b[20]|b[21]|b[22]|b[23]|b[24] ) - goto __normal; - if( b[25]|b[26]|b[27]|b[28]|b[29]|b[30] ) - goto __normal; - b[31] = 0; - return; - } - -__normal: - - __asm - { - mov esi, [block] - lea eax, [r] - lea edi, [tmp] - mov ebx, 8 - -__col1: - mov edx, [esi+0*2] - mov ecx, [esi+2*2] - or edx, [esi+4*2] - or ecx, [esi+6*2] - or edx, ecx - mov ecx, 4 - jnz __row1 - - fild word ptr [esi+0*2] - fmul qword ptr [eax+0*8*8] - fst qword ptr [edi+0*8] - fst qword ptr [edi+1*8] - fst qword ptr [edi+2*8] - fst qword ptr [edi+3*8] - fst qword ptr [edi+4*8] - fst qword ptr [edi+5*8] - fst qword ptr [edi+6*8] - fstp qword ptr [edi+7*8] - add edi, 64 - jmp __next1 - -__row1: - fild word ptr [esi+0*2] - fmul qword ptr [eax+0*8*8] - fild word ptr [esi+1*2] - fmul qword ptr [eax+1*8*8] - fadd - fild word ptr [esi+2*2] - fmul qword ptr [eax+2*8*8] - fadd - fild word ptr [esi+3*2] - fmul qword ptr [eax+3*8*8] - fadd - fild word ptr [esi+4*2] - fmul qword ptr [eax+4*8*8] - fadd - fild word ptr [esi+5*2] - fmul qword ptr [eax+5*8*8] - fadd - fild word ptr [esi+6*2] - fmul qword ptr [eax+6*8*8] - fadd - fild word ptr [esi+7*2] - fmul qword ptr [eax+7*8*8] - fadd - - fild word ptr [esi+0*2] - fmul qword ptr [eax+0*8*8+8] - fild word ptr [esi+1*2] - fmul qword ptr [eax+1*8*8+8] - fadd - fild word ptr [esi+2*2] - fmul qword ptr [eax+2*8*8+8] - fadd - fild word ptr [esi+3*2] - fmul qword ptr [eax+3*8*8+8] - fadd - fild word ptr [esi+4*2] - fmul qword ptr [eax+4*8*8+8] - fadd - fild word ptr [esi+5*2] - fmul qword ptr [eax+5*8*8+8] - fadd - fild word ptr [esi+6*2] - fmul qword ptr [eax+6*8*8+8] - fadd - fild word ptr [esi+7*2] - fmul qword ptr [eax+7*8*8+8] - fadd - add eax, 16 - fxch st(1) - fstp qword ptr [edi] - fstp qword ptr [edi+8] - add edi, 16 - - sub ecx, 1 - jnz __row1 - sub eax, 64 - -__next1: - add esi, 16 - - sub ebx, 1 - jnz __col1 - - lea esi, [tmp] - lea eax, [r] - lea edi, [rnd] - - mov ebx, 8 -__row2: - mov ecx, 4 - -__col2: - fld qword ptr [esi+0*8*8] - fmul qword ptr [eax+0*8*8] - fld qword ptr [esi+1*8*8] - fmul qword ptr [eax+1*8*8] - fadd - fld qword ptr [esi+2*8*8] - fmul qword ptr [eax+2*8*8] - fadd - fld qword ptr [esi+3*8*8] - fmul qword ptr [eax+3*8*8] - fadd - fld qword ptr [esi+4*8*8] - fmul qword ptr [eax+4*8*8] - fadd - fld qword ptr [esi+5*8*8] - fmul qword ptr [eax+5*8*8] - fadd - fld qword ptr [esi+6*8*8] - fmul qword ptr [eax+6*8*8] - fadd - fld qword ptr [esi+7*8*8] - fmul qword ptr [eax+7*8*8] - fadd - - fld qword ptr [esi+0*8*8] - fmul qword ptr [eax+0*8*8+8] - fld qword ptr [esi+1*8*8] - fmul qword ptr [eax+1*8*8+8] - fadd - fld qword ptr [esi+2*8*8] - fmul qword ptr [eax+2*8*8+8] - fadd - fld qword ptr [esi+3*8*8] - fmul qword ptr [eax+3*8*8+8] - fadd - fld qword ptr [esi+4*8*8] - fmul qword ptr [eax+4*8*8+8] - fadd - fld qword ptr [esi+5*8*8] - fmul qword ptr [eax+5*8*8+8] - fadd - fld qword ptr [esi+6*8*8] - fmul qword ptr [eax+6*8*8+8] - fadd - fld qword ptr [esi+7*8*8] - fmul qword ptr [eax+7*8*8+8] - fadd - add eax, 16 - - fxch st(1) - fstp qword ptr [edi] - fstp qword ptr [edi+8*8] - add edi, 128 - - sub ecx, 1 - jnz __col2 - sub eax, 64 - add esi, 8 - sub edi, 504 - - sub ebx, 1 - jnz __row2 - - lea esi, [rnd] - mov edi, [block] - mov ecx, 8 - -__round: - fld qword ptr [esi+0*8] - fistp word ptr [edi+0*2] - fld qword ptr [esi+1*8] - fistp word ptr [edi+1*2] - fld qword ptr [esi+2*8] - fistp word ptr [edi+2*2] - fld qword ptr [esi+3*8] - fistp word ptr [edi+3*2] - fld qword ptr [esi+4*8] - fistp word ptr [edi+4*2] - fld qword ptr [esi+5*8] - fistp word ptr [edi+5*2] - fld qword ptr [esi+6*8] - fistp word ptr [edi+6*2] - fld qword ptr [esi+7*8] - add esi, 64 - fistp word ptr [edi+7*2] - add edi, 16 - sub ecx,1 - jnz __round - } -} diff --git a/src/dgindex/initial_parse.cpp b/src/dgindex/initial_parse.cpp deleted file mode 100644 index 1726164..0000000 --- a/src/dgindex/initial_parse.cpp +++ /dev/null @@ -1,438 +0,0 @@ -/* - * Copyright (C) 2005, Donald Graft - * - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This file is distributed in the hope that 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 -#include "resource.h" -#include -#include -#include -#include "global.h" - -// Defines for the start code detection state machine. -#define NEED_FIRST_0 0 -#define NEED_SECOND_0 1 -#define NEED_1 2 - -static void determine_stream_type(void); -static void video_parser(int *); -static void pack_parser(void); -static unsigned char get_byte(void); - -static int file; -static int state, found; -// Should hold maximum size PES packet. -static unsigned char buffer[256000]; -static int buffer_length, buffer_ndx; -static int EOF_reached; - -int initial_parse(char *input_file, int *mpeg_type_p, int *is_program_stream_p) -{ - // Open the input file. - if (input_file[0] == 0 || (file = _open(input_file, _O_RDONLY | _O_BINARY | _O_SEQUENTIAL)) == -1) - { - return -1; - } - - // Determine the stream type: ES or program. - determine_stream_type(); - - // Re-open the input file. - _close(file); - file = _open(input_file, _O_RDONLY | _O_BINARY | _O_SEQUENTIAL); - if (file == -1) - { - return -1; - } - - // Determine MPEG type and find location of first video sequence header. - EOF_reached = 0; - video_parser(mpeg_type_p); - _close(file); - if (EOF_reached) - { - return -1; - } - *is_program_stream_p = program_stream_type; - return 0; -} - -static unsigned char get_byte(void) -{ - unsigned char val; - - if (program_stream_type != ELEMENTARY_STREAM) - { - if (buffer_ndx >= buffer_length) - { - // Need more data. Fill buffer with the next - // packet's worth of elementary data. - pack_parser(); - } - if (EOF_reached == 1) - { - return 0; - } - return buffer[buffer_ndx++]; - } - else - { - // No program stream parsing needed. Just read from - // the input file. - if (_read(file, &val, 1) != 1) - { - EOF_reached = 1; - return 0; - } - return val; - } -} - -static void video_parser(int *mpeg_type_p) -{ - unsigned char val; - int sequence_header_active = 0; - - buffer_length = buffer_ndx = 0; - - // Inits. - state = NEED_FIRST_0; - found = 0; - - // Let's go! Start by assuming it's not MPEG at all. - *mpeg_type_p = IS_NOT_MPEG; - for (;;) - { - // Parse for start codes. - val = get_byte(); - if (EOF_reached) return; - switch (state) - { - case NEED_FIRST_0: - if (val == 0) - state = NEED_SECOND_0; - break; - case NEED_SECOND_0: - if (val == 0) - state = NEED_1; - else - state = NEED_FIRST_0; - break; - case NEED_1: - if (val == 1) - { - found = 1; - state = NEED_FIRST_0; - } - else if (val != 0) - state = NEED_FIRST_0; - break; - } - if (found == 1) - { - // Found a start code. - found = 0; - val = get_byte(); - if (EOF_reached) return; - - if (val == 0xB3) - { - // Found a sequence header, so it's at least MPEG1. - *mpeg_type_p = IS_MPEG1; - // Sequence header. - if (sequence_header_active) - { - // Got another sequence header but didn't see a - // sequence header extension, so it's MPEG1. - return; - } - sequence_header_active = 1; - } - else if (val == 0xB5) - { - val = get_byte(); - if (EOF_reached) return; - if ((val & 0xf0) == 0x10) - { - // Sequence extension. - if (sequence_header_active) - { - // Must be MPEG2. - *mpeg_type_p = IS_MPEG2; - return; - } - } - else if (sequence_header_active) - { - // Got some other extension. Must be MPEG1. - *mpeg_type_p = IS_MPEG1; - return; - } - } - else - { - if (sequence_header_active) - { - // No sequence header extension. Must be MPEG1. - *mpeg_type_p = IS_MPEG1; - return; - } - } - } - } - return; -} - -static void pack_parser(void) -{ - unsigned char val, val2; - int state, found = 0; - int length; - unsigned short pes_packet_length, system_header_length; - unsigned char pes_packet_header_length, pack_stuffing_length; - unsigned char code; - - - // Look for start codes. - state = NEED_FIRST_0; - for (;;) - { - if (_read(file, &val, 1) != 1) { EOF_reached = 1; return; } - switch (state) - { - case NEED_FIRST_0: - if (val == 0) - state = NEED_SECOND_0; - break; - case NEED_SECOND_0: - if (val == 0) - state = NEED_1; - else - state = NEED_FIRST_0; - break; - case NEED_1: - if (val == 1) - { - found = 1; - state = NEED_FIRST_0; - } - else if (val != 0) - state = NEED_FIRST_0; - break; - } - if (found == 1) - { - // Found a start code. - found = 0; - // Get the start code. - if (_read(file, &val, 1) != 1) { EOF_reached = 1; return; } -// dprintf("DGIndex: code = %x\n", val); - if (val == 0xba) - { - // Pack header. Skip it. - if (_read(file, &val, 1) != 1) { EOF_reached = 1; return; } - if (program_stream_type == MPEG1_PROGRAM_STREAM) - { - // MPEG1 program stream. - if (_read(file, buffer, 7) != 7) { EOF_reached = 1; return; } - } - else - { - // MPEG2 program stream. - if (_read(file, buffer, 8) != 8) { EOF_reached = 1; return; } - if (_read(file, &pack_stuffing_length, 1) != 1) { EOF_reached = 1; return; } - pack_stuffing_length &= 0x03; - if (_read(file, buffer, pack_stuffing_length) != pack_stuffing_length) { EOF_reached = 1; return; } - } - } - if (val == 0xbb) - { - // System header. Skip it. - if (_read(file, &val, 1) != 1) { EOF_reached = 1; return; } - system_header_length = (unsigned short) (val << 8); - if (_read(file, &val2, 1) != 1) { EOF_reached = 1; return; } - system_header_length |= val2; - if (_read(file, buffer, system_header_length) != system_header_length) { EOF_reached = 1; return; } - } - else if (val >= 0xE0 && val <= 0xEF) - { - // Video stream. - // Packet length. - if (_read(file, &val, 1) != 1) { EOF_reached = 1; return; } - pes_packet_length = (unsigned short) (val << 8); - if (_read(file, &val2, 1) != 1) { EOF_reached = 1; return; } - pes_packet_length |= val2; - // if (pes_packet_length == 0) - // pes_packet_length = 256; - if (program_stream_type == MPEG1_PROGRAM_STREAM) - { - // MPEG1 program stream. - pes_packet_header_length = 0; - // Stuffing bytes. - do - { - if (_read(file, &val, 1) != 1) { EOF_reached = 1; return; } - pes_packet_header_length += 1; - } while (val == 0xff); - if ((val & 0xc0) == 0x40) - { - // STD bytes. - if (_read(file, &val, 1) != 1) { EOF_reached = 1; return; } - if (_read(file, &val, 1) != 1) { EOF_reached = 1; return; } - pes_packet_header_length += 2; - } - if ((val & 0xf0) == 0x20) - { - // PTS bytes. - if (_read(file, buffer, 4) != 4) { EOF_reached = 1; return; } - pes_packet_header_length += 4; - } - else if ((val & 0xf0) == 0x30) - { - // PTS/DTS bytes. - if (_read(file, buffer, 9) != 9) { EOF_reached = 1; return; } - pes_packet_header_length += 9; - } - // Send the video elementary data down the pipe to the video parser. - buffer_length = pes_packet_length - pes_packet_header_length; - if (buffer_length) - { - buffer_ndx = 0; - if (_read(file, buffer, buffer_length) != buffer_length) { EOF_reached = 1; return; } - return; - } - } - else - { - // MPEG2 program stream. - // Flags. - if (_read(file, &code, 1) != 1) { EOF_reached = 1; return; } - if ((code & 0xc0) == 0x80) - { - if (_read(file, &code, 1) != 1) { EOF_reached = 1; return; } - if (_read(file, &pes_packet_header_length, 1) != 1) { EOF_reached = 1; return; } - // Skip the PES packet header. - if (_read(file, buffer, pes_packet_header_length) != pes_packet_header_length) { EOF_reached = 1; return; } - // Send the video elementary data down the pipe to the video parser. - buffer_length = pes_packet_length - pes_packet_header_length - 3; - buffer_ndx = 0; - if (_read(file, buffer, buffer_length) != buffer_length) { EOF_reached = 1; return; } - return; - } - else - { - // No video data here. Skip it. - length = pes_packet_length - 1; - if (_read(file, buffer, length) != length) { EOF_reached = 1; return; } - } - } - } - else if (val > 0xbb) - { - // Not a stream that we are interested in. Skip it. - if (_read(file, &val, 1) != 1) { EOF_reached = 1; return; } - pes_packet_length = (unsigned short) (val << 8); - if (_read(file, &val2, 1) != 1) { EOF_reached = 1; return; } - pes_packet_length |= val2; - length = pes_packet_length; - if (_read(file, buffer, length) != length) { EOF_reached = 1; return; } - } - } - } -} - -unsigned char stream[2500000]; -static void determine_stream_type(void) -{ - unsigned char val; - int num_sequence_header = 0; - int num_picture_header = 0; - unsigned char *p; - unsigned int code, Read; - - // Start by assuming ES. Then look for a valid pack start. If one - // is found declare a program stream. - program_stream_type = ELEMENTARY_STREAM; - - Read = _read(file, stream, 2500000); - p = stream; - code = (p[0] << 16) + (p[1] << 8) + p[2]; - p += 3; - while (p < stream + Read) - { - code = ((code << 8) + *p++); - switch (code) - { - case 0x1ba: - val = *p++; - if ((val & 0xf0) == 0x20) - { - // Check all the marker bits just to be sure. - if (!(val & 1)) continue; - val = *p++; - val = *p++; - if (!(val & 1)) continue; - val = *p++; - val = *p++; - if (!(val & 1)) continue; - val = *p++; - if (!(val & 0x80)) continue; - val = *p++; - val = *p++; - if (!(val & 1)) continue; - // MPEG1 program stream. - program_stream_type = MPEG1_PROGRAM_STREAM; - return; - } - else if ((val & 0xc0) == 0x40) - { - // Check all the marker bits just to be sure. - if (!(val & 0x04)) continue; - val = *p++; - val = *p++; - if (!(val & 0x04)) continue; - val = *p++; - val = *p++; - if (!(val & 0x04)) continue; - val = *p++; - if (!(val & 0x01)) continue; - val = *p++; - val = *p++; - val = *p++; - if (!(val & 0x03)) continue; - // MPEG2 program stream. - program_stream_type = MPEG2_PROGRAM_STREAM; - return; - } - break; - case 0x1b3: - // Sequence header. - num_sequence_header++; - break; - case 0x100: - // Picture header. - num_picture_header++; - break; - } - if (num_sequence_header >= 2 && num_picture_header >= 2) - { - // We're seeing a lot of elementary stream data but we haven't seen - // a pack header yet. Declare ES. - return; - } - } -} diff --git a/src/dgindex/makefile b/src/dgindex/makefile deleted file mode 100644 index 0350355..0000000 --- a/src/dgindex/makefile +++ /dev/null @@ -1,137 +0,0 @@ -#----------------------------- -# makefile for DGIndex -#----------------------------- - -### Target ### - -OUTDIR=.\Release_nmake - -TARGET=DGIndex -TARGETEXE=$(OUTDIR)\$(TARGET).exe - - -### build utils ### - -MASM = "$(MASM_PATH)ml.exe" -AS = nasm.exe -CC = cl.exe -CPP = cl.exe -LD = link.exe -RC = rc.exe - - -### build flags ### - -ASFLAGS = -f win32 -DPREFIX -DWIN32 - -CPPFLAGS = \ - /c /Zi /nologo /W3 /WX- /O2 /Ob1 /Oi /Ot /Oy- \ - /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_CRT_SECURE_NO_WARNINGS" /D "_MBCS" \ - /GF /Gm- /EHsc /MT /GS /fp:precise /Zc:wchar_t /Zc:forScope \ - /Fp"$(OUTDIR)/$(TARGET).pch" /Fd"$(OUTDIR)/" \ - /Gd /analyze- /errorReport:none $(EXTRA_CPPFLAGS) - -LDFLAGS = \ - /OUT:"$(TARGETEXE)" \ - /INCREMENTAL:NO \ - /NOLOGO \ - /MANIFEST \ - /ManifestFile:"$(TARGETEXE).intermediate.manifest" \ - /ALLOWISOLATION \ - /MANIFESTUAC:"level='asInvoker' uiAccess='false'" \ - /SUBSYSTEM:WINDOWS,5.01 \ - /STACK:"4096000" \ - /TLBID:1 \ - /DYNAMICBASE \ - /NXCOMPAT \ - /MACHINE:X86 \ - /PDB:"$(OUTDIR)/$(TARGET).pdb" \ - /ERRORREPORT:NONE $(EXTRA_LDFLAGS) - -RFLAGS = /D "NDEBUG" /l 0x0409 /nologo - - -### link targets ### - -LIBS = vfw32.lib winmm.lib odbc32.lib odbccp32.lib shlwapi.lib kernel32.lib \ - user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib \ - ole32.lib oleaut32.lib uuid.lib - -OBJS = \ - idctmmx.obj \ - "$(OUTDIR)\gui.res" \ - "$(OUTDIR)\simple_idct_mmx.obj" \ - "$(OUTDIR)\skl_dct_sse.obj" \ - "$(OUTDIR)\d2vparse.obj" \ - "$(OUTDIR)\getbit.obj" \ - "$(OUTDIR)\gethdr.obj" \ - "$(OUTDIR)\getpic.obj" \ - "$(OUTDIR)\gui.obj" \ - "$(OUTDIR)\idctfpu.obj" \ - "$(OUTDIR)\idctref.obj" \ - "$(OUTDIR)\initial_parse.obj" \ - "$(OUTDIR)\misc.obj" \ - "$(OUTDIR)\motion.obj" \ - "$(OUTDIR)\mpeg2dec.obj" \ - "$(OUTDIR)\norm.obj" \ - "$(OUTDIR)\parse_cli.obj" \ - "$(OUTDIR)\pat.obj" \ - "$(OUTDIR)\store.obj" \ - "$(OUTDIR)\strverscmp.obj" \ - "$(OUTDIR)\wavefs44.obj" \ - "$(OUTDIR)\AC3Dec\bit_allocate.obj" \ - "$(OUTDIR)\AC3Dec\bitstream.obj" \ - "$(OUTDIR)\AC3Dec\coeff.obj" \ - "$(OUTDIR)\AC3Dec\crc.obj" \ - "$(OUTDIR)\AC3Dec\decode.obj" \ - "$(OUTDIR)\AC3Dec\downmix.obj" \ - "$(OUTDIR)\AC3Dec\exponent.obj" \ - "$(OUTDIR)\AC3Dec\imdct.obj" \ - "$(OUTDIR)\AC3Dec\parse.obj" \ - "$(OUTDIR)\AC3Dec\rematrix.obj" \ - "$(OUTDIR)\AC3Dec\sanity_check.obj" - - -### build ### - -.SUFFIXES : .exe .obj .asm .cpp .res .rc - - -ALL: "$(TARGETEXE)" - -"$(TARGETEXE)": "$(OUTDIR)" "$(OUTDIR)\AC3Dec" $(OBJS) - @echo $(LD) $(LDFLAGS) $(OBJS) $(LIBS) - @$(LD) $(LDFLAGS) $(OBJS) $(LIBS) - -idctmmx.obj: idctmmx.asm - @if not "$(MASM_PATH)" == "" @$(MASM) /c /coff /Cx /nologo /Fo idctmmx.obj idctmmx.asm - -.asm{$(OUTDIR)}.obj: - @echo nasm $< - @$(AS) $(ASFLAGS) $< -o $@ - -{AC3Dec\}.cpp{$(OUTDIR)\AC3Dec}.obj: - @$(CPP) $(CPPFLAGS) $< /Fo"$@" - -.cpp{$(OUTDIR)}.obj: - @$(CPP) $(CPPFLAGS) $< /Fo"$@" - -.rc{$(OUTDIR)}.res: - @echo rc $< - @$(RC) $(RFLAGS) /fo"$@" $< - -clean: - @echo delete "*.obj *.res *.pdb *.manifest" - @if exist "$(OUTDIR)\AC3Dec" @rmdir /S /Q "$(OUTDIR)\AC3Dec" >NUL - @if exist "$(OUTDIR)" @del /Q "$(OUTDIR)\*.res" "$(OUTDIR)\*.obj" "$(OUTDIR)\*.pdb" "$(OUTDIR)\*.manifest" 2>NUL 1>NUL - -"$(OUTDIR)": - @mkdir "$(OUTDIR)" - -"$(OUTDIR)\AC3Dec": - @mkdir "$(OUTDIR)\AC3Dec" - - -### depend #### - -!include "makefile.dep" diff --git a/src/dgindex/makefile.dep b/src/dgindex/makefile.dep deleted file mode 100644 index 871f792..0000000 --- a/src/dgindex/makefile.dep +++ /dev/null @@ -1,31 +0,0 @@ -$(OUTDIR)\simple_idct_mmx.obj: simple_idct_mmx.asm -$(OUTDIR)\skl_dct_sse.obj: skl_dct_sse.asm skl_nasm.h -$(OUTDIR)\d2vparse.obj : d2vparse.cpp global.h misc.h resource.h pat.h -$(OUTDIR)\getbit.obj : getbit.cpp global.h misc.h resource.h pat.h getbit.h AC3Dec\ac3.h -$(OUTDIR)\gethdr.obj : gethdr.cpp global.h misc.h resource.h pat.h getbit.h -$(OUTDIR)\getpic.obj : getpic.cpp global.h misc.h resource.h pat.h getbit.h -$(OUTDIR)\gui.obj : gui.cpp resource.h global.h misc.h pat.h -$(OUTDIR)\idctfpu.obj : idctfpu.cpp -$(OUTDIR)\idctref.obj : idctref.cpp -$(OUTDIR)\initial_parse.obj : initial_parse.cpp resource.h global.h misc.h pat.h -$(OUTDIR)\misc.obj : misc.cpp global.h misc.h resource.h pat.h -$(OUTDIR)\motion.obj : motion.cpp global.h misc.h resource.h pat.h getbit.h -$(OUTDIR)\mpeg2dec.obj : mpeg2dec.cpp global.h misc.h resource.h pat.h getbit.h -$(OUTDIR)\norm.obj : norm.cpp global.h misc.h resource.h pat.h -$(OUTDIR)\parse_cli.obj : parse_cli.cpp resource.h global.h misc.h pat.h -$(OUTDIR)\pat.obj : pat.cpp resource.h global.h misc.h pat.h -$(OUTDIR)\store.obj : store.cpp global.h misc.h resource.h pat.h filter.h -$(OUTDIR)\strverscmp.obj : strverscmp.cpp -$(OUTDIR)\wavefs44.obj : wavefs44.cpp global.h misc.h resource.h pat.h -$(OUTDIR)\AC3Dec\bit_allocate.obj : AC3Dec\bit_allocate.cpp AC3Dec\ac3.h -$(OUTDIR)\AC3Dec\bitstream.obj : AC3Dec\bitstream.cpp AC3Dec\ac3.h AC3Dec\bitstream.h -$(OUTDIR)\AC3Dec\coeff.obj : AC3Dec\coeff.cpp AC3Dec\ac3.h AC3Dec\bitstream.h -$(OUTDIR)\AC3Dec\crc.obj : AC3Dec\crc.cpp AC3Dec\ac3.h -$(OUTDIR)\AC3Dec\decode.obj : AC3Dec\decode.cpp global.h AC3Dec\ac3.h AC3Dec\bitstream.h -$(OUTDIR)\AC3Dec\downmix.obj : AC3Dec\downmix.cpp global.h AC3Dec\ac3.h -$(OUTDIR)\AC3Dec\exponent.obj : AC3Dec\exponent.cpp AC3Dec\ac3.h -$(OUTDIR)\AC3Dec\imdct.obj : AC3Dec\imdct.cpp AC3Dec\ac3.h -$(OUTDIR)\AC3Dec\parse.obj : AC3Dec\parse.cpp AC3Dec\ac3.h AC3Dec\bitstream.h -$(OUTDIR)\AC3Dec\rematrix.obj : AC3Dec\rematrix.cpp AC3Dec\ac3.h -$(OUTDIR)\AC3Dec\sanity_check.obj : AC3Dec\sanity_check.cpp AC3Dec\ac3.h -$(OUTDIR)\gui.res : gui.rc resource.h diff --git a/src/dgindex/misc.cpp b/src/dgindex/misc.cpp deleted file mode 100644 index 49c6454..0000000 --- a/src/dgindex/misc.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Misc Stuff (profiling) for MPEG2Dec3 - * - * Copyright (C) 2002-2003 Marc Fauconneau - * - * This file is part of MPEG2Dec3, a free MPEG-2 decoder - * - * MPEG2Dec3 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. - * - * MPEG2Dec3 is distributed in the hope that 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 "global.h" - -static ui64 local; -static char buffer[256]; - -unsigned __int64 read_counter(void) -{ - unsigned __int64 ts; - unsigned __int32 ts1, ts2; - __asm { - rdtsc - mov ts1, eax - mov ts2, edx - } - ts = ((unsigned __int64) ts2 << 32) | ((unsigned __int64) ts1); - return ts; -} - -// get CPU frequency in Hz (1MHz precision) -ui64 get_freq(void) -{ - unsigned __int64 x = 0; - time_t i; - i = time(NULL); - while (i == time(NULL)); - x -= read_counter(); - i++; - while (i == time(NULL)); - x += read_counter(); - return x; -} - -void init_first(ts* timers) { - memset(timers,0,sizeof(ts)); - timers->div = 0; timers->sum = 0; - timers->freq = get_freq()/1000; -// timers->freq = 1412*1000000; // shortcut for my athlon xp 1600+ (1.4 Gz) -} - -void init_timers(ts* timers) { - timers->idct = 0; - timers->conv = 0; - timers->mcpy = 0; - timers->post = 0; - timers->dec = 0; - timers->bit = 0; - timers->decMB = 0; - timers->mcmp = 0; - timers->addb = 0; - timers->overall = 0; - if (timers->div > 25) { timers->div = 0; timers->sum = 0; } -} - -void start_timer() { - local = read_counter(); -} - -ui64 read_timer() -{ - ui64 tmp; - - tmp = local; - local = read_counter(); - return (local - tmp); -} - -void start_timer2(ui64* timer) { - *timer -= read_counter(); -} - -void stop_timer(ui64* timer) { - *timer += (read_counter() - local); -} - -void stop_timer2(ui64* timer) { - *timer += read_counter(); -} - -void timer_debug(ts* timers) { - ts tim = *timers; - //tim.freq = ; -// sprintf(buffer,"conv = %I64d ",tim.conv); -// sprintf(buffer,"idct = %I64d overall=%I64d idct% = %f",tim.idct,tim.overall,(double)tim.idct*100/tim.overall); - sprintf(buffer,"| dec%% = %f > mcmp%% = %f addb%% = %f idct%% = %f decMB%% = %f bit%% = %f | conv%% = %f | post%% = %f | mcpy%% = %f | msec = %f fps = %f mean = %f", - (double)tim.dec*100/tim.overall, - (double)tim.idct*100/tim.overall, - (double)tim.addb*100/tim.overall, - (double)tim.mcmp*100/tim.overall, - (double)tim.decMB*100/tim.overall, - (double)tim.bit*100/tim.overall, - (double)tim.conv*100/tim.overall, - (double)tim.post*100/tim.overall, - (double)tim.mcpy*100/tim.overall, - (double)tim.overall*1000/tim.freq, - tim.freq/(double)tim.overall, - (tim.freq)/((double)tim.sum/tim.div) - ); - OutputDebugString(buffer); -} - -int dprintf(char* fmt, ...) -{ - char printString[1000]; - va_list argp; - va_start(argp, fmt); - vsprintf(printString, fmt, argp); - va_end(argp); - OutputDebugString(printString); - return strlen(printString); -} diff --git a/src/dgindex/misc.h b/src/dgindex/misc.h deleted file mode 100644 index 3c4b4e6..0000000 --- a/src/dgindex/misc.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Misc Stuff (profiling) for MPEG2Dec3 - * - * Copyright (C) 2002-2003 Marc Fauconneau - * - * This file is part of MPEG2Dec3, a free MPEG-2 decoder - * - * MPEG2Dec3 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. - * - * MPEG2Dec3 is distributed in the hope that 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. - * - */ - -#define ui64 unsigned __int64 - -struct ts_t -{ - ui64 idct; - ui64 conv; - ui64 mcpy; - ui64 post; - ui64 dec; - ui64 bit; - ui64 decMB; - ui64 mcmp; - ui64 addb; - ui64 overall; - ui64 sum; - int div; - ui64 freq; -}; - -typedef struct ts_t ts; - -ui64 read_counter(void); -ui64 get_freq(void); -int dprintf(char* fmt, ...); - -void init_first(ts* timers); -void init_timers(ts* timers); -void start_timer(); -ui64 read_timer(); -void start_timer2(ui64* timer); -void stop_timer(ui64* timer); -void stop_timer2(ui64* timer); -void timer_debug(ts* tim); diff --git a/src/dgindex/motion.cpp b/src/dgindex/motion.cpp deleted file mode 100644 index 788ace7..0000000 --- a/src/dgindex/motion.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */ - -/* - * Disclaimer of Warranty - * - * These software programs are available to the user without any license fee or - * royalty on an "as is" basis. The MPEG Software Simulation Group disclaims - * any and all warranties, whether express, implied, or statuary, including any - * implied warranties or merchantability or of fitness for a particular - * purpose. In no event shall the copyright-holder be liable for any - * incidental, punitive, or consequential damages of any kind whatsoever - * arising from the use of these programs. - * - * This disclaimer of warranty extends to the user of these programs and user's - * customers, employees, agents, transferees, successors, and assigns. - * - * The MPEG Software Simulation Group does not represent or warrant that the - * programs furnished hereunder are free of infringement of any third-party - * patents. - * - * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware, - * are subject to royalty fees to patent holders. Many of these patents are - * general enough such that they are unavoidable regardless of implementation - * design. - * - */ - -#include "global.h" -#include "getbit.h" - -void motion_vector(int *PMV, int *dmvector, int h_r_size, int v_r_size, - int dmv, int mvscale, int full_pel_vector); -__forceinline static void decode_motion_vector(int *pred, int r_size, int motion_code, - int motion_residualesidual, int full_pel_vector); -__forceinline static int Get_motion_code(void); -__forceinline static int Get_dmvector(void); -extern void SetFaultFlag(int val); - -/* ISO/IEC 13818-2 sections 6.2.5.2, 6.3.17.2, and 7.6.3: Motion vectors */ -void motion_vectors(int PMV[2][2][2],int dmvector[2], - int motion_vertical_field_select[2][2], int s, - int motion_vector_count, int mv_format, int h_r_size, - int v_r_size, int dmv, int mvscale) -{ - if (motion_vector_count==1) - { - if (mv_format==MV_FIELD && !dmv) - motion_vertical_field_select[1][s] = - motion_vertical_field_select[0][s] = Get_Bits(1); - - motion_vector(PMV[0][s],dmvector,h_r_size,v_r_size,dmv,mvscale,0); - - /* update other motion vector predictors */ - PMV[1][s][0] = PMV[0][s][0]; - PMV[1][s][1] = PMV[0][s][1]; - } - else - { - motion_vertical_field_select[0][s] = Get_Bits(1); - motion_vector(PMV[0][s],dmvector,h_r_size,v_r_size,dmv,mvscale,0); - motion_vertical_field_select[1][s] = Get_Bits(1); - motion_vector(PMV[1][s],dmvector,h_r_size,v_r_size,dmv,mvscale,0); - } -} - -/* get and decode motion vector and differential motion vector for one prediction */ -void motion_vector(int *PMV, int *dmvector, int h_r_size, int v_r_size, - int dmv, int mvscale, int full_pel_vector) -{ - int motion_code, motion_residual; - - /* horizontal component */ - /* ISO/IEC 13818-2 Table B-10 */ - motion_code = Get_motion_code(); - - motion_residual = (h_r_size!=0 && motion_code!=0) ? Get_Bits(h_r_size) : 0; - - decode_motion_vector(&PMV[0],h_r_size,motion_code,motion_residual,full_pel_vector); - - if (dmv) - dmvector[0] = Get_dmvector(); - - /* vertical component */ - motion_code = Get_motion_code(); - motion_residual = (v_r_size!=0 && motion_code!=0) ? Get_Bits(v_r_size) : 0; - - if (mvscale) - PMV[1] >>= 1; /* DIV 2 */ - - decode_motion_vector(&PMV[1],v_r_size,motion_code,motion_residual,full_pel_vector); - - if (mvscale) - PMV[1] <<= 1; - - if (dmv) - dmvector[1] = Get_dmvector(); -} - -/* calculate motion vector component */ -/* ISO/IEC 13818-2 section 7.6.3.1: Decoding the motion vectors */ -/* Note: the arithmetic here is more elegant than that which is shown - in 7.6.3.1. The end results (PMV[][][]) should, however, be the same. */ -static void decode_motion_vector(int *pred, int r_size, int motion_code, - int motion_residual, int full_pel_vector) -{ - int lim, vec; - - lim = 16<> 1) : (*pred); - - if (motion_code>0) - { - vec+= ((motion_code-1)<=lim) - vec-= lim + lim; - } - else if (motion_code<0) - { - vec-= ((-motion_code-1)<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 (picture_structure==TOP_FIELD) - DMV[0][1]--; - else - DMV[0][1]++; - } -} - -static int Get_motion_code() -{ - int code; - - if (Get_Bits(1)) - return 0; - - code = Show_Bits(9); - if (code >= 64) - { - code >>= 6; - Flush_Buffer(MVtab0[code].len); - return (Get_Bits(1) ? -MVtab0[code].val : MVtab0[code].val); - } - - if (code>=24) - { - code >>= 3; - Flush_Buffer(MVtab1[code].len); - return (Get_Bits(1) ? -MVtab1[code].val : MVtab1[code].val); - } - - if (code >= 12) - { - code -= 12; - Flush_Buffer(MVtab2[code].len); - return (Get_Bits(1) ? -MVtab2[code].val : MVtab2[code].val); - } - - SetFaultFlag(6); - return 0; -} - -/* get differential motion vector (for dual prime prediction) */ -static int Get_dmvector() -{ - if (Get_Bits(1)) - return Get_Bits(1) ? -1 : 1; - else - return 0; -} diff --git a/src/dgindex/movie.ico b/src/dgindex/movie.ico deleted file mode 100644 index d93f534..0000000 Binary files a/src/dgindex/movie.ico and /dev/null differ diff --git a/src/dgindex/mpeg2dec.cpp b/src/dgindex/mpeg2dec.cpp deleted file mode 100644 index 62a5ed2..0000000 --- a/src/dgindex/mpeg2dec.cpp +++ /dev/null @@ -1,680 +0,0 @@ -/* - * Mutated into DGIndex. Modifications Copyright (C) 2004, Donald Graft - * - * Copyright (C) Chia-chen Kuo - April 2001 - * - * This file is part of DVD2AVI, a free MPEG-2 decoder - * - * DVD2AVI 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. - * - * DVD2AVI is distributed in the hope that 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 "global.h" -#include "getbit.h" -#include "math.h" -#include "shlwapi.h" - -static BOOL GOPBack(void); -static void InitialDecoder(void); -extern void StartVideoDemux(void); - -#define DISABLE_EXCEPTION_HANDLING - -DWORD WINAPI MPEG2Dec(LPVOID n) -{ - int i = (int) n; // Prevent compiler warning. - extern __int64 VideoPTS; - extern __int64 AudioPTS; - extern FILE *mpafp, *mpvfp; - __int64 saveloc; - int savefile; - int field; - - extern int check_audio_packet_continue; - check_audio_packet_continue = 0; - extern unsigned int num_pmt_pids; - num_pmt_pids = pat_parser.GetNumPMTpids(); - - Pause_Flag = Stop_Flag = Start_Flag = HadAudioPTS = false; - VideoPTS = AudioPTS = 0; - Fault_Flag = 0; - Frame_Number = Second_Field = 0; - Sound_Max = 1; Bitrate_Monitor = 0; - Bitrate_Average = 0.0; - max_rate = 0.0; - GOPSeen = false; - AudioOnly_Flag = false; - AudioFilePath[0] = 0; - LowestAudioId = 0xffffffff; - StartLogging_Flag = 0; - d2v_current.picture_structure = -1; - - for (i = 0; i < 0xc8; i++) - { - audio[i].type = 0; - audio[i].rip = 0; - audio[i].size = 0; - } - mpafp = mpvfp = NULL; - - switch (process.locate) - { - case LOCATE_FORWARD: - process.startfile = process.file; - process.startloc = (process.lba + 1) * SECTOR_SIZE; - - process.end = Infiletotal - SECTOR_SIZE; - process.endfile = NumLoadedFiles - 1; - process.endloc = (Infilelength[NumLoadedFiles-1]/SECTOR_SIZE - 1) * SECTOR_SIZE; - break; - - case LOCATE_BACKWARD: - process.startfile = process.file; - process.startloc = process.lba * SECTOR_SIZE; - process.end = Infiletotal - SECTOR_SIZE; - process.endfile = NumLoadedFiles - 1; - process.endloc = (Infilelength[NumLoadedFiles-1]/SECTOR_SIZE - 1) * SECTOR_SIZE; - if (GOPBack() == false && CurrentFile > 0) - { - // Trying to step back to previous VOB file. - process.startfile--; - CurrentFile--; - process.startloc = Infilelength[process.startfile]; - process.run = 0; - for (i=0; i 10000000) - { - // We didn't find a sequence header. - MessageBox(hWnd, "No video sequence header found!", NULL, MB_OK | MB_ICONERROR); - ThreadKill(MISC_KILL); - } - Flush_Buffer(8); - count++; - } - - // Determine whether this is an MPEG2 file and whether it is a program stream. - if (SystemStream_Flag != TRANSPORT_STREAM && SystemStream_Flag != PVA_STREAM) - { - mpeg_type = IS_NOT_MPEG; - is_program_stream = 0; - if (initial_parse(Infilename[0], &mpeg_type, &is_program_stream) == -1) - { - MessageBox(hWnd, "Cannot find video stream!", NULL, MB_OK | MB_ICONERROR); - return 0; - } - if (is_program_stream) - { - SystemStream_Flag = PROGRAM_STREAM; - } - } - - CurrentFile = 0; - _lseeki64(Infile[0], 0, SEEK_SET); - Initialize_Buffer(); - - // We know the stream type now, so our parsing is immune to - // emulated video sequence headers in the pack layer. - while (!Check_Flag) - { - // Move to the next video start code. - next_start_code(); - code = Get_Bits(32); - switch (code) - { - case SEQUENCE_HEADER_CODE: - if (Stop_Flag == true) - ThreadKill(MISC_KILL); - sequence_header(); - InitialDecoder(); - Check_Flag = true; - break; - } - } - } - - Frame_Rate = (FO_Flag==FO_FILM) ? frame_rate * 0.8 : frame_rate; - - if (D2V_Flag) - { - i = NumLoadedFiles; - - // The first parameter is the format version number. - // It must be coordinated with the test in DGDecode - // and used to reject obsolete D2V files. - fprintf(D2VFile, "DGIndexProjectFile%d\n%d\n", D2V_FILE_VERSION, i); - while (i) - { - if (FullPathInFiles) - fprintf(D2VFile, "%s\n", Infilename[NumLoadedFiles-i]); - else - { - char path[DG_MAX_PATH]; - char* p = path; - - if (!PathRelativePathTo(path, D2VFilePath, 0, Infilename[NumLoadedFiles-i], 0)) - p = Infilename[NumLoadedFiles - i]; // different drives; - // Delete leading ".\" if it is present. - if (p[0] == '.' && p[1] == '\\') - p += 2; - fprintf(D2VFile, "%s\n", p); - } - i--; - } - - fprintf(D2VFile, "\nStream_Type=%d\n", SystemStream_Flag); - if (SystemStream_Flag == TRANSPORT_STREAM) - { - fprintf(D2VFile, "MPEG2_Transport_PID=%x,%x,%x\n", - MPEG2_Transport_VideoPID, MPEG2_Transport_AudioPID, MPEG2_Transport_PCRPID); - fprintf(D2VFile, "Transport_Packet_Size=%d\n", TransportPacketSize); - } - - fprintf(D2VFile, "MPEG_Type=%d\n", mpeg_type); - fprintf(D2VFile, "iDCT_Algorithm=%d\n", iDCT_Flag); - fprintf(D2VFile, "YUVRGB_Scale=%d\n", Scale_Flag); - if (Luminance_Flag) - { - fprintf(D2VFile, "Luminance_Filter=%d,%d\n", LumGamma, LumOffset); - } - else - { - fprintf(D2VFile, "Luminance_Filter=0,0\n"); - } - - if (Cropping_Flag) - { - fprintf(D2VFile, "Clipping=%d,%d,%d,%d\n", Clip_Left, Clip_Right, Clip_Top, Clip_Bottom); - } - else - { - fprintf(D2VFile, "Clipping=0,0,0,0\n"); - } - - if (mpeg_type == IS_MPEG2) - fprintf(D2VFile, "Aspect_Ratio=%s\n", AspectRatio[aspect_ratio_information]); - else - fprintf(D2VFile, "Aspect_Ratio=%s\n", AspectRatioMPEG1[aspect_ratio_information]); - fprintf(D2VFile, "Picture_Size=%dx%d\n", horizontal_size, vertical_size); - fprintf(D2VFile, "Field_Operation=%d\n", FO_Flag); - if (FO_Flag == FO_FILM) - { - if (fabs(Frame_Rate - 23.976) < 0.001) - { - fr_num = 24000; - fr_den = 1001; - } - else - { - fr_num = (unsigned int) (1000 * Frame_Rate); - fr_den = 1000; - } - } - fprintf(D2VFile, "Frame_Rate=%d (%u/%u)\n", (int)(Frame_Rate*1000), fr_num, fr_den); - fprintf(D2VFile, "Location=%d,%I64x,%d,%I64x\n\n", - process.leftfile, process.leftlba, process.rightfile, process.rightlba); - - // Determine the number of leading B frames from the start position. This will be used to - // adjust VideoPTS so that it refers to the correct access unit. - PTSAdjustDone = 0; - savefile = process.startfile; - saveloc = process.startloc; - CurrentFile = process.startfile; - _lseeki64(Infile[process.startfile], (process.startloc/SECTOR_SIZE)*SECTOR_SIZE, SEEK_SET); - // We initialize the following variables to the current start position, because if the user - // has set a range, and the packs are large such that we won't hit a pack/packet start - // before we hit an I frame, we don't want the pack/packet position to remain at 0. - // It has to be at least equal to or greater than the starting position in the stream. - CurrentPackHeaderPosition = PackHeaderPosition = (process.startloc/SECTOR_SIZE)*SECTOR_SIZE; - Initialize_Buffer(); - for (;;) - { - if (Stop_Flag) break; - Get_Hdr(0); - if (picture_coding_type == I_TYPE) break; - } - LeadingBFrames = 0; - for (;;) - { - if (Get_Hdr(1) == 1) - { - // We hit a sequence end code or end of file, so there are no - // more frames. - break; - } - if (picture_coding_type != B_TYPE) break; - if (picture_structure == FRAME_PICTURE) - LeadingBFrames += 2; - else - LeadingBFrames += 1; - } - LeadingBFrames /= 2; - process.startfile = savefile; - process.startloc = saveloc; - Stop_Flag = false; - } - - // Start normal decoding from the start position. - if (Timestamps) - { - StartLogging_Flag = 1; - fprintf(Timestamps, "leading B frames = %d\n", LeadingBFrames); - } - PTSAdjustDone = 0; - CurrentFile = process.startfile; - _lseeki64(Infile[process.startfile], (process.startloc/SECTOR_SIZE)*SECTOR_SIZE, SEEK_SET); - // We initialize the following variables to the current start position, because if the user - // has set a range, and the packs are large such that we won't hit a pack/packet start - // before we hit an I frame, we don't want the pack/packet position to remain at 0. - // It has to be at least equal to or greater than the starting position in the stream. - CurrentPackHeaderPosition = PackHeaderPosition = (process.startloc/SECTOR_SIZE)*SECTOR_SIZE; - if (MuxFile == (FILE *) 0 && process.locate == LOCATE_RIP) - StartVideoDemux(); - Initialize_Buffer(); - - timing.op = 0; - for (;;) - { - Get_Hdr(0); - if (Stop_Flag == true) - ThreadKill(MISC_KILL); - if (picture_coding_type == I_TYPE) break; - } - Start_Flag = true; - process.file = d2v_current.file; - process.lba = d2v_current.lba; - - Decode_Picture(); - - timing.op = timing.mi = timeGetTime(); - - field = 0; - for (;;) - { - Get_Hdr(0); - if (Stop_Flag && (!field || picture_structure == FRAME_PICTURE)) - { - // Stop only after every two fields if we are decoding field pictures. - Write_Frame(current_frame, d2v_current, Frame_Number - 1); - ThreadKill(MISC_KILL); - } - Decode_Picture(); - field ^= 1; - if (Stop_Flag && (!field || picture_structure == FRAME_PICTURE)) - { - // Stop only after every two fields if we are decoding field pictures. - Write_Frame(current_frame, d2v_current, Frame_Number - 1); - ThreadKill(MISC_KILL); - } - } - return 0; -} - -static BOOL GOPBack() -{ - int i; - int startfile; - __int64 startloc, endloc, curloc, startlba; - - startfile = process.startfile; - startloc = process.startloc; - startlba = process.lba; - - for (;;) - { - endloc = startloc; - startloc -= SECTOR_SIZE<<4; - - if (startloc >= 0) - { - process.startfile = startfile; - process.startloc = startloc; - } - else - { - process.startloc = 0; - return false; - } - - _lseeki64(Infile[process.startfile], process.startloc, SEEK_SET); - Initialize_Buffer(); - - for (;;) - { - curloc = _telli64(Infile[process.startfile]); - if (curloc >= endloc) break; - Get_Hdr(0); - if (Stop_Flag == true) - ThreadKill(MISC_KILL); - if (picture_structure != FRAME_PICTURE) - { - Get_Hdr(0); - if (Stop_Flag == true) - ThreadKill(MISC_KILL); - } - if (picture_coding_type==I_TYPE) - { - if (d2v_current.file > startfile) - { - // We've crossed back into the next file and found - // the first I frame. That's not the one we are looking for, - // so go back again and keep looking. - CurrentFile = startfile; - process.run = 0; - for (i=0; i < startfile; i++) - process.run += Infilelength[i]; - break; - } - if (d2v_current.lba == startlba) - { - // We've found the I frame we are trying to step back from. - // That's not the one we want, so keep looking. - break; - } - // We've found the I frame we want! - process.startfile = d2v_current.file; - process.startloc = d2v_current.lba * SECTOR_SIZE; - // This is a kludge. For PES streams, the pack start - // might be in the previous LBA! - if (SystemStream_Flag != ELEMENTARY_STREAM) - process.startloc -= SECTOR_SIZE + 4; - return true; - } - } - } -} - -static int ChromaFormat[4] = { - 0, 6, 8, 12 -}; - -static void InitialDecoder() -{ - int i, size; - extern int Clip_Width, Clip_Height; - - mb_width = (horizontal_size+15)/16; - mb_height = progressive_sequence ? (vertical_size+15)/16 : 2*((vertical_size+31)/32); - - Coded_Picture_Width = 16 * mb_width; - Coded_Picture_Height = 16 * mb_height; - - block_count = ChromaFormat[chroma_format]; - - for (i=0; i<3; i++) - { - if (i==0) - size = Coded_Picture_Width * Coded_Picture_Height; - else - size = ((chroma_format==CHROMA444) ? Coded_Picture_Width : Coded_Picture_Width>>1) * - ((chroma_format!=CHROMA420) ? Coded_Picture_Height : Coded_Picture_Height>>1); - - backward_reference_frame[i] = (unsigned char*)_aligned_malloc(size, 64); - forward_reference_frame[i] = (unsigned char*)_aligned_malloc(size, 64); - auxframe[i] = (unsigned char*)_aligned_malloc(size, 64); - } - - u422 = (unsigned char*)_aligned_malloc(Coded_Picture_Width*Coded_Picture_Height/2, 64); - v422 = (unsigned char*)_aligned_malloc(Coded_Picture_Width*Coded_Picture_Height/2, 64); - u444 = (unsigned char*)_aligned_malloc(Coded_Picture_Width*Coded_Picture_Height, 64); - v444 = (unsigned char*)_aligned_malloc(Coded_Picture_Width*Coded_Picture_Height, 64); - rgb24 = (unsigned char*)_aligned_malloc(Coded_Picture_Width*Coded_Picture_Height*3, 64); - rgb24small = (unsigned char*)_aligned_malloc(Coded_Picture_Width*Coded_Picture_Height*3, 64); - yuy2 = (unsigned char*)_aligned_malloc(Coded_Picture_Width*Coded_Picture_Height*2, 64); - lum = (unsigned char*)_aligned_malloc(Coded_Picture_Width*Coded_Picture_Height, 64); - Clip_Width = horizontal_size; - Clip_Height = vertical_size; -} - -void setRGBValues() -{ - if (Scale_Flag) - { - RGB_Scale = 0x1000254310002543; - RGB_Offset = 0x0010001000100010; - if (matrix_coefficients == 7) // SMPTE 240M (1987) - { - RGB_CBU = 0x0000428500004285; - RGB_CGX = 0xF7BFEEA3F7BFEEA3; - RGB_CRV = 0x0000396900003969; - } - else if (matrix_coefficients == 6 || matrix_coefficients == 5) // SMPTE 170M/ITU-R BT.470-2 -- BT.601 - { - RGB_CBU = 0x0000408D0000408D; - RGB_CGX = 0xF377E5FCF377E5FC; - RGB_CRV = 0x0000331300003313; - } - else if (matrix_coefficients == 4) // FCC - { - RGB_CBU = 0x000040D8000040D8; - RGB_CGX = 0xF3E9E611F3E9E611; - RGB_CRV = 0x0000330000003300; - } - else // ITU-R Rec.709 (1990) -- BT.709 - { - RGB_CBU = 0x0000439A0000439A; - RGB_CGX = 0xF92CEEF1F92CEEF1; - RGB_CRV = 0x0000395F0000395F; - } - } - else - { - RGB_Scale = 0x1000200010002000; - RGB_Offset = 0x0000000000000000; - if (matrix_coefficients == 7) // SMPTE 240M (1987) - { - RGB_CBU = 0x00003A6F00003A6F; - RGB_CGX = 0xF8C0F0BFF8C0F0BF; - RGB_CRV = 0x0000326E0000326E; - } - else if (matrix_coefficients == 6 || matrix_coefficients == 5) // SMPTE 170M/ITU-R BT.470-2 -- BT.601 - { - RGB_CBU = 0x000038B4000038B4; - RGB_CGX = 0xF4FDE926F4FDE926; - RGB_CRV = 0x00002CDD00002CDD; - } - else if (matrix_coefficients == 4) // FCC - { - RGB_CBU = 0x000038F6000038F6; - RGB_CGX = 0xF561E938F561E938; - RGB_CRV = 0x00002CCD00002CCD; - } - else // ITU-R Rec.709 (1990) -- BT.709 - { - RGB_CBU = 0x00003B6200003B62; - RGB_CGX = 0xFA00F104FA00F104; - RGB_CRV = 0x0000326600003266; - } - } -} diff --git a/src/dgindex/norm.cpp b/src/dgindex/norm.cpp deleted file mode 100644 index 5492016..0000000 --- a/src/dgindex/norm.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Mutated into DGIndex. Modifications Copyright (C) 2004, Donald Graft - * - * Copyright (C) Chia-chen Kuo - April 2001 - * - * This file is part of DVD2AVI, a free MPEG-2 decoder - * - * DVD2AVI 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. - * - * DVD2AVI is distributed in the hope that 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 "global.h" -#include - -#define NORM_SIZE 1048576 - -static short Norm_Table[65536]; // -32768 ~ 32767 -static short Norm_Buffer[NORM_SIZE]; - -static void TwoPass(FILE *WaveIn, int WaveInPos, FILE *WaveOut, int WaveOutPos, int size, int pass); - -void Normalize(FILE *WaveIn, int WaveInPos, char *filename, FILE *WaveOut, int WaveOutPos, int size) -{ - int i, norm; - bool trigger = false; - double ratio = 1.0; - - if (Norm_Flag) - { - if (WaveIn==NULL) // In = Out - WaveIn = fopen(filename, "rb"); - else - TwoPass(WaveIn, WaveInPos, NULL, 0, size, 0); - - ratio = 327.68 * Norm_Ratio / Sound_Max; - - if (ratio >= 1.01 || ratio < 1.0) - trigger = true; - } - else if (WaveIn!=NULL) - trigger = true; - - for (i=-32768; i<0; i++) - { - norm = (int)(ratio * i - 0.5); - - if (norm < -32768) - Norm_Table[i+32768] = -32768; - else - Norm_Table[i+32768] = norm; - } - - Norm_Table[32768] = 0; - - for (i=1; i<32768; i++) - { - if (Norm_Table[i] > -32767) - Norm_Table[65536-i] = -Norm_Table[i]; - else - Norm_Table[65536-i] = 32767; - } - - sprintf(szBuffer, "%.2f", ratio); - SetDlgItemText(hDlg, IDC_INFO, szBuffer); - - if (trigger) - TwoPass(WaveIn, WaveInPos, WaveOut, WaveOutPos, size, 1); -} - -static void TwoPass(FILE *WaveIn, int WaveInPos, FILE *WaveOut, int WaveOutPos, int size, int pass) -{ - int i, rsize, maxsize = size; - - fseek(WaveIn, WaveInPos, SEEK_SET); - - if (pass) - fseek(WaveOut, WaveOutPos, SEEK_SET); - - timing.op = timeGetTime(); - - while (size > 0) - { - float percent; - - rsize = (size >= NORM_SIZE ? NORM_SIZE : size); - - fread(Norm_Buffer, rsize, 1, WaveIn); - - if (pass) - { - for (i=0; i<(rsize>>1); i++) - Norm_Buffer[i] = Norm_Table[Norm_Buffer[i]+32768]; - - fwrite(Norm_Buffer, rsize, 1, WaveOut); - } - else - for (i=0; i<(rsize>>1); i++) - if (Sound_Max < abs(Norm_Buffer[i])) - Sound_Max = abs(Norm_Buffer[i]); - - size -= rsize; - - timing.ed = timeGetTime(); - elapsed = (timing.ed-timing.op)/1000; - percent = (float)(100.0*(maxsize-size)/maxsize); - remain = (int)((timing.ed-timing.op)*(100.0-percent)/percent)/1000; - - if (Info_Flag) - { - sprintf(szBuffer, "%d:%02d:%02d", elapsed/3600, (elapsed%3600)/60, elapsed%60); - SetDlgItemText(hDlg, IDC_ELAPSED, szBuffer); - - sprintf(szBuffer, "%d:%02d:%02d", remain/3600, (remain%3600)/60, remain%60); - SetDlgItemText(hDlg, IDC_REMAIN, szBuffer); - } - - InvalidateRect(hwndSelect, NULL, TRUE); - SendMessage(hTrack, TBM_SETPOS, (WPARAM)true, (int)(percent*TRACK_PITCH/100)); - } -} diff --git a/src/dgindex/parse_cli.cpp b/src/dgindex/parse_cli.cpp deleted file mode 100644 index 2b465b1..0000000 --- a/src/dgindex/parse_cli.cpp +++ /dev/null @@ -1,1280 +0,0 @@ -#include -#include "resource.h" -#include "Shlwapi.h" -#include "global.h" - -int parse_cli(LPSTR lpCmdLine, LPSTR ucCmdLine) -{ - char cwd[DG_MAX_PATH]; - int i; - - if (!strstr(lpCmdLine, "=")) - { - // UNIX-style CLI. - char *p = lpCmdLine, *q; - char *f, name[DG_MAX_PATH], *ptr; - int in_quote = 0; - int tmp; - int enable_demux = 0; - char opt[32], *o; - char suffix[DG_MAX_PATH]; - int val; - - // CLI invocation. - NumLoadedFiles = 0; - CLIPreview = 0; - ExitOnEnd = 0; - hadRGoption = 0; - - while (1) - { - while (*p == ' ' || *p == '\t') p++; - if (*p == '-') - { - p++; - o = opt; - while (*p != ' ' && *p != '\t' && *p != 0) - *o++ = *p++; - *o = 0; - if (!strncmp(opt, "i", 3)) - { -another: - while (*p == ' ' || *p == '\t') p++; - f = name; - while (1) - { - if ((in_quote == 0) && (*p == ' ' || *p == '\t' || *p == 0)) - break; - if ((in_quote == 1) && (*p == 0)) - break; - if (*p == '"') - { - if (in_quote == 0) - { - in_quote = 1; - p++; - } - else - { - in_quote = 0; - p++; - break; - } - } - *f++ = *p++; - } - *f = 0; - /* If the specified file does not include a path, use the - current directory. */ - if (name[0] != '\\' && name[1] != ':') - { - GetCurrentDirectory(sizeof(cwd) - 1, cwd); - strcat(cwd, "\\"); - strcat(cwd, name); - } - else - { - strcpy(cwd, name); - } - if ((tmp = _open(cwd, _O_RDONLY | _O_BINARY)) != -1) - { - strcpy(Infilename[NumLoadedFiles], cwd); - Infile[NumLoadedFiles] = tmp; - NumLoadedFiles++; - } - if (*p != 0 && *(p+1) != '-') - goto another; - Recovery(); - RefreshWindow(true); - } - if (!strncmp(opt, "ai", 3)) - { - while (*p == ' ' || *p == '\t') p++; - f = name; - while (1) - { - if ((in_quote == 0) && (*p == ' ' || *p == '\t' || *p == 0)) - break; - if ((in_quote == 1) && (*p == 0)) - break; - if (*p == '"') - { - if (in_quote == 0) - { - in_quote = 1; - p++; - } - else - { - in_quote = 0; - p++; - break; - } - } - *f++ = *p++; - } - *f = 0; - for (;;) - { - /* If the specified file does not include a path, use the - current directory. */ - if (name[0] != '\\' && name[1] != ':') - { - GetCurrentDirectory(sizeof(cwd) - 1, cwd); - strcat(cwd, "\\"); - strcat(cwd, name); - } - else - { - strcpy(cwd, name); - } - if ((tmp = _open(cwd, _O_RDONLY | _O_BINARY | _O_SEQUENTIAL)) == -1) - break; - strcpy(Infilename[NumLoadedFiles], cwd); - Infile[NumLoadedFiles] = tmp; - NumLoadedFiles++; - - // First scan back from the end of the name for an _ character. - ptr = name + strlen(name); - while (*ptr != '_' && ptr >= name) ptr--; - if (*ptr != '_') break; - // Now pick up the number value and increment it. - ptr++; - if (*ptr < '0' || *ptr > '9') break; - sscanf(ptr, "%d", &val); - val++; - // Save the suffix after the number. - q = ptr; - while (*ptr >= '0' && *ptr <= '9') ptr++; - strcpy(suffix, ptr); - // Write the new incremented number. - sprintf(q, "%d", val); - // Append the saved suffix. - strcat(name, suffix); - } - Recovery(); - RefreshWindow(true); - } - else if (!strncmp(opt, "rg", 3)) - { - while (*p == ' ' || *p == '\t') p++; - sscanf(p, "%d %I64x %d %I64x\n", - &process.leftfile, &process.leftlba, &process.rightfile, &process.rightlba); - while (*p != '-' && *p != 0) p++; - p--; - - process.startfile = process.leftfile; - process.startloc = process.leftlba * SECTOR_SIZE; - process.endfile = process.rightfile; - process.endloc = (process.rightlba - 1) * SECTOR_SIZE; - - process.run = 0; - for (i=0; i= '0' && *ptr <= '9') || (*ptr >= 'a' && *ptr <= 'f') || (*ptr >= 'A' && *ptr <= 'F')) - { - sscanf(ptr, "%x", &audio_id); - if (audio_id > 0xc7) - break; - audio[audio_id].selected_for_demux = true; - while (*ptr != ',' && *ptr != 0) ptr++; - if (*ptr == 0) - break; - ptr++; - } - - Method_Flag = AUDIO_DEMUX; - CheckMenuItem(hMenu, IDM_AUDIO_NONE, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_DEMUX, MF_CHECKED); - CheckMenuItem(hMenu, IDM_DEMUXALL, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_DECODE, MF_UNCHECKED); - EnableMenuItem(GetSubMenu(hMenu, 3), 1, MF_BYPOSITION | MF_ENABLED); - EnableMenuItem(GetSubMenu(hMenu, 3), 3, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(GetSubMenu(hMenu, 3), 4, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(GetSubMenu(hMenu, 3), 5, MF_BYPOSITION | MF_GRAYED); - } - else if (!strncmp(opt, "om", 3)) - { - CheckMenuItem(hMenu, IDM_AUDIO_NONE, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_DEMUX, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_DEMUXALL, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_DECODE, MF_UNCHECKED); - while (*p == ' ' || *p == '\t') p++; - - switch (*p++) - { - default: - case '0': - Method_Flag = AUDIO_NONE; - CheckMenuItem(hMenu, IDM_AUDIO_NONE, MF_CHECKED); - EnableMenuItem(GetSubMenu(hMenu, 3), 1, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(GetSubMenu(hMenu, 3), 3, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(GetSubMenu(hMenu, 3), 4, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(GetSubMenu(hMenu, 3), 5, MF_BYPOSITION | MF_GRAYED); - break; - - case '1': - Method_Flag = AUDIO_DEMUX; - CheckMenuItem(hMenu, IDM_DEMUX, MF_CHECKED); - EnableMenuItem(GetSubMenu(hMenu, 3), 1, MF_BYPOSITION | MF_ENABLED); - EnableMenuItem(GetSubMenu(hMenu, 3), 3, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(GetSubMenu(hMenu, 3), 4, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(GetSubMenu(hMenu, 3), 5, MF_BYPOSITION | MF_GRAYED); - break; - - case '2': - Method_Flag = AUDIO_DEMUXALL; - CheckMenuItem(hMenu, IDM_DEMUXALL, MF_CHECKED); - EnableMenuItem(GetSubMenu(hMenu, 3), 1, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(GetSubMenu(hMenu, 3), 3, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(GetSubMenu(hMenu, 3), 4, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(GetSubMenu(hMenu, 3), 5, MF_BYPOSITION | MF_GRAYED); - break; - - case '3': - Method_Flag = AUDIO_DECODE; - CheckMenuItem(hMenu, IDM_DECODE, MF_CHECKED); - EnableMenuItem(GetSubMenu(hMenu, 3), 1, MF_BYPOSITION | MF_ENABLED); - EnableMenuItem(GetSubMenu(hMenu, 3), 3, MF_BYPOSITION | MF_ENABLED); - EnableMenuItem(GetSubMenu(hMenu, 3), 4, MF_BYPOSITION | MF_ENABLED); - EnableMenuItem(GetSubMenu(hMenu, 3), 5, MF_BYPOSITION | MF_ENABLED); - break; - } - } - else if (!strncmp(opt, "drc", 3)) - { - CheckMenuItem(hMenu, IDM_DRC_NONE, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_DRC_LIGHT, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_DRC_NORMAL, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_DRC_HEAVY, MF_UNCHECKED); - while (*p == ' ' || *p == '\t') p++; - - switch (*p++) - { - default: - case '0': - CheckMenuItem(hMenu, IDM_DRC_NONE, MF_CHECKED); - DRC_Flag = DRC_NONE; - break; - case '1': - CheckMenuItem(hMenu, IDM_DRC_LIGHT, MF_CHECKED); - DRC_Flag = DRC_LIGHT; - break; - case '2': - CheckMenuItem(hMenu, IDM_DRC_NORMAL, MF_CHECKED); - DRC_Flag = DRC_NORMAL; - break; - case '3': - CheckMenuItem(hMenu, IDM_DRC_HEAVY, MF_CHECKED); - DRC_Flag = DRC_HEAVY; - break; - } - } - else if (!strncmp(opt, "dsd", 3)) - { - CheckMenuItem(hMenu, IDM_DSDOWN, MF_UNCHECKED); - while (*p == ' ' || *p == '\t') p++; - - DSDown_Flag = *p++ - '0'; - if (DSDown_Flag) - CheckMenuItem(hMenu, IDM_DSDOWN, MF_CHECKED); - } - else if (!strncmp(opt, "dsa", 3)) - { - CheckMenuItem(hMenu, IDM_SRC_NONE, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_SRC_LOW, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_SRC_MID, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_SRC_HIGH, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_SRC_UHIGH, MF_UNCHECKED); - while (*p == ' ' || *p == '\t') p++; - - switch (*p++) - { - default: - case '0': - SRC_Flag = SRC_NONE; - CheckMenuItem(hMenu, IDM_SRC_NONE, MF_CHECKED); - break; - case '1': - SRC_Flag = SRC_LOW; - CheckMenuItem(hMenu, IDM_SRC_LOW, MF_CHECKED); - break; - case '2': - SRC_Flag = SRC_MID; - CheckMenuItem(hMenu, IDM_SRC_MID, MF_CHECKED); - break; - case '3': - SRC_Flag = SRC_HIGH; - CheckMenuItem(hMenu, IDM_SRC_HIGH, MF_CHECKED); - break; - case '4': - SRC_Flag = SRC_UHIGH; - CheckMenuItem(hMenu, IDM_SRC_UHIGH, MF_CHECKED); - break; - } - } - else if (!strncmp(opt, "pre", 3)) - { - CLIPreview = 1; - } - else if (!strncmp(opt, "at", 3)) - { - FILE *bf; - - while (*p == ' ' || *p == '\t') p++; - if (*p == '-' || *p == 0) - { - // A null file name specifies no template. - AVSTemplatePath[0] = 0; - p--; - } - else - { - f = name; - while (1) - { - if ((in_quote == 0) && (*p == ' ' || *p == '\t' || *p == 0)) - break; - if ((in_quote == 1) && (*p == 0)) - break; - if (*p == '"') - { - if (in_quote == 0) - { - in_quote = 1; - p++; - } - else - { - in_quote = 0; - p++; - break; - } - } - *f++ = *p++; - } - *f = 0; - /* If the specified file does not include a path, use the - current directory. */ - if (name[0] != '\\' && name[1] != ':') - { - GetCurrentDirectory(sizeof(cwd) - 1, cwd); - strcat(cwd, "\\"); - strcat(cwd, name); - } - else - { - strcpy(cwd, name); - } - // Check that the specified template file exists and is readable. - bf = fopen(cwd, "r"); - if (bf != 0) - { - // Looks good; save the path. - fclose(bf); - strcpy(AVSTemplatePath, cwd); - } - else - { - // Something is wrong, so don't use a template. - AVSTemplatePath[0] = 0; - } - } - } - else if (!strncmp(opt, "exit", 4)) - { - ExitOnEnd = 1; - } - else if (!strncmp(opt, "o", 3) || !strncmp(opt, "od", 3)) - { - // Set up demuxing if requested. - if (p[-1] == 'd') - { - MuxFile = (FILE *) 0; - } - while (*p == ' ' || *p == '\t') p++; - - // Don't pop up warning boxes for automatic invocation. - crop1088_warned = true; - CLIActive = 1; - f = name; - while (1) - { - if ((in_quote == 0) && (*p == ' ' || *p == '\t' || *p == 0)) - break; - if ((in_quote == 1) && (*p == 0)) - break; - if (*p == '"') - { - if (in_quote == 0) - { - in_quote = 1; - p++; - } - else - { - in_quote = 0; - p++; - break; - } - } - *f++ = *p++; - } - *f = 0; - /* If the specified file does not include a path, use the - current directory. */ - if (name[0] != '\\' && name[1] != ':') - { - GetCurrentDirectory(sizeof(szOutput) - 1, szOutput); - strcat(szOutput, "\\"); - strcat(szOutput, name); - } - else - { - strcpy(szOutput, name); - } - } - else if (!strncmp(opt, "margin", 6)) - { - while (*p == ' ' || *p == '\t') p++; - sscanf(p, "%d", &TsParseMargin); - while (*p != '-' && *p != 0) p++; - p--; - } - else if (!strncmp(opt, "correct-d2v", 11) || !strncmp(opt, "cd", 2) || !strncmp(opt, "cfot", 4)) - { - while (*p == ' ' || *p == '\t') p++; - sscanf(p, "%d", &CorrectFieldOrderTrans); - while (*p != '-' && *p != 0) p++; - p--; - CheckMenuItem(hMenu, IDM_CFOT_DISABLE, (CorrectFieldOrderTrans) ? MF_UNCHECKED : MF_CHECKED); - CheckMenuItem(hMenu, IDM_CFOT_ENABLE , (CorrectFieldOrderTrans) ? MF_CHECKED : MF_UNCHECKED); - } - else if (!strncmp(opt, "pdas", 4)) - { - /* Parse d2v to after saving. */ - CLIParseD2V |= PARSE_D2V_AFTER_SAVING; - } - else if (!strncmp(opt, "parse-d2v", 9) || !strncmp(opt, "pd", 2)) - { - while (*p == ' ' || *p == '\t') p++; - f = name; - while (1) - { - if ((in_quote == 0) && (*p == ' ' || *p == '\t' || *p == 0)) - break; - if ((in_quote == 1) && (*p == 0)) - break; - if (*p == '"') - { - if (in_quote == 0) - { - in_quote = 1; - p++; - } - else - { - in_quote = 0; - p++; - break; - } - } - *f++ = *p++; - } - *f = 0; - /* If the specified file does not include a path, use the - current directory. */ - if (name[0] != '\\' && name[1] != ':') - { - GetCurrentDirectory(sizeof(szInput) - 1, szInput); - strcat(szInput, "\\"); - strcat(szInput, name); - } - else - { - strcpy(szInput, name); - } - CLIParseD2V |= PARSE_D2V_INPUT_FILE; - } - else if (!strncmp(opt, "no-progress", 11)) - { - CLINoProgress = 1; - } - } - else if (*p == 0) - break; - else - break; - } - if (NumLoadedFiles == 0 && WindowMode == SW_HIDE && CLIParseD2V == PARSE_D2V_NONE) - { - MessageBox(hWnd, "Couldn't open input file in HIDE mode! Exiting.", NULL, MB_OK | MB_ICONERROR); - return -1; - } - if (!CLIActive && WindowMode == SW_HIDE && CLIParseD2V == PARSE_D2V_NONE) - { - MessageBox(hWnd, "No output file in HIDE mode! Exiting.", NULL, MB_OK | MB_ICONERROR); - return -1; - } - CheckFlag(); - } - - else if(*lpCmdLine != 0) - { - // Old-style CLI. - int tmp; - int hadRGoption = 0; - char delimiter1[2], delimiter2[2]; - char *ende, save; - char *ptr, *fptr, *p, *q; - char aFName[DG_MAX_PATH]; - char suffix[DG_MAX_PATH]; - int val; - - NumLoadedFiles = 0; - delimiter1[0] = '['; - delimiter2[0] = ']'; - delimiter1[1] = delimiter2[1] = 0; - if ((ptr = strstr(ucCmdLine,"-SET-DELIMITER=")) || (ptr = strstr(ucCmdLine,"-SD="))) - { - ptr = lpCmdLine + (ptr - ucCmdLine); - while (*ptr++ != '='); - delimiter1[0] = delimiter2[0] = *ptr; - } - if ((ptr = strstr(ucCmdLine,"-AUTO-INPUT-FILES=")) || (ptr = strstr(ucCmdLine,"-AIF="))) - { - ptr = lpCmdLine + (ptr - ucCmdLine); - ptr = strstr(ptr, delimiter1) + 1; - ende = strstr(ptr + 1, delimiter2); - save = *ende; - *ende = 0; - strcpy(aFName, ptr); - *ende = save; - for (;;) - { - /* If the specified file does not include a path, use the - current directory. */ - if (!strstr(aFName, "\\")) - { - GetCurrentDirectory(sizeof(cwd) - 1, cwd); - strcat(cwd, "\\"); - strcat(cwd, aFName); - } - else - { - strcpy(cwd, aFName); - } - if ((tmp = _open(cwd, _O_RDONLY | _O_BINARY | _O_SEQUENTIAL)) == -1) break; - strcpy(Infilename[NumLoadedFiles], cwd); - Infile[NumLoadedFiles] = tmp; - NumLoadedFiles++; - - // First scan back from the end of the name for an _ character. - p = aFName+strlen(aFName); - while (*p != '_' && p >= aFName) p--; - if (*p != '_') break; - // Now pick up the number value and increment it. - p++; - if (*p < '0' || *p > '9') break; - sscanf(p, "%d", &val); - val++; - // Save the suffix after the number. - q = p; - while (*p >= '0' && *p <= '9') p++; - strcpy(suffix, p); - // Write the new incremented number. - sprintf(q, "%d", val); - // Append the saved suffix. - strcat(aFName, suffix); - } - } - else if ((ptr = strstr(ucCmdLine,"-INPUT-FILES=")) || (ptr = strstr(ucCmdLine,"-IF="))) - { - ptr = lpCmdLine + (ptr - ucCmdLine); - ptr = strstr(ptr, delimiter1) + 1; - ende = strstr(ptr + 1, delimiter2); - - do - { - i = 0; - if ((fptr = strstr(ptr, ",")) || (fptr = strstr(ptr + 1, delimiter2))) - { - while (ptr < fptr) - { - aFName[i] = *ptr; - ptr++; - i++; - } - aFName[i] = 0x00; - ptr++; - } - else - { - strcpy(aFName, ptr); - ptr = ende; - } - - /* If the specified file does not include a path, use the - current directory. */ - if (!strstr(aFName, "\\")) - { - GetCurrentDirectory(sizeof(cwd) - 1, cwd); - strcat(cwd, "\\"); - strcat(cwd, aFName); - } - else - { - strcpy(cwd, aFName); - } - if ((tmp = _open(cwd, _O_RDONLY | _O_BINARY)) != -1) - { - strcpy(Infilename[NumLoadedFiles], cwd); - Infile[NumLoadedFiles] = tmp; - NumLoadedFiles++; - } - } - while (ptr < ende); - } - else if ((ptr = strstr(ucCmdLine,"-BATCH-FILES=")) || (ptr = strstr(ucCmdLine,"-BF="))) - { - FILE *bf; - char line[1024]; - - ptr = lpCmdLine + (ptr - ucCmdLine); - ptr = strstr(ptr, delimiter1) + 1; - ende = strstr(ptr + 1, delimiter2); - save = *ende; - *ende = 0; - strcpy(aFName, ptr); - *ende = save; - /* If the specified batch file does not include a path, use the - current directory. */ - if (!strstr(aFName, "\\")) - { - GetCurrentDirectory(sizeof(cwd) - 1, cwd); - strcat(cwd, "\\"); - strcat(cwd, aFName); - } - else - { - strcpy(cwd, aFName); - } - bf = fopen(cwd, "r"); - if (bf != 0) - { - while (fgets(line, 1023, bf) != 0) - { - // Zap the newline. - line[strlen(line)-1] = 0; - /* If the specified batch file does not include a path, use the - current directory. */ - if (!strstr(line, "\\")) - { - GetCurrentDirectory(sizeof(cwd) - 1, cwd); - strcat(cwd, "\\"); - strcat(cwd, line); - } - else - { - strcpy(cwd, line); - } - if ((tmp = _open(cwd, _O_RDONLY | _O_BINARY)) != -1) - { - strcpy(Infilename[NumLoadedFiles], cwd); - Infile[NumLoadedFiles] = tmp; - NumLoadedFiles++; - } - } - } - } - Recovery(); - if ((ptr = strstr(ucCmdLine,"-RANGE=")) || (ptr = strstr(ucCmdLine,"-RG="))) - { - ptr = lpCmdLine + (ptr - ucCmdLine); - while (*ptr++ != '='); - - sscanf(ptr, "%d/%I64x/%d/%I64x\n", - &process.leftfile, &process.leftlba, &process.rightfile, &process.rightlba); - - process.startfile = process.leftfile; - process.startloc = process.leftlba * SECTOR_SIZE; - process.endfile = process.rightfile; - process.endloc = (process.rightlba - 1) * SECTOR_SIZE; - - process.run = 0; - for (i=0; i= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') || (*p >= 'A' && *p <= 'F')) - { - sscanf(p, "%x", &audio_id); - if (audio_id > 0xc7) - break; - audio[audio_id].selected_for_demux = true; - while (*p != ',' && *p != 0) p++; - if (*p == 0) - break; - p++; - } - - Method_Flag = AUDIO_DEMUX; - CheckMenuItem(hMenu, IDM_AUDIO_NONE, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_DEMUX, MF_CHECKED); - CheckMenuItem(hMenu, IDM_DEMUXALL, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_DECODE, MF_UNCHECKED); - EnableMenuItem(GetSubMenu(hMenu, 3), 1, MF_BYPOSITION | MF_ENABLED); - EnableMenuItem(GetSubMenu(hMenu, 3), 3, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(GetSubMenu(hMenu, 3), 4, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(GetSubMenu(hMenu, 3), 5, MF_BYPOSITION | MF_GRAYED); - } - - // Output Method - if ((ptr = strstr(ucCmdLine,"-OUTPUT-METHOD=")) || (ptr = strstr(ucCmdLine,"-OM="))) - { - ptr = lpCmdLine + (ptr - ucCmdLine); - CheckMenuItem(hMenu, IDM_AUDIO_NONE, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_DEMUX, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_DEMUXALL, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_DECODE, MF_UNCHECKED); - switch (*(strstr(ptr,"=")+1)) - { - default: - case '0': - Method_Flag = AUDIO_NONE; - CheckMenuItem(hMenu, IDM_AUDIO_NONE, MF_CHECKED); - EnableMenuItem(GetSubMenu(hMenu, 3), 1, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(GetSubMenu(hMenu, 3), 3, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(GetSubMenu(hMenu, 3), 4, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(GetSubMenu(hMenu, 3), 5, MF_BYPOSITION | MF_GRAYED); - break; - - case '1': - Method_Flag = AUDIO_DEMUX; - CheckMenuItem(hMenu, IDM_DEMUX, MF_CHECKED); - EnableMenuItem(GetSubMenu(hMenu, 3), 1, MF_BYPOSITION | MF_ENABLED); - EnableMenuItem(GetSubMenu(hMenu, 3), 3, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(GetSubMenu(hMenu, 3), 4, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(GetSubMenu(hMenu, 3), 5, MF_BYPOSITION | MF_GRAYED); - break; - - case '2': - Method_Flag = AUDIO_DEMUXALL; - CheckMenuItem(hMenu, IDM_DEMUXALL, MF_CHECKED); - EnableMenuItem(GetSubMenu(hMenu, 3), 1, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(GetSubMenu(hMenu, 3), 3, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(GetSubMenu(hMenu, 3), 4, MF_BYPOSITION | MF_GRAYED); - EnableMenuItem(GetSubMenu(hMenu, 3), 5, MF_BYPOSITION | MF_GRAYED); - break; - - case '3': - Method_Flag = AUDIO_DECODE; - CheckMenuItem(hMenu, IDM_DECODE, MF_CHECKED); - EnableMenuItem(GetSubMenu(hMenu, 3), 1, MF_BYPOSITION | MF_ENABLED); - EnableMenuItem(GetSubMenu(hMenu, 3), 3, MF_BYPOSITION | MF_ENABLED); - EnableMenuItem(GetSubMenu(hMenu, 3), 4, MF_BYPOSITION | MF_ENABLED); - EnableMenuItem(GetSubMenu(hMenu, 3), 5, MF_BYPOSITION | MF_ENABLED); - break; - } - } - - // Dynamic-Range-Control - if ((ptr = strstr(ucCmdLine,"-DYNAMIC-RANGE-CONTROL=")) || (ptr = strstr(ucCmdLine,"-DRC="))) - { - ptr = lpCmdLine + (ptr - ucCmdLine); - CheckMenuItem(hMenu, IDM_DRC_NONE, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_DRC_LIGHT, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_DRC_NORMAL, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_DRC_HEAVY, MF_UNCHECKED); - switch (*(strstr(ptr,"=")+1)) - { - default: - case '0': - CheckMenuItem(hMenu, IDM_DRC_NONE, MF_CHECKED); - DRC_Flag = DRC_NONE; - break; - case '1': - CheckMenuItem(hMenu, IDM_DRC_LIGHT, MF_CHECKED); - DRC_Flag = DRC_LIGHT; - break; - case '2': - CheckMenuItem(hMenu, IDM_DRC_NORMAL, MF_CHECKED); - DRC_Flag = DRC_NORMAL; - break; - case '3': - CheckMenuItem(hMenu, IDM_DRC_HEAVY, MF_CHECKED); - DRC_Flag = DRC_HEAVY; - break; - } - } - - // Dolby Surround Downmix - if ((ptr = strstr(ucCmdLine,"-DOLBY-SURROUND-DOWNMIX=")) || (ptr = strstr(ucCmdLine,"-DSD="))) - { - ptr = lpCmdLine + (ptr - ucCmdLine); - CheckMenuItem(hMenu, IDM_DSDOWN, MF_UNCHECKED); - DSDown_Flag = *(strstr(ptr,"=")+1) - '0'; - if (DSDown_Flag) - CheckMenuItem(hMenu, IDM_DSDOWN, MF_CHECKED); - } - - // 48 -> 44 kHz - if ((ptr = strstr(ucCmdLine,"-DOWNSAMPLE-AUDIO=")) || (ptr = strstr(ucCmdLine,"-DSA="))) - { - ptr = lpCmdLine + (ptr - ucCmdLine); - CheckMenuItem(hMenu, IDM_SRC_NONE, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_SRC_LOW, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_SRC_MID, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_SRC_HIGH, MF_UNCHECKED); - CheckMenuItem(hMenu, IDM_SRC_UHIGH, MF_UNCHECKED); - switch (*(strstr(ptr,"=")+1)) - { - default: - case '0': - SRC_Flag = SRC_NONE; - CheckMenuItem(hMenu, IDM_SRC_NONE, MF_CHECKED); - break; - case '1': - SRC_Flag = SRC_LOW; - CheckMenuItem(hMenu, IDM_SRC_LOW, MF_CHECKED); - break; - case '2': - SRC_Flag = SRC_MID; - CheckMenuItem(hMenu, IDM_SRC_MID, MF_CHECKED); - break; - case '3': - SRC_Flag = SRC_HIGH; - CheckMenuItem(hMenu, IDM_SRC_HIGH, MF_CHECKED); - break; - case '4': - SRC_Flag = SRC_UHIGH; - CheckMenuItem(hMenu, IDM_SRC_UHIGH, MF_CHECKED); - break; - } - } - - // Normalization not implemented - - RefreshWindow(true); - - // AVS Template - if ((ptr = strstr(ucCmdLine,"-AVS-TEMPLATE=")) || (ptr = strstr(ucCmdLine,"-AT="))) - { - FILE *bf; - - ptr = lpCmdLine + (ptr - ucCmdLine); - ptr = strstr(ptr, delimiter1) + 1; - if (ptr == (char *) 1 || *ptr == delimiter2[0]) - { - // A null file name specifies no template. - AVSTemplatePath[0] = 0; - } - else - { - ende = strstr(ptr + 1, delimiter2); - save = *ende; - *ende = 0; - strcpy(aFName, ptr); - *ende = save; - /* If the specified template file does not include a path, use the - current directory. */ - if (!strstr(aFName, "\\")) - { - GetCurrentDirectory(sizeof(cwd) - 1, cwd); - strcat(cwd, "\\"); - strcat(cwd, aFName); - } - else - { - strcpy(cwd, aFName); - } - // Check that the specified template file exists and is readable. - bf = fopen(cwd, "r"); - if (bf != 0) - { - // Looks good; save the path. - fclose(bf); - strcpy(AVSTemplatePath, cwd); - } - else - { - // Something is wrong, so don't use a template. - AVSTemplatePath[0] = 0; - } - } - } - - // Output D2V file - if ((ptr = strstr(ucCmdLine,"-OUTPUT-FILE=")) || (ptr = strstr(ucCmdLine,"-OF=")) || - (ptr = strstr(ucCmdLine,"-OUTPUT-FILE-DEMUX=")) || (ptr = strstr(ucCmdLine,"-OFD="))) - { - // Set up demuxing if requested. - if (strstr(ucCmdLine,"-OUTPUT-FILE-DEMUX=") || strstr(ucCmdLine,"-OFD=")) - { - MuxFile = (FILE *) 0; - } - - // Don't pop up warning boxes for automatic invocation. - crop1088_warned = true; - CLIActive = 1; - ExitOnEnd = strstr(ucCmdLine,"-EXIT") ? 1 : 0; - ptr = lpCmdLine + (ptr - ucCmdLine); - ptr = strstr(ptr, delimiter1) + 1; - ende = strstr(ptr + 1, delimiter2); - save = *ende; - *ende = 0; - strcpy(aFName, ptr); - *ende = save; - // We need to store the full path, so that all our path handling options work - // the same way as for GUI mode. - if (aFName[0] != '\\' && aFName[1] != ':') - { - GetCurrentDirectory(sizeof(szOutput) - 1, szOutput); - strcat(szOutput, "\\"); - strcat(szOutput, aFName); - } - else - { - strcpy(szOutput, aFName); - } - } - - // Preview mode for generating the Info log file - CLIPreview = strstr(ucCmdLine,"-PREVIEW") ? 1 : 0; - - if (ptr = strstr(ucCmdLine,"-MARGIN=")) - { - ptr = lpCmdLine + (ptr - ucCmdLine); - sscanf(strstr(ptr,"=")+1, "%d", &TsParseMargin); - } - if ((ptr = strstr(ucCmdLine,"-CORRECT-D2V=")) || (ptr = strstr(ucCmdLine,"-CD=")) || (ptr = strstr(ucCmdLine,"-CFOT="))) - { - ptr = lpCmdLine + (ptr - ucCmdLine); - sscanf(strstr(ptr,"=")+1, "%d", &CorrectFieldOrderTrans); - CheckMenuItem(hMenu, IDM_CFOT_DISABLE, (CorrectFieldOrderTrans) ? MF_UNCHECKED : MF_CHECKED); - CheckMenuItem(hMenu, IDM_CFOT_ENABLE , (CorrectFieldOrderTrans) ? MF_CHECKED : MF_UNCHECKED); - } - CLINoProgress = strstr(ucCmdLine,"-NO-PROGRESS") ? 1 : 0; - - if (!CLIActive && WindowMode == SW_HIDE && CLIParseD2V == PARSE_D2V_NONE) - { - MessageBox(hWnd, "No output file in HIDE mode! Exiting.", NULL, MB_OK | MB_ICONERROR); - return -1; - } - } - return 0; -} diff --git a/src/dgindex/pat.cpp b/src/dgindex/pat.cpp deleted file mode 100644 index 69aca3c..0000000 --- a/src/dgindex/pat.cpp +++ /dev/null @@ -1,1338 +0,0 @@ -/* - * Copyright (C) 2004-2006, Donald A Graft, All Rights Reserved - * - * PAT/PMT table parser for PID detection. - * - * This is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This is distributed in the hope that 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 code; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#include "windows.h" -#include "resource.h" -#include "global.h" - -PATParser::PATParser(void) -{ -} - -// Need to add transport re-syncing in case of errors. -int PATParser::SyncTransport(void) -{ - int i; - unsigned char byte; - - // Find a sync byte. - for (i = 0; i < LIMIT; i++) - { - if (fread(&byte, 1, 1, fin) == 0) - { - return 1; - } - if (byte == TS_SYNC_BYTE) - { - fseek(fin, TransportPacketSize - 1, SEEK_CUR); - if (fread(&byte, 1, 1, fin) == 0) - { - return 1; - } - if (byte == TS_SYNC_BYTE) - { - fseek(fin, -(TransportPacketSize + 1), SEEK_CUR); - break; - } - fseek(fin, -TransportPacketSize, SEEK_CUR); - } - } - if (i == LIMIT) - { - return 1; - } - return 0; -} - -int PATParser::DumpRaw(HWND _hDialog, char *_filename) -{ - hDialog = _hDialog; - filename = _filename; - return AnalyzeRaw(); -} - -int PATParser::AnalyzeRaw(void) -{ - unsigned int i, pid = 0; - unsigned char stream_id; - int afc, pkt_count; - unsigned char buffer[204]; - int read, pes_offset, pes_header_data_length, data_offset; - char listbox_line[255], description[80]; - struct - { - unsigned int pid; - unsigned char stream_id; - } Pids[MAX_PIDS]; - - // Open the input file for reading. - if ((fin = fopen(filename, "rb")) == NULL) - { - if (hDialog != NULL) - { - sprintf(listbox_line, "Cannot open the input file!"); - SendDlgItemMessage(hDialog, IDC_PID_LISTBOX, LB_ADDSTRING, 0, (LPARAM)listbox_line); - } - return 1; - } - - if (SyncTransport() == 1) - { - fclose(fin); - return 1; - } - - // Initialize the PID data table. - for (i = 0; i < MAX_PIDS; i++) - { - Pids[i].pid = 0xffffffff; - Pids[i].stream_id = 0; - } - - // Process the transport packets looking for PIDs. - pkt_count = 0; - while ((pkt_count++ < MAX_PACKETS) && (read = fread(buffer, 1, TransportPacketSize, fin)) == TransportPacketSize) - { - // Pick up the PID. - pid = ((buffer[1] & 0x1f) << 8) | buffer[2]; - stream_id = 0; - // Check payload_unit_start_indicator. - if (buffer[1] & 0x40) - { - // Look for a payload. - afc = (buffer[3] & 0x30) >> 4; - if (afc == 1 || afc == 3) - { - // Skip the adaptation field (if present). - if (afc == 1) - { - pes_offset = 4; - } - else - { - pes_offset = 5 + buffer[4]; - } - // Get the stream ID if there is a packet start code. - if (buffer[pes_offset] == 0 && buffer[pes_offset+1] == 0 && buffer[pes_offset+2] == 1) - stream_id = buffer[pes_offset+3]; - if (stream_id == 0xbd) - { - // This is private stream 1, which may carry AC3 or DTS audio. - // Since all DTS frames fit in one PES packet, we can just - // look for the DTS audio frame header to distinguish the two. - pes_header_data_length = buffer[pes_offset+8]; - data_offset = pes_offset + 9 + pes_header_data_length; - if (buffer[data_offset] == 0x7f && - buffer[data_offset+1] == 0xfe && - buffer[data_offset+2] == 0x80 && - buffer[data_offset+3] == 0x01) - { - // Borrow this reserved value to label DTS. - stream_id = 0xfe; - } - } - } - // Find an empty table entry and enter this PID if we haven't already. - for (i = 0; Pids[i].pid != 0xffffffff && i < MAX_PIDS; i++) - { - if (Pids[i].pid == pid) break; - } - if (Pids[i].pid == 0xffffffff) - { - Pids[i].pid = pid; - Pids[i].stream_id = stream_id; - } - } - } - - // Display the detection results in the dialog box. - for (i = 0; Pids[i].pid != 0xffffffff && i < MAX_PIDS; i++) - { - if (Pids[i].pid == 0) - strcpy(description, "PAT"); - else if (Pids[i].pid == 1) - strcpy(description, "CAT"); - else if (Pids[i].pid >= 2 && Pids[i].pid <= 0xf) - strcpy(description, "Reserved"); - else if (Pids[i].pid == 0x1fff) - strcpy(description, "Null"); - else if (Pids[i].stream_id == 0xbc) - strcpy(description, "Program Stream Map"); - else if (Pids[i].stream_id == 0xbd || Pids[i].stream_id == 0xfd) - { - if (!hDialog && Pids[i].pid == audio_pid) - { - audio_type = 0x81; - fclose(fin); - return 0; - } - if (op == InitialPids && MPEG2_Transport_AudioPID == 0x2) - MPEG2_Transport_AudioPID = Pids[i].pid; - strcpy(description, "Private Stream 1 (AC3/DTS Audio)"); - } - else if (Pids[i].stream_id == 0xbe) - strcpy(description, "Padding Stream"); - else if (Pids[i].stream_id == 0xbf) - strcpy(description, "Private Stream 2"); - else if (((Pids[i].stream_id & 0xe0) == 0xc0) || - (Pids[i].stream_id == 0xfa)) - { - if (!hDialog && Pids[i].pid == audio_pid) - { - // The demuxing code is the same for MPEG and AAC. - // The only difference will be the filename. - // The demuxing code will look at the audio sync word to - // decide between the two. - audio_type = 0x4; - fclose(fin); - return 0; - } - if (op == InitialPids && MPEG2_Transport_AudioPID == 0x2) - MPEG2_Transport_AudioPID = Pids[i].pid; - strcpy(description, "MPEG1/MPEG2/AAC Audio"); - } - else if ((Pids[i].stream_id & 0xf0) == 0xe0) - { - if (op == InitialPids && MPEG2_Transport_VideoPID == 0x2) - MPEG2_Transport_VideoPID = Pids[i].pid; - strcpy(description, "MPEG Video"); - } - else if (Pids[i].stream_id == 0xf0) - strcpy(description, "ECM Stream"); - else if (Pids[i].stream_id == 0xf1) - strcpy(description, "EMM Stream"); - else if (Pids[i].stream_id == 0xf9) - strcpy(description, "Ancillary Stream"); - else if (Pids[i].stream_id == 0xfe) - { - if (!hDialog && Pids[i].pid == audio_pid) - { - audio_type = 0xfe; - fclose(fin); - return 0; - } - if (op == InitialPids && MPEG2_Transport_AudioPID == 0x2) - MPEG2_Transport_AudioPID = Pids[i].pid; - strcpy(description, "Private Stream 1 (DTS Audio)"); - } - else if (Pids[i].stream_id == 0xff) - strcpy(description, "Program Stream Directory"); - else if (Pids[i].stream_id == PCR_STREAM) - strcpy(description, "PCR"); - else - strcpy(description, "Other"); - if (hDialog != NULL) - { - sprintf(listbox_line, "0x%x (%d): %s", Pids[i].pid, Pids[i].pid, description); - SendDlgItemMessage(hDialog, IDC_PID_LISTBOX, LB_ADDSTRING, 0, (LPARAM)listbox_line); - } - } - - fclose(fin); - return 0; -} - -int PATParser::DumpPAT(HWND _hDialog, char *_filename) -{ - op = Dump; - hDialog = _hDialog; - filename = _filename; - return AnalyzePAT(); -} - -int PATParser::DumpPSIP(HWND _hDialog, char *_filename) -{ - op = Dump; - hDialog = _hDialog; - filename = _filename; - return AnalyzePSIP(); -} - -int PATParser::GetAudioType(char *_filename, unsigned int _audio_pid) -{ - op = AudioType; - hDialog = NULL; - filename = _filename; - audio_pid = _audio_pid; - audio_type = 0xffffffff; - - if ((AnalyzePAT() == 0) && (audio_type != 0xffffffff)) - return audio_type; - else if ((AnalyzeRaw() == 0) && (audio_type != 0xffffffff)) - return audio_type; - else - return -1; -} - -int PATParser::DoInitialPids(char *_filename) -{ - op = InitialPids; - hDialog = NULL; - filename = _filename; - AnalyzePAT(); - if (MPEG2_Transport_VideoPID == 0x2) - { - AnalyzeRaw(); - } - return 0; -} - -int PATParser::AnalyzePAT(void) -{ - unsigned int entry; - char listbox_line[255]; - - // First, we need to get from the PAT the list of PMT PIDs that we will need - // to examine. - num_pmt_pids = 0; - first_pat = first_pmt = true; - - // Open the input file for reading. - if ((fin = fopen(filename, "rb")) == NULL) - { - if (op == Dump) - { - sprintf(listbox_line, "Cannot open the input file!"); - SendDlgItemMessage(hDialog, IDC_PID_LISTBOX, LB_ADDSTRING, 0, (LPARAM)listbox_line); - } - return 1; - } - - if (SyncTransport() == 1) - { - fclose(fin); - return 1; - } - - // Acquire and parse the PAT. - GetTable(PAT_PID); - - // Exit if we didn't find the PAT. - if (first_pat == true) - { - fclose(fin); - return 1; - } - - // Now we have to get the PMT tables to retrieve the actual - // program information. Scan on each PMT PID in turn. - for (entry = 0, num_programs = 0; entry < num_pmt_pids; entry++) - { - // Start again at the beginning of the file. - fseek(fin, 0, SEEK_SET); - if (SyncTransport() == 1) - { - fclose(fin); - return 1; - } - - // Acquire and parse the PMT. - GetTable(pmt_pids[entry]); - } - - // check margin. - int recheck_time = TsParseMargin; - int pmt_recheck = 0; - __int64 start_PCR, PCR; - if (recheck_time > 0) - { - fseek(fin, 0, SEEK_SET); - start_PCR = GetPCRValue(); - if (start_PCR != 0) - { - while (1) - { - PCR = GetPCRValue(); - if (PCR == 0) - break; - - if (start_PCR > PCR) - PCR += (0x1FFFFFFFFLL / 90); - if (PCR - start_PCR < recheck_time) - continue; - - if (op == InitialPids) - MPEG2_Transport_VideoPID = MPEG2_Transport_AudioPID = MPEG2_Transport_PCRPID = 0x02; - pmt_recheck = 1; - break; - } - } - - if (pmt_recheck) - { - for (entry = 0, num_programs = 0; entry < num_pmt_pids; entry++) - { - // Acquire and parse the PMT. - GetTable(pmt_pids[entry]); - } - } - } - - fclose(fin); - return 0; -} - -int PATParser::AnalyzePSIP(void) -{ - char listbox_line[255]; - - first_pat = true; - - // Open the input file for reading. - if ((fin = fopen(filename, "rb")) == NULL) - { - if (op == Dump) - { - sprintf(listbox_line, "Cannot open the input file!"); - SendDlgItemMessage(hDialog, IDC_PID_LISTBOX, LB_ADDSTRING, 0, (LPARAM)listbox_line); - } - return 1; - } - - if (SyncTransport() == 1) - { - fclose(fin); - return 1; - } - - // Acquire and parse the PAT. - GetTable(PSIP_PID); - - // Exit if we didn't find the PAT. - if (first_pat == true) - { - fclose(fin); - return 1; - } - - fclose(fin); - return 0; -} - -int PATParser::ProcessPSIPSection(void) -{ - unsigned int i, j, ndx, ndx2, program, num_channels_in_section, elements; - unsigned int descriptors_length, length, tag, pcrpid, type, pid; - char *stream_type; - char listbox_line[255]; - - // We want only current tables. - if (!(section[5] & 0x01)) - return 0; - - num_channels_in_section = section[9]; - first_pat = false; - - for (i = 0, ndx = 10; i < num_channels_in_section; i++) - { - program = (section[ndx+24] << 8) + section[ndx+25]; - if (op == Dump) - { - sprintf(listbox_line, "Program %d", program); - SendDlgItemMessage(hDialog, IDC_PID_LISTBOX, LB_ADDSTRING, 0, (LPARAM)listbox_line); - } - descriptors_length = (section[ndx+30] << 8) + section[ndx+31]; - descriptors_length &= 0x3ff; - ndx += 32; - ndx2 = ndx; - while (ndx2 < ndx + descriptors_length) - { - tag = section[ndx2]; - length = section[ndx2+1]; - pcrpid = (section[ndx2+2] << 8) + section[ndx2+3]; - pcrpid &= 0x1fff; - if (op == Dump) - { - sprintf(listbox_line, " PCR on PID 0x%x (%d)", pcrpid, pcrpid); - SendDlgItemMessage(hDialog, IDC_PID_LISTBOX, LB_ADDSTRING, 0, (LPARAM)listbox_line); - } - elements = section[ndx2+4]; - for (j = 0; j < elements; j++) - { - type = section[ndx2+5+j*6]; - switch (type) - { - case 0x01: - stream_type = "MPEG1 Video"; - break; - case 0x02: - stream_type = "MPEG2 Video"; - break; - case 0x03: - stream_type = "MPEG1 Audio"; - break; - case 0x04: - stream_type = "MPEG2 Audio"; - break; - case 0x05: - stream_type = "Private Sections"; - break; - case 0x07: - stream_type = "Teletext/Subtitling"; - break; - case 0x0f: - case 0x11: - stream_type = "AAC Audio"; - break; - case 0x80: - // This could be private stream video or LPCM audio. - stream_type = "Private Stream"; - break; - case 0x81: - // This could be AC3 or DTS audio. - stream_type = "AC3/DTS Audio"; - break; - // These are found on bluray disks. - case 0x85: - case 0x86: - stream_type = "DTS Audio"; - break; - default: - stream_type = "Other"; - break; - } - pid = (section[ndx2+5+j*6+1] << 8) + section[ndx2+5+j*6+2]; - pid &= 0x1fff; - if (op == Dump) - { - sprintf(listbox_line, " %s on PID 0x%x (%d)", stream_type, pid, pid); - SendDlgItemMessage(hDialog, IDC_PID_LISTBOX, LB_ADDSTRING, 0, (LPARAM)listbox_line); - } - } - ndx2 += length + 2; - } - ndx += descriptors_length; - } - - return 1; -} - -int PATParser::ProcessPATSection(void) -{ - unsigned int i, j, ndx, section_length, number, last, program, pmtpid; - - // We want only current tables. - if (!(section[5] & 0x01)) - return 0; - - section_length = ((section[1] & 0x03) << 8); - section_length |= section[2]; - - // Get the number of this section. - number = section[6]; - - // Get the number of the last section. - last = section[7]; - - // Now we parse the program/pid tuples. - ndx = 8; - for (i = 0; i < section_length - 9;) - { - program = section[ndx+i++] << 8; - program |= section[ndx+i++]; - pmtpid = (section[ndx+i++] & 0x1f) << 8; - pmtpid |= section[ndx+i++]; - // Skip the Network Information Table (NIT). - if (program != 0) - { - // Store the PMT PID if we haven't already. - for (j = 0; j < num_pmt_pids; j++) - if (pmt_pids[j] == pmtpid) - break; - if (j == num_pmt_pids) - pmt_pids[num_pmt_pids++] = pmtpid; - } - } - first_pat = false; - - // If this is the last section number, we're done. - return (number == last); -} - -int PATParser::ProcessPMTSection(void) -{ - unsigned int j, ndx, section_length, program, pid, pcrpid; - unsigned int descriptors_length, es_descriptors_length, type, encrypted; - char listbox_line[255]; - char *stream_type; - - // We want only current tables. - if (!(section[5] & 0x01)) - return 0; - - section_length = ((section[1] & 0x03) << 8); - section_length |= section[2]; - - // Check the program number. - program = section[3] << 8; - program |= section[4]; - - // If we're setting the initial PIDs automatically, then - // we're intersted in only the first program. - if (op == InitialPids && num_programs > 0) - return 0; - // We stop when we see a progam that we've already seen. - for (j = 0; j < num_programs; j++) - if (programs[j] == program) - break; - if (j != num_programs) - return 1; - programs[num_programs++] = program; - if (op == Dump) - { - sprintf(listbox_line, "Program %d", program); - SendDlgItemMessage(hDialog, IDC_PID_LISTBOX, LB_ADDSTRING, 0, (LPARAM)listbox_line); - } - - // Get the PCRPID. - pcrpid = (section[8] & 0x1f) << 8; - pcrpid |= section[9]; - if (op == InitialPids) - MPEG2_Transport_PCRPID = pcrpid; - else if (op == Dump) - { - sprintf(listbox_line, " PCR on PID 0x%x (%d)", pcrpid, pcrpid); - SendDlgItemMessage(hDialog, IDC_PID_LISTBOX, LB_ADDSTRING, 0, (LPARAM)listbox_line); - } - - // Skip the descriptors (if any). - ndx = 10; - descriptors_length = (section[ndx++] & 0x0f) << 8; - descriptors_length |= section[ndx++]; - ndx += descriptors_length; - - // Now we have the actual program data. - while (ndx < section_length - 4) - { - switch (type = section[ndx++]) - { - case 0x01: - stream_type = "MPEG1 Video"; - pid = (section[ndx++] & 0x1f) << 8; - pid |= section[ndx++]; - if (op == InitialPids && MPEG2_Transport_VideoPID == 0x02) - MPEG2_Transport_VideoPID = pid; - break; - case 0x02: - stream_type = "MPEG2 Video"; - pid = (section[ndx++] & 0x1f) << 8; - pid |= section[ndx++]; - if (op == InitialPids && MPEG2_Transport_VideoPID == 0x02) - MPEG2_Transport_VideoPID = pid; - break; - case 0x03: - stream_type = "MPEG1 Audio"; - pid = (section[ndx++] & 0x1f) << 8; - pid |= section[ndx++]; - if (op == InitialPids && MPEG2_Transport_AudioPID == 0x02) - MPEG2_Transport_AudioPID = pid; - break; - case 0x04: - stream_type = "MPEG2 Audio"; - pid = (section[ndx++] & 0x1f) << 8; - pid |= section[ndx++]; - if (op == InitialPids && MPEG2_Transport_AudioPID == 0x02) - MPEG2_Transport_AudioPID = pid; - break; - case 0x05: - stream_type = "Private Sections"; - pid = (section[ndx++] & 0x1f) << 8; - pid |= section[ndx++]; - break; - case 0x06: - // Have to parse the ES descriptors to figure this out. - pid = (section[ndx++] & 0x1f) << 8; - pid |= section[ndx++]; - break; - case 0x07: - stream_type = "Teletext/Subtitling"; - pid = (section[ndx++] & 0x1f) << 8; - pid |= section[ndx++]; - break; - case 0x0f: - case 0x11: - // The demuxing code is the same for MPEG and AAC. - // The only difference will be the filename. - // The demuxing code will look at the audio sync word to - // decide between the two. - type = 0x04; - stream_type = "AAC Audio"; - pid = (section[ndx++] & 0x1f) << 8; - pid |= section[ndx++]; - if (op == InitialPids && MPEG2_Transport_AudioPID == 0x02) - MPEG2_Transport_AudioPID = pid; - break; - case 0x80: - // This could be private stream video or LPCM audio. - stream_type = "Private Stream"; - pid = (section[ndx++] & 0x1f) << 8; - pid |= section[ndx++]; - break; - case 0x81: - // This could be AC3 or DTS audio. - stream_type = "AC3/DTS Audio"; - pid = (section[ndx++] & 0x1f) << 8; - pid |= section[ndx++]; - if (op == InitialPids && MPEG2_Transport_AudioPID == 0x02) - MPEG2_Transport_AudioPID = pid; - break; - // These are found on bluray disks. - case 0x85: - case 0x86: - stream_type = "DTS Audio"; - type = 0xfe; - pid = (section[ndx++] & 0x1f) << 8; - pid |= section[ndx++]; - if (op == InitialPids && MPEG2_Transport_AudioPID == 0x02) - MPEG2_Transport_AudioPID = pid; - break; - default: - stream_type = "Other"; - pid = (section[ndx++] & 0x1f) << 8; - pid |= section[ndx++]; - break; - } - - // Parse the ES descriptors if necessary. - es_descriptors_length = (section[ndx++] & 0x0f) << 8; - es_descriptors_length |= section[ndx++]; - encrypted = 0; - if (es_descriptors_length) - { - unsigned int start = ndx, end = ndx + es_descriptors_length; - int tag, length; - - // See if the ES is scrambled. - do - { - tag = section[ndx++]; - if (tag == 0x09) - encrypted = 1; - length = section[ndx++]; - ndx += length; - } while (ndx < end); - ndx = start; - - if (type == 0x80) - { - // This might be private stream video. - // Parse the descriptors for a video descriptor. - int hadVideo = 0, hadAudio = 0; - do - { - tag = section[ndx++]; - if (tag == 0x02) - hadVideo = 1; - else if (tag == 0x05) - hadAudio = 1; - length = section[ndx++]; - ndx += length; - } while (ndx < end); - ndx = end; - if (hadVideo == 1) - { - stream_type = "Private Stream Video"; - type = 0x02; - if (op == InitialPids && MPEG2_Transport_VideoPID == 0x02) - MPEG2_Transport_VideoPID = pid; - } - else if (hadAudio == 1) - { - stream_type = "LPCM Audio"; - if (op == InitialPids && MPEG2_Transport_AudioPID == 0x02) - MPEG2_Transport_AudioPID = pid; - } - } - else if (type == 0x06) - { - // Parse the descriptors for a DTS audio descriptor. - unsigned int end = ndx + es_descriptors_length; - int hadDTS = 0, hadTeletext = 0; - do - { - tag = section[ndx++]; - if (tag == 0x73) - hadDTS = 1; - else if (tag == 0x05) - { - if (section[ndx+1] == 0x44 && section[ndx+2] == 0x54 && section[ndx+3] == 0x53) - hadDTS = 1; - } - else if (tag == 0x56) - hadTeletext = 1; - length = section[ndx++]; - ndx += length; - } while (ndx < end); - ndx = end; - if (hadTeletext == 1) - { - stream_type = "Teletext"; - } - else if (hadDTS == 1) - { - stream_type = "DTS Audio"; - type = 0xfe; - if (op == InitialPids && MPEG2_Transport_AudioPID == 0x02) - MPEG2_Transport_AudioPID = pid; - } - else - { - stream_type = "AC3 Audio"; - type = 0x81; - if (op == InitialPids && MPEG2_Transport_AudioPID == 0x02) - MPEG2_Transport_AudioPID = pid; - } - } - else - { - ndx += es_descriptors_length; - } - - } - else if (type == 0x06) - { - // The following assignments will be used if there are no descriptors. - stream_type = "AC3/DTS Audio"; - type = 0x81; - } - if (op == Dump) - { - sprintf(listbox_line, " %s on PID 0x%x (%d)", stream_type, pid, pid); - SendDlgItemMessage(hDialog, IDC_PID_LISTBOX, LB_ADDSTRING, 0, (LPARAM)listbox_line); - if (encrypted == 1) - { - sprintf(listbox_line, " [Scrambled]"); - SendDlgItemMessage(hDialog, IDC_PID_LISTBOX, LB_ADDSTRING, 0, (LPARAM)listbox_line); - } - } - if (op == AudioType && pid == audio_pid) - { - if (type != 0x81) - { - audio_type = type; - return 0; - } - // If the packet size is 192, it's probably M2TS (bluray) - // and so we accept it as AC3. - else if (TransportPacketSize == 192) - { - audio_type = type; - return 0; - } - // If it's private stream 1, it could be AC3 or DTS. - // Force raw detection to find out which. - return 1; - } - } - - return 0; -} - -void PATParser::GetTable(unsigned int table_pid) -{ - unsigned char byte; - unsigned int pid, ndx, section_length; - int read; - int pkt_count; - int ret; - - // Process the transport packets. - pkt_count = 0; - section_ptr = section; - while ((pkt_count++ < MAX_PACKETS) && (read = fread(buffer, 1, TransportPacketSize, fin)) == TransportPacketSize) - { - // Check that this is the desired PID. - pid = ((buffer[1] & 0x1f) << 8) | buffer[2]; - if (pid != table_pid) - continue; - - // We have a table packet. - // Check error indicator. - if (buffer[1] & 0x80) - continue; - - // Check for presence of a section start. - if ((section_ptr == section) && !(buffer[1] & 0x40)) - continue; - - // Skip if there is no payload. - byte = (unsigned char) ((buffer[3] & 0x30) >> 4); - if (byte == 0 || byte == 2) - continue; - - // Skip the adaptation field (if any). - ndx = 4; - if (byte == 3) - { - ndx += buffer[ndx] + 1; - } - - // This equality will fail when we have started gathering a section, - // but it overflowed into the next transport packet. So here we collect - // the rest of the section. - if (section_ptr != section) - { - // Collect the section data. - if (section_length <= TransportPacketSize - ndx - (TransportPacketSize == 192 ? 4 : 0)) - { - // The remainder of the section is contained entirely - // in this packet. Skip the pointer field if one exists. - unsigned char *start; - start = &buffer[ndx]; - if (buffer[1] & 0x40) - start++; - memcpy(section_ptr, start, section_length); - section_ptr += section_length; - // Parse the table. - switch (table_pid) - { - case PAT_PID: - ret = ProcessPATSection(); - break; - case PSIP_PID: - ret = ProcessPSIPSection(); - break; - default: - ret = ProcessPMTSection(); - break; - } - if (ret) - break; - // Get ready for collection of the next section. - section_ptr = section; - // Check the section syntax indicator to see if another - // section follows in this packet. - if (!(buffer[1] & 0x40)) - { - // No more sections in this packet. - continue; - } - // If we reach here, there is another section following - // this one, so we fall through to the code below. - } - else - { - // The section is spilling over to the next packet. - // There can't be a pointer field, so there's no need to - // check for it. - memcpy(section_ptr, &buffer[ndx], TransportPacketSize - ndx - (TransportPacketSize == 192 ? 4 : 0)); - section_ptr += (TransportPacketSize - ndx - (TransportPacketSize == 192 ? 4 : 0)); - section_length -= (TransportPacketSize - ndx - (TransportPacketSize == 192 ? 4 : 0)); - continue; - } - } - - // Read the section pointer field and use it to skip to the start of the section. - ndx += buffer[ndx] + 1; - - // Now pointing to the start of the section. Check that the table id is correct. - if (buffer[ndx] != (table_pid == PAT_PID ? 0 : (table_pid == PSIP_PID ? 0xc8 : 2))) - continue; - -another_section: - - // Check the section syntax indicator. - if (table_pid == PSIP_PID) - { - if ((buffer[ndx+1] & 0xf0) != 0xf0) - continue; - } - else - { - if ((buffer[ndx+1] & 0xc0) != 0x80) - continue; - } - - // Check and get section length. - if ((buffer[ndx+1] & 0x0c) != 0) - continue; - section_length = ((buffer[ndx+1] & 0x03) << 8); - section_length |= buffer[ndx+2]; - if (section_length > 0x3fd) - continue; - - if (table_pid == PAT_PID) - first_pat = false; - else - first_pmt = false; - if (ndx + section_length + 3 <= (unsigned int) TransportPacketSize - (TransportPacketSize == 192 ? 4 : 0)) - { - // The section is entirely contained in this packet. - // Collect the section data. - memcpy(section_ptr, &buffer[ndx], section_length); - section_ptr += section_length; - // Parse the section. - switch (table_pid) - { - case PAT_PID: - ret = ProcessPATSection(); - break; - case PSIP_PID: - ret = ProcessPSIPSection(); - break; - default: - ret = ProcessPMTSection(); - break; - } - if (ret) - break; - // Get ready for collecting the next section. - section_ptr = section; - // Check to see if another section follows in this packet - // by looking for the table ID. It would be stuffing if - // there was no following section. - if (buffer[ndx+section_length+3] == 0x02) - { - ndx += section_length + 3; - goto another_section; - } - } - else - { - // This section spills over to the next transport packet. - // Collect the first part and get ready to collect the - // second part from the next packet. - memcpy(section_ptr, &buffer[ndx], TransportPacketSize - ndx - (TransportPacketSize == 192 ? 4 : 0)); - section_ptr += (TransportPacketSize - ndx - (TransportPacketSize == 192 ? 4 : 0)); - section_length -= (TransportPacketSize - 3 - ndx - (TransportPacketSize == 192 ? 4 : 0)); - continue; - } - } -} - -__int64 PATParser::GetPCRValue( void ) -{ - unsigned char byte, PCR_flag; - unsigned int pid; - int read; - int pkt_count; - - __int64 PCR, PCRbase, PCRext, tmp; - PCR = 0; - - // Process the transport packets. - pkt_count = 0; - section_ptr = section; - while ((pkt_count++ < MAX_PACKETS) && (read = fread(buffer, 1, TransportPacketSize, fin)) == TransportPacketSize) - { - // Check that this is the desired PID. - pid = ((buffer[1] & 0x1f) << 8) | buffer[2]; - if (pid != MPEG2_Transport_PCRPID) - continue; - - // We have a table packet. - // Check error indicator. - if (buffer[1] & 0x80) - continue; - - // Skip if there is no adaptation field. - byte = (unsigned char) ((buffer[3] & 0x30) >> 4); - if (byte == 0 || byte == 1) - continue; - - // Skip if there is small size, adaptation field. - if (buffer[4] < 7) - continue; - - // Skip if there is small size, adaptation field. - PCR_flag = (unsigned char) ((buffer[5] >> 4) & 0x01); - if (!PCR_flag) - continue; - - // Get PCR value. - tmp = (__int64) buffer[6]; - PCRbase = tmp << 25; - tmp = (__int64) buffer[7]; - PCRbase |= tmp << 17; - tmp = (__int64) buffer[8]; - PCRbase |= tmp << 9; - tmp = (__int64) buffer[9]; - PCRbase |= tmp << 1; - tmp = (__int64) buffer[10]; - PCRbase |= tmp >> 7; - PCRext = (tmp & 0x01) << 8; - tmp = (__int64) buffer[11]; - PCRext |= tmp; - PCR = 300 * PCRbase + PCRext; - - PCR = PCR/27000; - break; - } - - return PCR; -} - -unsigned int PATParser::GetNumPMTpids( void ) -{ - return num_pmt_pids; -} - -void PATParser::InitializePMTCheckItems( void ) -{ - check_pmt_selction_length = 0; - check_section_ptr = NULL; -} - -int PATParser::CheckPMTPid( int pkt_pid, int check_pmt_idx ) -{ - if (pkt_pid != pmt_pids[check_pmt_idx]) - return -1; - return 0; -} - -int PATParser::CheckPMTSection( int pkt_pid, unsigned char *pkt_ptr, unsigned int pkt_length, int check_pmt_idx ) -{ - int ret = -1; - - if (pkt_pid != pmt_pids[check_pmt_idx]) - return -1; - - unsigned int ndx, section_length; - - // Process the transport packets. - ndx = 0; - - if (check_section_ptr != NULL) - { - section_length = check_pmt_selction_length; - section_ptr = check_section_ptr; - - // This equality will fail when we have started gathering a section, - // but it overflowed into the next transport packet. So here we collect - // the rest of the section. - if (section_ptr != section) - { - // Collect the section data. - if (section_length <= pkt_length) - { - // The remainder of the section is contained entirely - // in this packet. Skip the pointer field if one exists. - unsigned char *start; - start = &pkt_ptr[ndx]; - if (pkt_ptr[1] & 0x40) - start++; - memcpy(section_ptr, start, section_length); - section_ptr += section_length; - - // Parse the table. - if (ParsePMTSection() > 0) - return 1; - - // Get ready for collection of the next section. - section_ptr = section; - // Check the section syntax indicator to see if another - // section follows in this packet. - if (!(pkt_ptr[1] & 0x40)) - { - // No more sections in this packet. - ret = 2; - } - else - { - // If we reach here, there is another section following - // this one, so we fall through to the code below. - goto check_pmt_another_section; - } - } - else - { - // The section is spilling over to the next packet. - // There can't be a pointer field, so there's no need to - // check for it. - memcpy(section_ptr, &pkt_ptr[ndx], pkt_length); - section_ptr += pkt_length; - section_length -= pkt_length; - - check_pmt_selction_length = section_length; - check_section_ptr = section_ptr; - ret = 0; - } - } - - } - else - { - section_ptr = section; - - // Read the section pointer field and use it to skip to the start of the section. - ndx += pkt_ptr[ndx] + 1; - - // Now pointing to the start of the section. Check that the table id is correct. - if (pkt_ptr[ndx] != 2) - return -1; - -check_pmt_another_section: - - // Check the section syntax indicator. - if ((pkt_ptr[ndx+1] & 0xc0) != 0x80) - return -1; - - // Check and get section length. - if ((pkt_ptr[ndx+1] & 0x0c) != 0) - return -1; - section_length = ((pkt_ptr[ndx+1] & 0x03) << 8); - section_length |= pkt_ptr[ndx+2]; - if (section_length > 0x3fd) - return -1; - - if (ndx + section_length + 3 <= pkt_length) - { - // The section is entirely contained in this packet. - // Collect the section data. - memcpy(section_ptr, &pkt_ptr[ndx], section_length); - section_ptr += section_length; - - // Parse the section. - if (ParsePMTSection() > 0) - return 1; - - // Get ready for collecting the next section. - section_ptr = section; - // Check to see if another section follows in this packet - // by looking for the table ID. It would be stuffing if - // there was no following section. - if (pkt_ptr[ndx+section_length+3] == 0x02) - { - ndx += section_length + 3; - goto check_pmt_another_section; - } - ret = 2; - } - else - { - // This section spills over to the next transport packet. - // Collect the first part and get ready to collect the - // second part from the next packet. - memcpy(section_ptr, &pkt_ptr[ndx], pkt_length - ndx); - section_ptr += (pkt_length - ndx); - section_length -= (pkt_length - 3 - ndx); - - check_pmt_selction_length = section_length; - check_section_ptr = section_ptr; - ret = 0; - } - } - - return ret; -} - -int PATParser::ParsePMTSection( void ) -{ - unsigned int ndx, section_length, pid; - unsigned int descriptors_length, es_descriptors_length, type, encrypted; - - // We want only current tables. - if (!(section[5] & 0x01)) - return 0; - - section_length = ((section[1] & 0x03) << 8); - section_length |= section[2]; - - // Skip the descriptors (if any). - ndx = 10; - descriptors_length = (section[ndx++] & 0x0f) << 8; - descriptors_length |= section[ndx++]; - ndx += descriptors_length; - - // Now we have the actual program data. - while (ndx < section_length - 4) - { - type = section[ndx++]; - - pid = (section[ndx++] & 0x1f) << 8; - pid |= section[ndx++]; - - if (MPEG2_Transport_VideoPID == pid - || (MPEG2_Transport_AudioPID == pid && MPEG2_Transport_VideoPID == 2)) - { - return 1; - } - - // Parse the ES descriptors if necessary. - es_descriptors_length = (section[ndx++] & 0x0f) << 8; - es_descriptors_length |= section[ndx++]; - encrypted = 0; - if (es_descriptors_length) - { - unsigned int start = ndx, end = ndx + es_descriptors_length; - int tag, length; - - // See if the ES is scrambled. - do - { - tag = section[ndx++]; - if (tag == 0x09) - encrypted = 1; - length = section[ndx++]; - ndx += length; - } while (ndx < end); - ndx = start; - - if (type == 0x80) - { - // This might be private stream video. - // Parse the descriptors for a video descriptor. - int hadVideo = 0, hadAudio = 0; - do - { - tag = section[ndx++]; - if (tag == 0x02) - hadVideo = 1; - else if (tag == 0x05) - hadAudio = 1; - length = section[ndx++]; - ndx += length; - } while (ndx < end); - ndx = end; - if (hadVideo == 1) - { - // "Private Stream Video"; - type = 0x02; - if (MPEG2_Transport_VideoPID == pid) - { - return 1; - } - } - else if (hadAudio == 1) - { - // "LPCM Audio"; - if (MPEG2_Transport_AudioPID == pid && MPEG2_Transport_VideoPID == 2) - { - return 1; - } - } - } - else if (type == 0x06) - { - // Parse the descriptors for a DTS audio descriptor. - unsigned int end = ndx + es_descriptors_length; - ndx = end; - } - else - { - ndx += es_descriptors_length; - } - } - - } - - return 0; -} diff --git a/src/dgindex/pat.h b/src/dgindex/pat.h deleted file mode 100644 index 678e534..0000000 --- a/src/dgindex/pat.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2004-2006, Donald A Graft, All Rights Reserved - * - * PAT/PMT table parser for PID detection. - * - * This is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This is distributed in the hope that 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 code; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -#include - -#define TS_SYNC_BYTE 0x47 -#define PAT_PID 0 -#define PSIP_PID 0x1ffb -#define LIMIT 10000000 -#define MAX_PROGRAMS 500 -#define MAX_SECTION 4096 -#define MAX_PIDS 500 -#define MAX_PACKETS 100000 -#define PCR_STREAM 1 - -class PATParser -{ -private: - enum operation {Dump=1, AudioType, InitialPids} op; - HWND hDialog; - char *filename; - unsigned int audio_pid; - unsigned int audio_type; - FILE *fin; - unsigned int num_pmt_pids, num_programs; - bool first_pat, first_pmt; - unsigned int pmt_pids[MAX_PIDS]; - unsigned int programs[MAX_PROGRAMS]; - unsigned char section[MAX_SECTION]; - unsigned char *section_ptr; - unsigned char buffer[204]; -private: - int SyncTransport(void); - void PATParser::GetTable(unsigned int table_pid); - int AnalyzePAT(void); - int AnalyzePSIP(void); - int AnalyzeRaw(void); - int ProcessPATSection(void); - int ProcessPMTSection(void); - int ProcessPSIPSection(void); - __int64 GetPCRValue( void ); -public: - PATParser(void); - int DumpPAT(HWND hDialog, char *filename); - int DumpPSIP(HWND hDialog, char *filename); - int DumpRaw(HWND hDialog, char *filename); - int GetAudioType(char *filename, unsigned int audio_pid); - int DoInitialPids(char *filename); -private: - int check_pmt_selction_length; - unsigned char *check_section_ptr; -public: - unsigned int GetNumPMTpids( void ); - void InitializePMTCheckItems(void); - int CheckPMTPid( int pkt_pid, int check_pmt_idx ); - int CheckPMTSection( int pkt_pid, unsigned char *pkt_ptr, unsigned int pkt_length, int check_pmt_idx ); -private: - int ParsePMTSection( void ); -}; diff --git a/src/dgindex/resource.h b/src/dgindex/resource.h deleted file mode 100644 index 485c859..0000000 --- a/src/dgindex/resource.h +++ /dev/null @@ -1,269 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Developer Studio generated include file. -// Used by gui.rc -// -#define ID_LEFT_BUTTON 1 -#define ID_LEFT_ARROW 2 -#define ID_RIGHT_BUTTON 3 -#define ID_RIGHT_ARROW 4 -#define ID_TRACKBAR 5 -#define ID_ADD 6 -#define ID_DEL 7 -#define ID_DELALL 8 -#define ID_UP 9 -#define ID_DOWN 10 -#define IDD_ABOUT 11 -#define IDC_GUI 12 -#define IDI_MOVIE 13 -#define IDI_SMALL 14 -#define IDR_ACCELERATOR 15 -#define IDD_INFO 16 -#define IDD_FILELIST 17 -#define IDD_LUMINANCE 18 -#define IDD_NORM 19 -#define IDD_CROPPING 20 -#define IDD_SET_PIDS 21 -#define IDD_DETECT_PIDS 22 -#define IDD_AVS_TEMPLATE 23 -#define IDD_SELECT_TRACKS 24 -#define IDD_BMP_PATH 25 -#define IDD_SELECT_DELAY_TRACK 26 -#define IDD_SET_MARGIN 27 -#define IDC_CODED_NUMBER 1016 -#define IDC_PLAYBACK_NUMBER 1017 -#define IDC_FRAME_RATE 1018 -#define IDC_VOB_ID 1019 -#define IDC_CELL_ID 1020 -#define IDC_VIDEO_TYPE 1021 -#define IDC_FRAME_TYPE 1022 -#define IDC_ASPECT_RATIO 1023 -#define IDC_REMAIN 1024 -#define IDC_ELAPSED 1025 -#define IDC_FRAME_SIZE 1026 -#define IDC_PROFILE 1027 -#define IDC_FPS 1028 -#define IDC_COLORIMETRY 1029 -#define IDC_TIMESTAMP 1030 -#define IDC_LIST 1031 -#define IDC_FRAME_REPEATS 1032 -#define IDC_FIELD_REPEATS 1033 -#define IDC_FRAME_STRUCTURE 1034 -#define IDC_INFO 1035 -#define IDC_FIELD_ORDER 1036 -#define IDC_BITRATE 1037 -#define IDC_BITRATE_AVG 1038 -#define IDC_LUM_CHECK 1039 -#define IDC_NORM_SLIDER 1040 -#define IDC_NORM_CHECK 1041 -#define IDC_NORM 1042 -#define IDC_TOP_SLIDER 1043 -#define IDC_BOTTOM_SLIDER 1044 -#define IDC_TOP 1045 -#define IDC_BOTTOM 1046 -#define IDC_RIGHT_SLIDER 1047 -#define IDC_LEFT_SLIDER 1048 -#define IDC_RIGHT 1049 -#define IDC_LEFT 1050 -#define IDC_CROPPING_CHECK 1051 -#define IDC_VERSION 1052 -#define IDC_HEIGHT 1053 -#define IDC_WIDTH 1054 -#define IDC_FWIDTH 1055 -#define IDC_FHEIGHT 1056 -#define IDC_VIDEO_PID 1057 -#define IDC_AUDIO_PID 1058 -#define IDC_PIDS_OK 1059 -#define IDC_PIDS_CANCEL 1060 -#define IDC_PID_LISTBOX 1061 -#define IDC_PCR_PID 1062 -#define IDC_SET_AUDIO 1063 -#define IDC_SET_VIDEO 1064 -#define IDC_SET_PCR 1065 -#define IDC_SET_DONE 1066 -#define IDC_AUDIO_TYPE 1067 -#define IDC_AUDIO_TYPE2 1068 -#define IDC_AUDIO_TYPE3 1069 -#define IDC_AUDIO_TYPE4 1070 -#define IDC_AUDIO_TYPE5 1071 -#define IDC_AUDIO_TYPE6 1072 -#define IDC_AUDIO_TYPE7 1073 -#define IDC_AUDIO_TYPE8 1074 -#define IDC_NO_TEMPLATE 1075 -#define IDC_CHANGE_TEMPLATE 1076 -#define IDC_KEEP_TEMPLATE 1077 -#define IDC_AVS_TEMPLATE 1078 -#define IDC_GAMMA_SPIN 1079 -#define IDC_OFFSET_SPIN 1080 -#define IDC_GAMMA_BOX 1081 -#define IDC_OFFSET_BOX 1082 -#define IDC_STREAM_TYPE 1083 -#define IDC_TRACK_OK 1084 -#define IDC_TRACK_CANCEL 1085 -#define IDC_AUDIO_LIST 1086 -#define IDC_TRACK_LIST 1087 -#define IDC_CODING_TYPE 1088 -#define IDC_BITRATE_MAX 1089 -#define IDC_CHANGE_BMP_PATH 1090 -#define IDC_KEEP_BMP_PATH 1091 -#define IDC_BMP_PATH 1092 -#define IDC_BMP_PATH_OK 1093 -#define IDC_BMP_PATH_CANCEL 1094 -#define IDC_DISPLAY_SIZE 1095 -#define IDC_DELAY_LIST 1096 -#define IDC_DELAY_OK 1097 -#define IDC_DELAY_CANCEL 1098 -#define IDC_SEQUENCE 1099 -#define IDC_MARGIN 1100 -#define IDC_MARGIN_OK 1101 -#define IDC_MARGIN_CANCEL 1102 -#define IDC_STATIC_ABOUT 1103 -#define IDC_STATIC_THANK 1104 -#define IDC_STATIC_OFFSET 1105 -#define IDC_STATIC_GAMMA 1106 -#define IDC_STATIC_VOLUME 1107 -#define IDC_STATIC_VIDEO_PID 1108 -#define IDC_STATIC_AUDIO_PID 1109 -#define IDC_STATIC_PCR_PID 1110 -#define IDC_STATIC_SET_PIDS 1111 -#define IDC_STATIC_AVS_TEMPLATE 1112 -#define IDC_STATIC_BMP_PATH 1113 -#define IDC_STATIC_FLEFT 1114 -#define IDC_STATIC_FRIGHT 1115 -#define IDC_STATIC_FTOP 1116 -#define IDC_STATIC_FBOTTOM 1117 -#define IDC_STATIC_DETECT_PIDS 1118 -#define IDC_STATIC_SELECT_TRACKS 1119 -#define IDC_STATIC_SELECT_DELAY_TRACK 1120 -#define IDC_STATIC_SET_MARGIN 1121 -#define IDC_STATIC_MSEC 1122 -#define IDC_SELECT_VIDEO_PID 1123 -#define IDC_SELECT_AUDIO_PID 1124 -#define IDC_SELECT_PCR_PID 1125 -#define IDM_ABOUT 32769 -#define IDM_EXIT 32770 -#define IDM_OPEN 32771 -#define IDM_SAVE_D2V 32772 -#define IDM_LOAD_D2V 32774 -#define IDM_PREVIEW 32775 -#define IDM_PREVIEW_NO_INFO 32776 -#define IDM_PAUSE 32777 -#define IDM_STOP 32778 -#define IDM_DISPLAY 32779 -#define IDM_PP_HIGH 32780 -#define IDM_PP_NORMAL 32781 -#define IDM_PP_LOW 32782 -#define IDM_FO_FILM 32784 -#define IDM_INFO 32785 -#define IDM_DIRECTDRAW 32786 -#define IDM_VFAPI 32787 -#define IDM_IDCT_MMX 32788 -#define IDM_IDCT_FPU 32789 -#define IDM_IDCT_REF 32790 -#define IDM_MMX 32791 -#define IDM_SSEMMX 32792 -#define IDM_SRC_NONE 32795 -#define IDM_SRC_LOW 32796 -#define IDM_SRC_MID 32797 -#define IDM_SRC_HIGH 32798 -#define IDM_SRC_UHIGH 32799 -#define IDM_NORM 32800 -#define IDM_TRACK_1 32801 -#define IDM_TRACK_2 32802 -#define IDM_TRACK_3 32803 -#define IDM_TRACK_4 32804 -#define IDM_TRACK_5 32805 -#define IDM_TRACK_6 32806 -#define IDM_TRACK_7 32807 -#define IDM_TRACK_8 32808 -#define IDM_TVSCALE 32809 -#define IDM_PCSCALE 32810 -#define IDM_BMP 32811 -#define IDM_LUMINANCE 32812 -#define IDM_DSDOWN 32813 -#define IDM_FO_NONE 32814 -#define IDM_DRC_NONE 32815 -#define IDM_DRC_LIGHT 32816 -#define IDM_DRC_NORMAL 32817 -#define IDM_DRC_HEAVY 32818 -#define IDM_CROPPING 32819 -#define IDM_PRESCALE 32820 -#define IDM_IDCT_SSEMMX 32821 -#define IDM_3DNOW 32822 -#define IDM_SSEFPU 32823 -#define IDM_SSE2 32827 -#define IDM_IDCT_SSE2MMX 32828 -#define IDM_DEMUX 32829 -#define IDM_DEMUXALL 32830 -#define IDM_DECODE 32831 -#define IDM_AUDIO_NONE 32832 -#define IDM_PLAY 32834 -#define IDM_JACKEI 32835 -#define IDM_NEURON2 32836 -#define IDM_FO_RAW 32837 -#define IDM_SET_PIDS 32838 -#define IDM_DETECT_PIDS 32839 -#define IDM_DETECT_PIDS_PSIP 32840 -#define IDM_DETECT_PIDS_RAW 32841 -#define IDM_SAVE_D2V_AND_DEMUX 32842 -#define IDM_PARSE_D2V 32843 -#define IDM_FIX_D2V 32844 -#define IDM_IDCT_SKAL 32845 -#define IDM_IDCT_SIMPLE 32846 -#define IDM_LOG_QUANTS 32847 -#define IDM_SPEED_SUPER_SLOW 32848 -#define IDM_SPEED_SLOW 32849 -#define IDM_SPEED_NORMAL 32850 -#define IDM_SPEED_FAST 32851 -#define IDM_SPEED_MAXIMUM 32852 -#define IDM_FORCE_OPEN 32853 -#define IDM_SPEED_SINGLE_STEP 32854 -#define IDM_DGINDEX_MANUAL 32855 -#define IDM_DGDECODE_MANUAL 32856 -#define IDM_QUICK_START 32857 -#define IDM_AVS_TEMPLATE 32859 -#define IDM_FULL_PATH 32860 -#define IDM_LOG_TIMESTAMPS 32862 -#define IDM_FUSION_AUDIO 32863 -#define IDM_DEMUX_AUDIO 32864 -#define IDM_TRACK_NUMBER 32865 -#define IDM_SYNC1 32866 -#define IDM_SYNC2 32867 -#define IDM_SYNC3 32868 -#define IDM_SYNC4 32869 -#define IDM_SYNC5 32870 -#define IDM_SYNC6 32871 -#define IDM_SYNC7 32872 -#define IDM_SYNC8 32873 -#define IDM_LOOP_PLAYBACK 32874 -#define IDM_SHRINK_BY_HALF 32875 -#define IDM_TOP_LEFT 32876 -#define IDM_TOP_RIGHT 32877 -#define IDM_BOTTOM_LEFT 32878 -#define IDM_BOTTOM_RIGHT 32879 -#define IDM_BMP_PATH 32880 -#define IDM_INFO_LOG 32881 -#define IDM_ANALYZESYNC 32882 -#define ID_FILE_CLOSE 32883 -#define IDM_CLOSE 32883 -#define IDM_COPYFRAMETOCLIPBOARD 32884 -#define IDM_FULL_SIZED 32885 -#define IDM_SET_MARGIN 32886 -#define IDM_CFOT_DISABLE 32887 -#define IDM_CFOT_ENABLE 32888 -#define ID_MRU_FILE0 50000 -#define ID_MRU_FILE1 50001 -#define ID_MRU_FILE2 50002 -#define ID_MRU_FILE3 50003 -#define IDC_STATIC -1 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NO_MFC 1 -#define _APS_NEXT_RESOURCE_VALUE 28 -#define _APS_NEXT_COMMAND_VALUE 32889 -#define _APS_NEXT_CONTROL_VALUE 1126 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/src/dgindex/simple_idct_mmx.asm b/src/dgindex/simple_idct_mmx.asm deleted file mode 100644 index 53ed433..0000000 --- a/src/dgindex/simple_idct_mmx.asm +++ /dev/null @@ -1,1116 +0,0 @@ -;/* -; * Simple IDCT MMX -; * -; * Copyright (c) 2001, 2002 Michael Niedermayer -; * -; * This library is free software; you can redistribute it and/or -; * modify it under the terms of the GNU Lesser General Public -; * License as published by the Free Software Foundation; either -; * version 2 of the License, or (at your option) any later version. -; * -; * This library is distributed in the hope that it will be useful, -; * but WITHOUT ANY WARRANTY; without even the implied warranty of -; * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -; * Lesser General Public License for more details. -; * -; * You should have received a copy of the GNU Lesser General Public -; * License along with this library; if not, write to the Free Software -; * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -; * -; * Ported to nasm by Peter Ross -; */ - -bits 32 - - -;=========================================================================== -; data -;=========================================================================== - -%ifdef FORMAT_COFF -section .data -align 8 -%else -section .data data align=8 -%endif - -wm1010 dw 0, 0xffff, 0, 0xffff -d40000 dd 0x40000, 0 - - -%define ROW_SHIFT 11 -%define COL_SHIFT 20 -%define C0 23170 ;cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 = 23170.475006 -%define C1 22725 ;cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 = 22725.260826 -%define C2 21407 ;cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 = 21406.727617 -%define C3 19266 ;cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 = 19265.545870 -%define C4 16383 ;cos(i*M_PI/16)*sqrt(2)*(1<<14) - 0.5 = 16384.000000 -%define C5 12873 ;cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 = 12872.826198 -%define C6 8867 ;cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 = 8866.956905 -%define C7 4520 ;cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 = 4520.335430 - -coeffs: - dw 1<<(ROW_SHIFT-1), 0, 1<<(ROW_SHIFT-1), 0, ; 0 - dw 1<<(ROW_SHIFT-1), 1, 1<<(ROW_SHIFT-1), 0, ; 8 - - dw C4, C4, C4, C4 ; 16 - dw C4, -C4, C4, -C4 ; 24 - - dw C2, C6, C2, C6 ; 32 - dw C6, -C2, C6, -C2 ; 40 - - dw C1, C3, C1, C3 ; 48 - dw C5, C7, C5, C7 ; 56 - - dw C3, -C7, C3, -C7 ; 64 - dw -C1, -C5, -C1, -C5 ; 72 - - dw C5, -C1, C5, -C1 ; 80 - dw C7, C3, C7, C3 ; 88 - - dw C7, -C5, C7, -C5 ; 96 - dw C3, -C1, C3, -C1 ; 104 - - -;=========================================================================== -; text -;=========================================================================== -section .text - -%macro DC_COND_IDCT 8 -%define src0 %1 -%define src4 %2 -%define src1 %3 -%define src5 %4 -%define dst %5 -%define rounder_op %6 -%define rounder_arg %7 -%define shift %8 - movq mm0,[src0] ; R4 R0 r4 r0 - movq mm1,[src4] ; R6 R2 r6 r2 - movq mm2,[src1] ; R3 R1 r3 r1 - movq mm3,[src5] ; R7 R5 r7 r5 - movq mm4,[wm1010] - pand mm4,mm0 - por mm4,mm1 - por mm4,mm2 - por mm4,mm3 - packssdw mm4,mm4 - movd eax,mm4 - or eax,eax - jz near .skip1 - movq mm4,[coeffs+16] ; C4 C4 C4 C4 - pmaddwd mm4,mm0 ; C4R4+C4R0 C4r4+C4r0 - movq mm5,[coeffs+24] ; -C4 C4 -C4 C4 - pmaddwd mm0,mm5 ; -C4R4+C4R0 -C4r4+C4r0 - movq mm5,[coeffs+32] ; C6 C2 C6 C2 - pmaddwd mm5,mm1 ; C6R6+C2R2 C6r6+C2r2 - movq mm6,[coeffs+40] ; -C2 C6 -C2 C6 - pmaddwd mm1,mm6 ; -C2R6+C6R2 -C2r6+C6r2 - movq mm7,[coeffs+48] ; C3 C1 C3 C1 - pmaddwd mm7,mm2 ; C3R3+C1R1 C3r3+C1r1 - rounder_op mm4, rounder_arg - movq mm6,mm4 ; C4R4+C4R0 C4r4+C4r0 - paddd mm4,mm5 ; A0 a0 - psubd mm6,mm5 ; A3 a3 - movq mm5,[coeffs+56] ; C7 C5 C7 C5 - pmaddwd mm5,mm3 ; C7R7+C5R5 C7r7+C5r5 - rounder_op mm0, rounder_arg - paddd mm1,mm0 ; A1 a1 - paddd mm0,mm0 - psubd mm0,mm1 ; A2 a2 - pmaddwd mm2,[coeffs+64] ; -C7R3+C3R1 -C7r3+C3r1 - paddd mm7,mm5 ; B0 b0 - movq mm5,[coeffs+72] ; -C5 -C1 -C5 -C1 - pmaddwd mm5,mm3 ; -C5R7-C1R5 -C5r7-C1r5 - paddd mm7,mm4 ; A0+B0 a0+b0 - paddd mm4,mm4 ; 2A0 2a0 - psubd mm4,mm7 ; A0-B0 a0-b0 - paddd mm5,mm2 ; B1 b1 - psrad mm7,shift - psrad mm4,shift - movq mm2,mm1 ; A1 a1 - paddd mm1,mm5 ; A1+B1 a1+b1 - psubd mm2,mm5 ; A1-B1 a1-b1 - psrad mm1,shift - psrad mm2,shift - packssdw mm7,mm1 ; A1+B1 a1+b1 A0+B0 a0+b0 - packssdw mm2,mm4 ; A0-B0 a0-b0 A1-B1 a1-b1 - movq [dst],mm7 - movq mm1,[src1] ; R3 R1 r3 r1 - movq mm4,[coeffs+80] ;-C1 C5 -C1 C5 - movq [dst + 24],mm2 - pmaddwd mm4,mm1 ; -C1R3+C5R1 -C1r3+C5r1 - movq mm7,[coeffs+88] ; C3 C7 C3 C7 - pmaddwd mm1,[coeffs+96] ; -C5R3+C7R1 -C5r3+C7r1 - pmaddwd mm7,mm3 ; C3R7+C7R5 C3r7+C7r5 - movq mm2,mm0 ; A2 a2 - pmaddwd mm3,[coeffs+104] ; -C1R7+C3R5 -C1r7+C3r5 - paddd mm4,mm7 ; B2 b2 - paddd mm2,mm4 ; A2+B2 a2+b2 - psubd mm0,mm4 ; a2-B2 a2-b2 - psrad mm2,shift - psrad mm0,shift - movq mm4,mm6 ; A3 a3 - paddd mm3,mm1 ; B3 b3 - paddd mm6,mm3 ; A3+B3 a3+b3 - psubd mm4,mm3 ; a3-B3 a3-b3 - psrad mm6,shift - packssdw mm2,mm6 ; A3+B3 a3+b3 A2+B2 a2+b2 - movq [ dst + 8],mm2 - psrad mm4,shift - packssdw mm4,mm0 ; A2-B2 a2-b2 A3-B3 a3-b3 - movq [ dst + 16],mm4 - jmp short .skip2 -.skip1: - pslld mm0,16 - paddd mm0,[d40000] - psrad mm0,13 - packssdw mm0,mm0 - movq [ dst ],mm0 - movq [ dst + 8],mm0 - movq [ dst + 16],mm0 - movq [ dst + 24],mm0 -.skip2: -%undef src0 -%undef src4 -%undef src1 -%undef src5 -%undef dst -%undef rounder_op -%undef rounder_arg -%undef shift -%endmacro - - - -%macro Z_COND_IDCT 9 -%define src0 %1 -%define src4 %2 -%define src1 %3 -%define src5 %4 -%define dst %5 -%define rounder_op %6 -%define rounder_arg %7 -%define shift %8 -%define bt %9 - movq mm0,[src0] ; R4 R0 r4 r0 - movq mm1,[src4] ; R6 R2 r6 r2 - movq mm2,[src1] ; R3 R1 r3 r1 - movq mm3,[src5] ; R7 R5 r7 r5 - movq mm4,mm0 - por mm4,mm1 - por mm4,mm2 - por mm4,mm3 - packssdw mm4,mm4 - movd eax,mm4 - or eax,eax - jz near bt - movq mm4,[coeffs+16] ; C4 C4 C4 C4 - pmaddwd mm4,mm0 ; C4R4+C4R0 C4r4+C4r0 - movq mm5,[coeffs+24] ; -C4 C4 -C4 C4 - pmaddwd mm0,mm5 ; -C4R4+C4R0 -C4r4+C4r0 - movq mm5,[coeffs+32] ; C6 C2 C6 C2 - pmaddwd mm5,mm1 ; C6R6+C2R2 C6r6+C2r2 - movq mm6,[coeffs+40] ; -C2 C6 -C2 C6 - pmaddwd mm1,mm6 ; -C2R6+C6R2 -C2r6+C6r2 - movq mm7,[coeffs+48] ; C3 C1 C3 C1 - pmaddwd mm7,mm2 ; C3R3+C1R1 C3r3+C1r1 - rounder_op mm4, rounder_arg - movq mm6,mm4 ; C4R4+C4R0 C4r4+C4r0 - paddd mm4,mm5 ; A0 a0 - psubd mm6,mm5 ; A3 a3 - movq mm5,[coeffs+56] ; C7 C5 C7 C5 - pmaddwd mm5,mm3 ; C7R7+C5R5 C7r7+C5r5 - rounder_op mm0, rounder_arg - paddd mm1,mm0 ; A1 a1 - paddd mm0,mm0 - psubd mm0,mm1 ; A2 a2 - pmaddwd mm2,[coeffs+64] ; -C7R3+C3R1 -C7r3+C3r1 - paddd mm7,mm5 ; B0 b0 - movq mm5,[coeffs+72] ; -C5 -C1 -C5 -C1 - pmaddwd mm5,mm3 ; -C5R7-C1R5 -C5r7-C1r5 - paddd mm7,mm4 ; A0+B0 a0+b0 - paddd mm4,mm4 ; 2A0 2a0 - psubd mm4,mm7 ; A0-B0 a0-b0 - paddd mm5,mm2 ; B1 b1 - psrad mm7,shift - psrad mm4,shift - movq mm2,mm1 ; A1 a1 - paddd mm1,mm5 ; A1+B1 a1+b1 - psubd mm2,mm5 ; A1-B1 a1-b1 - psrad mm1,shift - psrad mm2,shift - packssdw mm7,mm1 ; A1+B1 a1+b1 A0+B0 a0+b0 - packssdw mm2,mm4 ; A0-B0 a0-b0 A1-B1 a1-b1 - movq [ dst ],mm7 - movq mm1,[src1] ; R3 R1 r3 r1 - movq mm4,[coeffs+80] ; -C1 C5 -C1 C5 - movq [ dst + 24 ],mm2 - pmaddwd mm4,mm1 ; -C1R3+C5R1 -C1r3+C5r1 - movq mm7,[coeffs+88] ; C3 C7 C3 C7 - pmaddwd mm1,[coeffs+96] ; -C5R3+C7R1 -C5r3+C7r1 - pmaddwd mm7,mm3 ; C3R7+C7R5 C3r7+C7r5 - movq mm2,mm0 ; A2 a2 - pmaddwd mm3,[coeffs+104] ; -C1R7+C3R5 -C1r7+C3r5 - paddd mm4,mm7 ; B2 b2 - paddd mm2,mm4 ; A2+B2 a2+b2 - psubd mm0,mm4 ; a2-B2 a2-b2 - psrad mm2,shift - psrad mm0,shift - movq mm4,mm6 ; A3 a3 - paddd mm3,mm1 ; B3 b3 - paddd mm6,mm3 ; A3+B3 a3+b3 - psubd mm4,mm3 ; a3-B3 a3-b3 - psrad mm6,shift - packssdw mm2,mm6 ; A3+B3 a3+b3 A2+B2 a2+b2 - movq [ dst + 8],mm2 - psrad mm4,shift - packssdw mm4,mm0 ; A2-B2 a2-b2 A3-B3 a3-b3 - movq [dst + 16],mm4 -%undef src0 -%undef src4 -%undef src1 -%undef src5 -%undef dst -%undef rounder_op -%undef rounder_arg -%undef shift -%undef bt -%endmacro - - - -%macro IDCT0 8 -%define src0 %1 -%define src4 %2 -%define src1 %3 -%define src5 %4 -%define dst %5 -%define rounder_op %6 -%define rounder_arg %7 -%define shift %8 - movq mm0,[src0] ; R4 R0 r4 r0 - movq mm1,[src4] ; R6 R2 r6 r2 - movq mm2,[src1] ; R3 R1 r3 r1 - movq mm3,[src5] ; R7 R5 r7 r5 - movq mm4,[coeffs+16] ; C4 C4 C4 C4 - pmaddwd mm4,mm0 ; C4R4+C4R0 C4r4+C4r0 - movq mm5,[coeffs+24] ; -C4 C4 -C4 C4 - pmaddwd mm0,mm5 ; -C4R4+C4R0 -C4r4+C4r0 - movq mm5,[coeffs+32] ; C6 C2 C6 C2 - pmaddwd mm5,mm1 ; C6R6+C2R2 C6r6+C2r2 - movq mm6,[coeffs+40] ; -C2 C6 -C2 C6 - pmaddwd mm1,mm6 ; -C2R6+C6R2 -C2r6+C6r2 - ; rounder_op mm4, rounder_arg - movq mm6,mm4 ; C4R4+C4R0 C4r4+C4r0 - movq mm7,[coeffs+48] ; C3 C1 C3 C1 - ; rounder_op mm0, rounder_arg - pmaddwd mm7,mm2 ; C3R3+C1R1 C3r3+C1r1 - paddd mm4,mm5 ; A0 a0 - psubd mm6,mm5 ; A3 a3 - movq mm5,mm0 ; -C4R4+C4R0 -C4r4+C4r0 - paddd mm0,mm1 ; A1 a1 - psubd mm5,mm1 ; A2 a2 - movq mm1,[coeffs+56] ; C7 C5 C7 C5 - pmaddwd mm1,mm3 ; C7R7+C5R5 C7r7+C5r5 - pmaddwd mm2,[coeffs+64] ; -C7R3+C3R1 -C7r3+C3r1 - paddd mm7,mm1 ; B0 b0 - movq mm1,[coeffs+72] ; -C5 -C1 -C5 -C1 - pmaddwd mm1,mm3 ; -C5R7-C1R5 -C5r7-C1r5 - paddd mm7,mm4 ; A0+B0 a0+b0 - paddd mm4,mm4 ; 2A0 2a0 - psubd mm4,mm7 ; A0-B0 a0-b0 - paddd mm1,mm2 ; B1 b1 - psrad mm7,shift - psrad mm4,shift - movq mm2,mm0 ; A1 a1 - paddd mm0,mm1 ; A1+B1 a1+b1 - psubd mm2,mm1 ; A1-B1 a1-b1 - psrad mm0,shift - psrad mm2,shift - packssdw mm7,mm7 ; A0+B0 a0+b0 - movd [ dst ],mm7 - packssdw mm0,mm0 ; A1+B1 a1+b1 - movd [ dst + 16],mm0 - packssdw mm2,mm2 ; A1-B1 a1-b1 - movd [ dst + 96 ],mm2 - packssdw mm4,mm4 ; A0-B0 a0-b0 - movd [ dst + 112],mm4 - movq mm0,[src1] ; R3 R1 r3 r1 - movq mm4,[coeffs+80] ; -C1 C5 -C1 C5 - pmaddwd mm4,mm0 ; -C1R3+C5R1 -C1r3+C5r1 - movq mm7,[coeffs+88] ; C3 C7 C3 C7 - pmaddwd mm0,[coeffs+96] ; -C5R3+C7R1 -C5r3+C7r1 - pmaddwd mm7,mm3 ; C3R7+C7R5 C3r7+C7r5 - movq mm2,mm5 ; A2 a2 - pmaddwd mm3,[coeffs+104] ; -C1R7+C3R5 -C1r7+C3r5 - paddd mm4,mm7 ; B2 b2 - paddd mm2,mm4 ; A2+B2 a2+b2 - psubd mm5,mm4 ; a2-B2 a2-b2 - psrad mm2,shift - psrad mm5,shift - movq mm4,mm6 ; A3 a3 - paddd mm3,mm0 ; B3 b3 - paddd mm6,mm3 ; A3+B3 a3+b3 - psubd mm4,mm3 ; a3-B3 a3-b3 - psrad mm6,shift - psrad mm4,shift - packssdw mm2,mm2 ; A2+B2 a2+b2 - packssdw mm6,mm6 ; A3+B3 a3+b3 - movd [ dst + 32 ],mm2 - packssdw mm4,mm4 ; A3-B3 a3-b3 - packssdw mm5,mm5 ; A2-B2 a2-b2 - movd [ dst + 48 ],mm6 - movd [ dst + 64 ],mm4 - movd [ dst + 80 ],mm5 -%undef src0 -%undef src4 -%undef src1 -%undef src5 -%undef dst -%undef rounder_op -%undef rounder_arg -%undef shift -%endmacro - - - -%macro IDCT4 8 -%define src0 %1 -%define src4 %2 -%define src1 %3 -%define src5 %4 -%define dst %5 -%define rounder_op %6 -%define rounder_arg %7 -%define shift %8 - movq mm0,[src0] ; R4 R0 r4 r0 - movq mm1,[src4] ; R6 R2 r6 r2 - movq mm3,[src5] ; R7 R5 r7 r5 - movq mm4,[coeffs+16] ; C4 C4 C4 C4 - pmaddwd mm4,mm0 ; C4R4+C4R0 C4r4+C4r0 - movq mm5,[coeffs+24] ; -C4 C4 -C4 C4 - pmaddwd mm0,mm5 ; -C4R4+C4R0 -C4r4+C4r0 - movq mm5,[coeffs+32] ; C6 C2 C6 C2 - pmaddwd mm5,mm1 ; C6R6+C2R2 C6r6+C2r2 - movq mm6,[coeffs+40] ; -C2 C6 -C2 C6 - pmaddwd mm1,mm6 ; -C2R6+C6R2 -C2r6+C6r2 - ; rounder_op mm4, rounder_arg - movq mm6,mm4 ; C4R4+C4R0 C4r4+C4r0 - ; rounder_op mm0, rounder_arg - paddd mm4,mm5 ; A0 a0 - psubd mm6,mm5 ; A3 a3 - movq mm5,mm0 ; -C4R4+C4R0 -C4r4+C4r0 - paddd mm0,mm1 ; A1 a1 - psubd mm5,mm1 ; A2 a2 - movq mm1,[coeffs+56] ; C7 C5 C7 C5 - pmaddwd mm1,mm3 ; C7R7+C5R5 C7r7+C5r5 - movq mm7,[coeffs+72] ; -C5 -C1 -C5 -C1 - pmaddwd mm7,mm3 ; -C5R7-C1R5 -C5r7-C1r5 - paddd mm1,mm4 ; A0+B0 a0+b0 - paddd mm4,mm4 ; 2A0 2a0 - psubd mm4,mm1 ; A0-B0 a0-b0 - psrad mm1,shift - psrad mm4,shift - movq mm2,mm0 ; A1 a1 - paddd mm0,mm7 ; A1+B1 a1+b1 - psubd mm2,mm7 ; A1-B1 a1-b1 - psrad mm0,shift - psrad mm2,shift - packssdw mm1,mm1 ; A0+B0 a0+b0 - movd [ dst ],mm1 - packssdw mm0,mm0 ; A1+B1 a1+b1 - movd [ dst + 16 ],mm0 - packssdw mm2,mm2 ; A1-B1 a1-b1 - movd [ dst + 96 ],mm2 - packssdw mm4,mm4 ; A0-B0 a0-b0 - movd [ dst + 112 ],mm4 - movq mm1,[coeffs+88] ; C3 C7 C3 C7 - pmaddwd mm1,mm3 ; C3R7+C7R5 C3r7+C7r5 - movq mm2,mm5 ; A2 a2 - pmaddwd mm3,[coeffs+104] ; -C1R7+C3R5 -C1r7+C3r5 - paddd mm2,mm1 ; A2+B2 a2+b2 - psubd mm5,mm1 ; a2-B2 a2-b2 - psrad mm2,shift - psrad mm5,shift - movq mm1,mm6 ; A3 a3 - paddd mm6,mm3 ; A3+B3 a3+b3 - psubd mm1,mm3 ; a3-B3 a3-b3 - psrad mm6,shift - psrad mm1,shift - packssdw mm2,mm2 ; A2+B2 a2+b2 - packssdw mm6,mm6 ; A3+B3 a3+b3 - movd [dst + 32],mm2 - packssdw mm1,mm1 ; A3-B3 a3-b3 - packssdw mm5,mm5 ; A2-B2 a2-b2 - movd [dst + 48],mm6 - movd [dst + 64],mm1 - movd [dst + 80],mm5 -%undef src0 -%undef src4 -%undef src1 -%undef src5 -%undef dst -%undef rounder_op -%undef rounder_arg -%undef shift -%endmacro - - - -%macro IDCT6 8 -%define src0 %1 -%define src4 %2 -%define src1 %3 -%define src5 %4 -%define dst %5 -%define rounder_op %6 -%define rounder_arg %7 -%define shift %8 - movq mm0,[src0] ; R4 R0 r4 r0 - movq mm3,[src5] ; R7 R5 r7 r5 - movq mm4,[coeffs+16] ; C4 C4 C4 C4 - pmaddwd mm4,mm0 ; C4R4+C4R0 C4r4+C4r0 - movq mm5,[coeffs+24] ; -C4 C4 -C4 C4 - pmaddwd mm0,mm5 ; -C4R4+C4R0 -C4r4+C4r0 - ; rounder_op mm4, rounder_arg - movq mm6,mm4 ; C4R4+C4R0 C4r4+C4r0 - ; rounder_op mm0, rounder_arg - movq mm5,mm0 ; -C4R4+C4R0 -C4r4+C4r0 - movq mm1,[coeffs+56] ; C7 C5 C7 C5 - pmaddwd mm1,mm3 ; C7R7+C5R5 C7r7+C5r5 - movq mm7,[coeffs+72] ; -C5 -C1 -C5 -C1 - pmaddwd mm7,mm3 ; -C5R7-C1R5 -C5r7-C1r5 - paddd mm1,mm4 ; A0+B0 a0+b0 - paddd mm4,mm4 ; 2A0 2a0 - psubd mm4,mm1 ; A0-B0 a0-b0 - psrad mm1,shift - psrad mm4,shift - movq mm2,mm0 ; A1 a1 - paddd mm0,mm7 ; A1+B1 a1+b1 - psubd mm2,mm7 ; A1-B1 a1-b1 - psrad mm0,shift - psrad mm2,shift - packssdw mm1,mm1 ; A0+B0 a0+b0 - movd [ dst ],mm1 - packssdw mm0,mm0 ; A1+B1 a1+b1 - movd [ dst + 16 ],mm0 - packssdw mm2,mm2 ; A1-B1 a1-b1 - movd [ dst + 96 ],mm2 - packssdw mm4,mm4 ; A0-B0 a0-b0 - movd [ dst + 112 ],mm4 - movq mm1,[coeffs+88] ; C3 C7 C3 C7 - pmaddwd mm1,mm3 ; C3R7+C7R5 C3r7+C7r5 - movq mm2,mm5 ; A2 a2 - pmaddwd mm3,[coeffs+104] ; -C1R7+C3R5 -C1r7+C3r5 - paddd mm2,mm1 ; A2+B2 a2+b2 - psubd mm5,mm1 ; a2-B2 a2-b2 - psrad mm2,shift - psrad mm5,shift - movq mm1,mm6 ; A3 a3 - paddd mm6,mm3 ; A3+B3 a3+b3 - psubd mm1,mm3 ; a3-B3 a3-b3 - psrad mm6,shift - psrad mm1,shift - packssdw mm2,mm2 ; A2+B2 a2+b2 - packssdw mm6,mm6 ; A3+B3 a3+b3 - movd [dst + 32],mm2 - packssdw mm1,mm1 ; A3-B3 a3-b3 - packssdw mm5,mm5 ; A2-B2 a2-b2 - movd [dst + 48],mm6 - movd [dst + 64],mm1 - movd [dst + 80],mm5 -%undef src0 -%undef src4 -%undef src1 -%undef src5 -%undef dst -%undef rounder_op -%undef rounder_arg -%undef shift -%endmacro - - - - -%macro IDCT2 8 -%define src0 %1 -%define src4 %2 -%define src1 %3 -%define src5 %4 -%define dst %5 -%define rounder_op %6 -%define rounder_arg %7 -%define shift %8 - movq mm0,[src0] ; R4 R0 r4 r0 - movq mm2,[src1] ; R3 R1 r3 r1 - movq mm3,[src5] ; R7 R5 r7 r5 - movq mm4,[coeffs+16] ; C4 C4 C4 C4 - pmaddwd mm4,mm0 ; C4R4+C4R0 C4r4+C4r0 - movq mm5,[coeffs+24] ; -C4 C4 -C4 C4 - pmaddwd mm0,mm5 ; -C4R4+C4R0 -C4r4+C4r0 - ; rounder_op mm4, rounder_arg - movq mm6,mm4 ; C4R4+C4R0 C4r4+C4r0 - movq mm7,[coeffs+48] ; C3 C1 C3 C1 - ; rounder_op mm0, rounder_arg - pmaddwd mm7,mm2 ; C3R3+C1R1 C3r3+C1r1 - movq mm5,mm0 ; -C4R4+C4R0 -C4r4+C4r0 - movq mm1,[coeffs+56] ; C7 C5 C7 C5 - pmaddwd mm1,mm3 ; C7R7+C5R5 C7r7+C5r5 - pmaddwd mm2,[coeffs+64] ; -C7R3+C3R1 -C7r3+C3r1 - paddd mm7,mm1 ; B0 b0 - movq mm1,[coeffs+72] ; -C5 -C1 -C5 -C1 - pmaddwd mm1,mm3 ; -C5R7-C1R5 -C5r7-C1r5 - paddd mm7,mm4 ; A0+B0 a0+b0 - paddd mm4,mm4 ; 2A0 2a0 - psubd mm4,mm7 ; A0-B0 a0-b0 - paddd mm1,mm2 ; B1 b1 - psrad mm7,shift - psrad mm4,shift - movq mm2,mm0 ; A1 a1 - paddd mm0,mm1 ; A1+B1 a1+b1 - psubd mm2,mm1 ; A1-B1 a1-b1 - psrad mm0,shift - psrad mm2,shift - packssdw mm7,mm7 ; A0+B0 a0+b0 - movd [dst],mm7 - packssdw mm0,mm0 ; A1+B1 a1+b1 - movd [dst + 16],mm0 - packssdw mm2,mm2 ; A1-B1 a1-b1 - movd [dst + 96],mm2 - packssdw mm4,mm4 ; A0-B0 a0-b0 - movd [dst + 112],mm4 - movq mm0,[src1] ; R3 R1 r3 r1 - movq mm4,[coeffs+80] ; -C1 C5 -C1 C5 - pmaddwd mm4,mm0 ; -C1R3+C5R1 -C1r3+C5r1 - movq mm7,[coeffs+88] ; C3 C7 C3 C7 - pmaddwd mm0,[coeffs+96] ; -C5R3+C7R1 -C5r3+C7r1 - pmaddwd mm7,mm3 ; C3R7+C7R5 C3r7+C7r5 - movq mm2,mm5 ; A2 a2 - pmaddwd mm3,[coeffs+104] ; -C1R7+C3R5 -C1r7+C3r5 - paddd mm4,mm7 ; B2 b2 - paddd mm2,mm4 ; A2+B2 a2+b2 - psubd mm5,mm4 ; a2-B2 a2-b2 - psrad mm2,shift - psrad mm5,shift - movq mm4,mm6 ; A3 a3 - paddd mm3,mm0 ; B3 b3 - paddd mm6,mm3 ; A3+B3 a3+b3 - psubd mm4,mm3 ; a3-B3 a3-b3 - psrad mm6,shift - psrad mm4,shift - packssdw mm2,mm2 ; A2+B2 a2+b2 - packssdw mm6,mm6 ; A3+B3 a3+b3 - movd [dst + 32],mm2 - packssdw mm4,mm4 ; A3-B3 a3-b3 - packssdw mm5,mm5 ; A2-B2 a2-b2 - movd [dst + 48],mm6 - movd [dst + 64],mm4 - movd [dst + 80],mm5 -%undef src0 -%undef src4 -%undef src1 -%undef src5 -%undef dst -%undef rounder_op -%undef rounder_arg -%undef shift -%endmacro - - - -%macro IDCT3 8 -%define src0 %1 -%define src4 %2 -%define src1 %3 -%define src5 %4 -%define dst %5 -%define rounder_op %6 -%define rounder_arg %7 -%define shift %8 - movq mm0,[src0] ; R4 R0 r4 r0 - movq mm2,[src1] ; R3 R1 r3 r1 - movq mm4,[coeffs+16] ; C4 C4 C4 C4 - pmaddwd mm4,mm0 ; C4R4+C4R0 C4r4+C4r0 - movq mm5,[coeffs+24] ; -C4 C4 -C4 C4 - pmaddwd mm0,mm5 ; -C4R4+C4R0 -C4r4+C4r0 - ; rounder_op mm4, rounder_arg - movq mm6,mm4 ; C4R4+C4R0 C4r4+C4r0 - movq mm7,[coeffs+48] ; C3 C1 C3 C1 - ; rounder_op mm0, rounder_arg - pmaddwd mm7,mm2 ; C3R3+C1R1 C3r3+C1r1 - movq mm5,mm0 ; -C4R4+C4R0 -C4r4+C4r0 - movq mm3,[coeffs+64] - pmaddwd mm3,mm2 ; -C7R3+C3R1 -C7r3+C3r1 - paddd mm7,mm4 ; A0+B0 a0+b0 - paddd mm4,mm4 ; 2A0 2a0 - psubd mm4,mm7 ; A0-B0 a0-b0 - psrad mm7,shift - psrad mm4,shift - movq mm1,mm0 ; A1 a1 - paddd mm0,mm3 ; A1+B1 a1+b1 - psubd mm1,mm3 ; A1-B1 a1-b1 - psrad mm0,shift - psrad mm1,shift - packssdw mm7,mm7 ; A0+B0 a0+b0 - movd [dst],mm7 - packssdw mm0,mm0 ; A1+B1 a1+b1 - movd [dst + 16],mm0 - packssdw mm1,mm1 ; A1-B1 a1-b1 - movd [dst + 96],mm1 - packssdw mm4,mm4 ; A0-B0 a0-b0 - movd [dst + 112],mm4 - movq mm4,[coeffs+80] ; -C1 C5 -C1 C5 - pmaddwd mm4,mm2 ; -C1R3+C5R1 -C1r3+C5r1 - pmaddwd mm2,[coeffs+96] ; -C5R3+C7R1 -C5r3+C7r1 - movq mm1,mm5 ; A2 a2 - paddd mm1,mm4 ; A2+B2 a2+b2 - psubd mm5,mm4 ; a2-B2 a2-b2 - psrad mm1,shift - psrad mm5,shift - movq mm4,mm6 ; A3 a3 - paddd mm6,mm2 ; A3+B3 a3+b3 - psubd mm4,mm2 ; a3-B3 a3-b3 - psrad mm6,shift - psrad mm4,shift - packssdw mm1,mm1 ; A2+B2 a2+b2 - packssdw mm6,mm6 ; A3+B3 a3+b3 - movd [dst + 32],mm1 - packssdw mm4,mm4 ; A3-B3 a3-b3 - packssdw mm5,mm5 ; A2-B2 a2-b2 - movd [dst + 48],mm6 - movd [dst + 64],mm4 - movd [dst + 80],mm5 -%undef src0 -%undef src4 -%undef src1 -%undef src5 -%undef dst -%undef rounder_op -%undef rounder_arg -%undef shift -%endmacro - - - -%macro IDCT5 8 -%define src0 %1 -%define src4 %2 -%define src1 %3 -%define src5 %4 -%define dst %5 -%define rounder_op %6 -%define rounder_arg %7 -%define shift %8 - movq mm0,[src0] ; R4 R0 r4 r0 - movq mm1,[src4] ; R6 R2 r6 r2 - movq mm4,[coeffs+16] ; C4 C4 C4 C4 - pmaddwd mm4,mm0 ; C4R4+C4R0 C4r4+C4r0 - movq mm5,[coeffs+24] ; -C4 C4 -C4 C4 - pmaddwd mm0,mm5 ; -C4R4+C4R0 -C4r4+C4r0 - movq mm5,[coeffs+32] ; C6 C2 C6 C2 - pmaddwd mm5,mm1 ; C6R6+C2R2 C6r6+C2r2 - movq mm6,[coeffs+40] ; -C2 C6 -C2 C6 - pmaddwd mm1,mm6 ; -C2R6+C6R2 -C2r6+C6r2 - ; rounder_op mm4, rounder_arg - movq mm6,mm4 ; C4R4+C4R0 C4r4+C4r0 - paddd mm4,mm5 ; A0 a0 - ; rounder_op mm0, rounder_arg - psubd mm6,mm5 ; A3 a3 - movq mm5,mm0 ; -C4R4+C4R0 -C4r4+C4r0 - paddd mm0,mm1 ; A1 a1 - psubd mm5,mm1 ; A2 a2 - movq mm2,[src0 + 8] ; R4 R0 r4 r0 - movq mm3,[src4 + 8] ; R6 R2 r6 r2 - movq mm1,[coeffs+16] ; C4 C4 C4 C4 - pmaddwd mm1,mm2 ; C4R4+C4R0 C4r4+C4r0 - movq mm7,[coeffs+24] ; -C4 C4 -C4 C4 - pmaddwd mm2,mm7 ; -C4R4+C4R0 -C4r4+C4r0 - movq mm7,[coeffs+32] ; C6 C2 C6 C2 - pmaddwd mm7,mm3 ; C6R6+C2R2 C6r6+C2r2 - pmaddwd mm3,[coeffs+40] ; -C2R6+C6R2 -C2r6+C6r2 - ; rounder_op mm1, rounder_arg - paddd mm7,mm1 ; A0 a0 - paddd mm1,mm1 ; 2C0 2c0 - ; rounder_op mm2, rounder_arg - psubd mm1,mm7 ; A3 a3 - paddd mm3,mm2 ; A1 a1 - paddd mm2,mm2 ; 2C1 2c1 - psubd mm2,mm3 ; A2 a2 - psrad mm4,shift - psrad mm7,shift - psrad mm3,shift - packssdw mm4,mm7 ; A0 a0 - movq [dst],mm4 - psrad mm0,shift - packssdw mm0,mm3 ; A1 a1 - movq [dst + 16],mm0 - movq [dst + 96],mm0 - movq [dst + 112],mm4 - psrad mm5,shift - psrad mm6,shift - psrad mm2,shift - packssdw mm5,mm2 ; A2-B2 a2-b2 - movq [dst + 32],mm5 - psrad mm1,shift - packssdw mm6,mm1 ; A3+B3 a3+b3 - movq [dst + 48],mm6 - movq [dst + 64],mm6 - movq [dst + 80],mm5 -%undef src0 -%undef src4 -%undef src1 -%undef src5 -%undef dst -%undef rounder_op -%undef rounder_arg -%undef shift -%endmacro - - -%macro IDCT1 8 -%define src0 %1 -%define src4 %2 -%define src1 %3 -%define src5 %4 -%define dst %5 -%define rounder_op %6 -%define rounder_arg %7 -%define shift %8 - movq mm0,[src0] ; R4 R0 r4 r0 - movq mm1,[src4] ; R6 R2 r6 r2 - movq mm2,[src1] ; R3 R1 r3 r1 - movq mm4,[coeffs+16] ; C4 C4 C4 C4 - pmaddwd mm4,mm0 ; C4R4+C4R0 C4r4+C4r0 - movq mm5,[coeffs+24] ; -C4 C4 -C4 C4 - pmaddwd mm0,mm5 ; -C4R4+C4R0 -C4r4+C4r0 - movq mm5,[coeffs+32] ; C6 C2 C6 C2 - pmaddwd mm5,mm1 ; C6R6+C2R2 C6r6+C2r2 - movq mm6,[coeffs+40] ; -C2 C6 -C2 C6 - pmaddwd mm1,mm6 ; -C2R6+C6R2 -C2r6+C6r2 - ; rounder_op mm4, rounder_arg - movq mm6,mm4 ; C4R4+C4R0 C4r4+C4r0 - movq mm7,[coeffs+48] ; C3 C1 C3 C1 - ; rounder_op mm0, rounder_arg - pmaddwd mm7,mm2 ; C3R3+C1R1 C3r3+C1r1 - paddd mm4,mm5 ; A0 a0 - psubd mm6,mm5 ; A3 a3 - movq mm5,mm0 ; -C4R4+C4R0 -C4r4+C4r0 - paddd mm0,mm1 ; A1 a1 - psubd mm5,mm1 ; A2 a2 - movq mm1,[coeffs+64] - pmaddwd mm1,mm2 ; -C7R3+C3R1 -C7r3+C3r1 - paddd mm7,mm4 ; A0+B0 a0+b0 - paddd mm4,mm4 ; 2A0 2a0 - psubd mm4,mm7 ; A0-B0 a0-b0 - psrad mm7,shift - psrad mm4,shift - movq mm3,mm0 ; A1 a1 - paddd mm0,mm1 ; A1+B1 a1+b1 - psubd mm3,mm1 ; A1-B1 a1-b1 - psrad mm0,shift - psrad mm3,shift - packssdw mm7,mm7 ; A0+B0 a0+b0 - movd [dst],mm7 - packssdw mm0,mm0 ; A1+B1 a1+b1 - movd [dst + 16],mm0 - packssdw mm3,mm3 ; A1-B1 a1-b1 - movd [dst + 96],mm3 - packssdw mm4,mm4 ; A0-B0 a0-b0 - movd [dst + 112],mm4 - movq mm4,[coeffs+80] ; -C1 C5 -C1 C5 - pmaddwd mm4,mm2 ; -C1R3+C5R1 -C1r3+C5r1 - pmaddwd mm2,[coeffs+96] ; -C5R3+C7R1 -C5r3+C7r1 - movq mm3,mm5 ; A2 a2 - paddd mm3,mm4 ; A2+B2 a2+b2 - psubd mm5,mm4 ; a2-B2 a2-b2 - psrad mm3,shift - psrad mm5,shift - movq mm4,mm6 ; A3 a3 - paddd mm6,mm2 ; A3+B3 a3+b3 - psubd mm4,mm2 ; a3-B3 a3-b3 - psrad mm6,shift - packssdw mm3,mm3 ; A2+B2 a2+b2 - movd [dst + 32],mm3 - psrad mm4,shift - packssdw mm6,mm6 ; A3+B3 a3+b3 - movd [dst + 48],mm6 - packssdw mm4,mm4 ; A3-B3 a3-b3 - packssdw mm5,mm5 ; A2-B2 a2-b2 - movd [dst + 64],mm4 - movd [dst + 80],mm5 -%undef src0 -%undef src4 -%undef src1 -%undef src5 -%undef dst -%undef rounder_op -%undef rounder_arg -%undef shift -%endmacro - - - - -%macro IDCT7 8 -%define src0 %1 -%define src4 %2 -%define src1 %3 -%define src5 %4 -%define dst %5 -%define rounder_op %6 -%define rounder_arg %7 -%define shift %8 - movq mm0,[src0] ; R4 R0 r4 r0 - movq mm4,[coeffs+16] ; C4 C4 C4 C4 - pmaddwd mm4,mm0 ; C4R4+C4R0 C4r4+C4r0 - movq mm5,[coeffs+24] ; -C4 C4 -C4 C4 - pmaddwd mm0,mm5 ; -C4R4+C4R0 -C4r4+C4r0 - ; rounder_op mm4, rounder_arg - ; rounder_op mm0, rounder_arg - psrad mm4,shift - psrad mm0,shift - movq mm2,[src0 + 8] ; R4 R0 r4 r0 - movq mm1,[coeffs+16] ; C4 C4 C4 C4 - pmaddwd mm1,mm2 ; C4R4+C4R0 C4r4+C4r0 - movq mm7,[coeffs+24] ; -C4 C4 -C4 C4 - pmaddwd mm2,mm7 ; -C4R4+C4R0 -C4r4+C4r0 - movq mm7,[coeffs+32] ; C6 C2 C6 C2 - ; rounder_op mm1, rounder_arg - ; rounder_op mm2, rounder_arg - psrad mm1,shift - packssdw mm4,mm1 ; A0 a0 - movq [dst],mm4 - psrad mm2,shift - packssdw mm0,mm2 ; A1 a1 - movq [dst + 16],mm0 - movq [dst + 96],mm0 - movq [dst + 112],mm4 - movq [dst + 32],mm0 - movq [dst + 48],mm4 - movq [dst + 64],mm4 - movq [dst + 80],mm0 -%undef src0 -%undef src4 -%undef src1 -%undef src5 -%undef dst -%undef rounder_op -%undef rounder_arg -%undef shift -%endmacro - - -%macro cfastcall 1 - global @%1@4 - %define %1 @%1@4 -%endmacro - -%macro cglobal 1 - %ifdef PREFIX - global _%1 - %define %1 _%1 - %else - global %1 - %endif -%endmacro - -;------------------ again with permuted parms -------- -; -; simple_idct_mmx_P is the same function as simple_idct_mmx above except that on entry it will -; do a fast in-line and in-place permutation on the iDCT parm list. This means that same parm list -; will also not have to be copied on the way out. - trbarry 6/2003 - -%macro XLODA 2 - mov bx, [srcP+2*%2] ; get src contents - mov ax, [srcP+2*%1] ; get dest contents - mov [srcP+2*%1], bx ; store new dest val -%endmacro - -%macro XCHGA 2 - mov ax, [srcP+2*%1] ; get dest contents - mov [srcP+2*%1], bx ; store new dest val -%endmacro - -%macro XCHGB 2 - mov bx, [srcP+2*%1] ; get dest contents - mov [srcP+2*%1], ax ; store new dest val -%endmacro - -%macro XSTRA 2 - mov [srcP+2*%1], bx ; store dest val -%endmacro - -%macro XSTRB 2 - mov [srcP+2*%1], ax ; store dest val -%endmacro - -%macro PERMUTEP 1 -%define srcP %1 - push ebx - -; XCHGA 0x00, 0x00 ; nothing to do - - XLODA 0x08, 0x01 - XCHGB 0x10, 0x08 - XCHGA 0x20, 0x10 - XCHGB 0x02, 0x20 - XCHGA 0x04, 0x02 - XSTRB 0x01, 0x04 - - XLODA 0x09, 0x03 - XCHGB 0x18, 0x09 - XCHGA 0x12, 0x18 - XCHGB 0x24, 0x12 - XSTRA 0x03, 0x24 - - XLODA 0x0C, 0x05 - XCHGB 0x11, 0x0C - XCHGA 0x28, 0x11 - XCHGB 0x30, 0x28 - XCHGA 0x22, 0x30 - XCHGB 0x06, 0x22 - XSTRA 0x05, 0x06 - - XLODA 0x0D, 0x07 - XCHGB 0x1C, 0x0D - XCHGA 0x13, 0x1C - XCHGB 0x29, 0x13 - XCHGA 0x38, 0x29 - XCHGB 0x32, 0x38 - XCHGA 0x26, 0x32 - XSTRB 0x07, 0x26 - - XLODA 0x14, 0x0A - XCHGB 0x21, 0x14 - XSTRA 0x0A, 0x21 - - XLODA 0x19, 0x0B - XCHGB 0x1A, 0x19 - XCHGA 0x16, 0x1A - XCHGB 0x25, 0x16 - XCHGA 0x0E, 0x25 - XCHGB 0x15, 0x0E - XCHGA 0x2C, 0x15 - XCHGB 0x31, 0x2C - XCHGA 0x2A, 0x31 - XCHGB 0x34, 0x2A - XCHGA 0x23, 0x34 - XSTRB 0x0B, 0x23 - - XLODA 0x1D, 0x0F - XCHGB 0x1E, 0x1D - XCHGA 0x17, 0x1E - XCHGB 0x2D, 0x17 - XCHGA 0x3C, 0x2D - XCHGB 0x33, 0x3C - XCHGA 0x2B, 0x33 - XCHGB 0x39, 0x2B - XCHGA 0x3A, 0x39 - XCHGB 0x36, 0x3A - XCHGA 0x27, 0x36 - XSTRB 0x0F, 0x27 - -; XCHGA 0x1B, 0x1B - -; XCHGA 0x1F, 0x1F - - XLODA 0x35, 0x2E - XSTRB 0x2E, 0x35 - - XLODA 0x3D, 0x2F - XCHGB 0x3E, 0x3D - XCHGA 0x37, 0x3E - XSTRB 0x2F, 0x37 - -; XCHGA 0x3B, 0x3B - -; XCHGA 0x3F, 0x3F - pop ebx -%undef srcP -%endmacro - -; void simple_idct_mmx(int16_t * const block); -align 16 -cfastcall simple_idct_mmx - -simple_idct_mmx: - sub esp, 128 - - PERMUTEP ecx ; permute parm list in place - -; src0, src4, src1, src5, dst, rndop, rndarg, shift, bt - - DC_COND_IDCT ecx+0, ecx+8, ecx+16, ecx+24, esp, paddd, [coeffs+8], 11 - Z_COND_IDCT ecx+32, ecx+40, ecx+48, ecx+56, esp+32, paddd, [coeffs], 11, .fourP - Z_COND_IDCT ecx+64, ecx+72, ecx+80, ecx+88, esp+64, paddd, [coeffs], 11, .twoP - Z_COND_IDCT ecx+96, ecx+104,ecx+112,ecx+120,esp+96, paddd, [coeffs], 11, .oneP - IDCT0 esp, esp+64, esp+32, esp+96, ecx, nop, 0, 20 - IDCT0 esp+8, esp+72, esp+40, esp+104,ecx+4, nop, 0, 20 - IDCT0 esp+16, esp+80, esp+48, esp+112,ecx+8, nop, 0, 20 - IDCT0 esp+24, esp+88, esp+56, esp+120,ecx+12, nop, 0, 20 - jmp .retP - -align 16 -.fourP: - Z_COND_IDCT ecx+64, ecx+72, ecx+80, ecx+88, esp+64, paddd, [coeffs], 11, .sixP - Z_COND_IDCT ecx+96, ecx+104,ecx+112,ecx+120,esp+96, paddd, [coeffs], 11, .fiveP - IDCT4 esp, esp+64, esp+32, esp+96, ecx, nop, 0, 20 - IDCT4 esp+8, esp+72, esp+40, esp+104,ecx+4, nop, 0, 20 - IDCT4 esp+16, esp+80, esp+48, esp+112,ecx+8, nop, 0, 20 - IDCT4 esp+24, esp+88, esp+56, esp+120,ecx+12, nop, 0, 20 - jmp .retP - -align 16 -.sixP: - Z_COND_IDCT ecx+96, ecx+104,ecx+112,ecx+120,esp+96, paddd, [coeffs], 11, .sevenP - IDCT6 esp, esp+64, esp+32, esp+96, ecx, nop, 0, 20 - IDCT6 esp+8, esp+72, esp+40, esp+104,ecx+4, nop, 0, 20 - IDCT6 esp+16, esp+80, esp+48, esp+112,ecx+8, nop, 0, 20 - IDCT6 esp+24, esp+88, esp+56, esp+120,ecx+12, nop, 0, 20 - jmp .retP - -align 16 -.twoP: - Z_COND_IDCT ecx+96, ecx+104,ecx+112,ecx+120,esp+96, paddd, [coeffs], 11, .threeP - IDCT2 esp, esp+64, esp+32, esp+96, ecx, nop, 0, 20 - IDCT2 esp+8, esp+72, esp+40, esp+104,ecx+4, nop, 0, 20 - IDCT2 esp+16, esp+80, esp+48, esp+112,ecx+8, nop, 0, 20 - IDCT2 esp+24, esp+88, esp+56, esp+120,ecx+12, nop, 0, 20 - jmp .retP - -align 16 -.threeP: - IDCT3 esp, esp+64, esp+32, esp+96, ecx, nop, 0, 20 - IDCT3 esp+8, esp+72, esp+40, esp+104,ecx+4, nop, 0, 20 - IDCT3 esp+16, esp+80, esp+48, esp+112,ecx+8, nop, 0, 20 - IDCT3 esp+24, esp+88, esp+56, esp+120,ecx+12, nop, 0, 20 - jmp .retP - -align 16 -.fiveP: - IDCT5 esp, esp+64, esp+32, esp+96, ecx, nop, 0, 20 - ; IDCT5 esp+8, esp+72, esp+40, esp+104,ecx+4, nop, 0, 20 - IDCT5 esp+16, esp+80, esp+48, esp+112,ecx+8, nop, 0, 20 - ; IDCT5 esp+24, esp+88, esp+56, esp+120,ecx+12, nop, 0, 20 - jmp .retP - -align 16 -.oneP: - IDCT1 esp, esp+64, esp+32, esp+96, ecx, nop, 0, 20 - IDCT1 esp+8, esp+72, esp+40, esp+104,ecx+4, nop, 0, 20 - IDCT1 esp+16, esp+80, esp+48, esp+112,ecx+8, nop, 0, 20 - IDCT1 esp+24, esp+88, esp+56, esp+120,ecx+12, nop, 0, 20 - jmp .retP - -align 16 -.sevenP: - IDCT7 esp, esp+64, esp+32, esp+96, ecx, nop, 0, 20 - ; IDCT7 esp+8, esp+72, esp+40, esp+104,ecx+4, nop, 0, 20 - IDCT7 esp+16, esp+80, esp+48, esp+112,ecx+8, nop, 0, 20 - ; IDCT7 esp+24, esp+88, esp+56, esp+120,ecx+12, nop, 0, 20 - -.retP: - add esp, 128 - ret diff --git a/src/dgindex/skl_dct_sse.asm b/src/dgindex/skl_dct_sse.asm deleted file mode 100644 index 378f136..0000000 --- a/src/dgindex/skl_dct_sse.asm +++ /dev/null @@ -1,1171 +0,0 @@ -;/******************************************************** -; * Some code. Copyright (C) 2003 by Pascal Massimino. * -; * All Rights Reserved. (http://skal.planet-d.net) * -; * For Educational/Academic use ONLY. See 'LICENSE.TXT'.* -; ********************************************************/ -; [BITS 32] - -%include "skl_nasm.h" - -;////////////////////////////////////////////////////////////////////// - -%macro cfastcall 1 - global @%1@4 - %define %1 @%1@4 -%endmacro - -cfastcall Skl_IDct16_SSE -cfastcall Skl_IDct16_Sparse_SSE -;globl Skl_IDct16_SSE -;globl Skl_IDct16_Sparse_SSE - -globl Skl_IDct16_MMX -globl Skl_IDct16_Sparse_MMX -globl Skl_IDct16_Put_SSE -globl Skl_IDct16_Put_MMX -globl Skl_IDct16_Add_SSE -globl Skl_IDct16_Add_MMX -globl Skl_IDct16_Sparse_8x4_SSE -globl Skl_IDct16_Sparse_8x4_MMX -globl Skl_IDct16_Put_8x4_SSE -globl Skl_IDct16_Put_8x4_MMX -globl Skl_IDct16_Add_8x4_SSE -globl Skl_IDct16_Add_8x4_MMX - -globl Skl_Dct16_SSE -globl Skl_Dct16_MMX - -;////////////////////////////////////////////////////////////////////// -; -; -=FDCT=- -; -; Vertical pass is an implementation of the scheme: -; Loeffler C., Ligtenberg A., and Moschytz C.S.: -; Practical Fast 1D DCT Algorithm with Eleven Multiplications, -; Proc. ICASSP 1989, 988-991. -; -; Horizontal pass is a double 4x4 vector/matrix multiplication, -; (see also Intel's Application Note 922: -; http://developer.intel.com/vtune/cbts/strmsimd/922down.htm -; Copyright (C) 1999 Intel Corporation) -; -; Notes: -; * tan(3pi/16) is greater than 0.5, and would use the -; sign bit when turned into 16b fixed-point precision. So, -; we use the trick: x*tan3 = x*(tan3-1)+x -; -; * There's only one SSE-specific instruction (pshufw). -; -; * There's still 1 or 2 ticks to save in fLLM_PASS, but -; I prefer having a readable code, instead of a tightly -; scheduled one... -; -; * Quantization stage (as well as pre-transposition for the -; idct way back) can be included in the fTab* constants -; (with induced loss of precision, somehow) -; -; * Some more details at: http://skal.planet-d.net/coding/dct.html -; -; -;////////////////////////////////////////////////////////////////////// -; -; == Mean square errors == -; 0.000 0.001 0.001 0.002 0.000 0.002 0.001 0.000 [0.001] -; 0.035 0.029 0.032 0.032 0.031 0.032 0.034 0.035 [0.032] -; 0.026 0.028 0.027 0.027 0.025 0.028 0.028 0.025 [0.027] -; 0.037 0.032 0.031 0.030 0.028 0.029 0.026 0.031 [0.030] -; 0.000 0.001 0.001 0.002 0.000 0.002 0.001 0.001 [0.001] -; 0.025 0.024 0.022 0.022 0.022 0.022 0.023 0.023 [0.023] -; 0.026 0.028 0.025 0.028 0.030 0.025 0.026 0.027 [0.027] -; 0.021 0.020 0.020 0.022 0.020 0.022 0.017 0.019 [0.020] -; -; == Abs Mean errors == -; 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 [0.000] -; 0.020 0.001 0.003 0.003 0.000 0.004 0.002 0.003 [0.002] -; 0.000 0.001 0.001 0.001 0.001 0.004 0.000 0.000 [0.000] -; 0.027 0.001 0.000 0.002 0.002 0.002 0.001 0.000 [0.003] -; 0.000 0.000 0.000 0.000 0.000 0.001 0.000 0.001 [-0.000] -; 0.001 0.003 0.001 0.001 0.002 0.001 0.000 0.000 [-0.000] -; 0.000 0.002 0.002 0.001 0.001 0.002 0.001 0.000 [-0.000] -; 0.000 0.002 0.001 0.002 0.001 0.002 0.001 0.001 [-0.000] -; -; ========================= -; Peak error: 1.0000 -; Peak MSE: 0.0365 -; Overall MSE: 0.0201 -; Peak ME: 0.0265 -; Overall ME: 0.0006 -; -;////////////////////////////////////////////////////////////////////// -; -; -=IDCT=- -; -; A little slower than fdct, because the final stages (butterflies and -; descaling) require some unpairable shifting and packing, all on -; the same CPU unit. -; -; THIS IDCT IS NOT IEEE-COMPLIANT: IT WILL FAIL THE [-300,300] -; INPUT RANGE TEST (because of overflow). But the [-256,255] one -; is OK, and I'm fine with it (for now;) -; -; == Mean square errors == -; 0.007 0.006 0.005 0.007 0.006 0.007 0.005 0.007 [0.006] -; 0.006 0.008 0.007 0.007 0.007 0.008 0.008 0.008 [0.007] -; 0.008 0.008 0.008 0.008 0.007 0.009 0.010 0.007 [0.008] -; 0.007 0.007 0.006 0.007 0.008 0.007 0.006 0.008 [0.007] -; 0.007 0.006 0.006 0.006 0.006 0.005 0.006 0.006 [0.006] -; 0.008 0.007 0.006 0.008 0.007 0.008 0.009 0.009 [0.008] -; 0.008 0.006 0.010 0.008 0.008 0.008 0.007 0.007 [0.008] -; 0.007 0.006 0.006 0.007 0.007 0.006 0.006 0.007 [0.006] -; -; == Abs Mean errors == -; 0.001 0.000 0.000 0.001 0.001 0.000 0.000 0.000 [0.000] -; 0.000 0.002 0.002 0.000 0.001 0.001 0.000 0.002 [0.000] -; 0.001 0.002 0.001 0.001 0.001 0.001 0.000 0.001 [-0.001] -; 0.000 0.002 0.000 0.000 0.001 0.000 0.000 0.001 [-0.000] -; 0.000 0.001 0.001 0.001 0.000 0.001 0.000 0.001 [0.000] -; 0.000 0.001 0.001 0.001 0.001 0.000 0.001 0.000 [0.000] -; 0.001 0.001 0.002 0.001 0.001 0.002 0.001 0.001 [0.001] -; 0.000 0.000 0.001 0.000 0.000 0.000 0.000 0.000 [0.000] -; -; ========================= -; -; Peak error: 1.0000 -; Peak MSE: 0.0092 -; Overall MSE: 0.0071 -; Peak ME: 0.0022 -; Overall ME: -0.0002 -; -;////////////////////////////////////////////////////////////////////// - -DATA - -align 16 -tan1: dw 0x32ec,0x32ec,0x32ec,0x32ec ; tan( pi/16) -tan2: dw 0x6a0a,0x6a0a,0x6a0a,0x6a0a ; tan(2pi/16) (=sqrt(2)-1) -tan3: dw 0xab0e,0xab0e,0xab0e,0xab0e ; tan(3pi/16)-1 -sqrt2: dw 0x5a82,0x5a82,0x5a82,0x5a82 ; 0.5/sqrt(2) - -;////////////////////////////////////////////////////////////////////// - -align 16 -iTab1: - dw 0x4000, 0x539f, 0x4000, 0x22a3, - dw 0x4000, 0x22a3, 0xc000, 0xac61, - dw 0x4000, 0xdd5d, 0x4000, 0xac61, - dw 0xc000, 0x539f, 0x4000, 0xdd5d, - dw 0x58c5, 0x4b42, 0x4b42, 0xee58, - dw 0x3249, 0x11a8, 0xa73b, 0xcdb7, - dw 0x3249, 0xa73b, 0x11a8, 0xcdb7, - dw 0x11a8, 0x4b42, 0x4b42, 0xa73b - -iTab2: - dw 0x58c5, 0x73fc, 0x58c5, 0x300b, - dw 0x58c5, 0x300b, 0xa73b, 0x8c04, - dw 0x58c5, 0xcff5, 0x58c5, 0x8c04, - dw 0xa73b, 0x73fc, 0x58c5, 0xcff5, - dw 0x7b21, 0x6862, 0x6862, 0xe782, - dw 0x45bf, 0x187e, 0x84df, 0xba41, - dw 0x45bf, 0x84df, 0x187e, 0xba41, - dw 0x187e, 0x6862, 0x6862, 0x84df - -iTab3: - dw 0x539f, 0x6d41, 0x539f, 0x2d41, - dw 0x539f, 0x2d41, 0xac61, 0x92bf, - dw 0x539f, 0xd2bf, 0x539f, 0x92bf, - dw 0xac61, 0x6d41, 0x539f, 0xd2bf, - dw 0x73fc, 0x6254, 0x6254, 0xe8ee, - dw 0x41b3, 0x1712, 0x8c04, 0xbe4d, - dw 0x41b3, 0x8c04, 0x1712, 0xbe4d, - dw 0x1712, 0x6254, 0x6254, 0x8c04 - -iTab4: - dw 0x4b42, 0x6254, 0x4b42, 0x28ba, - dw 0x4b42, 0x28ba, 0xb4be, 0x9dac, - dw 0x4b42, 0xd746, 0x4b42, 0x9dac, - dw 0xb4be, 0x6254, 0x4b42, 0xd746, - dw 0x6862, 0x587e, 0x587e, 0xeb3d, - dw 0x3b21, 0x14c3, 0x979e, 0xc4df, - dw 0x3b21, 0x979e, 0x14c3, 0xc4df, - dw 0x14c3, 0x587e, 0x587e, 0x979e - -align 16 -iTab1_MMX: - dw 0x4000, 0x4000, 0x4000, 0xc000 - dw 0x539f, 0x22a3, 0x22a3, 0xac61 - dw 0x4000, 0xc000, 0x4000, 0x4000 - dw 0xdd5d, 0x539f, 0xac61, 0xdd5d - dw 0x58c5, 0x3249, 0x4b42, 0xa73b - dw 0x4b42, 0x11a8, 0xee58, 0xcdb7 - dw 0x3249, 0x11a8, 0x11a8, 0x4b42 - dw 0xa73b, 0x4b42, 0xcdb7, 0xa73b - -iTab2_MMX: - dw 0x58c5, 0x58c5, 0x58c5, 0xa73b - dw 0x73fc, 0x300b, 0x300b, 0x8c04 - dw 0x58c5, 0xa73b, 0x58c5, 0x58c5 - dw 0xcff5, 0x73fc, 0x8c04, 0xcff5 - dw 0x7b21, 0x45bf, 0x6862, 0x84df - dw 0x6862, 0x187e, 0xe782, 0xba41 - dw 0x45bf, 0x187e, 0x187e, 0x6862 - dw 0x84df, 0x6862, 0xba41, 0x84df - -iTab3_MMX: - dw 0x539f, 0x539f, 0x539f, 0xac61 - dw 0x6d41, 0x2d41, 0x2d41, 0x92bf - dw 0x539f, 0xac61, 0x539f, 0x539f - dw 0xd2bf, 0x6d41, 0x92bf, 0xd2bf - dw 0x73fc, 0x41b3, 0x6254, 0x8c04 - dw 0x6254, 0x1712, 0xe8ee, 0xbe4d - dw 0x41b3, 0x1712, 0x1712, 0x6254 - dw 0x8c04, 0x6254, 0xbe4d, 0x8c04 - -iTab4_MMX: - dw 0x4b42, 0x4b42, 0x4b42, 0xb4be - dw 0x6254, 0x28ba, 0x28ba, 0x9dac - dw 0x4b42, 0xb4be, 0x4b42, 0x4b42 - dw 0xd746, 0x6254, 0x9dac, 0xd746 - dw 0x6862, 0x3b21, 0x587e, 0x979e - dw 0x587e, 0x14c3, 0xeb3d, 0xc4df - dw 0x3b21, 0x14c3, 0x14c3, 0x587e - dw 0x979e, 0x587e, 0xc4df, 0x979e - - ; the original rounding trick is by - ; Michel Lespinasse (hi Walken!) - -align 16 -Idct_Rnd0 dd 65535, 65535 -Idct_Rnd1 dd 3612, 3612 -Idct_Rnd2 dd 2271, 2271 -Idct_Rnd3 dd 1203, 1203 -Idct_Rnd4 dd 1023, 1023 -Idct_Rnd5 dd 102, 102 -Idct_Rnd6 dd 398, 398 -Idct_Rnd7 dd 469, 469 - -Idct_Sparse_Rnd0 times 4 dw (65535>>11) -Idct_Sparse_Rnd1 times 4 dw ( 3612>>11) -Idct_Sparse_Rnd2 times 4 dw ( 2271>>11) - ; other rounders are zero... - -;////////////////////////////////////////////////////////////////////// - -align 16 -fTab1: - dw 0x4000, 0x4000, 0x58c5, 0x4b42, - dw 0x4000, 0x4000, 0x3249, 0x11a8, - dw 0x539f, 0x22a3, 0x4b42, 0xee58, - dw 0xdd5d, 0xac61, 0xa73b, 0xcdb7, - dw 0x4000, 0xc000, 0x3249, 0xa73b, - dw 0xc000, 0x4000, 0x11a8, 0x4b42, - dw 0x22a3, 0xac61, 0x11a8, 0xcdb7, - dw 0x539f, 0xdd5d, 0x4b42, 0xa73b - -fTab2: - dw 0x58c5, 0x58c5, 0x7b21, 0x6862, - dw 0x58c5, 0x58c5, 0x45bf, 0x187e, - dw 0x73fc, 0x300b, 0x6862, 0xe782, - dw 0xcff5, 0x8c04, 0x84df, 0xba41, - dw 0x58c5, 0xa73b, 0x45bf, 0x84df, - dw 0xa73b, 0x58c5, 0x187e, 0x6862, - dw 0x300b, 0x8c04, 0x187e, 0xba41, - dw 0x73fc, 0xcff5, 0x6862, 0x84df - -fTab3: - dw 0x539f, 0x539f, 0x73fc, 0x6254, - dw 0x539f, 0x539f, 0x41b3, 0x1712, - dw 0x6d41, 0x2d41, 0x6254, 0xe8ee, - dw 0xd2bf, 0x92bf, 0x8c04, 0xbe4d, - dw 0x539f, 0xac61, 0x41b3, 0x8c04, - dw 0xac61, 0x539f, 0x1712, 0x6254, - dw 0x2d41, 0x92bf, 0x1712, 0xbe4d, - dw 0x6d41, 0xd2bf, 0x6254, 0x8c04 - -fTab4: - dw 0x4b42, 0x4b42, 0x6862, 0x587e, - dw 0x4b42, 0x4b42, 0x3b21, 0x14c3, - dw 0x6254, 0x28ba, 0x587e, 0xeb3d, - dw 0xd746, 0x9dac, 0x979e, 0xc4df, - dw 0x4b42, 0xb4be, 0x3b21, 0x979e, - dw 0xb4be, 0x4b42, 0x14c3, 0x587e, - dw 0x28ba, 0x9dac, 0x14c3, 0xc4df, - dw 0x6254, 0xd746, 0x587e, 0x979e - -align 16 -Fdct_Rnd0: dw 6,8,8,8 -Fdct_Rnd1: dw 8,8,8,8 -Fdct_Rnd2: dw 10,8,8,8 -MMX_One: dw 1,1,1,1 - -;////////////////////////////////////////////////////////////////////// - -TEXT - -;////////////////////////////////////////////////////////////////////// -; iMTX_MULT (~24c) -;////////////////////////////////////////////////////////////////////// - -%macro iMTX_MULT 4 ; %1=src, %2 = Table to use, %3=rounder, %4=Shift - movq mm0, [ecx+%1*16+0] ; mm0 = [0123] - movq mm1, [ecx+%1*16+8] ; mm1 = [4567] - - movq mm3, [%2+0] ; [ M00 M01 M04 M05] - pshufw mm2, mm0, 11011101b ; [1313] - movq mm4, [%2+8] ; [ M02 M03 M06 M07] - pshufw mm0, mm0, 10001000b ; [0202] - movq mm6, [%2+32] ; [ M16 M17 M20 M21] - pshufw mm5, mm1, 11011101b ; [5757] - movq mm7, [%2+40] ; [ M18 M19 M22 M23] - pshufw mm1, mm1, 10001000b ; [4646] - pmaddwd mm3, mm0 ; [i0.M00+i2.M01 | i0.M04+i2.M05] - pmaddwd mm6, mm2 ; [i1.M16+i3.M17 | i1.M20+i3.M21] - pmaddwd mm4, mm1 ; [i4.M02+i6.M03 | i4.M06+i6.M07] - pmaddwd mm7, mm5 ; [i5.M18+i7.M19 | i5.M22+i7.M23] - pmaddwd mm2, [%2+48] ; [i1.M24+i3.M25 | i1.M28+i3.M29] - pmaddwd mm5, [%2+56] ; [i5.M26+i7.M27 | i5.M30+i7.M31] - pmaddwd mm0, [%2+16] ; [i0.M08+i2.M09 | i0.M12+i2.M13] - pmaddwd mm1, [%2+24] ; [i4.M10+i6.M11 | i4.M14+i6.M15] - - paddd mm3, [%3] ; Round - paddd mm6, mm7 ; => b0 | b1 - paddd mm0, [%3] ; Round - paddd mm2, mm5 ; => b2 | b3 - paddd mm3, mm4 ; => a0 | a1 - paddd mm0, mm1 ; => a2 | a3 - - movq mm4, mm3 ; a0 | a1 - movq mm7, mm0 ; a2 | a3 - paddd mm3, mm6 ; a0+b0 | a1+b1 - psubd mm4, mm6 ; a0-b0 | a1-b1 - psubd mm7, mm2 ; a2-b2 | a3-b3 - paddd mm0, mm2 ; a2+b2 | a3+b3 - - psrad mm3, %4 ; => out0 | out1 - psrad mm4, %4 ; => out7 | out6 - psrad mm0, %4 ; => out2 | out3 - psrad mm7, %4 ; => out5 | out4 - - packssdw mm3, mm0 ; [0123] - packssdw mm7, mm4 ; [5476] - - movq [ecx+%1*16+0], mm3 - pshufw mm7, mm7, 10110001b ; [4567] - - movq [ecx+%1*16+8], mm7 -%endmacro - -%macro iMTX_MULT_03 4 ; %1=src, %2 = Table to use, %3=rounder, %4=Shift - ; this version assume [4567] coeffs are zero... - movq mm0, [ecx+%1*16+0] ; mm0 = [0123] - - movq mm3, [%2+0] ; [ M00 M01 M04 M05] - pshufw mm2, mm0, 11011101b ; [1313] - movq mm6, [%2+32] ; [ M16 M17 M20 M21] - pshufw mm0, mm0, 10001000b ; [0202] - - pmaddwd mm6, mm2 ; [i1.M16+i3.M17 | i1.M20+i3.M21] - pmaddwd mm3, mm0 ; [i0.M00+i2.M01 | i0.M04+i2.M05] - pmaddwd mm2, [%2+48] ; [i1.M24+i3.M25 | i1.M28+i3.M29] - pmaddwd mm0, [%2+16] ; [i0.M08+i2.M09 | i0.M12+i2.M13] - - ; mm2=b2|b3 mm6 = b0|b1 - paddd mm3, [%3] ; Round - paddd mm0, [%3] ; Round - - movq mm4, mm3 ; a0 | a1 - movq mm7, mm0 ; a2 | a3 - paddd mm3, mm6 ; a0+b0 | a1+b1 - psubd mm4, mm6 ; a0-b0 | a1-b1 - psubd mm7, mm2 ; a2-b2 | a3-b3 - paddd mm0, mm2 ; a2+b2 | a3+b3 - - psrad mm3, %4 ; => out0 | out1 - psrad mm4, %4 ; => out7 | out6 - psrad mm0, %4 ; => out2 | out3 - psrad mm7, %4 ; => out5 | out4 - - packssdw mm3, mm0 ; [0123] - packssdw mm7, mm4 ; [5476] - - movq [ecx+%1*16+0], mm3 - pshufw mm7, mm7, 10110001b ; [4567] - - movq [ecx+%1*16+8], mm7 -%endmacro - -;////////////////////////////////////////////////////////////////////// -; iMTX_MULT_MMX (~27c) -;////////////////////////////////////////////////////////////////////// - -%macro iMTX_MULT_MMX 4 ; %1=src, %2 = Table to use, %3=rounder, %4=Shift - movq mm0, [ecx+%1*16+0] ; [0123] - - movq mm1, [ecx+%1*16+8] ; [4567] - movq mm2, mm0 - - punpcklwd mm0, mm1 ; [0415] - punpckhwd mm2, mm1 ; [2637] - - movq mm1, mm0 - movq mm3, mm2 - - punpckldq mm0, mm0 ; [0404] - punpckldq mm2, mm2 ; [2626] - punpckhdq mm1, mm1 ; [1515] - punpckhdq mm3, mm3 ; [3737] - - movq mm4, [%2+ 0] ; [ M00 M02 M04 M06] - movq mm6, [%2+ 8] ; [ M01 M03 M05 M07] - pmaddwd mm4, mm0 ; [i0.M00+i4.M02 | i0.M04+i4.M06] - movq mm5, [%2+32] ; [ M16 M18 M20 M22] - movq mm7, [%2+40] ; [ M17 M19 M21 M23] - pmaddwd mm6, mm2 ; [i2.M01+i6.M03 | i2.M05+i6.M07] - pmaddwd mm5, mm1 ; [i1.M16+i5.M18 | i1.M20+i5.M22] - pmaddwd mm7, mm3 ; [i3.M17+i7.M19 | i3.M21+i7.M23] - pmaddwd mm0, [%2+16] ; [i0.M08+i4.M10 | i0.M12+i4.M14] - pmaddwd mm2, [%2+24] ; [i2.M09+i6.M11 | i2.M13+i6.M15] - pmaddwd mm1, [%2+48] ; [i1.M24+i5.M26 | i1.M28+i5.M30] - pmaddwd mm3, [%2+56] ; [i3.M25+i7.M27 | i3.M29+i7.M31] - - paddd mm0, [%3] ; Round - paddd mm1, mm3 ; => b2 | b3 - paddd mm4, [%3] ; Round - paddd mm5, mm7 ; => b0 | b1 - paddd mm4, mm6 ; => a0 | a1 - movq mm6, mm4 ; a0 | a1 - paddd mm0, mm2 ; => a2 | a3 - movq mm2, mm0 ; a2 | a3 - paddd mm4, mm5 ; a0+b0 | a1+b1 - psrad mm4, %4 ; => out0 | out1 - paddd mm0, mm1 ; a2+b2 | a3+b3 - psrad mm0, %4 ; => out2 | out3 - - psubd mm6, mm5 ; a0-b0 | a1-b1 - psubd mm2, mm1 ; a2-b2 | a3-b3 - psrad mm6, %4 ; => out7 | out6 - psrad mm2, %4 ; => out5 | out4 - - - packssdw mm2, mm6 ; [5476] - packssdw mm4, mm0 ; [0123] - - movq mm7, mm2 - psrld mm2, 16 ; [4-6-] - pslld mm7, 16 ; [-5-7] - - movq [ecx+%1*16+0], mm4 - por mm2, mm7 - movq [ecx+%1*16+8], mm2 -%endmacro - -;////////////////////////////////////////////////////////////////////// -;// iLLM_PASS (~42c) -;////////////////////////////////////////////////////////////////////// - -%macro ADD_TO_DST 4 ; %1:src1 %2:dst1 %3:src2 %4:dst2 - ; trashes mm0,mm4 - punpcklbw mm0, [%2] - punpcklbw mm4, [%4] - psrlw mm0, 8 ; will zero the high words - psrlw mm4, 8 - paddsw mm0, %1 - paddsw mm4, %3 - packuswb mm0, mm0 - packuswb mm4, mm4 - movd [%2], mm0 - movd [%4], mm4 -%endmacro - -%macro iLLM_PASS 3 ; %1: src/dst, %2: combine func (0:none, 1:Put, 2:Add) - ; %3: dst offset (only for Add) - - movq mm0, [tan3] ; t3-1 - movq mm3, [%1+16*3] ; x3 - movq mm1, mm0 ; t3-1 - movq mm5, [%1+16*5] ; x5 - - movq mm4, [tan1] ; t1 - movq mm6, [%1+16*1] ; x1 - movq mm7, [%1+16*7] ; x7 - movq mm2, mm4 ; t1 - - pmulhw mm0, mm3 ; x3*(t3-1) - pmulhw mm1, mm5 ; x5*(t3-1) - paddsw mm0, mm3 ; x3*t3 - paddsw mm1, mm5 ; x5*t3 - psubsw mm0, mm5 ; x3*t3-x5 = tm35 - paddsw mm1, mm3 ; x3+x5*t3 = tp35 - - pmulhw mm4, mm7 ; x7*t1 - pmulhw mm2, mm6 ; x1*t1 - paddsw mm4, mm6 ; x1+t1*x7 = tp17 - psubsw mm2, mm7 ; x1*t1-x7 = tm17 - - - movq mm3, [sqrt2] - movq mm7, mm4 - movq mm6, mm2 - psubsw mm4, mm1 ; tp17-tp35 = t1 - psubsw mm2, mm0 ; tm17-tm35 = b3 - paddsw mm1, mm7 ; tp17+tp35 = b0 - paddsw mm0, mm6 ; tm17+tm35 = t2 - - ; mm1 = b0, mm2 = b3. preserved - - movq mm6, mm4 - psubsw mm4, mm0 ; t1-t2 - paddsw mm0, mm6 ; t1+t2 - - pmulhw mm4, mm3 ; (t1-t2)/(2.sqrt2) - pmulhw mm0, mm3 ; (t1+t2)/(2.sqrt2) - - paddsw mm0, mm0 ; 2.(t1+t2) = b1 - paddsw mm4, mm4 ; 2.(t1-t2) = b2 - - movq mm7, [tan2] ; t2 - movq mm3, [%1+2*16] ; x2 - movq mm6, [%1+6*16] ; x6 - movq mm5, mm7 ; t2 - - pmulhw mm7, mm6 ; x6*t2 - pmulhw mm5, mm3 ; x2*t2 - - paddsw mm7, mm3 ; x2+x6*t2 = tp26 - psubsw mm5, mm6 ; x2*t2-x6 = tm26 - - ; use:mm3,mm5,mm6,mm7 frozen: mm0,mm4,mm1,mm2 - - movq mm3, [%1+0*16] ; x0 - movq mm6, [%1+4*16] ; x4 - - psubsw mm3, mm6 ; x0-x4 = tm04 - paddsw mm6, mm6 - paddsw mm6, mm3 ; x0+x4 = tp04 - - psubsw mm3, mm5 ; tm04-tm26 = a2 - psubsw mm6, mm7 ; tp04-tp26 = a3 - paddsw mm5, mm5 ; 2.tm26 - paddsw mm7, mm7 ; 2.tp26 - paddsw mm5, mm3 ; tm04+tm26 = a1 - paddsw mm7, mm6 ; tp04+tp26 = a0 - - psubsw mm5, mm0 ; a1-b1 - psubsw mm3, mm4 ; a2-b2 - paddsw mm0, mm0 ; 2.b1 - paddsw mm4, mm4 ; 2.b2 - paddsw mm0, mm5 ; a1+b1 - paddsw mm4, mm3 ; a2+b2 - - psraw mm5, 6 ; out6 - psraw mm3, 6 ; out5 - psraw mm0, 6 ; out1 - psraw mm4, 6 ; out2 - -%if (%2==0) - - movq [%1+5*16], mm3 - movq [%1+6*16], mm5 - movq [%1+1*16], mm0 - movq [%1+2*16], mm4 - -%elif (%2==2) - movq [%1 ], mm0 ; spill - movq [%1+16], mm4 ; spill - ADD_TO_DST [%1], eax+ edx+%3, [%1+16], eax+2*edx+%3 ; #1 - #2 -%else - packuswb mm0,[%1+1*16+8] - packuswb mm4,[%1+2*16+8] - movq [eax+ edx], mm0 ; #1 - movq [eax+2*edx], mm4 ; #2 -%endif - - ; reminder: mm1=b0, mm2=b3, mm7=a0, mm6=a3 - - movq mm0, mm7 - movq mm4, mm6 - psubsw mm7, mm1 ; a0-b0 - psubsw mm6, mm2 ; a3-b3 - paddsw mm1, mm0 ; a0+b0 - paddsw mm2, mm4 ; a3+b3 - - psraw mm1, 6 ; out0 - psraw mm7, 6 ; out7 - psraw mm2, 6 ; out3 - psraw mm6, 6 ; out4 - -%if (%2==0) - - movq [%1+0*16], mm1 - movq [%1+7*16], mm7 - movq [%1+3*16], mm2 - movq [%1+4*16], mm6 - -%elif (%2==2) - ADD_TO_DST mm1, eax +%3, mm6, eax+4*edx+%3 ; #0 - #4 - lea eax, [eax+2*edx] ; -> #2 - ADD_TO_DST mm2, eax+ edx+%3, mm5, eax+4*edx+%3 ; #3 - #6 - lea eax, [eax+ edx] ; -> #3 - ADD_TO_DST mm3, eax+2*edx+%3, mm7, eax+4*edx+%3 ; #5 - #7 -%else - packuswb mm1,[%1+0*16+8] - packuswb mm6,[%1+4*16+8] - packuswb mm2,[%1+3*16+8] - packuswb mm5,[%1+6*16+8] - packuswb mm3,[%1+5*16+8] - packuswb mm7,[%1+7*16+8] - movq [eax ], mm1 ; #0 - movq [eax+4*edx], mm6 ; #4 - lea eax, [eax+2*edx] ; -> #2 - movq [eax+ edx], mm2 ; #3 - movq [eax+4*edx], mm5 ; #6 - lea eax, [eax+ edx] ; -> #3 - movq [eax+2*edx], mm3 ; #5 - movq [eax+4*edx], mm7 ; #7 -%endif - -%endmacro - -%macro iLLM_PASS_03 3 ; %1: src/dst, %2: combine func (0:none, 1:Put, 2:Add) - ; %3: dst offset (only for Add) - - movq mm0, [tan3] ; t3-1 - movq mm1, [%1+16*3] ; x3 - movq mm2, [%1+16*1] ; x1 - - pmulhw mm0, mm1 ; x3*(t3-1) - movq mm4, mm2 - pmulhw mm2, [tan1] ; x1*t1 => mm2:tm17, mm4:tp17 - paddsw mm0, mm1 ; x3*t3 => mm0:tm35, mm1:tp35 - - movq mm3, [sqrt2] - movq mm7, mm4 - movq mm6, mm2 - psubsw mm4, mm1 ; tp17-tp35 = t1 - psubsw mm2, mm0 ; tm17-tm35 = b3 - paddsw mm1, mm7 ; tp17+tp35 = b0 - paddsw mm0, mm6 ; tm17+tm35 = t2 - - ; mm1 = b0, mm2 = b3. preserved - - movq mm6, mm4 - psubsw mm4, mm0 ; t1-t2 - paddsw mm0, mm6 ; t1+t2 - - pmulhw mm4, mm3 ; (t1-t2)/(2.sqrt2) - pmulhw mm0, mm3 ; (t1+t2)/(2.sqrt2) - - paddsw mm0, mm0 ; 2.(t1+t2) = b1 - paddsw mm4, mm4 ; 2.(t1-t2) = b2 - - movq mm5, [tan2] ; t2 - movq mm3, [%1+0*16] ; x0 => mm3:tm04 - movq mm7, [%1+2*16] ; x2 => mm7:tp26 - - pmulhw mm5, mm7 ; x2*t2 => mm5:tm26 - - movq mm6, mm3 ; mm6:tp04 - psubsw mm3, mm5 ; tm04-tm26 = a2 - psubsw mm6, mm7 ; tp04-tp26 = a3 - paddsw mm5, mm5 ; 2.tm26 - paddsw mm7, mm7 ; 2.tp26 - paddsw mm5, mm3 ; tm04+tm26 = a1 - paddsw mm7, mm6 ; tp04+tp26 = a0 - - psubsw mm5, mm0 ; a1-b1 - psubsw mm3, mm4 ; a2-b2 - paddsw mm0, mm0 ; 2.b1 - paddsw mm4, mm4 ; 2.b2 - paddsw mm0, mm5 ; a1+b1 - paddsw mm4, mm3 ; a2+b2 - - psraw mm5, 6 ; out6 - psraw mm3, 6 ; out5 - psraw mm0, 6 ; out1 - psraw mm4, 6 ; out2 - -%if (%2==0) - - movq [%1+5*16], mm3 - movq [%1+6*16], mm5 - movq [%1+1*16], mm0 - movq [%1+2*16], mm4 - -%elif (%2==2) - movq [%1 ], mm0 ; spill - movq [%1+16], mm4 ; spill - ADD_TO_DST [%1], eax+ edx+%3, [%1+16], eax+2*edx+%3 ; #1 - #2 -%else - packuswb mm0,[%1+1*16+8] - packuswb mm4,[%1+2*16+8] - movq [eax+ edx], mm0 ; #1 - movq [eax+2*edx], mm4 ; #2 -%endif - - ; reminder: mm1=b0, mm2=b3, mm7=a0, mm6=a3 - - movq mm0, mm7 - movq mm4, mm6 - psubsw mm7, mm1 ; a0-b0 - psubsw mm6, mm2 ; a3-b3 - paddsw mm1, mm0 ; a0+b0 - paddsw mm2, mm4 ; a3+b3 - - psraw mm1, 6 ; out0 - psraw mm7, 6 ; out7 - psraw mm2, 6 ; out3 - psraw mm6, 6 ; out4 - -%if (%2==0) - - movq [%1+0*16], mm1 - movq [%1+7*16], mm7 - movq [%1+3*16], mm2 - movq [%1+4*16], mm6 - -%elif (%2==2) - ADD_TO_DST mm1, eax +%3, mm6, eax+4*edx+%3 ; #0 - #4 - lea eax, [eax+2*edx] ; -> #2 - ADD_TO_DST mm2, eax+ edx+%3, mm5, eax+4*edx+%3 ; #3 - #6 - lea eax, [eax+ edx] ; -> #3 - ADD_TO_DST mm3, eax+2*edx+%3, mm7, eax+4*edx+%3 ; #5 - #7 -%else - packuswb mm1,[%1+0*16+8] - packuswb mm6,[%1+4*16+8] - packuswb mm2,[%1+3*16+8] - packuswb mm5,[%1+6*16+8] - packuswb mm3,[%1+5*16+8] - packuswb mm7,[%1+7*16+8] - movq [eax ], mm1 ; #0 - movq [eax+4*edx], mm6 ; #4 - lea eax, [eax+2*edx] ; -> #2 - movq [eax+ edx], mm2 ; #3 - movq [eax+4*edx], mm5 ; #6 - lea eax, [eax+ edx] ; -> #3 - movq [eax+2*edx], mm3 ; #5 - movq [eax+4*edx], mm7 ; #7 -%endif - -%endmacro - -;////////////////////////////////////////////////////////////////////// -;// basic IDCTs... -; Nic - Changed to fastcall convention -align 16 -Skl_IDct16_SSE: ; 249c - ; mov ecx, [esp+4] ; Old cdecl way, ecx is the pointer anyway with - iMTX_MULT 0, iTab1, Idct_Rnd0, 11 - iMTX_MULT 1, iTab2, Idct_Rnd1, 11 - iMTX_MULT 2, iTab3, Idct_Rnd2, 11 - iMTX_MULT 3, iTab4, Idct_Rnd3, 11 - iMTX_MULT 4, iTab1, Idct_Rnd4, 11 - iMTX_MULT 5, iTab4, Idct_Rnd5, 11 - iMTX_MULT 6, iTab3, Idct_Rnd6, 11 - iMTX_MULT 7, iTab2, Idct_Rnd7, 11 - iLLM_PASS ecx+0, 0,0 - iLLM_PASS ecx+8, 0,0 - ret - -align 16 -Skl_IDct16_MMX: ; 288c - mov ecx, [esp+4] - iMTX_MULT_MMX 0, iTab1_MMX, Idct_Rnd0, 11 - iMTX_MULT_MMX 1, iTab2_MMX, Idct_Rnd1, 11 - iMTX_MULT_MMX 2, iTab3_MMX, Idct_Rnd2, 11 - iMTX_MULT_MMX 3, iTab4_MMX, Idct_Rnd3, 11 - iMTX_MULT_MMX 4, iTab1_MMX, Idct_Rnd4, 11 - iMTX_MULT_MMX 5, iTab4_MMX, Idct_Rnd5, 11 - iMTX_MULT_MMX 6, iTab3_MMX, Idct_Rnd6, 11 - iMTX_MULT_MMX 7, iTab2_MMX, Idct_Rnd7, 11 - iLLM_PASS ecx+0, 0,0 - iLLM_PASS ecx+8, 0,0 - ret - -;////////////////////////////////////////////////////////////////////// -;// Optimized Sparse/Put/Add MMX/SSE IDCTs - -%macro TEST_ROW 3 ; %1:src, %2:label x8, %3: label x4 - mov eax, [%1 ] - mov edx, [%1+ 8] - or eax, [%1+ 4] - or edx, [%1+12] - or eax, edx - jz near %2 - test edx, 0xffffffff - jz near %3 -%endmacro - -%macro IDCT_IMPL 4 ; %1: combine func (0:none, 1:Put, 2:Add) - ; %2:HPASS macro, %3:HPASS-03 macro, %4:VPASS macro -; mov ecx, [esp+ 4] ; Src - Nic FastCall, ecx is pointer anyway - - TEST_ROW ecx, .Row0_Round, .Row0_4 - %2 0, ITAB1, Idct_Rnd0, 11 - jmp .Row1 -.Row0_4: - %3 0, ITAB1, Idct_Rnd0, 11 - jmp .Row1 -.Row0_Round: - movq mm0, [Idct_Sparse_Rnd0] - movq [ecx ], mm0 - movq [ecx+8], mm0 - -.Row1: - TEST_ROW ecx+16, .Row1_Round, .Row1_4 - %2 1, ITAB2, Idct_Rnd1, 11 - jmp .Row2 -.Row1_4: - %3 1, ITAB2, Idct_Rnd1, 11 - jmp .Row2 -.Row1_Round: - movq mm0, [Idct_Sparse_Rnd1] - movq [ecx+16 ], mm0 - movq [ecx+16+8], mm0 - -.Row2: - TEST_ROW ecx+32, .Row2_Round, .Row2_4 - %2 2, ITAB3, Idct_Rnd2, 11 - jmp .Row3 -.Row2_4: - %3 2, ITAB3, Idct_Rnd2, 11 - jmp .Row3 -.Row2_Round: - movq mm0, [Idct_Sparse_Rnd2] - movq [ecx+32 ], mm0 - movq [ecx+32+8], mm0 - -.Row3: - TEST_ROW ecx+48, .Row4, .Row3_4 - %2 3, ITAB4, Idct_Rnd3, 11 - jmp .Row4 -.Row3_4: - %3 3, ITAB4, Idct_Rnd3, 11 - -.Row4: - TEST_ROW ecx+64, .Row5, .Row4_4 - %2 4, ITAB1, Idct_Rnd4, 11 - jmp .Row5 -.Row4_4: - %3 4, ITAB1, Idct_Rnd4, 11 - -.Row5: - TEST_ROW ecx+80, .Row6, .Row5_4 - %2 5, ITAB4, Idct_Rnd5, 11 - jmp .Row6 -.Row5_4: - %3 5, ITAB4, Idct_Rnd5, 11 - -.Row6: - TEST_ROW ecx+96, .Row7, .Row6_4 - %2 6, ITAB3, Idct_Rnd6, 11 - jmp .Row7 -.Row6_4: - %3 6, ITAB3, Idct_Rnd6, 11 -.Row7: - TEST_ROW ecx+112, .End, .Row7_4 - %2 7, ITAB2, Idct_Rnd7, 11 - jmp .End -.Row7_4: - %3 7, ITAB2, Idct_Rnd7, 11 -.End: - -%if (%1==0) - %4 ecx+0, 0,0 - %4 ecx+8, 0,0 -%elif (%1==1) - mov eax, [esp+ 8] ; Dst - mov edx, [esp+12] ; BpS - %4 ecx+8, 0,0 - %4 ecx+0, 1,0 -%else - mov eax, [esp+ 8] ; Dst - mov edx, [esp+12] ; BpS - %4 ecx+0, 2,0 - mov eax, [esp+ 8] ; reload Dst - %4 ecx+8, 2,4 -%endif - -%endmacro - -;////////////////////////////////////////////////////////////////////// - -%define ITAB1 iTab1 -%define ITAB2 iTab2 -%define ITAB3 iTab3 -%define ITAB4 iTab4 - -align 16 -Skl_IDct16_Sparse_SSE: ; <= ~249c - IDCT_IMPL 0, iMTX_MULT, iMTX_MULT_03, iLLM_PASS - ret - -align 16 -Skl_IDct16_Put_SSE: - IDCT_IMPL 1, iMTX_MULT, iMTX_MULT_03, iLLM_PASS - ret - -align 16 -Skl_IDct16_Add_SSE: - IDCT_IMPL 2, iMTX_MULT, iMTX_MULT_03, iLLM_PASS - ret - -align 16 -Skl_IDct16_Sparse_8x4_SSE: ; <= ~249c - IDCT_IMPL 0, iMTX_MULT, iMTX_MULT_03, iLLM_PASS_03 - ret - -align 16 -Skl_IDct16_Put_8x4_SSE: - IDCT_IMPL 1, iMTX_MULT, iMTX_MULT_03, iLLM_PASS_03 - ret - -align 16 -Skl_IDct16_Add_8x4_SSE: - IDCT_IMPL 2, iMTX_MULT, iMTX_MULT_03, iLLM_PASS_03 - ret - -;////////////////////////////////////////////////////////////////////// - -%define ITAB1 iTab1_MMX -%define ITAB2 iTab2_MMX -%define ITAB3 iTab3_MMX -%define ITAB4 iTab4_MMX - -align 16 -Skl_IDct16_Sparse_MMX: ; <= ~288c - IDCT_IMPL 0, iMTX_MULT_MMX, iMTX_MULT_MMX, iLLM_PASS - ret - -align 16 -Skl_IDct16_Put_MMX: - IDCT_IMPL 1, iMTX_MULT_MMX, iMTX_MULT_MMX, iLLM_PASS - ret - -align 16 -Skl_IDct16_Add_MMX: - IDCT_IMPL 2, iMTX_MULT_MMX, iMTX_MULT_MMX, iLLM_PASS - ret - -align 16 -Skl_IDct16_Sparse_8x4_MMX: - IDCT_IMPL 0, iMTX_MULT_MMX, iMTX_MULT_MMX, iLLM_PASS_03 - ret - -align 16 -Skl_IDct16_Put_8x4_MMX: - IDCT_IMPL 1, iMTX_MULT_MMX, iMTX_MULT_MMX, iLLM_PASS_03 - ret - -align 16 -Skl_IDct16_Add_8x4_MMX: - IDCT_IMPL 2, iMTX_MULT_MMX, iMTX_MULT_MMX, iLLM_PASS_03 - ret - -;////////////////////////////////////////////////////////////////////// -;// fLLM_PASS (~39c) -;////////////////////////////////////////////////////////////////////// - -%macro fLLM_PASS 2 ; %1: src/dst, %2:Shift - - movq mm0, [%1+0*16] ; In0 - movq mm2, [%1+2*16] ; In2 - movq mm3, mm0 - movq mm4, mm2 - movq mm7, [%1+7*16] ; In7 - movq mm5, [%1+5*16] ; In5 - - psubsw mm0, mm7 ; t7 = In0-In7 - paddsw mm7, mm3 ; t0 = In0+In7 - psubsw mm2, mm5 ; t5 = In2-In5 - paddsw mm5, mm4 ; t2 = In2+In5 - - movq mm3, [%1+3*16] ; In3 - movq mm4, [%1+4*16] ; In4 - movq mm1, mm3 - psubsw mm3, mm4 ; t4 = In3-In4 - paddsw mm4, mm1 ; t3 = In3+In4 - movq mm6, [%1+6*16] ; In6 - movq mm1, [%1+1*16] ; In1 - psubsw mm1, mm6 ; t6 = In1-In6 - paddsw mm6, [%1+1*16] ; t1 = In1+In6 - - psubsw mm7, mm4 ; tm03 = t0-t3 - psubsw mm6, mm5 ; tm12 = t1-t2 - paddsw mm4, mm4 ; 2.t3 - paddsw mm5, mm5 ; 2.t2 - paddsw mm4, mm7 ; tp03 = t0+t3 - paddsw mm5, mm6 ; tp12 = t1+t2 - - psllw mm2, %2+1 ; shift t5 (shift +1 to.. - psllw mm1, %2+1 ; shift t6 ..compensate cos4/2) - psllw mm4, %2 ; shift t3 - psllw mm5, %2 ; shift t2 - psllw mm7, %2 ; shift t0 - psllw mm6, %2 ; shift t1 - psllw mm3, %2 ; shift t4 - psllw mm0, %2 ; shift t7 - - psubsw mm4, mm5 ; out4 = tp03-tp12 - psubsw mm1, mm2 ; mm1: t6-t5 - paddsw mm5, mm5 - paddsw mm2, mm2 - paddsw mm5, mm4 ; out0 = tp03+tp12 - movq [%1+4*16], mm4 ; => out4 - paddsw mm2, mm1 ; mm2: t6+t5 - movq [%1+0*16], mm5 ; => out0 - - movq mm4, [tan2] ; mm4 <= tan2 - pmulhw mm4, mm7 ; tm03*tan2 - movq mm5, [tan2] ; mm5 <= tan2 - psubsw mm4, mm6 ; out6 = tm03*tan2 - tm12 - pmulhw mm5, mm6 ; tm12*tan2 - paddsw mm5, mm7 ; out2 = tm12*tan2 + tm03 - - movq mm6, [sqrt2] - movq mm7, [MMX_One] - - pmulhw mm2, mm6 ; mm2: tp65 = (t6 + t5)*cos4 - por mm5, mm7 ; correct out2 - por mm4, mm7 ; correct out6 - pmulhw mm1, mm6 ; mm1: tm65 = (t6 - t5)*cos4 - por mm2, mm7 ; correct tp65 - - movq [%1+2*16], mm5 ; => out2 - movq mm5, mm3 ; save t4 - movq [%1+6*16], mm4 ; => out6 - movq mm4, mm0 ; save t7 - - psubsw mm3, mm1 ; mm3: tm465 = t4 - tm65 - psubsw mm0, mm2 ; mm0: tm765 = t7 - tp65 - paddsw mm2, mm4 ; mm2: tp765 = t7 + tp65 - paddsw mm1, mm5 ; mm1: tp465 = t4 + tm65 - - movq mm4, [tan3] ; tan3 - 1 - movq mm5, [tan1] ; tan1 - - movq mm7, mm3 ; save tm465 - pmulhw mm3, mm4 ; tm465*(tan3-1) - movq mm6, mm1 ; save tp465 - pmulhw mm1, mm5 ; tp465*tan1 - - paddsw mm3, mm7 ; tm465*tan3 - pmulhw mm4, mm0 ; tm765*(tan3-1) - paddsw mm4, mm0 ; tm765*tan3 - pmulhw mm5, mm2 ; tp765*tan1 - - paddsw mm1, mm2 ; out1 = tp765 + tp465*tan1 - psubsw mm0, mm3 ; out3 = tm765 - tm465*tan3 - paddsw mm7, mm4 ; out5 = tm465 + tm765*tan3 - psubsw mm5, mm6 ; out7 =-tp465 + tp765*tan1 - - movq [%1+1*16], mm1 ; => out1 - movq [%1+3*16], mm0 ; => out3 - movq [%1+5*16], mm7 ; => out5 - movq [%1+7*16], mm5 ; => out7 - -%endmacro - -;////////////////////////////////////////////////////////////////////// -;// fMTX_MULT (~20c) (~26c for MMX) -;////////////////////////////////////////////////////////////////////// - -%macro fMTX_MULT 5 ; %1=src, %2 = Coeffs, %3/%4=rounders, %5=MMX-Only - -%if %5==0 - - ; SSE version ('pshufw') - - movq mm0, [ecx+%1*16+0] ; mm0 = [0123] - - pshufw mm1, [ecx+%1*16+8], 00011011b ; mm1 = [7654] - movq mm7, mm0 - -%else - - ; MMX-only version (~10% slower overall) - - movd mm1, [ecx+%1*16+8+4] ; [67..] - movq mm0, [ecx+%1*16+0] ; mm0 = [0123] - movq mm7, mm0 - punpcklwd mm1, [ecx+%1*16+8] ; [6475] - movq mm2, mm1 - psrlq mm1, 32 ; [75..] - punpcklwd mm1,mm2 ; [7654] - -%endif - - paddsw mm0, mm1 ; mm0 = [a0 a1 a2 a3] - psubsw mm7, mm1 ; mm7 = [b0 b1 b2 b3] - - movq mm1, mm0 - punpckldq mm0, mm7 ; mm0 = [a0 a1 b0 b1] - punpckhdq mm1, mm7 ; mm1 = [b2 b3 a2 a3] - - movq mm2, [%2+ 0] ; [ M00 M01 M16 M17] - movq mm3, [%2+ 8] ; [ M02 M03 M18 M19] - pmaddwd mm2, mm0 ; [a0.M00+a1.M01 | b0.M16+b1.M17] - movq mm4, [%2+16] ; [ M04 M05 M20 M21] - pmaddwd mm3, mm1 ; [a2.M02+a3.M03 | b2.M18+b3.M19] - movq mm5, [%2+24] ; [ M06 M07 M22 M23] - pmaddwd mm4, mm0 ; [a0.M04+a1.M05 | b0.M20+b1.M21] - movq mm6, [%2+32] ; [ M08 M09 M24 M25] - pmaddwd mm5, mm1 ; [a2.M06+a3.M07 | b2.M22+b3.M23] - movq mm7, [%2+40] ; [ M10 M11 M26 M27] - pmaddwd mm6, mm0 ; [a0.M08+a1.M09 | b0.M24+b1.M25] - paddd mm2, mm3 ; [ out0 | out1 ] - pmaddwd mm7, mm1 ; [a0.M10+a1.M11 | b0.M26+b1.M27] - psrad mm2, 16 - pmaddwd mm0, [%2+48] ; [a0.M12+a1.M13 | b0.M28+b1.M29] - paddd mm4, mm5 ; [ out2 | out3 ] - pmaddwd mm1, [%2+56] ; [a0.M14+a1.M15 | b0.M30+b1.M31] - psrad mm4, 16 - - paddd mm6, mm7 ; [ out4 | out5 ] - psrad mm6, 16 - paddd mm0, mm1 ; [ out6 | out7 ] - psrad mm0, 16 - - packssdw mm2, mm4 ; [ out0|out1|out2|out3 ] - paddsw mm2, [%3] ; Round - packssdw mm6, mm0 ; [ out4|out5|out6|out7 ] - paddsw mm6, [%4] ; Round - - psraw mm2, 4 ; => [-2048, 2047] - psraw mm6, 4 - - movq [ecx+%1*16+0], mm2 - movq [ecx+%1*16+8], mm6 -%endmacro - -;////////////////////////////////////////////////////////////////////// - -align 16 -Skl_Dct16_SSE: ; ~240c - mov ecx, [esp+4] - fLLM_PASS ecx+0, 3 - fLLM_PASS ecx+8, 3 - fMTX_MULT 0, fTab1, Fdct_Rnd0, Fdct_Rnd0, 0 - fMTX_MULT 1, fTab2, Fdct_Rnd2, Fdct_Rnd1, 0 - fMTX_MULT 2, fTab3, Fdct_Rnd1, Fdct_Rnd1, 0 - fMTX_MULT 3, fTab4, Fdct_Rnd1, Fdct_Rnd1, 0 - fMTX_MULT 4, fTab1, Fdct_Rnd0, Fdct_Rnd0, 0 - fMTX_MULT 5, fTab4, Fdct_Rnd1, Fdct_Rnd1, 0 - fMTX_MULT 6, fTab3, Fdct_Rnd1, Fdct_Rnd1, 0 - fMTX_MULT 7, fTab2, Fdct_Rnd1, Fdct_Rnd1, 0 - ret - -align 16 -Skl_Dct16_MMX: ; ~269c - mov ecx, [esp+4] - fLLM_PASS ecx+0, 3 - fLLM_PASS ecx+8, 3 - fMTX_MULT 0, fTab1, Fdct_Rnd0, Fdct_Rnd0, 1 - fMTX_MULT 1, fTab2, Fdct_Rnd2, Fdct_Rnd1, 1 - fMTX_MULT 2, fTab3, Fdct_Rnd1, Fdct_Rnd1, 1 - fMTX_MULT 3, fTab4, Fdct_Rnd1, Fdct_Rnd1, 1 - fMTX_MULT 4, fTab1, Fdct_Rnd0, Fdct_Rnd0, 1 - fMTX_MULT 5, fTab4, Fdct_Rnd1, Fdct_Rnd1, 1 - fMTX_MULT 6, fTab3, Fdct_Rnd1, Fdct_Rnd1, 1 - fMTX_MULT 7, fTab2, Fdct_Rnd1, Fdct_Rnd1, 1 - ret - -;////////////////////////////////////////////////////////////////////// diff --git a/src/dgindex/skl_nasm.h b/src/dgindex/skl_nasm.h deleted file mode 100644 index 35215c9..0000000 --- a/src/dgindex/skl_nasm.h +++ /dev/null @@ -1,88 +0,0 @@ -;/******************************************************** -; * Some code. Copyright (C) 2003 by Pascal Massimino. * -; * All Rights Reserved. (http://skal.planet-d.net) * -; * For Educational/Academic use ONLY. See 'LICENSE.TXT'.* -; ********************************************************/ -;////////////////////////////////////////////////////////// -;// NASM macros -;////////////////////////////////////////////////////////// - -%ifdef LINUX - -;////////////////////////////////////////////////////////// -; LINUX / egcs / macros -;////////////////////////////////////////////////////////// - -%macro extrn 1 - extern %1 - %define %1 %1 -%endmacro -%macro globl 1 - global %1 - %define %1 %1 -%endmacro - -%macro DATA 0 -[section data align=16 write alloc USE32] -%endmacro -%macro TEXT 0 -[section text align=16 nowrite alloc exec USE32] -%endmacro - -%endif ; LINUX - -;////////////////////////////////////////////////////////// - -%ifdef WIN32 - -%macro extrn 1 - extern _%1 - %define %1 _%1 -%endmacro - -%macro globl 1 - global _%1 - %define %1 _%1 -%endmacro - -%macro DATA 0 -[section .data align=16 write alloc USE32] -%endmacro -%macro TEXT 0 -[section .text align=16 nowrite alloc exec USE32] -%endmacro - -%endif ; WIN32 - -;////////////////////////////////////////////////////////// -; -; MACRO for timing. NASM. -; Total additional code size is 0xb0. -; this keep code alignment right. - -;extrn Skl_Cur_Count_ -;extrn Skl_Print_Tics - -%macro SKL_USE_RDSTC 0 -extrn SKL_RDTSC_0_ASM -extrn SKL_RDTSC_1_ASM -extrn SKL_RDTSC_2_ASM -%endmacro -%define SKL_RDTSC_OFFSET 15 ; check value with skl_rdtsc.h... - -%macro SKL_RDTSC_IN 0 - SKL_USE_RDSTC - call SKL_RDTSC_0_ASM -.Skl_RDTSC_Loop_: - call SKL_RDTSC_1_ASM -%endmacro - -;%macro SKL_RDTSC_OUT 0 -; call SKL_RDTSC_2_ASM -; dec dword [Skl_Cur_Count_] -; jge near .Skl_RDTSC_Loop_ -; push dword 53 -; call Skl_Print_Tics -;%endmacro - -;////////////////////////////////////////////////////////// diff --git a/src/dgindex/store.cpp b/src/dgindex/store.cpp deleted file mode 100644 index d0e3202..0000000 --- a/src/dgindex/store.cpp +++ /dev/null @@ -1,590 +0,0 @@ -/* - * Mutated into DGIndex. Modifications Copyright (C) 2004, Donald Graft - * - * Copyright (C) Chia-chen Kuo - April 2001 - * - * This file is part of DVD2AVI, a free MPEG-2 decoder - * - * DVD2AVI 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. - * - * DVD2AVI is distributed in the hope that 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 "global.h" -#include "filter.h" - -#define MAX_WINDOW_WIDTH 800 -#define MAX_WINDOW_HEIGHT 600 - -__forceinline static void Store_RGB24(unsigned char *src[]); - -static void FlushRGB24(void); - -static BITMAPINFOHEADER birgb, birgbsmall; - -static char VideoOut[DG_MAX_PATH]; -static unsigned char *y444; -static long frame_size; -static bool TFF, RFF, TFB, BFB, frame_type; - -static char *FrameType[] = { - "Interlaced", "Progressive" -}; - -void Write_Frame(unsigned char *src[], D2VData d2v, DWORD frame) -{ - int repeat; - - frame_type = d2v.pf; - TFF = d2v.trf>>1; - if (FO_Flag == FO_RAW) - RFF = 0; - else - RFF = d2v.trf & 0x01; - - if (!frame) - { - TFB = BFB = false; - playback = frame_repeats = field_repeats = Old_Playback = 0; - frame_size = 0; - - Clip_Width = horizontal_size; - Clip_Height = vertical_size; - CLIP_AREA = HALF_CLIP_AREA = CLIP_STEP = CLIP_HALF_STEP = 0; - - if (Luminance_Flag) - InitializeFilter(); - - if (Cropping_Flag) - { - if (Clip_Top || Clip_Bottom || Clip_Left || Clip_Right) - { - Clip_Width -= Clip_Left+Clip_Right; - Clip_Height -= Clip_Top+Clip_Bottom; - - CLIP_AREA = Coded_Picture_Width * Clip_Top; - HALF_CLIP_AREA = (Coded_Picture_Width>>1) * Clip_Top; - - CLIP_STEP = Coded_Picture_Width * Clip_Top + Clip_Left; - CLIP_HALF_STEP = (Coded_Picture_Width>>1) * Clip_Top + (Clip_Left>>1); - } - } - - NINE_CLIP_WIDTH = Clip_Width * 9; - QUAD_CLIP_WIDTH = Clip_Width<<2; - DOUBLE_CLIP_WIDTH = Clip_Width<<1; - HALF_CLIP_WIDTH = Clip_Width>>1; - - LUM_AREA = Coded_Picture_Width * Clip_Height; - DOUBLE_WIDTH = Coded_Picture_Width<<1; - HALF_WIDTH = Coded_Picture_Width>>1; - HALF_WIDTH_D8 = (Coded_Picture_Width>>1) - 8; - PROGRESSIVE_HEIGHT = (Coded_Picture_Height>>1) - 2; - INTERLACED_HEIGHT = (Coded_Picture_Height>>2) - 2; - RGB_DOWN1 = Clip_Width * (Clip_Height - 1) * 3; - RGB_DOWN2 = Clip_Width * (Clip_Height - 2) * 3; - - if ((HDDisplay != HD_DISPLAY_FULL_SIZED) && (Clip_Width > MAX_WINDOW_WIDTH || Clip_Height > MAX_WINDOW_HEIGHT)) - { - ResizeWindow(Clip_Width/2, Clip_Height/2); - ResizeWindow(Clip_Width/2, Clip_Height/2); - } - else - { - ResizeWindow(Clip_Width, Clip_Height); - ResizeWindow(Clip_Width, Clip_Height); - } - - ZeroMemory(&birgb, sizeof(BITMAPINFOHEADER)); - birgb.biSize = sizeof(BITMAPINFOHEADER); - birgb.biWidth = Clip_Width; - birgb.biHeight = Clip_Height; - birgb.biPlanes = 1; - birgb.biBitCount = 24; - birgb.biCompression = BI_RGB; - birgb.biSizeImage = Clip_Width * Clip_Height * 3; - - ZeroMemory(&birgbsmall, sizeof(BITMAPINFOHEADER)); - birgbsmall.biSize = sizeof(BITMAPINFOHEADER); - birgbsmall.biWidth = Clip_Width; - birgbsmall.biHeight = Clip_Height; - birgbsmall.biPlanes = 1; - birgbsmall.biBitCount = 24; - birgbsmall.biCompression = BI_RGB; - birgbsmall.biSizeImage = Clip_Width * Clip_Height * 3; - - if (d2v.picture_structure == FRAME_PICTURE) - { - if (TFF) - SetDlgItemText(hDlg, IDC_FIELD_ORDER, "Top"); - else - SetDlgItemText(hDlg, IDC_FIELD_ORDER, "Bottom"); - } - else - { - SetDlgItemText(hDlg, IDC_FIELD_ORDER, d2v.picture_structure == TOP_FIELD ? "Top" : "Bottom"); - } - } - - if (Info_Flag && process.locate==LOCATE_RIP) - { - sprintf(szBuffer, "%s", FrameType[frame_type]); - SetDlgItemText(hDlg, IDC_FRAME_TYPE, szBuffer); - - sprintf(szBuffer, "%s", progressive_sequence ? "Frame only" : "Field/Frame"); - SetDlgItemText(hDlg, IDC_SEQUENCE, szBuffer); - - switch (matrix_coefficients) - { - case 1: - sprintf(szBuffer, "%s", "BT.709"); - break; - case 2: - sprintf(szBuffer, "%s", "Unknown"); - break; - case 3: - sprintf(szBuffer, "%s", "Reserved"); - break; - case 4: - sprintf(szBuffer, "%s", "BT.470-2 M"); - break; - case 5: - sprintf(szBuffer, "%s", "BT.470-2 B,G"); - break; - case 6: - sprintf(szBuffer, "%s", "SMPTE 170M"); - break; - case 7: - sprintf(szBuffer, "%s", "SMPTE 240M"); - break; - case 0: - default: - sprintf(szBuffer, "%s", "Reserved"); - break; - } - if (default_matrix_coefficients == true) - strcat(szBuffer, "*"); - SetDlgItemText(hDlg, IDC_COLORIMETRY, szBuffer); - - sprintf(szBuffer, "%s", picture_structure == 3 ? "Frame" : "Field"); - SetDlgItemText(hDlg, IDC_FRAME_STRUCTURE, szBuffer); - - sprintf(szBuffer, "%d", frame+1); - SetDlgItemText(hDlg, IDC_CODED_NUMBER, szBuffer); - - sprintf(szBuffer, "%d", playback+1); - SetDlgItemText(hDlg, IDC_PLAYBACK_NUMBER, szBuffer); - - sprintf(szBuffer, "%d", frame_repeats); - SetDlgItemText(hDlg, IDC_FRAME_REPEATS, szBuffer); - - sprintf(szBuffer, "%d", field_repeats); - SetDlgItemText(hDlg, IDC_FIELD_REPEATS, szBuffer); - - if (playback - Old_Playback >= 30) - { - double rate, rate_avg; - timing.ed = timeGetTime(); - - sprintf(szBuffer, "%.2f", 1000.0*(playback-Old_Playback)/(timing.ed-timing.mi+1)); - SetDlgItemText(hDlg, IDC_FPS, szBuffer); - // The first time through seems to be unreliable so don't use it. - if (playback > 30) - { - rate = ((double) (Bitrate_Monitor * 8 * Frame_Rate) / (playback-Old_Playback)) / 1000000.0; - Bitrate_Average += Bitrate_Monitor; - rate_avg = (Bitrate_Average * 8 * Frame_Rate) / (playback-30) / 1000000.0; - if (rate > max_rate) - { - max_rate = rate; - } - sprintf(szBuffer, "%.3f Mbps", rate); - SetDlgItemText(hDlg, IDC_BITRATE, szBuffer); - sprintf(szBuffer, "%.3f Mbps", max_rate); - SetDlgItemText(hDlg, IDC_BITRATE_MAX, szBuffer); - sprintf(szBuffer, "%.3f Mbps", rate_avg); - SetDlgItemText(hDlg, IDC_BITRATE_AVG, szBuffer); - } - Bitrate_Monitor = 0; - timing.mi = timing.ed; - Old_Playback = playback; - } - - sprintf(szBuffer, "%s", d2v.type == I_TYPE ? "I" : (d2v.type == P_TYPE ? "P" : "B")); - SetDlgItemText(hDlg, IDC_CODING_TYPE, szBuffer); - } - - if (progressive_sequence) - { - DetectVideoType(frame, d2v.trf); - if (chroma_format==CHROMA420) - { - conv420to422(src[1], u422, frame_type); - conv420to422(src[2], v422, frame_type); - - conv422to444(u422, u444); - conv422to444(v422, v444); - } - else - { - conv422to444(src[1], u444); - conv422to444(src[2], v444); - } - - if (Luminance_Flag) - { - LuminanceFilter(src[0], lum); - y444 = lum; - } - else - y444 = src[0]; - conv444toRGB24odd(y444, u444, v444, rgb24); - conv444toRGB24even(y444, u444, v444, rgb24); - TFB = BFB = true; - FlushRGB24(); - if ((FO_Flag != FO_RAW) && (d2v.trf & 1)) - { - TFB = BFB = true; - FlushRGB24(); - frame_repeats++; - if (d2v.trf & 2) - { - TFB = BFB = true; - FlushRGB24(); - frame_repeats++; - } - } - } - else - { - repeat = DetectVideoType(frame, d2v.trf); - - if ((FO_Flag != FO_RAW) && (d2v.trf & 1)) - field_repeats++; - - if (FO_Flag != FO_FILM || repeat) - { - Store_RGB24(src); - } - - if (FO_Flag != FO_FILM && repeat==2) - { - Store_RGB24(src); - } - } -} - -static void Store_RGB24(unsigned char *src[]) -{ - if (chroma_format==CHROMA420) - { - conv420to422(src[1], u422, frame_type); - conv420to422(src[2], v422, frame_type); - - conv422to444(u422, u444); - conv422to444(v422, v444); - } - else - { - conv422to444(src[1], u444); - conv422to444(src[2], v444); - } - - if (Luminance_Flag) - { - LuminanceFilter(src[0], lum); - y444 = lum; - } - else - y444 = src[0]; - - if (BFB) - { - conv444toRGB24odd(y444, u444, v444, rgb24); - TFB = true; - FlushRGB24(); - - conv444toRGB24even(y444, u444, v444, rgb24); - BFB = true; - FlushRGB24(); - } - else - { - conv444toRGB24even(y444, u444, v444, rgb24); - BFB = true; - FlushRGB24(); - - conv444toRGB24odd(y444, u444, v444, rgb24); - TFB = true; - FlushRGB24(); - } - - if (FO_Flag!=FO_FILM && FO_Flag!=FO_RAW && RFF) - if (TFF) - { - TFB = true; - FlushRGB24(); - } - else - { - BFB = true; - FlushRGB24(); - } -} - -static void FlushRGB24() -{ - static double DisplayTime = 0; - static unsigned int timeOffset = 0; - double rate; - int sleep_time; - int elapsed; - - if (TFB & BFB) - { - if (PlaybackSpeed == SPEED_MAXIMUM) - { - // maximum - ShowFrame(false); - OldPlaybackSpeed = PlaybackSpeed; - } - else if (PlaybackSpeed == SPEED_SINGLE_STEP) - { - ShowFrame(false); - OldPlaybackSpeed = PlaybackSpeed; - if (process.locate == LOCATE_RIP) - { - for (;;) - { - // Wait for right arrow to be hit before displaying - // the next frame. - Sleep(100); - if (Stop_Flag || RightArrowHit == true) - break; - } - RightArrowHit = false; - } - } - else - { - if (playback == 0 || PlaybackSpeed != OldPlaybackSpeed) - { - DisplayTime = 0; - timeOffset = timeGetTime(); - } - OldPlaybackSpeed = PlaybackSpeed; - elapsed = timeGetTime() - timeOffset; - sleep_time = (int) (DisplayTime - elapsed); - if (sleep_time >= 0) - Sleep(sleep_time); - ShowFrame(false); - switch (PlaybackSpeed) - { - case SPEED_SUPER_SLOW: // super slow - rate = 5.0; - break; - case SPEED_SLOW: // slow - rate = 10.0; - break; - default: - case SPEED_NORMAL: // normal - rate = Frame_Rate; - break; - case SPEED_FAST: // fast - rate = 2 * Frame_Rate; - break; - } - DisplayTime += 1000.0 / rate; - } - playback++; - TFB = BFB = false; - } -} - -int DetectVideoType(int frame, int trf) -{ - static int Old_TRF, Repeat_On, Repeat_Off; - static bool Repeat_Init; - - if (progressive_sequence) - { - if (frame) - { - if ((trf == 3 && Old_TRF == 1) || (trf == 1 && Old_TRF == 3)) - FILM_Purity++; - else - VIDEO_Purity++; - } - else - { - FILM_Purity = VIDEO_Purity = Repeat_On = Repeat_Off = 0; - Repeat_Init = false; - } - Old_TRF = trf; - return 0; - } - - if (frame) - { - if ((trf & 3) == ((Old_TRF+1) & 3)) - FILM_Purity++; - else - VIDEO_Purity++; - } - else - { - FILM_Purity = VIDEO_Purity = Repeat_On = Repeat_Off = 0; - Repeat_Init = false; - } - - Old_TRF = trf; - - if (trf & 1) - Repeat_On ++; - else - Repeat_Off ++; - - if (Repeat_Init) - { - if (Repeat_Off-Repeat_On == 5) - { - Repeat_Off = Repeat_On = 0; - return 0; - } - else if (Repeat_On-Repeat_Off == 5) - { - Repeat_Off = Repeat_On = 0; - return 2; - } - } - else - { - if (Repeat_Off-Repeat_On == 3) - { - Repeat_Off = Repeat_On = 0; - Repeat_Init = true; - return 0; - } - else if (Repeat_On-Repeat_Off == 3) - { - Repeat_Off = Repeat_On = 0; - Repeat_Init = true; - return 2; - } - } - - return 1; -} - -void ShowFrame(bool move) -{ - unsigned int x, xx, y, yy, incy, incyy; - unsigned char *yp, *yyp; - unsigned int Clip_HeightOver2 = Clip_Height / 2; - unsigned int Clip_WidthTimes3Over2 = Clip_Width * 3 / 2; - - - if (!Check_Flag) - return; - - if (rgb24 && rgb24small && (move || Display_Flag)) - { - if ((HDDisplay != HD_DISPLAY_FULL_SIZED) && (Clip_Width > MAX_WINDOW_WIDTH || Clip_Height > MAX_WINDOW_HEIGHT)) - { - if (HDDisplay == HD_DISPLAY_SHRINK_BY_HALF) - { - // Zoom out by two in both directions. Quick and dirty. - yp = rgb24small + (Clip_Height - 1) * Clip_Width * 3; - yyp = rgb24 + (Clip_Height - 1) * Clip_Width * 3; - incy = Clip_Width * 3; - incyy = 2 * Clip_Width * 3; - for (y = yy = Clip_Height - 1; y >= Clip_HeightOver2; y--, yy-=2) - { - for (x = xx = 0; x < Clip_WidthTimes3Over2; x+=3, xx+=6) - { - yp[x] = yyp[xx]; - yp[x+1] = yyp[xx+1]; - yp[x+2] = yyp[xx+2]; - } - yp -= incy; - yyp -= incyy; - } - SetDIBitsToDevice(hDC, 0, 0, Clip_Width / 2, Clip_Height, 0, 0, Clip_Height/2, Clip_Height/2, - rgb24small + Clip_Height/2 * Clip_Width * 3, (LPBITMAPINFO) &birgbsmall, DIB_RGB_COLORS); - } - else if (HDDisplay == HD_DISPLAY_BOTTOM_LEFT) - { - // Bottom left quadrant - SetDIBitsToDevice(hDC, - 0, - 0, - Clip_Width/2, // dest width - Clip_Height/2, // dest height - 0, // X source - 0, // Y source - 0, // start scan - Clip_Height, // scan lines - rgb24, (LPBITMAPINFO)&birgb, DIB_RGB_COLORS); - } - else if (HDDisplay == HD_DISPLAY_BOTTOM_RIGHT) - { - // Bottom right quadrant - SetDIBitsToDevice(hDC, - 0, - 0, - Clip_Width/2, // dest width - Clip_Height/2, // dest height - Clip_Width/2, // X source - 0, // Y source - 0, // start scan - Clip_Height, // scan lines - rgb24, (LPBITMAPINFO)&birgb, DIB_RGB_COLORS); - } - else if (HDDisplay == HD_DISPLAY_TOP_LEFT) - { - // Top left quadrant - SetDIBitsToDevice(hDC, - 0, - 0, - Clip_Width/2, // dest width - Clip_Height/2, // dest height - 0, // X source - Clip_Height/2, // Y source - 0, // start scan - Clip_Height, // scan lines - rgb24, (LPBITMAPINFO)&birgb, DIB_RGB_COLORS); - } - else - { - // Top right quadrant - SetDIBitsToDevice(hDC, - 0, - 0, - Clip_Width/2, // dest width - Clip_Height/2, // dest height - Clip_Width/2, // X source - Clip_Height/2, // Y source - 0, // start scan - Clip_Height, // scan lines - rgb24, (LPBITMAPINFO)&birgb, DIB_RGB_COLORS); - } - } - else - { - // Full size display. - SetDIBitsToDevice(hDC, 0, 0, Clip_Width, Clip_Height, 0, 0, 0, Clip_Height, - rgb24, (LPBITMAPINFO)&birgb, DIB_RGB_COLORS); - } - } -} diff --git a/src/dgindex/strverscmp.cpp b/src/dgindex/strverscmp.cpp deleted file mode 100644 index 20af22c..0000000 --- a/src/dgindex/strverscmp.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* Compare strings while treating digits characters numerically. - Copyright (C) 1997, 2002 Free Software Foundation, Inc. - This file is part of the GNU C Library. - Contributed by Jean-Franois Bignolles , 1997. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA. */ - -#include -#include -#include - -/* states: S_N: normal, S_I: comparing integral part, S_F: comparing - fractionnal parts, S_Z: idem but with leading Zeroes only */ -#define S_N 0x0 -#define S_I 0x4 -#define S_F 0x8 -#define S_Z 0xC - -/* result_type: CMP: return diff; LEN: compare using len_diff/diff */ -#define CMP 2 -#define LEN 3 - - -/* Compare S1 and S2 as strings holding indices/version numbers, - returning less than, equal to or greater than zero if S1 is less than, - equal to or greater than S2 (for more info, see the texinfo doc). -*/ - -int -strverscmp(const char *s1, const char *s2) -{ - const unsigned char *p1 = (const unsigned char *) s1; - const unsigned char *p2 = (const unsigned char *) s2; - unsigned char c1, c2; - int state; - int diff; - - /* Symbol(s) 0 [1-9] others (padding) - Transition (10) 0 (01) d (00) x (11) - */ - static const unsigned int next_state[] = - { - /* state x d 0 - */ - /* S_N */ S_N, S_I, S_Z, S_N, - /* S_I */ S_N, S_I, S_I, S_I, - /* S_F */ S_N, S_F, S_F, S_F, - /* S_Z */ S_N, S_F, S_Z, S_Z - }; - - static const int result_type[] = - { - /* state x/x x/d x/0 x/- d/x d/d d/0 d/- - 0/x 0/d 0/0 0/- -/x -/d -/0 -/- */ - - /* S_N */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP, - CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP, - /* S_I */ CMP, -1, -1, CMP, +1, LEN, LEN, CMP, - +1, LEN, LEN, CMP, CMP, CMP, CMP, CMP, - /* S_F */ CMP, CMP, CMP, CMP, CMP, LEN, CMP, CMP, - CMP, CMP, CMP, CMP, CMP, CMP, CMP, CMP, - /* S_Z */ CMP, +1, +1, CMP, -1, CMP, CMP, CMP, - -1, CMP, CMP, CMP - }; - - if (p1 == p2) - return 0; - - c1 = *p1++; - c2 = *p2++; - /* Hint: '0' is a digit too. */ - state = S_N | ((c1 == '0') + (isdigit (c1) != 0)); - - while ((diff = c1 - c2) == 0 && c1 != '\0') - { - state = next_state[state]; - c1 = *p1++; - c2 = *p2++; - state |= (c1 == '0') + (isdigit (c1) != 0); - } - - state = result_type[state << 2 | (((c2 == '0') + (isdigit (c2) != 0)))]; - - switch (state) - { - case CMP: - return diff; - - case LEN: - while (isdigit (*p1++)) - if (!isdigit (*p2++)) - return 1; - - return isdigit (*p2) ? -1 : diff; - - default: - return state; - } -} diff --git a/src/dgindex/wavefs44.cpp b/src/dgindex/wavefs44.cpp deleted file mode 100644 index feb2064..0000000 --- a/src/dgindex/wavefs44.cpp +++ /dev/null @@ -1,324 +0,0 @@ -/* - * Copyright (c) 2000 by WTC - * - * This file is part of WAVEFS44, a free sound sampling rate converter - * - * WAVEFS44 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. - * - * WAVEFS44 is distributed in the hope that 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 "global.h" -#include - -#define M_PI 3.1415926535897932384626433832795 -#define ISRM 147 -#define OSRM 160 -#define WINSIZ 16384 -#define MAXFIRODR 65535 -#define ALPHA 10.0 - -typedef struct { - short l; - short r; -} SmplData; - -static int firodr[5] = {0, 4095, 12287, 24575, 32767}; -static int lpfcof[5] = {0, 19400, 21200, 21400, 21600}; - -static int sptr, sptrr, eptr, eptrr, ismd, ismr, winpos, iptr, firodrv; -static double hfir[MAXFIRODR+1]; -static double suml, sumr, frqc, frqs, regv, wfnc, divisor, hgain; -static SmplData smpld[WINSIZ*2], smplo, *spp; - -static double bessel0(double); -static void DownKernel(FILE *file); - -__forceinline short SaturateRound(double flt) -{ - int tmp; - - __asm - { - fld [flt] - fistp [tmp] - } - - return (tmp<-32768) ? -32768 : ((tmp>32767) ? 32767 : tmp); -} - -void InitialSRC() -{ - int i; - - frqs = 44100*OSRM; // virtual high sampling rate - frqc = lpfcof[SRC_Flag]; // cutoff freq. - firodrv = firodr[SRC_Flag]; // FIR order = firodrv*2+1 - - divisor = bessel0(ALPHA); - hgain = (2.0*ISRM*frqc)/frqs; - hfir[0] = hgain; - - for (i=1; i<=firodrv; i++) - { - regv = (double)(i*i)/(firodrv*firodrv); - wfnc = bessel0(sqrt(1.0-regv)*ALPHA)/divisor; - regv = (2.0*M_PI*frqc*i)/frqs; - hfir[i] = (hgain*sin(regv)*wfnc)/regv; - } - - ismd=OSRM/ISRM; - ismr=OSRM%ISRM; - - sptr = -(firodrv/ISRM); - sptrr = -(firodrv%ISRM); - eptr = firodrv/ISRM; - eptrr = firodrv%ISRM; - - ZeroMemory(smpld, sizeof(smpld)); - - winpos = 0; - iptr = 0; -} - -void Wavefs44(FILE *file, int size, unsigned char *buffer) -{ - if (winpos < WINSIZ) - { - if ((winpos + (size>>2)) < WINSIZ) - memcpy(&smpld[winpos], buffer, size); - else - { - memcpy(&smpld[winpos], buffer, (WINSIZ-winpos)<<2); - DownKernel(file); - memcpy(&smpld[WINSIZ], buffer+((WINSIZ-winpos)<<2), size-((WINSIZ-winpos)<<2)); - } - winpos += size>>2; - } - else - { - if ((winpos + (size>>2)) < (WINSIZ<<1)) - { - memcpy(&smpld[winpos], buffer, size); - winpos += size>>2; - } - else - { - memcpy(&smpld[winpos], buffer, ((WINSIZ<<1)-winpos)<<2); - DownKernel(file); - memcpy(&smpld[0], buffer+(((WINSIZ<<1)-winpos)<<2), size-(((WINSIZ<<1)-winpos)<<2)); - winpos += (size>>2) - (WINSIZ<<1); - } - } -} - -void EndSRC(FILE *file) -{ - int i; - - if (winpos < WINSIZ) - { - for (i=WINSIZ-1; i>=winpos; i--) - { - smpld[i].l = 0; - smpld[i].r = 0; - } - - DownKernel(file); - } - else - { - for (i=WINSIZ-1; i>=winpos; i--) - { - smpld[WINSIZ+i].l = 0; - smpld[WINSIZ+i].r = 0; - } - - DownKernel(file); - } -} - -bool CheckWAV() -{ - HMMIO hmmio; - MMCKINFO mmckinfoParent; - MMCKINFO mmckinfoSubchunk; - WAVEFORMATEX wfx; - - int FmtSize; - bool Error_Flag =false; - - hmmio = mmioOpen(szInput, NULL, MMIO_READ | MMIO_ALLOCBUF); - - mmckinfoParent.fccType = mmioFOURCC('W','A','V','E'); - if (mmioDescend(hmmio, (LPMMCKINFO) &mmckinfoParent, NULL, MMIO_FINDRIFF)) - Error_Flag = true; - - mmckinfoSubchunk.ckid = mmioFOURCC('f','m','t',' '); - if (mmioDescend(hmmio, &mmckinfoSubchunk, &mmckinfoParent, MMIO_FINDCHUNK)) - Error_Flag = true; - - FmtSize = mmckinfoSubchunk.cksize; - - if (mmioRead(hmmio, (HPSTR) &wfx, FmtSize) != FmtSize) - Error_Flag = true; - - if (wfx.wFormatTag!=WAVE_FORMAT_PCM || wfx.nChannels!=2 || wfx.nBlockAlign!=4 || - (wfx.nSamplesPerSec!=48000 && wfx.nSamplesPerSec!=44100)) - Error_Flag = true; - - mmioAscend(hmmio, &mmckinfoSubchunk, 0); - - mmckinfoSubchunk.ckid = mmioFOURCC('d','a','t','a'); - if (mmioDescend(hmmio, &mmckinfoSubchunk, &mmckinfoParent, MMIO_FINDCHUNK)) - Error_Flag = true; - - mmioClose(hmmio, 0); - - if (Error_Flag) - return false; - else - return true; -} - -void StartWAV(FILE *file, unsigned char format) -{ - int i; - - WAVEFORMATEX wfx; - - wfx.wFormatTag = WAVE_FORMAT_PCM; - wfx.nChannels = (format & 0x07) + 1; - if ((format & 0x30) == 0) - wfx.nSamplesPerSec = 48000; - else - wfx.nSamplesPerSec = 96000; - if ((format & 0xc0) == 0) - wfx.wBitsPerSample = 16; - else - wfx.wBitsPerSample = 24; - wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8; - wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; - - fwrite("RIFF", sizeof(FOURCC), 1, file); - - for (i=0; i<4; i++) - fputc(0, file); - - fwrite("WAVE", sizeof(FOURCC), 1, file); - - fwrite("fmt ", sizeof(FOURCC), 1, file); - - i = sizeof(WAVEFORMATEX) - sizeof(WORD); - fwrite(&i, sizeof(DWORD), 1, file); - - fwrite(&wfx, i, 1, file); - - fwrite("data", sizeof(FOURCC), 1, file); - - for (i=0; i<4; i++) - fputc(0, file); -} - -void CloseWAV(FILE *file, int size) -{ - fseek(file, 40, SEEK_SET); - fwrite(&size, sizeof(int), 1, file); - size += 36; - fseek(file, 4, SEEK_SET); - fwrite(&size, sizeof(int), 1, file); -} - -void DownWAV(FILE *file) -{ - int position = ftell(file); - - WAVEFORMATEX wfx; - - wfx.wFormatTag = WAVE_FORMAT_PCM; - wfx.nChannels = 2; - wfx.nSamplesPerSec = 44100; - wfx.wBitsPerSample = 16; - wfx.nBlockAlign = wfx.nChannels * wfx.wBitsPerSample / 8; - wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; - - fseek(file, 20, SEEK_SET); - fwrite(&wfx, sizeof(WAVEFORMATEX) - sizeof(WORD), 1, file); - fseek(file, position, SEEK_SET); -} - -static void DownKernel(FILE *file) -{ - int i, j, l; - - iptr += WINSIZ; - - while (iptr > eptr) - { - suml = 0; - sumr = 0; - j = -firodrv-sptrr; - - for (i=sptr; i<=eptr; i++, j+=ISRM) - { - l = j > 0 ? j : -j; - - spp = &smpld[i & ((WINSIZ<<1)-1)]; - hgain = hfir[l]; - suml += hgain * spp->l; - sumr += hgain * spp->r; - } - - smplo.l = SaturateRound(suml); - smplo.r = SaturateRound(sumr); - - if (Sound_Max < abs(smplo.l)) - Sound_Max = abs(smplo.l); - - if (Sound_Max < abs(smplo.r)) - Sound_Max = abs(smplo.r); - - fwrite(&smplo, sizeof(SmplData), 1, file); - - sptr += ismd; - sptrr += ismr; - if (sptrr>0) - { - sptrr -= ISRM; - sptr++; - } - - eptr += ismd; - eptrr += ismr; - if (eptrr>=ISRM) - { - eptrr -= ISRM; - eptr++; - } - } -} - -static double bessel0(double x) -{ - double value = 1.0, step = 1.0, part = x/2; - - while (part > 1.0E-10) - { - value += part*part; - step += 1.0; - part = (part*x)/(2.0*step); - } - - return value; -} diff --git a/src/dgdecode/getbit.cpp b/src/getbit.cpp similarity index 78% rename from src/dgdecode/getbit.cpp rename to src/getbit.cpp index 39c0dce..48ff81e 100644 --- a/src/dgdecode/getbit.cpp +++ b/src/getbit.cpp @@ -26,7 +26,7 @@ void CMPEG2Decoder::Initialize_Buffer() { Rdptr = Rdbfr + BUFFER_SIZE; Rdmax = Rdptr; - buffer_invalid = (uint8_t *)(UINTPTR_MAX); + buffer_invalid = (uint8_t*)(UINTPTR_MAX); if (SystemStream_Flag) { @@ -52,7 +52,7 @@ void CMPEG2Decoder::Initialize_Buffer() { Fill_Buffer(); - CurrentBfr = (*Rdptr << 24) + (*(Rdptr+1) << 16) + (*(Rdptr+2) << 8) + *(Rdptr+3); + CurrentBfr = (*Rdptr << 24) + (*(Rdptr + 1) << 16) + (*(Rdptr + 2) << 8) + *(Rdptr + 3); Rdptr += 4; Fill_Next(); @@ -62,7 +62,7 @@ void CMPEG2Decoder::Initialize_Buffer() } -struct transport_packet{ +struct transport_packet { // 1 byte uint8_t sync_byte; // 8 bslbf @@ -113,7 +113,7 @@ void CMPEG2Decoder::Next_Transport_Packet() int Packet_Length; // bytes remaining in MPEG-2 transport packet int Packet_Header_Length; uint32_t code; - transport_packet tp = {0}; + transport_packet tp = { 0 }; for (;;) { @@ -131,19 +131,19 @@ void CMPEG2Decoder::Next_Transport_Packet() } // 1) Search for a sync byte. Gives some protection against emulation. - for(;;) + for (;;) { if ((tp.sync_byte = Get_Byte()) != 0x47) continue; if (Rdptr - Rdbfr > TransportPacketSize) { - if (Rdptr[-(TransportPacketSize+1)] == 0x47) + if (Rdptr[-(TransportPacketSize + 1)] == 0x47) break; } - else if (Rdbfr + Read - Rdptr > TransportPacketSize - 1) + else if (Rdbfr + Read - Rdptr > TransportPacketSize - static_cast(1)) { - if (Rdptr[+(TransportPacketSize-1)] == 0x47) + if (Rdptr[+(TransportPacketSize - 1)] == 0x47) break; } else @@ -166,29 +166,29 @@ void CMPEG2Decoder::Next_Transport_Packet() code = Get_Byte(); --Packet_Length; // decrement the 1 byte we just got; tp.transport_scrambling_control = (code >> 6) & 0x03;// 2 bslbf - tp.adaptation_field_control = (code >> 4 ) & 0x03;// 2 bslbf + tp.adaptation_field_control = (code >> 4) & 0x03;// 2 bslbf tp.continuity_counter = code & 0x0F;// 4 uimsbf // 4) check for early-exit conditions ... (possibly skip packet) // we don't care about the continuity counter // if ( tp.continuity_counter != previous_continuity_counter ) ... - if ( tp.transport_error_indicator || - (tp.adaptation_field_control == 0) ) + if (tp.transport_error_indicator || + (tp.adaptation_field_control == 0)) { // skip remaining bytes in current packet - SKIP_TRANSPORT_PACKET_BYTES( Packet_Length ) - continue; // abort, and circle back to top of 'for() loop' + SKIP_TRANSPORT_PACKET_BYTES(Packet_Length) + continue; // abort, and circle back to top of 'for() loop' } // 5) check - if ( tp.adaptation_field_control == 2 || tp.adaptation_field_control == 3) + if (tp.adaptation_field_control == 2 || tp.adaptation_field_control == 3) { // adaptation field is present tp.adaptation_field_length = Get_Byte(); // 8-bits --Packet_Length; // decrement the 1 byte we just got; - if ( tp.adaptation_field_length != 0 ) // end of field already? + if (tp.adaptation_field_length != 0) // end of field already? { // if we made it this far, we no longer need to decrement // Packet_Length. We took care of it up there! @@ -204,56 +204,56 @@ void CMPEG2Decoder::Next_Transport_Packet() tp.adaptation_field_extension_flag = (code >> 0) & 0x01; // 1 bslbf // skip the remainder of the adaptation_field - SKIP_TRANSPORT_PACKET_BYTES( tp.adaptation_field_length-1 ) + SKIP_TRANSPORT_PACKET_BYTES(tp.adaptation_field_length - 1) } // if ( tp.adaptation_field_length != 0 ) } // if ( tp.adaptation_field_control != 1 ) // we've processed the header, so now just the payload is left... // video - if ( tp.pid == MPEG2_Transport_VideoPID && Packet_Length > 0) + if (tp.pid == MPEG2_Transport_VideoPID && Packet_Length > 0) { #if 0 code = Get_Short(); - code = (code & 0xffff)<<16 | Get_Short(); + code = (code & 0xffff) << 16 | Get_Short(); Packet_Length = Packet_Length - 4; // remove these two bytes // Packet start? - if (code < 0x000001E0 || code > 0x000001EF ) - if (!tp.payload_unit_start_indicator) - { - // No, move the buffer-pointer back. - Rdptr -= 4; - Packet_Length = Packet_Length + 4; // restore these four bytes - } - else -#endif - if (tp.payload_unit_start_indicator) - { - // YES, pull out PTS - //Get_Short(); - //Get_Short(); - //Get_Short(); // MPEG2-PES total Packet_Length - //Get_Byte(); // skip a byte - Rdptr += 7; - code = Get_Byte(); - Packet_Header_Length = Get_Byte(); - Packet_Length = Packet_Length - 9; // compensate the bytes we extracted - - // get PTS, and skip rest of PES-header - if (code>=0x80 && Packet_Header_Length > 4 ) // Extension_flag ? + if (code < 0x000001E0 || code > 0x000001EF) + if (!tp.payload_unit_start_indicator) { - // Skip PES_PTS - //Get_Short(); - //Get_Short(); - Rdptr += 4; - Get_Byte(); - Packet_Length = Packet_Length - 5; - SKIP_TRANSPORT_PACKET_BYTES( Packet_Header_Length-5 ) + // No, move the buffer-pointer back. + Rdptr -= 4; + Packet_Length = Packet_Length + 4; // restore these four bytes } else - SKIP_TRANSPORT_PACKET_BYTES( Packet_Header_Length ) - } +#endif + if (tp.payload_unit_start_indicator) + { + // YES, pull out PTS + //Get_Short(); + //Get_Short(); + //Get_Short(); // MPEG2-PES total Packet_Length + //Get_Byte(); // skip a byte + Rdptr += 7; + code = Get_Byte(); + Packet_Header_Length = Get_Byte(); + Packet_Length = Packet_Length - 9; // compensate the bytes we extracted + + // get PTS, and skip rest of PES-header + if (code >= 0x80 && Packet_Header_Length > 4) // Extension_flag ? + { + // Skip PES_PTS + //Get_Short(); + //Get_Short(); + Rdptr += 4; + Get_Byte(); + Packet_Length = Packet_Length - 5; + SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length - static_cast(5)) + } + else + SKIP_TRANSPORT_PACKET_BYTES(Packet_Header_Length) + } Rdmax = Rdptr + Packet_Length; if (TransportPacketSize == 204) Rdmax -= 16; @@ -262,7 +262,7 @@ void CMPEG2Decoder::Next_Transport_Packet() // fall through case // skip the remainder of the adaptation_field - SKIP_TRANSPORT_PACKET_BYTES( Packet_Length ) + SKIP_TRANSPORT_PACKET_BYTES(Packet_Length) } // for } @@ -329,7 +329,7 @@ void CMPEG2Decoder::Next_PVA_Packet() { // The spec is unclear about the significance of the prebytes field. // It appears to be safe to ignore it. - PTS = (int) ((Get_Byte() << 24) | (Get_Byte() << 16) | (Get_Byte() << 8) | Get_Byte()); + PTS = (int)((Get_Byte() << 24) | (Get_Byte() << 16) | (Get_Byte() << 8) | Get_Byte()); Packet_Length -= 4; } @@ -345,12 +345,12 @@ void CMPEG2Decoder::Next_PVA_Packet() void CMPEG2Decoder::Next_Packet() { - if ( SystemStream_Flag == 2 ) // MPEG-2 transport packet? + if (SystemStream_Flag == 2) // MPEG-2 transport packet? { Next_Transport_Packet(); return; } - else if ( SystemStream_Flag == 3 ) // PVA packet? + else if (SystemStream_Flag == 3) // PVA packet? { Next_PVA_Packet(); return; @@ -360,7 +360,7 @@ void CMPEG2Decoder::Next_Packet() static int stream_type; while (true) { code = Get_Short(); - code = (code<<16) + Get_Short(); + code = (code << 16) + Get_Short(); // remove system layer byte stuffing while ((code & 0xffffff00) != 0x00000100) { @@ -373,11 +373,13 @@ void CMPEG2Decoder::Next_Packet() if ((Get_Byte() & 0xf0) == 0x20) { Rdptr += 7; // MPEG1 program stream stream_type = MPEG1_PROGRAM_STREAM; - } else { + } + else { Rdptr += 8; // MPEG2 program stream stream_type = MPEG2_PROGRAM_STREAM; } - } else if ((code & 0xfffffff0) == VIDEO_ELEMENTARY_STREAM) { + } + else if ((code & 0xfffffff0) == VIDEO_ELEMENTARY_STREAM) { Packet_Length = Get_Short(); Rdmax = Rdptr + Packet_Length; @@ -400,7 +402,8 @@ void CMPEG2Decoder::Next_Packet() Get_Short(); Get_Short(); Packet_Header_Length += 4; - } else if ((code & 0xf0) == 0x30) { + } + else if ((code & 0xf0) == 0x30) { // PTS/DTS bytes. Get_Short(); Get_Short(); @@ -410,10 +413,11 @@ void CMPEG2Decoder::Next_Packet() Packet_Header_Length += 9; } return; - } else { + } + else { // MPEG2 program stream. code = Get_Byte(); - if ((code & 0xc0)==0x80) + if ((code & 0xc0) == 0x80) { //code = Get_Byte(); ++Rdptr; @@ -426,7 +430,7 @@ void CMPEG2Decoder::Next_Packet() Rdptr += Packet_Length - 1; } } - else if (code>=SYSTEM_START_CODE) + else if (code >= SYSTEM_START_CODE) { code = Get_Short(); Rdptr += code; @@ -438,9 +442,10 @@ void CMPEG2Decoder::Next_Packet() void CMPEG2Decoder::Next_File() { if (File_Flag < static_cast(Infile.size() - 1)) { - File_Flag ++; + File_Flag++; - } else { + } + else { File_Flag = 0; } // Even if we ran out of files, we reread the first one, just so @@ -448,9 +453,9 @@ void CMPEG2Decoder::Next_File() // fault flag and exits. _lseeki64(Infile[File_Flag], 0, SEEK_SET); int bytes = _read(Infile[File_Flag], Rdbfr + Read, BUFFER_SIZE - Read); - if (Read + bytes == BUFFER_SIZE) + if (Read + static_cast(bytes) == BUFFER_SIZE) // The whole buffer has valid data. - buffer_invalid = (uint8_t *)(UINTPTR_MAX); + buffer_invalid = (uint8_t*)(UINTPTR_MAX); else // Point to the first invalid buffer location. buffer_invalid = Rdbfr + Read + bytes; diff --git a/src/dgdecode/gethdr.cpp b/src/gethdr.cpp similarity index 81% rename from src/dgdecode/gethdr.cpp rename to src/gethdr.cpp index 7ff4f21..04db7fe 100644 --- a/src/dgdecode/gethdr.cpp +++ b/src/gethdr.cpp @@ -29,7 +29,7 @@ #include "MPEG2Decoder.h" -/* decode headers from one input stream */ + /* decode headers from one input stream */ int CMPEG2Decoder::Get_Hdr() { for (;;) @@ -86,17 +86,17 @@ __forceinline void CMPEG2Decoder::group_of_pictures_header() /* ISO/IEC 13818-2 section 6.2.3 */ inline void CMPEG2Decoder::picture_header() { - temporal_reference = Get_Bits(10); + temporal_reference = Get_Bits(10); picture_coding_type = Get_Bits(3); Flush_Buffer(16);//Get_Bits(16); //vbv_delay - if (picture_coding_type==P_TYPE || picture_coding_type==B_TYPE) + if (picture_coding_type == P_TYPE || picture_coding_type == B_TYPE) { full_pel_forward_vector = Get_Bits(1); forward_f_code = Get_Bits(3); } - if (picture_coding_type==B_TYPE) + if (picture_coding_type == B_TYPE) { full_pel_backward_vector = Get_Bits(1); backward_f_code = Get_Bits(3); @@ -127,43 +127,42 @@ void CMPEG2Decoder::Sequence_Header() int i; horizontal_size = Get_Bits(12); - vertical_size = Get_Bits(12); + vertical_size = Get_Bits(12); + aspect_ratio_information = Get_Bits(4); #if 0 - Get_Bits(4); //aspect_ratio_information Get_Bits(4); //frame_rate_code Get_Bits(18); //bit_rate_value Flush_Buffer(1); // marker bit Get_Bits(10); //vbv_buffer_size Get_Bits(1); //constrained_parameters_flag #else - Flush_Buffer(32); - Flush_Buffer(6); + Flush_Buffer(34); #endif - if (load_intra_quantizer_matrix = Get_Bits(1)) + if ((load_intra_quantizer_matrix = Get_Bits(1))) { - for (i=0; i<64; i++) + for (i = 0; i < 64; i++) intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8); } else { - for (i=0; i<64; i++) + for (i = 0; i < 64; i++) intra_quantizer_matrix[i] = default_intra_quantizer_matrix[i]; } - if (load_non_intra_quantizer_matrix = Get_Bits(1)) + if ((load_non_intra_quantizer_matrix = Get_Bits(1))) { - for (i=0; i<64; i++) + for (i = 0; i < 64; i++) non_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8); } else { - for (i=0; i<64; i++) + for (i = 0; i < 64; i++) non_intra_quantizer_matrix[i] = 16; } /* copy luminance to chrominance matrices */ - for (i=0; i<64; i++) + for (i = 0; i < 64; i++) { chroma_intra_quantizer_matrix[i] = intra_quantizer_matrix[i]; chroma_non_intra_quantizer_matrix[i] = non_intra_quantizer_matrix[i]; @@ -189,7 +188,7 @@ int CMPEG2Decoder::slice_header() int quantizer_scale_code = Get_Bits(5); if (mpeg_type == IS_MPEG2) - quantizer_scale = q_scale_type ? Non_Linear_quantizer_scale[quantizer_scale_code] : quantizer_scale_code<<1; + quantizer_scale = q_scale_type ? Non_Linear_quantizer_scale[quantizer_scale_code] : quantizer_scale_code << 1; else quantizer_scale = quantizer_scale_code; @@ -206,11 +205,11 @@ void CMPEG2Decoder::extension_and_user_data() Next_Start_Code(); - while ((code = Show_Bits(32))==EXTENSION_START_CODE || code==USER_DATA_START_CODE) + while ((code = Show_Bits(32)) == EXTENSION_START_CODE || code == USER_DATA_START_CODE) { if (Fault_Flag == OUT_OF_BITS) return; - if (code==EXTENSION_START_CODE) + if (code == EXTENSION_START_CODE) { Flush_Buffer(32); ext_ID = Get_Bits(4); @@ -256,10 +255,10 @@ void CMPEG2Decoder::extension_and_user_data() __forceinline void CMPEG2Decoder::sequence_extension() { Flush_Buffer(8); //Get_Bits(8); //profile_and_level_indication - progressive_sequence = Get_Bits(1); - chroma_format = Get_Bits(2); + progressive_sequence = Get_Bits(1); + chroma_format = Get_Bits(2); int horizontal_size_extension = Get_Bits(2) << 12; - int vertical_size_extension = Get_Bits(2) << 12; + int vertical_size_extension = Get_Bits(2) << 12; #if 0 Get_Bits(12); //bit_rate_extension Flush_Buffer(1); // marker bit @@ -304,22 +303,22 @@ void CMPEG2Decoder::quant_matrix_extension() { int i; - if (load_intra_quantizer_matrix = Get_Bits(1)) - for (i=0; i<64; i++) + if ((load_intra_quantizer_matrix = Get_Bits(1))) + for (i = 0; i < 64; i++) chroma_intra_quantizer_matrix[scan[ZIG_ZAG][i]] - = intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8); + = intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8); - if (load_non_intra_quantizer_matrix = Get_Bits(1)) - for (i=0; i<64; i++) + if ((load_non_intra_quantizer_matrix = Get_Bits(1))) + for (i = 0; i < 64; i++) chroma_non_intra_quantizer_matrix[scan[ZIG_ZAG][i]] - = non_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8); + = non_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8); - if (load_chroma_intra_quantizer_matrix = Get_Bits(1)) - for (i=0; i<64; i++) + if ((load_chroma_intra_quantizer_matrix = Get_Bits(1))) + for (i = 0; i < 64; i++) chroma_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8); - if (load_chroma_non_intra_quantizer_matrix = Get_Bits(1)) - for (i=0; i<64; i++) + if ((load_chroma_non_intra_quantizer_matrix = Get_Bits(1))) + for (i = 0; i < 64; i++) chroma_non_intra_quantizer_matrix[scan[ZIG_ZAG][i]] = Get_Bits(8); } @@ -336,7 +335,7 @@ void CMPEG2Decoder::picture_display_extension() /* based on ISO/IEC 13818-2 section 6.3.12 (November 1994) Picture display extensions */ - /* derive number_of_frame_center_offsets */ + /* derive number_of_frame_center_offsets */ if (progressive_sequence) { if (repeat_first_field) @@ -351,7 +350,7 @@ void CMPEG2Decoder::picture_display_extension() } else { - if (picture_structure!=FRAME_PICTURE) + if (picture_structure != FRAME_PICTURE) number_of_frame_center_offsets = 1; else { @@ -363,7 +362,7 @@ void CMPEG2Decoder::picture_display_extension() } /* now parse */ - for (i=0; i #include "global.h" @@ -71,12 +71,12 @@ void CMPEG2Decoder::Decode_Picture(YV12PICT& dst) void CMPEG2Decoder::update_picture_buffers() { int cc; /* color component index */ - uint8_t *tmp; /* temporary swap pointer */ + uint8_t* tmp; /* temporary swap pointer */ - for (cc=0; cc<3; cc++) + for (cc = 0; cc < 3; cc++) { /* B pictures do not need to be save for future reference */ - if (picture_coding_type==B_TYPE) + if (picture_coding_type == B_TYPE) { current_frame[cc] = auxframe[cc]; } @@ -102,8 +102,8 @@ void CMPEG2Decoder::update_picture_buffers() current_frame[cc] = backward_reference_frame[cc]; } - if (picture_structure==BOTTOM_FIELD) - current_frame[cc] += (cc==0) ? Coded_Picture_Width : Chroma_Width; + if (picture_structure == BOTTOM_FIELD) + current_frame[cc] += (cc == 0) ? Coded_Picture_Width : Chroma_Width; } } @@ -157,12 +157,12 @@ inline void CMPEG2Decoder::slice(int MBAmax, uint32_t code) int dc_dct_pred[3] = { 0 }; /* ISO/IEC 13818-2 section 7.6.3.4: Resetting motion vector predictors */ - int PMV[2][2][2] = { 0 }; + int PMV[2][2][2] = { { { 0 } } }; // Set up pointer for storing quants for info and showQ. int* qp = (picture_coding_type == B_TYPE) ? auxQP : backwardQP; if (picture_structure == BOTTOM_FIELD) - qp += mb_width*mb_height / 2; + qp += mb_width * mb_height / 2; // This while loop condition just prevents us from processing more than // the maximum number of macroblocks possible in a picture. The loop is @@ -186,8 +186,9 @@ inline void CMPEG2Decoder::slice(int MBAmax, uint32_t code) } if (MBAinc == 1) { decode_macroblock(macroblock_type, motion_type, dct_type, PMV, - dc_dct_pred, motion_vertical_field_select, dmvector); - } else { + dc_dct_pred, motion_vertical_field_select, dmvector); + } + else { /* ISO/IEC 13818-2 section 7.6.6 */ skipped_macroblock(dc_dct_pred, PMV, motion_type, motion_vertical_field_select, macroblock_type); } @@ -200,7 +201,7 @@ inline void CMPEG2Decoder::slice(int MBAmax, uint32_t code) /* ISO/IEC 13818-2 section 7.6 */ motion_compensation(MBA, macroblock_type, motion_type, PMV, - motion_vertical_field_select, dmvector, dct_type); + motion_vertical_field_select, dmvector, dct_type); /* advance to next macroblock */ ++MBA; @@ -210,8 +211,8 @@ inline void CMPEG2Decoder::slice(int MBAmax, uint32_t code) /* ISO/IEC 13818-2 section 6.3.17.1: Macroblock modes */ void CMPEG2Decoder::macroblock_modes(int& macroblock_type, int& motion_type, - int& motion_vector_count, int& mv_format, - int& dmv, int& mvscale, int& dct_type) + int& motion_vector_count, int& mv_format, + int& dmv, int& mvscale, int& dct_type) { /* get macroblock_type */ macroblock_type = Get_macroblock_type(); @@ -219,14 +220,16 @@ void CMPEG2Decoder::macroblock_modes(int& macroblock_type, int& motion_type, return; /* get frame/field motion type */ - if (macroblock_type & (MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD)) { + if (macroblock_type & (MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD)) { if (picture_structure == FRAME_PICTURE && frame_pred_frame_dct) motion_type = MC_FRAME; else motion_type = Get_Bits(2); - } else if (picture_structure == FRAME_PICTURE) { + } + else if (picture_structure == FRAME_PICTURE) { motion_type = MC_FRAME; - } else { + } + else { motion_type = MC_FIELD; } @@ -234,7 +237,8 @@ void CMPEG2Decoder::macroblock_modes(int& macroblock_type, int& motion_type, if (picture_structure == FRAME_PICTURE) { motion_vector_count = (motion_type == MC_FIELD) ? 2 : 1; mv_format = (motion_type == MC_FRAME) ? MV_FRAME : MV_FIELD; - } else { + } + else { motion_vector_count = (motion_type == MC_16X8) ? 2 : 1; mv_format = MV_FIELD; } @@ -248,8 +252,8 @@ void CMPEG2Decoder::macroblock_modes(int& macroblock_type, int& motion_type, mvscale = (mv_format == MV_FIELD && picture_structure == FRAME_PICTURE); /* get dct_type (frame DCT / field DCT) */ - dct_type = (picture_structure==FRAME_PICTURE) && (!frame_pred_frame_dct) - && (macroblock_type & (MACROBLOCK_PATTERN|MACROBLOCK_INTRA)) ? Get_Bits(1) : 0; + dct_type = (picture_structure == FRAME_PICTURE) && (!frame_pred_frame_dct) + && (macroblock_type & (MACROBLOCK_PATTERN | MACROBLOCK_INTRA)) ? Get_Bits(1) : 0; } /* move/add 8x8-Block from block[comp] to backward_reference_frame */ @@ -280,33 +284,38 @@ void CMPEG2Decoder::add_block(int count, int bx, int by, int dct_type, int addfl if (cc == 0) { if (picture_structure == FRAME_PICTURE) { if (dct_type) { - rfp = current_frame[0] + Coded_Picture_Width * (by + (comp & 2) / 2) + bx + (comp & 1) * 8; + rfp = current_frame[0] + Coded_Picture_Width * (by + (comp & 2) / static_cast(2)) + bx + (comp & static_cast(1)) * 8; iincr = Coded_Picture_Width * 2; - } else { - rfp = current_frame[0] + Coded_Picture_Width * (by + (comp & 2) * 4) + bx + (comp & 1) * 8; + } + else { + rfp = current_frame[0] + Coded_Picture_Width * (by + (comp & 2) * static_cast(4)) + bx + (comp & static_cast(1)) * 8; iincr = Coded_Picture_Width; } - } else { - rfp = current_frame[0] + (Coded_Picture_Width * 2) * (by + (comp & 2) * 4) + bx + (comp & 1) * 8; + } + else { + rfp = current_frame[0] + (Coded_Picture_Width * static_cast(2)) * (by + (comp & 2) * static_cast(4)) + bx + (comp & 1) * static_cast(8); iincr = Coded_Picture_Width * 2; } - } else { + } + else { if (chroma_format != CHROMA444) bxh /= 2; - if (chroma_format==CHROMA420) byh /= 2; + if (chroma_format == CHROMA420) byh /= 2; - if (picture_structure==FRAME_PICTURE) { + if (picture_structure == FRAME_PICTURE) { if (dct_type && chroma_format != CHROMA420) { /* field DCT coding */ - rfp = current_frame[cc] + Chroma_Width * (byh + (comp & 2) / 2) + bxh + (comp & 8); + rfp = current_frame[cc] + Chroma_Width * (byh + (comp & 2) / static_cast(2)) + bxh + (comp & 8); iincr = Chroma_Width * 2; - } else { + } + else { /* frame DCT coding */ - rfp = current_frame[cc] + Chroma_Width * (byh + (comp & 2) * 4) + bxh + (comp & 8); + rfp = current_frame[cc] + Chroma_Width * (byh + (comp & 2) * static_cast(4)) + bxh + (comp & 8); iincr = Chroma_Width; } - } else { + } + else { /* field picture */ - rfp = current_frame[cc] + (Chroma_Width * 2) * (byh + (comp & 2) * 4) + bxh + (comp & 8); + rfp = current_frame[cc] + (Chroma_Width * static_cast(2)) * (byh + (comp & 2) * static_cast(4)) + bxh + (comp & 8); iincr = Chroma_Width * 2; } } @@ -358,7 +367,8 @@ void CMPEG2Decoder::add_block(int count, int bx, int by, int dct_type, int addfl _mm_storel_epi64(reinterpret_cast<__m128i*>(rfp), _mm_packus_epi16(r0, r0)); _mm_storel_epi64(reinterpret_cast<__m128i*>(rfp1), _mm_packus_epi16(r1, r1)); - } else { + } + else { r0 = _mm_load_si128(reinterpret_cast(blockp)); r1 = _mm_load_si128(reinterpret_cast(blockp + 8)); r0 = _mm_add_epi8(_mm_packs_epi16(r0, r1), mask); @@ -413,15 +423,15 @@ void CMPEG2Decoder::clear_block(int count) /* ISO/IEC 13818-2 section 7.6 */ void CMPEG2Decoder::motion_compensation(int MBA, int macroblock_type, int motion_type, - int PMV[2][2][2], int motion_vertical_field_select[2][2], - int dmvector[2], int dct_type) + int PMV[2][2][2], int motion_vertical_field_select[2][2], + int dmvector[2], int dct_type) { prefetchTables(); /* derive current macroblock position within picture */ /* ISO/IEC 13818-2 section 6.3.1.6 and 6.3.1.7 */ - int bx = 16*(MBA%mb_width); - int by = 16*(MBA/mb_width); + int bx = 16 * (MBA % mb_width); + int by = 16 * (MBA / mb_width); /* motion compensation */ if (!(macroblock_type & MACROBLOCK_INTRA)) @@ -435,24 +445,24 @@ void CMPEG2Decoder::motion_compensation(int MBA, int macroblock_type, int motion } idctFunction(block[block_count - 1]); - add_block(block_count, bx, by, dct_type, (macroblock_type & MACROBLOCK_INTRA)==0); + add_block(block_count, bx, by, dct_type, (macroblock_type & MACROBLOCK_INTRA) == 0); } /* ISO/IEC 13818-2 section 7.6.6 */ void CMPEG2Decoder::skipped_macroblock(int dc_dct_pred[3], int PMV[2][2][2], int& motion_type, - int motion_vertical_field_select[2][2], int& macroblock_type) + int motion_vertical_field_select[2][2], int& macroblock_type) { clear_block(block_count); /* reset intra_dc predictors */ /* ISO/IEC 13818-2 section 7.2.1: DC coefficients in intra blocks */ - dc_dct_pred[0] = dc_dct_pred[1] = dc_dct_pred[2]=0; + dc_dct_pred[0] = dc_dct_pred[1] = dc_dct_pred[2] = 0; /* reset motion vector predictors */ /* ISO/IEC 13818-2 section 7.6.3.4: Resetting motion vector predictors */ if (picture_coding_type == P_TYPE) - PMV[0][0][0]=PMV[0][0][1]=PMV[1][0][0]=PMV[1][0][1]=0; + PMV[0][0][0] = PMV[0][0][1] = PMV[1][0][0] = PMV[1][0][1] = 0; /* derive motion_type */ if (picture_structure == FRAME_PICTURE) @@ -476,15 +486,15 @@ void CMPEG2Decoder::skipped_macroblock(int dc_dct_pred[3], int PMV[2][2][2], int /* ISO/IEC 13818-2 sections 7.2 through 7.5 */ void CMPEG2Decoder::decode_macroblock(int& macroblock_type, int& motion_type, int& dct_type, - int PMV[2][2][2], int dc_dct_pred[3], - int motion_vertical_field_select[2][2], int dmvector[2]) + int PMV[2][2][2], int dc_dct_pred[3], + int motion_vertical_field_select[2][2], int dmvector[2]) { int quantizer_scale_code, comp, motion_vector_count, mv_format; int dmv, mvscale, coded_block_pattern; /* ISO/IEC 13818-2 section 6.3.17.1: Macroblock modes */ macroblock_modes(macroblock_type, motion_type, motion_vector_count, mv_format, - dmv, mvscale, dct_type); + dmv, mvscale, dct_type); if (Fault_Flag) { return; // go to next slice @@ -514,11 +524,11 @@ void CMPEG2Decoder::decode_macroblock(int& macroblock_type, int& motion_type, in if (mpeg_type == IS_MPEG2) { motion_vectors(PMV, dmvector, motion_vertical_field_select, 0, - motion_vector_count, mv_format, f_code[0][0]-1, f_code[0][1]-1, dmv, mvscale); + motion_vector_count, mv_format, f_code[0][0] - 1, f_code[0][1] - 1, dmv, mvscale); } else { - motion_vector(PMV[0][0], dmvector, forward_f_code-1, forward_f_code-1, dmv, mvscale, full_pel_forward_vector); + motion_vector(PMV[0][0], dmvector, forward_f_code - 1, forward_f_code - 1, dmv, mvscale, full_pel_forward_vector); } } if (Fault_Flag) @@ -532,11 +542,11 @@ void CMPEG2Decoder::decode_macroblock(int& macroblock_type, int& motion_type, in if (mpeg_type == IS_MPEG2) { motion_vectors(PMV, dmvector, motion_vertical_field_select, 1, - motion_vector_count,mv_format, f_code[1][0]-1, f_code[1][1]-1, 0, mvscale); + motion_vector_count, mv_format, f_code[1][0] - 1, f_code[1][1] - 1, 0, mvscale); } else { - motion_vector(PMV[0][1], dmvector, backward_f_code-1, backward_f_code-1, dmv, mvscale, full_pel_backward_vector); + motion_vector(PMV[0][1], dmvector, backward_f_code - 1, backward_f_code - 1, dmv, mvscale, full_pel_backward_vector); } } if (Fault_Flag) @@ -553,13 +563,13 @@ void CMPEG2Decoder::decode_macroblock(int& macroblock_type, int& motion_type, in { coded_block_pattern = Get_coded_block_pattern(); - if (chroma_format==CHROMA422) - coded_block_pattern = (coded_block_pattern<<2) | Get_Bits(2); - else if (chroma_format==CHROMA444) - coded_block_pattern = (coded_block_pattern<<6) | Get_Bits(6); + if (chroma_format == CHROMA422) + coded_block_pattern = (coded_block_pattern << 2) | Get_Bits(2); + else if (chroma_format == CHROMA444) + coded_block_pattern = (coded_block_pattern << 6) | Get_Bits(6); } else - coded_block_pattern = (macroblock_type & MACROBLOCK_INTRA) ? (1<=16384) - tab = &DCTtabnext[(code>>12)-4]; + if (code >= 16384) + tab = &DCTtabnext[(code >> 12) - 4]; else if (code >= 1024) - tab = &DCTtab0[(code>>8)-4]; + tab = &DCTtab0[(code >> 8) - 4]; else if (code >= 512) - tab = &DCTtab1[(code>>6)-8]; + tab = &DCTtab1[(code >> 6) - 8]; else if (code >= 256) - tab = &DCTtab2[(code>>4)-16]; + tab = &DCTtab2[(code >> 4) - 16]; else if (code >= 128) - tab = &DCTtab3[(code>>3)-16]; + tab = &DCTtab3[(code >> 3) - 16]; else if (code >= 64) - tab = &DCTtab4[(code>>2)-16]; + tab = &DCTtab4[(code >> 2) - 16]; else if (code >= 32) - tab = &DCTtab5[(code>>1)-16]; + tab = &DCTtab5[(code >> 1) - 16]; else if (code >= 16) - tab = &DCTtab6[code-16]; + tab = &DCTtab6[code - 16]; else { Fault_Flag = 1; @@ -694,7 +704,7 @@ void CMPEG2Decoder::decode_mpeg1_intra_block(int comp, int dc_dct_pred[]) if (val == 65) { // escape - i+= Get_Bits(6); + i += Get_Bits(6); val = Get_Bits(8); if (val == 0) val = Get_Bits(8); @@ -704,7 +714,7 @@ void CMPEG2Decoder::decode_mpeg1_intra_block(int comp, int dc_dct_pred[]) val -= 256; sign = (val < 0); if (sign) - val = - val; + val = -val; } else { @@ -727,45 +737,45 @@ void CMPEG2Decoder::decode_mpeg1_intra_block(int comp, int dc_dct_pred[]) if (val >= 2048) val = 2047 + sign; // saturation if (sign) val = -val; - bp[j] = (int16_t) val; + bp[j] = (int16_t)val; } } /* decode one non-intra coded MPEG-1 block */ void CMPEG2Decoder::decode_mpeg1_non_intra_block(int comp) { - int32_t code, val=0, i, j, sign; - const DCTtab *tab; - int16_t *bp; + int32_t code, val = 0, i, j, sign; + const DCTtab* tab; + int16_t* bp; bp = block[comp]; /* decode AC coefficients */ - for (i=0; ; i++) + for (i = 0; ; i++) { code = Show_Bits(16); if (code >= 16384) { if (i) - tab = &DCTtabnext[(code>>12)-4]; + tab = &DCTtabnext[(code >> 12) - 4]; else - tab = &DCTtabfirst[(code>>12)-4]; + tab = &DCTtabfirst[(code >> 12) - 4]; } else if (code >= 1024) - tab = &DCTtab0[(code>>8)-4]; + tab = &DCTtab0[(code >> 8) - 4]; else if (code >= 512) - tab = &DCTtab1[(code>>6)-8]; + tab = &DCTtab1[(code >> 6) - 8]; else if (code >= 256) - tab = &DCTtab2[(code>>4)-16]; + tab = &DCTtab2[(code >> 4) - 16]; else if (code >= 128) - tab = &DCTtab3[(code>>3)-16]; + tab = &DCTtab3[(code >> 3) - 16]; else if (code >= 64) - tab = &DCTtab4[(code>>2)-16]; + tab = &DCTtab4[(code >> 2) - 16]; else if (code >= 32) - tab = &DCTtab5[(code>>1)-16]; + tab = &DCTtab5[(code >> 1) - 16]; else if (code >= 16) - tab = &DCTtab6[code-16]; + tab = &DCTtab6[code - 16]; else { Fault_Flag = 1; @@ -778,7 +788,7 @@ void CMPEG2Decoder::decode_mpeg1_non_intra_block(int comp) if (val == 65) { // escape - i+= Get_Bits(6); + i += Get_Bits(6); val = Get_Bits(8); if (val == 0) val = Get_Bits(8); @@ -787,9 +797,9 @@ void CMPEG2Decoder::decode_mpeg1_non_intra_block(int comp) else if (val > 128) val -= 256; - sign = (val<0); + sign = (val < 0); if (sign) - val = - val; + val = -val; } else { @@ -806,14 +816,14 @@ void CMPEG2Decoder::decode_mpeg1_non_intra_block(int comp) } j = scan[0][i]; - val = (((val<<1)+1) * quantizer_scale * non_intra_quantizer_matrix[j]) >> 4; + val = (((val << 1) + 1) * quantizer_scale * non_intra_quantizer_matrix[j]) >> 4; if (val) val = (val - 1) | 1; // mismatch if (val >= 2048) val = 2047 + sign; //saturation if (sign) val = -val; - bp[j] = (int16_t) val; + bp[j] = (int16_t)val; } } @@ -821,12 +831,12 @@ void CMPEG2Decoder::decode_mpeg1_non_intra_block(int comp) void CMPEG2Decoder::Decode_MPEG2_Intra_Block(int comp, int dc_dct_pred[]) { int32_t code, val = 0, i, j, sign, sum; - const DCTtab *tab; - int16_t *bp; - int *qmat; + const DCTtab* tab; + int16_t* bp; + int* qmat; bp = block[comp]; - qmat = (comp<4 || chroma_format==CHROMA420) + qmat = (comp < 4 || chroma_format == CHROMA420) ? intra_quantizer_matrix : chroma_intra_quantizer_matrix; /* ISO/IEC 13818-2 section 7.2.1: decode DC coefficients */ @@ -846,44 +856,44 @@ void CMPEG2Decoder::Decode_MPEG2_Intra_Block(int comp, int dc_dct_pred[]) } sum = val << (3 - intra_dc_precision); - bp[0] = (int16_t) sum; + bp[0] = (int16_t)sum; /* decode AC coefficients */ - for (i=1; ; i++) + for (i = 1; ; i++) { code = Show_Bits(16); if (code >= 16384) { if (intra_vlc_format) - tab = &DCTtab0a[(code>>8)-4]; + tab = &DCTtab0a[(code >> 8) - 4]; else - tab = &DCTtabnext[(code>>12)-4]; + tab = &DCTtabnext[(code >> 12) - 4]; } else if (code >= 1024) { if (intra_vlc_format) - tab = &DCTtab0a[(code>>8)-4]; + tab = &DCTtab0a[(code >> 8) - 4]; else - tab = &DCTtab0[(code>>8)-4]; + tab = &DCTtab0[(code >> 8) - 4]; } else if (code >= 512) { if (intra_vlc_format) - tab = &DCTtab1a[(code>>6)-8]; + tab = &DCTtab1a[(code >> 6) - 8]; else - tab = &DCTtab1[(code>>6)-8]; + tab = &DCTtab1[(code >> 6) - 8]; } else if (code >= 256) - tab = &DCTtab2[(code>>4)-16]; + tab = &DCTtab2[(code >> 4) - 16]; else if (code >= 128) - tab = &DCTtab3[(code>>3)-16]; + tab = &DCTtab3[(code >> 3) - 16]; else if (code >= 64) - tab = &DCTtab4[(code>>2)-16]; + tab = &DCTtab4[(code >> 2) - 16]; else if (code >= 32) - tab = &DCTtab5[(code>>1)-16]; + tab = &DCTtab5[(code >> 1) - 16]; else if (code >= 16) - tab = &DCTtab6[code-16]; + tab = &DCTtab6[code - 16]; else { Fault_Flag = 1; @@ -896,7 +906,7 @@ void CMPEG2Decoder::Decode_MPEG2_Intra_Block(int comp, int dc_dct_pred[]) if (val == 65) { // escape - i+= Get_Bits(6); + i += Get_Bits(6); val = Get_Bits(12); if (!(val & 2047)) { @@ -911,7 +921,7 @@ void CMPEG2Decoder::Decode_MPEG2_Intra_Block(int comp, int dc_dct_pred[]) { if (val == 64) break; - i+= val; + i += val; val = tab->level; sign = Get_Bits(1); } @@ -926,7 +936,7 @@ void CMPEG2Decoder::Decode_MPEG2_Intra_Block(int comp, int dc_dct_pred[]) val = 2047 + sign; // saturation if (sign) val = -val; - bp[j] = (int16_t) val; + bp[j] = (int16_t)val; sum ^= val; // mismatch } @@ -938,41 +948,41 @@ void CMPEG2Decoder::Decode_MPEG2_Intra_Block(int comp, int dc_dct_pred[]) void CMPEG2Decoder::Decode_MPEG2_Non_Intra_Block(int comp) { int32_t code, val = 0, i, j, sign, sum; - const DCTtab *tab; - int16_t *bp; - int *qmat; + const DCTtab* tab; + int16_t* bp; + int* qmat; bp = block[comp]; - qmat = (comp<4 || chroma_format==CHROMA420) + qmat = (comp < 4 || chroma_format == CHROMA420) ? non_intra_quantizer_matrix : chroma_non_intra_quantizer_matrix; /* decode AC coefficients */ sum = 0; - for (i=0; ; i++) + for (i = 0; ; i++) { code = Show_Bits(16); if (code >= 16384) { if (i) - tab = &DCTtabnext[(code>>12)-4]; + tab = &DCTtabnext[(code >> 12) - 4]; else - tab = &DCTtabfirst[(code>>12)-4]; + tab = &DCTtabfirst[(code >> 12) - 4]; } else if (code >= 1024) - tab = &DCTtab0[(code>>8)-4]; + tab = &DCTtab0[(code >> 8) - 4]; else if (code >= 512) - tab = &DCTtab1[(code>>6)-8]; + tab = &DCTtab1[(code >> 6) - 8]; else if (code >= 256) - tab = &DCTtab2[(code>>4)-16]; + tab = &DCTtab2[(code >> 4) - 16]; else if (code >= 128) - tab = &DCTtab3[(code>>3)-16]; + tab = &DCTtab3[(code >> 3) - 16]; else if (code >= 64) - tab = &DCTtab4[(code>>2)-16]; + tab = &DCTtab4[(code >> 2) - 16]; else if (code >= 32) - tab = &DCTtab5[(code>>1)-16]; + tab = &DCTtab5[(code >> 1) - 16]; else if (code >= 16) - tab = &DCTtab6[code-16]; + tab = &DCTtab6[code - 16]; else { Fault_Flag = 1; @@ -985,7 +995,7 @@ void CMPEG2Decoder::Decode_MPEG2_Non_Intra_Block(int comp) if (val == 65) { // escape - i+= Get_Bits(6); + i += Get_Bits(6); val = Get_Bits(12); if (!(val & 2047)) { @@ -1000,7 +1010,7 @@ void CMPEG2Decoder::Decode_MPEG2_Non_Intra_Block(int comp) { if (val == 64) break; - i+= val; + i += val; val = tab->level; sign = Get_Bits(1); } @@ -1011,12 +1021,12 @@ void CMPEG2Decoder::Decode_MPEG2_Non_Intra_Block(int comp) } j = scan[alternate_scan][i]; - val = (((val<<1)+1) * quantizer_scale * qmat[j]) >> 5; + val = (((val << 1) + 1) * quantizer_scale * qmat[j]) >> 5; if (val >= 2048) val = 2047 + sign; // saturation if (sign) val = -val; - bp[j] = (int16_t) val; + bp[j] = (int16_t)val; sum ^= val; // mismatch } @@ -1164,7 +1174,7 @@ int CMPEG2Decoder::Get_macroblock_address_increment() if (code == 8) { /* macroblock_escape */ - val+= 33; + val += 33; } else if (code == 0) { @@ -1226,7 +1236,7 @@ int CMPEG2Decoder::Get_Luma_DC_dct_diff() /* decode length */ code = Show_Bits(5); - if (code<31) + if (code < 31) { size = DClumtab0[code].val; Flush_Buffer(DClumtab0[code].len); @@ -1238,14 +1248,14 @@ int CMPEG2Decoder::Get_Luma_DC_dct_diff() Flush_Buffer(DClumtab1[code].len); } - if (size==0) + if (size == 0) dct_diff = 0; else { dct_diff = Get_Bits(size); - if ((dct_diff & (1<<(size-1)))==0) - dct_diff-= (1<>1, PMV[0][0][0], PMV[0][0][1]>>1, stw); + current_frame, 0, Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8, + bx, by >> 1, PMV[0][0][0], PMV[0][0][1] >> 1, stw); /* bottom field prediction */ form_prediction(forward_reference_frame, motion_vertical_field_select[1][0], - current_frame, 1, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, - bx, by>>1, PMV[1][0][0], PMV[1][0][1]>>1, stw); + current_frame, 1, Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8, + bx, by >> 1, PMV[1][0][0], PMV[1][0][1] >> 1, stw); } - else if (motion_type==MC_DMV) /* dual prime prediction */ + else if (motion_type == MC_DMV) /* dual prime prediction */ { /* calculate derived motion vectors */ - Dual_Prime_Arithmetic(DMV, dmvector, PMV[0][0][0], PMV[0][0][1]>>1); + Dual_Prime_Arithmetic(DMV, dmvector, PMV[0][0][0], PMV[0][0][1] >> 1); /* predict top field from top field */ form_prediction(forward_reference_frame, 0, current_frame, 0, - Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, bx, by>>1, - PMV[0][0][0], PMV[0][0][1]>>1, 0); + Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8, bx, by >> 1, + PMV[0][0][0], PMV[0][0][1] >> 1, 0); /* predict and add to top field from bottom field */ form_prediction(forward_reference_frame, 1, current_frame, 0, - Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, bx, by>>1, + Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8, bx, by >> 1, DMV[0][0], DMV[0][1], 1); /* predict bottom field from bottom field */ form_prediction(forward_reference_frame, 1, current_frame, 1, - Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, bx, by>>1, - PMV[0][0][0], PMV[0][0][1]>>1, 0); + Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8, bx, by >> 1, + PMV[0][0][0], PMV[0][0][1] >> 1, 0); /* predict and add to bottom field from top field */ form_prediction(forward_reference_frame, 0, current_frame, 1, - Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, bx, by>>1, + Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8, bx, by >> 1, DMV[1][0], DMV[1][1], 1); } } else { /* field picture */ - currentfield = (picture_structure==BOTTOM_FIELD); + currentfield = (picture_structure == BOTTOM_FIELD); /* determine which frame to use for prediction */ - if (picture_coding_type==P_TYPE && Second_Field && currentfield!=motion_vertical_field_select[0][0]) + if (picture_coding_type == P_TYPE && Second_Field && currentfield != motion_vertical_field_select[0][0]) predframe = backward_reference_frame; else predframe = forward_reference_frame; - if ((motion_type==MC_FIELD) || !(macroblock_type & MACROBLOCK_MOTION_FORWARD)) + if ((motion_type == MC_FIELD) || !(macroblock_type & MACROBLOCK_MOTION_FORWARD)) { form_prediction(predframe, motion_vertical_field_select[0][0], current_frame, 0, - Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 16, bx, by, + Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 16, bx, by, PMV[0][0][0], PMV[0][0][1], stw); } - else if (motion_type==MC_16X8) + else if (motion_type == MC_16X8) { form_prediction(predframe, motion_vertical_field_select[0][0], current_frame, 0, - Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, bx, by, + Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8, bx, by, PMV[0][0][0], PMV[0][0][1], stw); - if (picture_coding_type==P_TYPE && Second_Field && currentfield!=motion_vertical_field_select[1][0]) + if (picture_coding_type == P_TYPE && Second_Field && currentfield != motion_vertical_field_select[1][0]) predframe = backward_reference_frame; else predframe = forward_reference_frame; form_prediction(predframe, motion_vertical_field_select[1][0], current_frame, - 0, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, bx, by+8, + 0, Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8, bx, by + 8, PMV[1][0][0], PMV[1][0][1], stw); } - else if (motion_type==MC_DMV) + else if (motion_type == MC_DMV) { if (Second_Field) predframe = backward_reference_frame; @@ -1399,12 +1409,12 @@ void CMPEG2Decoder::form_predictions(int bx, int by, int macroblock_type, int mo /* predict from field of same parity */ form_prediction(forward_reference_frame, currentfield, current_frame, 0, - Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 16, bx, by, + Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 16, bx, by, PMV[0][0][0], PMV[0][0][1], 0); /* predict from field of opposite parity */ form_prediction(predframe, !currentfield, current_frame, 0, - Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 16, bx, by, + Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 16, bx, by, DMV[0][0], DMV[0][1], 1); } } @@ -1414,108 +1424,108 @@ void CMPEG2Decoder::form_predictions(int bx, int by, int macroblock_type, int mo if (macroblock_type & MACROBLOCK_MOTION_BACKWARD) { - if (picture_structure==FRAME_PICTURE) + if (picture_structure == FRAME_PICTURE) { - if (motion_type==MC_FRAME) + if (motion_type == MC_FRAME) { /* frame-based prediction */ form_prediction(backward_reference_frame, 0, current_frame, 0, - Coded_Picture_Width, Coded_Picture_Width<<1, 16, 8, bx, by, + Coded_Picture_Width, Coded_Picture_Width << 1, 16, 8, bx, by, PMV[0][1][0], PMV[0][1][1], stw); form_prediction(backward_reference_frame, 1, current_frame, 1, - Coded_Picture_Width, Coded_Picture_Width<<1, 16, 8, bx, by, + Coded_Picture_Width, Coded_Picture_Width << 1, 16, 8, bx, by, PMV[0][1][0], PMV[0][1][1], stw); } else /* field-based prediction */ { /* top field prediction */ form_prediction(backward_reference_frame, motion_vertical_field_select[0][1], - current_frame, 0, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, - bx, by>>1, PMV[0][1][0], PMV[0][1][1]>>1, stw); + current_frame, 0, Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8, + bx, by >> 1, PMV[0][1][0], PMV[0][1][1] >> 1, stw); /* bottom field prediction */ form_prediction(backward_reference_frame, motion_vertical_field_select[1][1], - current_frame, 1, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, - bx, by>>1, PMV[1][1][0], PMV[1][1][1]>>1, stw); + current_frame, 1, Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8, + bx, by >> 1, PMV[1][1][0], PMV[1][1][1] >> 1, stw); } } else { /* field picture */ - if (motion_type==MC_FIELD) + if (motion_type == MC_FIELD) { /* field-based prediction */ form_prediction(backward_reference_frame, motion_vertical_field_select[0][1], - current_frame, 0, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 16, + current_frame, 0, Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 16, bx, by, PMV[0][1][0], PMV[0][1][1], stw); } - else if (motion_type==MC_16X8) + else if (motion_type == MC_16X8) { form_prediction(backward_reference_frame, motion_vertical_field_select[0][1], - current_frame, 0, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, + current_frame, 0, Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8, bx, by, PMV[0][1][0], PMV[0][1][1], stw); form_prediction(backward_reference_frame, motion_vertical_field_select[1][1], - current_frame, 0, Coded_Picture_Width<<1, Coded_Picture_Width<<1, 16, 8, - bx, by+8, PMV[1][1][0], PMV[1][1][1], stw); + current_frame, 0, Coded_Picture_Width << 1, Coded_Picture_Width << 1, 16, 8, + bx, by + 8, PMV[1][1][0], PMV[1][1][1], stw); } } } } // Minor rewrite to use the function pointer array - Vlad59 04-20-2002 -void CMPEG2Decoder::form_prediction(uint8_t *src[], int sfield, uint8_t *dst[], - int dfield, int lx, int lx2, int w, int h, int x, int y, - int dx, int dy, int average_flag) +void CMPEG2Decoder::form_prediction(uint8_t* src[], int sfield, uint8_t* dst[], + int dfield, int lx, int lx2, int w, int h, int x, int y, + int dx, int dy, int average_flag) { - if ( y+(dy>>1) < 0 ) + if (y + (dy >> 1) < 0) { return; } - uint8_t *s = (src[0]+(sfield?lx2>>1:0)) + lx * (y + (dy>>1)) + x + (dx>>1); - uint8_t *d = (dst[0]+(dfield?lx2>>1:0)) + lx * y + x; - int flag = ((dx & 1)<<1) + (dy & 1); + uint8_t* s = (src[0] + (sfield ? lx2 >> 1 : 0)) + lx * (static_cast(y) + (dy >> 1)) + x + (dx >> 1); + uint8_t* d = (dst[0] + (dfield ? lx2 >> 1 : 0)) + lx * static_cast(y) + x; + int flag = ((dx & 1) << 1) + (dy & 1); - ppppf_motion[average_flag][w>>4][flag] (d, s, lx2, lx, h); + ppppf_motion[average_flag][w >> 4][flag](d, s, lx2, lx, h); - if (chroma_format!=CHROMA444) + if (chroma_format != CHROMA444) { - lx>>=1; lx2>>=1; w>>=1; x>>=1; dx/=2; + lx >>= 1; lx2 >>= 1; w >>= 1; x >>= 1; dx /= 2; } - if (chroma_format==CHROMA420) + if (chroma_format == CHROMA420) { - h>>=1; y>>=1; dy/=2; + h >>= 1; y >>= 1; dy /= 2; } /* Cb */ - s = (src[1]+(sfield?lx2>>1:0)) + lx * (y + (dy>>1)) + x + (dx>>1); - d = (dst[1]+(dfield?lx2>>1:0)) + lx * y + x; - flag = ((dx & 1)<<1) + (dy & 1); - ppppf_motion[average_flag][w>>4][flag] (d, s, lx2, lx, h); + s = (src[1] + (sfield ? lx2 >> 1 : 0)) + lx * (static_cast(y) + (dy >> 1)) + x + (dx >> 1); + d = (dst[1] + (dfield ? lx2 >> 1 : 0)) + lx * static_cast(y) + x; + flag = ((dx & 1) << 1) + (dy & 1); + ppppf_motion[average_flag][w >> 4][flag](d, s, lx2, lx, h); /* Cr */ - s = (src[2]+(sfield?lx2>>1:0)) + lx * (y + (dy>>1)) + x + (dx>>1); - d = (dst[2]+(dfield?lx2>>1:0)) + lx * y + x; - ppppf_motion[average_flag][w>>4][flag] (d, s, lx2, lx, h); + s = (src[2] + (sfield ? lx2 >> 1 : 0)) + lx * (static_cast(y) + (dy >> 1)) + x + (dx >> 1); + d = (dst[2] + (dfield ? lx2 >> 1 : 0)) + lx * static_cast(y) + x; + ppppf_motion[average_flag][w >> 4][flag](d, s, lx2, lx, h); } /* ISO/IEC 13818-2 sections 6.2.5.2, 6.3.17.2, and 7.6.3: Motion vectors */ -void CMPEG2Decoder::motion_vectors(int PMV[2][2][2],int dmvector[2], +void CMPEG2Decoder::motion_vectors(int PMV[2][2][2], int dmvector[2], int motion_vertical_field_select[2][2], int s, int motion_vector_count, int mv_format, int h_r_size, int v_r_size, int dmv, int mvscale) { - if (motion_vector_count==1) + if (motion_vector_count == 1) { - if (mv_format==MV_FIELD && !dmv) + if (mv_format == MV_FIELD && !dmv) motion_vertical_field_select[1][s] = motion_vertical_field_select[0][s] = Get_Bits(1); - motion_vector(PMV[0][s],dmvector,h_r_size,v_r_size,dmv,mvscale,0); + motion_vector(PMV[0][s], dmvector, h_r_size, v_r_size, dmv, mvscale, 0); /* update other motion vector predictors */ PMV[1][s][0] = PMV[0][s][0]; @@ -1524,47 +1534,47 @@ void CMPEG2Decoder::motion_vectors(int PMV[2][2][2],int dmvector[2], else { motion_vertical_field_select[0][s] = Get_Bits(1); - motion_vector(PMV[0][s],dmvector,h_r_size,v_r_size,dmv,mvscale,0); + motion_vector(PMV[0][s], dmvector, h_r_size, v_r_size, dmv, mvscale, 0); motion_vertical_field_select[1][s] = Get_Bits(1); - motion_vector(PMV[1][s],dmvector,h_r_size,v_r_size,dmv,mvscale,0); + motion_vector(PMV[1][s], dmvector, h_r_size, v_r_size, dmv, mvscale, 0); } } /* ISO/IEC 13818-2 section 7.6.3.6: Dual prime additional arithmetic */ -void CMPEG2Decoder::Dual_Prime_Arithmetic(int DMV[][2],int *dmvector, int mvx,int mvy) +void CMPEG2Decoder::Dual_Prime_Arithmetic(int DMV[][2], int* dmvector, int mvx, int mvy) { - if (picture_structure==FRAME_PICTURE) + if (picture_structure == FRAME_PICTURE) { if (top_field_first) { /* 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; + 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; + 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; + 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; + 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]; + DMV[0][0] = ((mvx + (mvx > 0)) >> 1) + dmvector[0]; + DMV[0][1] = ((mvy + (mvy > 0)) >> 1) + dmvector[1]; /* correct for vertical field shift */ - if (picture_structure==TOP_FIELD) + if (picture_structure == TOP_FIELD) DMV[0][1]--; else DMV[0][1]++; @@ -1572,7 +1582,7 @@ void CMPEG2Decoder::Dual_Prime_Arithmetic(int DMV[][2],int *dmvector, int mvx,in } /* get and decode motion vector and differential motion vector for one prediction */ -void CMPEG2Decoder::motion_vector(int *PMV, int *dmvector, int h_r_size, int v_r_size, +void CMPEG2Decoder::motion_vector(int* PMV, int* dmvector, int h_r_size, int v_r_size, int dmv, int mvscale, int full_pel_vector) { int motion_code, motion_residual; @@ -1581,21 +1591,21 @@ void CMPEG2Decoder::motion_vector(int *PMV, int *dmvector, int h_r_size, int v_r /* ISO/IEC 13818-2 Table B-10 */ motion_code = Get_motion_code(); - motion_residual = (h_r_size!=0 && motion_code!=0) ? Get_Bits(h_r_size) : 0; + motion_residual = (h_r_size != 0 && motion_code != 0) ? Get_Bits(h_r_size) : 0; - decode_motion_vector(&PMV[0],h_r_size,motion_code,motion_residual,full_pel_vector); + decode_motion_vector(&PMV[0], h_r_size, motion_code, motion_residual, full_pel_vector); if (dmv) dmvector[0] = Get_dmvector(); /* vertical component */ - motion_code = Get_motion_code(); - motion_residual = (v_r_size!=0 && motion_code!=0) ? Get_Bits(v_r_size) : 0; + motion_code = Get_motion_code(); + motion_residual = (v_r_size != 0 && motion_code != 0) ? Get_Bits(v_r_size) : 0; if (mvscale) PMV[1] >>= 1; /* DIV 2 */ - decode_motion_vector(&PMV[1],v_r_size,motion_code,motion_residual,full_pel_vector); + decode_motion_vector(&PMV[1], v_r_size, motion_code, motion_residual, full_pel_vector); if (mvscale) PMV[1] <<= 1; @@ -1608,28 +1618,28 @@ void CMPEG2Decoder::motion_vector(int *PMV, int *dmvector, int h_r_size, int v_r /* ISO/IEC 13818-2 section 7.6.3.1: Decoding the motion vectors */ /* Note: the arithmetic here is more elegant than that which is shown in 7.6.3.1. The end results (PMV[][][]) should, however, be the same. */ -void CMPEG2Decoder::decode_motion_vector(int *pred, int r_size, int motion_code, +void CMPEG2Decoder::decode_motion_vector(int* pred, int r_size, int motion_code, int motion_residual, int full_pel_vector) { int lim, vec; - lim = 16<> 1) : (*pred); - if (motion_code>0) + if (motion_code > 0) { - vec+= ((motion_code-1)<=lim) - vec-= lim + lim; + vec += ((motion_code - 1) << r_size) + motion_residual + 1; + if (vec >= lim) + vec -= lim + lim; } - else if (motion_code<0) + else if (motion_code < 0) { - vec-= ((-motion_code-1)< -//#include "misc.h" + //#include "misc.h" #ifdef GLOBAL @@ -41,11 +41,11 @@ #endif enum { - MACROBLOCK_INTRA = 1, - MACROBLOCK_PATTERN = 2, + MACROBLOCK_INTRA = 1, + MACROBLOCK_PATTERN = 2, MACROBLOCK_MOTION_BACKWARD = 4, - MACROBLOCK_MOTION_FORWARD = 8, - MACROBLOCK_QUANT = 16, + MACROBLOCK_MOTION_FORWARD = 8, + MACROBLOCK_QUANT = 16, }; @@ -505,7 +505,7 @@ XTN DCTtab DCTtab6[16] #endif ; // add extra table of table ptrs for performance - trbarry 5/2003 -XTN DCTtab *pDCTtabNonI[28] // ptr to non_intra tables +XTN DCTtab* pDCTtabNonI[28] // ptr to non_intra tables #ifdef GLOBAL = { @@ -541,7 +541,7 @@ XTN DCTtab *pDCTtabNonI[28] // ptr to non_intra tables #endif ; // same as above but for when intra_vlc_format - trbarry 5/2003 -XTN DCTtab *pDCTtab_intra[28] // ptr to non_intra tables +XTN DCTtab* pDCTtab_intra[28] // ptr to non_intra tables #ifdef GLOBAL = { @@ -622,10 +622,10 @@ XTN VLCtab PMBtab0[8] {ERROR_VALUE,0}, {MACROBLOCK_MOTION_FORWARD,3}, {MACROBLOCK_PATTERN,2}, {MACROBLOCK_PATTERN,2}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,1}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,1}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,1}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,1} + {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_PATTERN,1}, + {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_PATTERN,1}, + {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_PATTERN,1}, + {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_PATTERN,1} } #endif ; @@ -636,9 +636,9 @@ XTN VLCtab PMBtab1[8] = { {ERROR_VALUE,0}, - {MACROBLOCK_QUANT|MACROBLOCK_INTRA,6}, - {MACROBLOCK_QUANT|MACROBLOCK_PATTERN,5}, {MACROBLOCK_QUANT|MACROBLOCK_PATTERN,5}, - {MACROBLOCK_QUANT|MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,5}, {MACROBLOCK_QUANT|MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,5}, + {MACROBLOCK_QUANT | MACROBLOCK_INTRA,6}, + {MACROBLOCK_QUANT | MACROBLOCK_PATTERN,5}, {MACROBLOCK_QUANT | MACROBLOCK_PATTERN,5}, + {MACROBLOCK_QUANT | MACROBLOCK_MOTION_FORWARD | MACROBLOCK_PATTERN,5}, {MACROBLOCK_QUANT | MACROBLOCK_MOTION_FORWARD | MACROBLOCK_PATTERN,5}, {MACROBLOCK_INTRA,5}, {MACROBLOCK_INTRA,5} } #endif @@ -652,19 +652,19 @@ XTN VLCtab BMBtab0[16] {ERROR_VALUE,0}, {ERROR_VALUE,0}, {MACROBLOCK_MOTION_FORWARD,4}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,4}, + {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_PATTERN,4}, {MACROBLOCK_MOTION_BACKWARD,3}, {MACROBLOCK_MOTION_BACKWARD,3}, - {MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,3}, - {MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,3}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD,2}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD,2}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD,2}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD,2}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,2}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,2}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,2}, - {MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,2} + {MACROBLOCK_MOTION_BACKWARD | MACROBLOCK_PATTERN,3}, + {MACROBLOCK_MOTION_BACKWARD | MACROBLOCK_PATTERN,3}, + {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD,2}, + {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD,2}, + {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD,2}, + {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD,2}, + {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD | MACROBLOCK_PATTERN,2}, + {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD | MACROBLOCK_PATTERN,2}, + {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD | MACROBLOCK_PATTERN,2}, + {MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD | MACROBLOCK_PATTERN,2} } #endif ; @@ -675,11 +675,11 @@ XTN VLCtab BMBtab1[8] = { {ERROR_VALUE,0}, - {MACROBLOCK_QUANT|MACROBLOCK_INTRA,6}, - {MACROBLOCK_QUANT|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,6}, - {MACROBLOCK_QUANT|MACROBLOCK_MOTION_FORWARD|MACROBLOCK_PATTERN,6}, - {MACROBLOCK_QUANT|MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,5}, - {MACROBLOCK_QUANT|MACROBLOCK_MOTION_FORWARD|MACROBLOCK_MOTION_BACKWARD|MACROBLOCK_PATTERN,5}, + {MACROBLOCK_QUANT | MACROBLOCK_INTRA,6}, + {MACROBLOCK_QUANT | MACROBLOCK_MOTION_BACKWARD | MACROBLOCK_PATTERN,6}, + {MACROBLOCK_QUANT | MACROBLOCK_MOTION_FORWARD | MACROBLOCK_PATTERN,6}, + {MACROBLOCK_QUANT | MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD | MACROBLOCK_PATTERN,5}, + {MACROBLOCK_QUANT | MACROBLOCK_MOTION_FORWARD | MACROBLOCK_MOTION_BACKWARD | MACROBLOCK_PATTERN,5}, {MACROBLOCK_INTRA,5}, {MACROBLOCK_INTRA,5} } diff --git a/src/idct.h b/src/idct.h new file mode 100644 index 0000000..538da82 --- /dev/null +++ b/src/idct.h @@ -0,0 +1,25 @@ +#ifndef MPEG2DECPLUS_IDCT_H +#define MPEG2DECPLUS_IDCT_H + +#include +#ifndef _WIN32 +#include "win_import_min.h" +#endif + +void idct_ref_sse3(int16_t* block); + +void prefetch_ref(); + +void idct_ap922_sse2(int16_t* block); + +void prefetch_ap922(); + +void idct_llm_float_sse2(int16_t* block); + +void idct_llm_float_avx2(int16_t* block); + +void prefetch_llm_float_sse2(); + +void prefetch_llm_float_avx2(); + +#endif diff --git a/src/dgdecode/idct_ap922_sse2.cpp b/src/idct_ap922_sse2.cpp similarity index 92% rename from src/dgdecode/idct_ap922_sse2.cpp rename to src/idct_ap922_sse2.cpp index 0b8e223..5b1c9e4 100644 --- a/src/dgdecode/idct_ap922_sse2.cpp +++ b/src/idct_ap922_sse2.cpp @@ -83,47 +83,51 @@ These examples contain code fragments for first stage iDCT 8x8 #include #include +#ifndef _WIN32 +#include "win_import_min.h" +#endif -alignas(64) static const int16_t table04[] = { + +alignas(64) static constexpr int16_t table04[] = { 16384, 21407, 16384, 8867, 16384, -8867, 16384, -21407, // w0, w1, w4, w5, w8, w9,w12,w13 16384, 8867, -16384, -21407, -16384, 21407, 16384, -8867, // w2, w3, w6, w7,w10,w11,w14,w15 22725, 19266, 19266, -4520, 12873, -22725, 4520, -12873, //w16,w17,w20,w21,w24,w25,w28,w29 12873, 4520, -22725, -12873, 4520, 19266, 19266, -22725, //w18,w19,w22,w23,w26,w27,w30,w31 }; -alignas(64) static const int16_t table17[] = { +alignas(64) static constexpr int16_t table17[] = { 22725, 29692, 22725, 12299, 22725, -12299, 22725, -29692, // w0, w1, w4, w5, w8, w9,w12,w13 22725, 12299, -22725, -29692, -22725, 29692, 22725, -12299, // w2, w3, w6, w7,w10,w11,w14,w15 31521, 26722, 26722, -6270, 17855, -31521, 6270, -17855, //w16,w17,w20,w21,w24,w25,w28,w29 17855, 6270, -31521, -17855, 6270, 26722, 26722, -31521, //w18,w19,w22,w23,w26,w27,w30,w31 }; -alignas(64) static const int16_t table26[] = { +alignas(64) static constexpr int16_t table26[] = { 21407, 27969, 21407, 11585, 21407, -11585, 21407, -27969, // w0, w1, w4, w5, w8, w9,w12,w13 21407, 11585, -21407, -27969, -21407, 27969, 21407, -11585, // w2, w3, w6, w7,w10,w11,w14,w15 29692, 25172, 25172, -5906, 16819, -29692, 5906, -16819, //w16,w17,w20,w21,w24,w25,w28,w29 16819, 5906, -29692, -16819, 5906, 25172, 25172, -29692, //w18,w19,w22,w23,w26,w27,w30,w31 }; -alignas(64) static const int16_t table35[] = { +alignas(64) static constexpr int16_t table35[] = { 19266, 25172, 19266, 10426, 19266, -10426, 19266, -25172, // w0, w1, w4, w5, w8, w9,w12,w13 19266, 10426, -19266, -25172, -19266, 25172, 19266, -10426, // w2, w3, w6, w7,w10,w11,w14,w15 26722, 22654, 22654, -5315, 15137, -26722, 5315, -15137, //w16,w17,w20,w21,w24,w25,w28,w29 15137, 5315, -26722, -15137, 5315, 22654, 22654, -26722, //w18,w19,w22,w23,w26,w27,w30,w31 }; -alignas(64) static const int32_t rounders[8][4] = { - 65536, 65536, 65536, 65536, - 3597, 3597, 3597, 3597, - 2260, 2260, 2260, 2260, - 1203, 1203, 1203, 1203, - 0, 0, 0, 0, - 120, 120, 120, 120, - 512, 512, 512, 512, - 512, 512, 512, 512, +alignas(64) static constexpr int32_t rounders[8][4] = { + { 65536, 65536, 65536, 65536 }, + { 3597, 3597, 3597, 3597 }, + { 2260, 2260, 2260, 2260 }, + { 1203, 1203, 1203, 1203 }, + { 0, 0, 0, 0 }, + { 120, 120, 120, 120 }, + { 512, 512, 512, 512 }, + { 512, 512, 512, 512 }, }; -alignas(64) static const int16_t tg[4][8] = { +alignas(64) static constexpr int16_t tg[4][8] = { { 13036, 13036, 13036, 13036, 13036, 13036, 13036, 13036 }, { 27146, 27146, 27146, 27146, 27146, 27146, 27146, 27146}, {-21746, -21746, -21746, -21746, -21746, -21746, -21746, -21746}, @@ -244,10 +248,10 @@ idct_colx8_sse2(int16_t* block) noexcept } -void __fastcall idct_ap922_sse2(int16_t* block) noexcept +void idct_ap922_sse2(int16_t* block) { - idct_row_sse2(block + 0, table04, rounders[0]); - idct_row_sse2(block + 8, table17, rounders[1]); + idct_row_sse2(block + 0, table04, rounders[0]); + idct_row_sse2(block + 8, table17, rounders[1]); idct_row_sse2(block + 16, table26, rounders[2]); idct_row_sse2(block + 24, table35, rounders[3]); idct_row_sse2(block + 32, table04, rounders[4]); @@ -259,7 +263,7 @@ void __fastcall idct_ap922_sse2(int16_t* block) noexcept } -void __fastcall prefetch_ap922() noexcept +void prefetch_ap922() { _mm_prefetch(reinterpret_cast(table04), _MM_HINT_NTA); _mm_prefetch(reinterpret_cast(table17), _MM_HINT_NTA); diff --git a/src/dgdecode/idct_llm_float_avx2.cpp b/src/idct_llm_float_avx2.cpp similarity index 96% rename from src/dgdecode/idct_llm_float_avx2.cpp rename to src/idct_llm_float_avx2.cpp index 763d0a6..5f3918b 100644 --- a/src/dgdecode/idct_llm_float_avx2.cpp +++ b/src/idct_llm_float_avx2.cpp @@ -84,8 +84,8 @@ idct_8x8_fma3(__m256& s0, __m256& s1, __m256& s2, __m256& s3, __m256& s4, __m256 z0 = _mm256_add_ps(s0, s4); z1 = _mm256_sub_ps(s0, s4); - z2=_mm256_fmadd_ps(s6, _mm256_load_ps(llm_coefs + 80), z4); - z3=_mm256_fmadd_ps(s2, _mm256_load_ps(llm_coefs + 88), z4); + z2 = _mm256_fmadd_ps(s6, _mm256_load_ps(llm_coefs + 80), z4); + z3 = _mm256_fmadd_ps(s2, _mm256_load_ps(llm_coefs + 88), z4); __m256 a0 = _mm256_add_ps(z0, z3); __m256 a3 = _mm256_sub_ps(z0, z3); @@ -119,7 +119,7 @@ float_to_dst_avx2(const __m256& s0, const __m256& s1, int16_t* dst) noexcept } -void __fastcall idct_llm_float_avx2(int16_t* block) noexcept +void idct_llm_float_avx2(int16_t* block) { __m256 s0 = load_and_convert_to_float_x8_avx2(block); __m256 s1 = load_and_convert_to_float_x8_avx2(block + 8); @@ -138,14 +138,14 @@ void __fastcall idct_llm_float_avx2(int16_t* block) noexcept idct_8x8_fma3(s0, s1, s2, s3, s4, s5, s6, s7); - float_to_dst_avx2(s0, s1, block + 0); + float_to_dst_avx2(s0, s1, block + 0); float_to_dst_avx2(s2, s3, block + 16); float_to_dst_avx2(s4, s5, block + 32); float_to_dst_avx2(s6, s7, block + 48); } -void __fastcall prefetch_llm_float_avx2() noexcept +void prefetch_llm_float_avx2() { _mm_prefetch(reinterpret_cast(llm_coefs), _MM_HINT_NTA); _mm_prefetch(reinterpret_cast(llm_coefs + 16), _MM_HINT_NTA); diff --git a/src/dgdecode/idct_llm_float_sse2.cpp b/src/idct_llm_float_sse2.cpp similarity index 76% rename from src/dgdecode/idct_llm_float_sse2.cpp rename to src/idct_llm_float_sse2.cpp index f477352..3a61e17 100644 --- a/src/dgdecode/idct_llm_float_sse2.cpp +++ b/src/idct_llm_float_sse2.cpp @@ -18,7 +18,7 @@ alignas(64) static const float llm_coefs[] = { }; -static inline void short_to_float(const short* srcp, float*dstp) noexcept +static inline void short_to_float(const short* srcp, float* dstp) noexcept { const __m128i zero = _mm_setzero_si128(); @@ -52,31 +52,31 @@ static inline void idct_8x4_with_transpose(const float* srcp, float* dstp) noexc __m128 z3 = _mm_add_ps(s1, s5); __m128 z4 = _mm_mul_ps(_mm_add_ps(z0, z1), _mm_load_ps(llm_coefs)); - z2 =_mm_add_ps(_mm_mul_ps(z2, _mm_load_ps(llm_coefs + 4)), z4); - z3 =_mm_add_ps(_mm_mul_ps(z3, _mm_load_ps(llm_coefs + 8)), z4); - z0 =_mm_mul_ps(z0, _mm_load_ps(llm_coefs + 12)); - z1 =_mm_mul_ps(z1, _mm_load_ps(llm_coefs + 16)); + z2 = _mm_add_ps(_mm_mul_ps(z2, _mm_load_ps(llm_coefs + 4)), z4); + z3 = _mm_add_ps(_mm_mul_ps(z3, _mm_load_ps(llm_coefs + 8)), z4); + z0 = _mm_mul_ps(z0, _mm_load_ps(llm_coefs + 12)); + z1 = _mm_mul_ps(z1, _mm_load_ps(llm_coefs + 16)); - __m128 b3 =_mm_add_ps(_mm_add_ps(_mm_mul_ps(s7, _mm_load_ps(llm_coefs + 20)), z0), z2); - __m128 b2 =_mm_add_ps(_mm_add_ps(_mm_mul_ps(s5, _mm_load_ps(llm_coefs + 24)), z1), z3); - __m128 b1 =_mm_add_ps(_mm_add_ps(_mm_mul_ps(s3, _mm_load_ps(llm_coefs + 28)), z1), z2); - __m128 b0 =_mm_add_ps(_mm_add_ps(_mm_mul_ps(s1, _mm_load_ps(llm_coefs + 32)), z0), z3); + __m128 b3 = _mm_add_ps(_mm_add_ps(_mm_mul_ps(s7, _mm_load_ps(llm_coefs + 20)), z0), z2); + __m128 b2 = _mm_add_ps(_mm_add_ps(_mm_mul_ps(s5, _mm_load_ps(llm_coefs + 24)), z1), z3); + __m128 b1 = _mm_add_ps(_mm_add_ps(_mm_mul_ps(s3, _mm_load_ps(llm_coefs + 28)), z1), z2); + __m128 b0 = _mm_add_ps(_mm_add_ps(_mm_mul_ps(s1, _mm_load_ps(llm_coefs + 32)), z0), z3); z4 = _mm_mul_ps(_mm_add_ps(s2, s6), _mm_load_ps(llm_coefs + 36)); - z0=_mm_add_ps(s0, s4); - z1=_mm_sub_ps(s0, s4); + z0 = _mm_add_ps(s0, s4); + z1 = _mm_sub_ps(s0, s4); - z2=_mm_add_ps(z4, _mm_mul_ps(s6, _mm_load_ps(llm_coefs + 40))); - z3=_mm_add_ps(z4, _mm_mul_ps(s2, _mm_load_ps(llm_coefs + 44))); + z2 = _mm_add_ps(z4, _mm_mul_ps(s6, _mm_load_ps(llm_coefs + 40))); + z3 = _mm_add_ps(z4, _mm_mul_ps(s2, _mm_load_ps(llm_coefs + 44))); s0 = _mm_add_ps(z0, z3); s3 = _mm_sub_ps(z0, z3); s1 = _mm_add_ps(z1, z2); s2 = _mm_sub_ps(z1, z2); - _mm_store_ps(dstp , _mm_add_ps(s0, b0)); + _mm_store_ps(dstp, _mm_add_ps(s0, b0)); _mm_store_ps(dstp + 56, _mm_sub_ps(s0, b0)); - _mm_store_ps(dstp + 8, _mm_add_ps(s1, b1)); + _mm_store_ps(dstp + 8, _mm_add_ps(s1, b1)); _mm_store_ps(dstp + 48, _mm_sub_ps(s1, b1)); _mm_store_ps(dstp + 16, _mm_add_ps(s2, b2)); _mm_store_ps(dstp + 40, _mm_sub_ps(s2, b2)); @@ -103,7 +103,7 @@ static inline void float_to_dst_llm(const float* srcp, int16_t* dstp) noexcept } -void __fastcall idct_llm_float_sse2(int16_t* block) noexcept +void idct_llm_float_sse2(int16_t* block) { alignas(64) float blockf[64]; alignas(64) float tmp[64]; @@ -120,7 +120,7 @@ void __fastcall idct_llm_float_sse2(int16_t* block) noexcept } -void __fastcall prefetch_llm_float_sse2() noexcept +void prefetch_llm_float_sse2() { _mm_prefetch(reinterpret_cast(llm_coefs), _MM_HINT_NTA); _mm_prefetch(reinterpret_cast(llm_coefs + 16), _MM_HINT_NTA); diff --git a/src/dgdecode/idct_ref_sse3.cpp b/src/idct_ref_sse3.cpp similarity index 92% rename from src/dgdecode/idct_ref_sse3.cpp rename to src/idct_ref_sse3.cpp index 3a63631..c6bd9a8 100644 --- a/src/dgdecode/idct_ref_sse3.cpp +++ b/src/idct_ref_sse3.cpp @@ -119,13 +119,13 @@ static inline void transpose_8x8_sse2(const double* srcp, double* dstp) noexcept static inline void idct_ref_8x8_sse3(const double* srcp, double* dstp) noexcept { for (int i = 0; i < 8; ++i) { - __m128d s0 = _mm_load_pd(srcp + 8 * i); - __m128d s1 = _mm_load_pd(srcp + 8 * i + 2); - __m128d s2 = _mm_load_pd(srcp + 8 * i + 4); - __m128d s3 = _mm_load_pd(srcp + 8 * i + 6); + __m128d s0 = _mm_load_pd(srcp + 8 * static_cast(i)); + __m128d s1 = _mm_load_pd(srcp + 8 * static_cast(i) + 2); + __m128d s2 = _mm_load_pd(srcp + 8 * static_cast(i) + 4); + __m128d s3 = _mm_load_pd(srcp + 8 * static_cast(i) + 6); for (int j = 0; j < 8; j += 2) { - const double* mpos = ref_dct_matrix_t + 8 * j; + const double* mpos = ref_dct_matrix_t + 8 * static_cast(j); __m128d m0 = _mm_mul_pd(_mm_load_pd(mpos), s0); __m128d m1 = _mm_mul_pd(_mm_load_pd(mpos + 2), s1); @@ -139,7 +139,7 @@ static inline void idct_ref_8x8_sse3(const double* srcp, double* dstp) noexcept m3 = _mm_mul_pd(_mm_load_pd(mpos + 14), s3); __m128d d1 = _mm_add_pd(_mm_add_pd(m0, m1), _mm_add_pd(m2, m3)); - _mm_store_pd(dstp + 8 * i + j, _mm_hadd_pd(d0, d1)); + _mm_store_pd(dstp + 8 * static_cast(i) + j, _mm_hadd_pd(d0, d1)); } } } @@ -163,7 +163,7 @@ static inline void double_to_dst_sse2(const double* srcp, int16_t* dst) noexcept } -void __fastcall idct_ref_sse3(int16_t* block) noexcept +void idct_ref_sse3(int16_t* block) { alignas(64) double blockf[64]; alignas(64) double tmp[64]; @@ -182,10 +182,10 @@ void __fastcall idct_ref_sse3(int16_t* block) noexcept } -void __fastcall prefetch_ref() noexcept +void prefetch_ref() { - _mm_prefetch(reinterpret_cast(ref_dct_matrix_t + 0), _MM_HINT_NTA); - _mm_prefetch(reinterpret_cast(ref_dct_matrix_t + 8), _MM_HINT_NTA); + _mm_prefetch(reinterpret_cast(ref_dct_matrix_t + 0), _MM_HINT_NTA); + _mm_prefetch(reinterpret_cast(ref_dct_matrix_t + 8), _MM_HINT_NTA); _mm_prefetch(reinterpret_cast(ref_dct_matrix_t + 16), _MM_HINT_NTA); _mm_prefetch(reinterpret_cast(ref_dct_matrix_t + 24), _MM_HINT_NTA); _mm_prefetch(reinterpret_cast(ref_dct_matrix_t + 32), _MM_HINT_NTA); diff --git a/src/dgdecode/mc.cpp b/src/mc.cpp similarity index 88% rename from src/dgdecode/mc.cpp rename to src/mc.cpp index f01c85e..9eef17f 100644 --- a/src/dgdecode/mc.cpp +++ b/src/mc.cpp @@ -22,19 +22,17 @@ */ -// SSE2 intrinsic implementation -// OKA Motofumi - August 23, 2016 + // SSE2 intrinsic implementation + // OKA Motofumi - August 23, 2016 #include #include "mc.h" +#ifndef _WIN32 +#include "win_import_min.h" +#endif -static __forceinline __m128i load(const uint8_t* p) -{ - return _mm_load_si128(reinterpret_cast(p)); -} - static __forceinline __m128i loadl(const uint8_t* p) { return _mm_loadl_epi64(reinterpret_cast(p)); @@ -50,11 +48,6 @@ static __forceinline __m128i avgu8(const __m128i& x, const __m128i& y) return _mm_avg_epu8(x, y); } -static __forceinline void store(uint8_t* p, const __m128i& x) -{ - _mm_store_si128(reinterpret_cast<__m128i*>(p), x); -} - static __forceinline void storel(uint8_t* p, const __m128i& x) { _mm_storel_epi64(reinterpret_cast<__m128i*>(p), x); @@ -66,7 +59,7 @@ static __forceinline void storeu(uint8_t* p, const __m128i& x) } -static void MC_put_8_c(uint8_t * dest, const uint8_t * ref, int stride, int, int height) +static void MC_put_8_c(uint8_t* dest, const uint8_t* ref, int stride, int, int height) { do { *reinterpret_cast(dest) = *reinterpret_cast(ref); @@ -75,7 +68,7 @@ static void MC_put_8_c(uint8_t * dest, const uint8_t * ref, int stride, int, int } -static void MC_put_16_sse2(uint8_t * dest, const uint8_t * ref, int stride, int, int height) +static void MC_put_16_sse2(uint8_t* dest, const uint8_t* ref, int stride, int, int height) { do { storeu(dest, loadu(ref)); @@ -84,7 +77,7 @@ static void MC_put_16_sse2(uint8_t * dest, const uint8_t * ref, int stride, int, } -static void MC_avg_8_sse2(uint8_t * dest, const uint8_t * ref, int stride, int, int height) +static void MC_avg_8_sse2(uint8_t* dest, const uint8_t* ref, int stride, int, int height) { do { storel(dest, avgu8(loadl(ref), loadl(dest))); @@ -93,7 +86,7 @@ static void MC_avg_8_sse2(uint8_t * dest, const uint8_t * ref, int stride, int, } -static void MC_avg_16_sse2(uint8_t * dest, const uint8_t * ref, int stride, int, int height) +static void MC_avg_16_sse2(uint8_t* dest, const uint8_t* ref, int stride, int, int height) { do { storeu(dest, avgu8(loadu(ref), loadu(dest))); @@ -102,7 +95,7 @@ static void MC_avg_16_sse2(uint8_t * dest, const uint8_t * ref, int stride, int, } -static void MC_put_x8_sse2(uint8_t * dest, const uint8_t * ref, int stride, int, int height) +static void MC_put_x8_sse2(uint8_t* dest, const uint8_t* ref, int stride, int, int height) { do { storel(dest, avgu8(loadl(ref), loadl(ref + 1))); @@ -111,7 +104,7 @@ static void MC_put_x8_sse2(uint8_t * dest, const uint8_t * ref, int stride, int, } -static void MC_put_y8_sse2(uint8_t * dest, const uint8_t * ref, int stride, int offs, int height) +static void MC_put_y8_sse2(uint8_t* dest, const uint8_t* ref, int stride, int offs, int height) { do { storel(dest, avgu8(loadl(ref), loadl(ref + offs))); @@ -120,7 +113,7 @@ static void MC_put_y8_sse2(uint8_t * dest, const uint8_t * ref, int stride, int } -static void MC_put_x16_sse2(uint8_t * dest, const uint8_t * ref, int stride, int, int height) +static void MC_put_x16_sse2(uint8_t* dest, const uint8_t* ref, int stride, int, int height) { do { storeu(dest, avgu8(loadu(ref), loadu(ref + 1))); @@ -176,7 +169,7 @@ static void MC_avg_y16_sse2(uint8_t* dest, const uint8_t* ref, int stride, int o static __forceinline __m128i get_correcter(const __m128i& r0, const __m128i& r1, const __m128i& r2, const __m128i& r3, - const __m128i& avg0, const __m128i& avg1, const __m128i& one) + const __m128i& avg0, const __m128i& avg1, const __m128i& one) { __m128i t0 = _mm_or_si128(_mm_xor_si128(r0, r3), _mm_xor_si128(r1, r2)); t0 = _mm_and_si128(t0, _mm_xor_si128(avg0, avg1)); diff --git a/src/dgdecode/mc.h b/src/mc.h similarity index 92% rename from src/dgdecode/mc.h rename to src/mc.h index c392051..182391f 100644 --- a/src/dgdecode/mc.h +++ b/src/mc.h @@ -26,7 +26,7 @@ #include -typedef void (MCFunc) (uint8_t* dest, const uint8_t* ref, int stride, int offs, int height); +typedef void (MCFunc)(uint8_t* dest, const uint8_t* ref, int stride, int offs, int height); typedef MCFunc* MCFuncPtr; // Form prediction (motion compensation) function pointer array (GetPic.c) - Vlad59 04-20-2002 diff --git a/src/misc.cpp b/src/misc.cpp new file mode 100644 index 0000000..e60ef46 --- /dev/null +++ b/src/misc.cpp @@ -0,0 +1,63 @@ +/* + * Misc Stuff for MPEG2Dec3 + * + * Copyright (C) 2002-2003 Marc Fauconneau + * + * This file is part of MPEG2Dec3, a free MPEG-2 decoder + * + * MPEG2Dec3 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. + * + * MPEG2Dec3 is distributed in the hope that 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 +#include +#include + +#include "misc.h" + + +size_t __cdecl dprintf(char* fmt, ...) +{ + char printString[1024]; + + va_list argp; + + va_start(argp, fmt); + vsprintf_s(printString, 1024, fmt, argp); + va_end(argp); + fprintf(stderr, "%s", printString); + return strlen(printString); +} + + +void __stdcall +fast_copy(const uint8_t* src, const int src_stride, uint8_t* dst, + const int dst_stride, const int horizontal_size, int vertical_size) noexcept +{ + if (vertical_size == 0) { + return; + } + else if (horizontal_size == src_stride && src_stride == dst_stride) { + memcpy(dst, src, static_cast(horizontal_size) * vertical_size); + } + else { + do { + memcpy(dst, src, horizontal_size); + dst += dst_stride; + src += src_stride; + } while (--vertical_size != 0); + } +} diff --git a/src/dgdecode/misc.h b/src/misc.h similarity index 77% rename from src/dgdecode/misc.h rename to src/misc.h index 902263b..1726267 100644 --- a/src/dgdecode/misc.h +++ b/src/misc.h @@ -24,21 +24,16 @@ #ifndef MPEG2DECPLUS_MISC_H #define MPEG2DECPLUS_MISC_H - -#include -#include +#ifndef _WIN32 +#include +#include "win_import_min.h" +#endif void __stdcall -fast_copy(const uint8_t *src, const int src_stride, uint8_t *dst, - const int dst_stride, const int horizontal_size, - const int vertical_size) noexcept; +fast_copy(const uint8_t* src, const int src_stride, uint8_t* dst, + const int dst_stride, const int horizontal_size, + const int vertical_size) noexcept; size_t __cdecl dprintf(char* fmt, ...); -bool has_sse2() noexcept; - -bool has_sse3() noexcept; - -bool has_avx2() noexcept; - #endif diff --git a/src/dgdecode/store.cpp b/src/store.cpp similarity index 75% rename from src/dgdecode/store.cpp rename to src/store.cpp index 69c8bab..707f8da 100644 --- a/src/dgdecode/store.cpp +++ b/src/store.cpp @@ -24,28 +24,28 @@ */ -#include "MPEG2Decoder.h" -//#include "postprocess.h" #include "color_convert.h" + //#include "postprocess.h" #include "misc.h" +#include "MPEG2Decoder.h" // Write 2-digits numbers in a 16x16 zone. static void write_quants(uint8_t* dst, int stride, int mb_width, int mb_height, - const int* qp) + const int* qp) { const uint8_t rien[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; const uint8_t nums[10][8] = { - 1, 4, 4, 4, 4, 4, 1, 0, - 3, 3, 3, 3, 3, 3, 3, 0, - 1, 3, 3, 1, 2, 2, 1, 0, - 1, 3, 3, 1, 3, 3, 1, 0, - 4, 4, 4, 1, 3, 3, 3, 0, - 1, 2, 2, 1, 3, 3, 1, 0, - 1, 2, 2, 1, 4, 4, 1, 0, - 1, 3, 3, 3, 3, 3, 3, 0, - 1, 4, 4, 1, 4, 4, 1, 0, - 1, 4, 4, 1, 3, 3, 1, 0, + { 1, 4, 4, 4, 4, 4, 1, 0 }, + { 3, 3, 3, 3, 3, 3, 3, 0 }, + { 1, 3, 3, 1, 2, 2, 1, 0 }, + { 1, 3, 3, 1, 3, 3, 1, 0 }, + { 4, 4, 4, 1, 3, 3, 3, 0 }, + { 1, 2, 2, 1, 3, 3, 1, 0 }, + { 1, 2, 2, 1, 4, 4, 1, 0 }, + { 1, 3, 3, 3, 3, 3, 3, 0 }, + { 1, 4, 4, 1, 4, 4, 1, 0 }, + { 1, 4, 4, 1, 3, 3, 1, 0 }, }; auto write = [](const uint8_t* num, uint8_t* dst, const int stride) { @@ -72,7 +72,7 @@ static void write_quants(uint8_t* dst, int stride, int mb_width, int mb_height, for (int y = 0; y < mb_height; ++y) { for (int x = 0; x < mb_width; ++x) { int number = qp[x + y * mb_width]; - uint8_t* dstp = dst + x * 16 + 3 * stride; + uint8_t* dstp = dst + static_cast(x) * 16 + static_cast(3) * stride; int c = (number / 100) % 10; const uint8_t* num = nums[c]; // x00 @@ -82,20 +82,20 @@ static void write_quants(uint8_t* dst, int stride, int mb_width, int mb_height, dstp += 5; int d = (number / 10) % 10; num = nums[d]; // 0x0 - if (c==0 && d==0) num = rien; + if (c == 0 && d == 0) num = rien; write(num, dstp, stride); dstp += 5; num = nums[number % 10]; // 00x write(num, dstp, stride); } - dst += 16 * stride; + dst += static_cast(16) * stride; } } static void set_qparams(const int* qp, size_t mb_size, int& minquant, - int& maxquant, int& avgquant) + int& maxquant, int& avgquant) { int minq = qp[0], maxq = qp[0], sum = qp[0]; for (size_t i = 1; i < mb_size; ++i) { @@ -133,20 +133,20 @@ void CMPEG2Decoder::assembleFrame(uint8_t* src[], int pf, YV12PICT& dst) if (iPP == 1 || (iPP == -1 && pf == 0)) iPPt = true; else iPPt = false; postprocess(src, this->Coded_Picture_Width, this->Chroma_Width, - ppptr, dst->ypitch, dst->uvpitch, this->Coded_Picture_Width, - this->Coded_Picture_Height, this->QP, this->mb_width, pp_mode, moderate_h, moderate_v, - chroma_format == 1 ? false : true, iPPt); + ppptr, dst->ypitch, dst->uvpitch, this->Coded_Picture_Width, + this->Coded_Picture_Height, this->QP, this->mb_width, pp_mode, moderate_h, moderate_v, + chroma_format == 1 ? false : true, iPPt); if (upConv > 0 && chroma_format == 1) { if (iCC == 1 || (iCC == -1 && pf == 0)) { - conv420to422I(ppptr[1],dst->u,dst->uvpitch,dst->uvpitch,Coded_Picture_Width,Coded_Picture_Height); - conv420to422I(ppptr[2],dst->v,dst->uvpitch,dst->uvpitch,Coded_Picture_Width,Coded_Picture_Height); + conv420to422I(ppptr[1], dst->u, dst->uvpitch, dst->uvpitch, Coded_Picture_Width, Coded_Picture_Height); + conv420to422I(ppptr[2], dst->v, dst->uvpitch, dst->uvpitch, Coded_Picture_Width, Coded_Picture_Height); } else { - conv420to422P(ppptr[1],dst->u,dst->uvpitch,dst->uvpitch,Coded_Picture_Width,Coded_Picture_Height); - conv420to422P(ppptr[2],dst->v,dst->uvpitch,dst->uvpitch,Coded_Picture_Width,Coded_Picture_Height); + conv420to422P(ppptr[1], dst->u, dst->uvpitch, dst->uvpitch, Coded_Picture_Width, Coded_Picture_Height); + conv420to422P(ppptr[2], dst->v, dst->uvpitch, dst->uvpitch, Coded_Picture_Width, Coded_Picture_Height); } } } @@ -158,21 +158,23 @@ void CMPEG2Decoder::assembleFrame(uint8_t* src[], int pf, YV12PICT& dst) if (iCC == 1 || (iCC == -1 && pf == 0)) { conv420to422I(src[1], dst.u, Chroma_Width, dst.uvpitch, Coded_Picture_Width, Coded_Picture_Height); conv420to422I(src[2], dst.v, Chroma_Width, dst.uvpitch, Coded_Picture_Width, Coded_Picture_Height); - } else { + } + else { conv420to422P(src[1], dst.u, Chroma_Width, dst.uvpitch, Coded_Picture_Width, Coded_Picture_Height); conv420to422P(src[2], dst.v, Chroma_Width, dst.uvpitch, Coded_Picture_Width, Coded_Picture_Height); } - } else { + } + else { fast_copy(src[1], Chroma_Width, dst.u, dst.uvpitch, Chroma_Width, Chroma_Height); fast_copy(src[2], Chroma_Width, dst.v, dst.uvpitch, Chroma_Width, Chroma_Height); } } - if (info == 1 || info == 2 || showQ) { + if (has_prop || info == 1 || info == 2 || showQ) { // Re-order quant data for display order. const int* qp = (picture_coding_type == B_TYPE) ? auxQP : backwardQP; - if (info == 1 || info == 2) { - set_qparams(qp, mb_width * mb_height, minquant, maxquant, avgquant); + if (has_prop || info == 1 || info == 2) { + set_qparams(qp, static_cast(mb_width) * mb_height, minquant, maxquant, avgquant); } if (showQ) { write_quants(dst.y, dst.ypitch, mb_width, mb_height, qp); diff --git a/src/win_import_min.h b/src/win_import_min.h new file mode 100644 index 0000000..fe73f7e --- /dev/null +++ b/src/win_import_min.h @@ -0,0 +1,38 @@ + +#ifndef WIN_IMPORT_MIN_H +#define WIN_IMPORT_MIN_H + +/* support from recent _mingw.h */ + +#ifdef __cplusplus +#define __forceinline inline __attribute__((__always_inline__)) +#else +#define __forceinline extern __inline__ __attribute__((__always_inline__,__gnu_inline__)) +#endif /* __cplusplus */ + +#ifdef __GNUC__ +#define _byteswap_ulong(x) __builtin_bswap32(x) +#endif + +#define _read read +#define _lseeki64 lseek +#define _close close + +/* gnu libc offers the equivalent 'aligned_alloc' BUT requested 'size' + has to be a multiple of 'alignment' - in case it isn't, I'll set + a different size, rounding up the value */ +#define _aligned_malloc(s,a) ( \ + aligned_alloc(a,((s-1)/a+1)*a) \ + ) + +#define _aligned_free(x) free(x) + +#define _atoi64(x) strtoll(x,NULL,10) +#define sprintf_s(buf,...) snprintf((buf),sizeof(buf),__VA_ARGS__) +#define strncpy_s(d,n,s,c) strncpy(d,s,c) +#define vsprintf_s(d,n,t,v) vsprintf(d,t,v) +#define sscanf_s(buf,...) sscanf((buf),__VA_ARGS__) +#define fscanf_s(f,t,...) fscanf(f,t,__VA_ARGS__) + +#endif // WIN_IMPORT_MIN_H + diff --git a/src/dgdecode/yv12pict.cpp b/src/yv12pict.cpp similarity index 83% rename from src/dgdecode/yv12pict.cpp rename to src/yv12pict.cpp index 4d68d69..daec044 100644 --- a/src/dgdecode/yv12pict.cpp +++ b/src/yv12pict.cpp @@ -19,11 +19,15 @@ * */ -// replace with one that doesn't need fixed size table - trbarry 3-22-2002 + // replace with one that doesn't need fixed size table - trbarry 3-22-2002 -#include #include -#include "YV12PICT.h" +#include + +#include "yv12pict.h" +#ifndef _WIN32 +#include "win_import_min.h" +#endif //#define ptr_t unsigned int @@ -60,9 +64,9 @@ YV12PICT::YV12PICT(int height, int width, int chroma_format) : uvpitch = (uvwidth + 15) & ~15; ypitch = (ywidth + 31) & ~31; - y = reinterpret_cast(_aligned_malloc(height * ypitch, 32)); - u = reinterpret_cast(_aligned_malloc(uvheight * uvpitch, 16)); - v = reinterpret_cast(_aligned_malloc(uvheight * uvpitch, 16)); + y = reinterpret_cast(_aligned_malloc(static_cast(height) * ypitch, 32)); + u = reinterpret_cast(_aligned_malloc(static_cast(uvheight) * uvpitch, 16)); + v = reinterpret_cast(_aligned_malloc(static_cast(uvheight) * uvpitch, 16)); if (!y || !u || !v) { _aligned_free(y); _aligned_free(u); @@ -82,7 +86,7 @@ YV12PICT::YV12PICT(PVideoFrame& frame) : {} -YV12PICT::YV12PICT(uint8_t* py, uint8_t* pu, uint8_t*pv, int yw, int cw, int h) : +YV12PICT::YV12PICT(uint8_t* py, uint8_t* pu, uint8_t* pv, int yw, int cw, int h) : allocated(false), y(py), u(pu), v(pv), ypitch((yw + 31) & ~31), uvpitch((cw + 15) & ~15), diff --git a/src/dgdecode/yv12pict.h b/src/yv12pict.h similarity index 70% rename from src/dgdecode/yv12pict.h rename to src/yv12pict.h index 1ad3c0d..67ee145 100644 --- a/src/dgdecode/yv12pict.h +++ b/src/yv12pict.h @@ -1,24 +1,25 @@ -#ifndef YV12PICT_H -#define YV12PICT_H - -#include -#include - - +#ifndef YV12PICT_H +#define YV12PICT_H + +#include + +#include "avisynth.h" + + class YV12PICT { const bool allocated; public: - uint8_t *y, *u, *v; + uint8_t* y, * u, * v; int ypitch, uvpitch; int ywidth, uvwidth; int yheight, uvheight; int pf; YV12PICT(PVideoFrame& frame); - YV12PICT(uint8_t* py, uint8_t* pu, uint8_t*pv, int yw, int cw, int h); + YV12PICT(uint8_t* py, uint8_t* pu, uint8_t* pv, int yw, int cw, int h); YV12PICT(int height, int width, int chroma_format); ~YV12PICT(); }; - -#endif - + +#endif +