@mentra/bluetooth-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +278 -0
- package/android/build.gradle +167 -0
- package/android/lc3Lib/CMakeLists.txt +6 -0
- package/android/lc3Lib/build.gradle +109 -0
- package/android/lc3Lib/proguard-rules.pro +33 -0
- package/android/lc3Lib/src/main/AndroidManifest.xml +2 -0
- package/android/lc3Lib/src/main/cpp/CMakeLists.txt +8 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/CMakeLists.txt +30 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/CMakeLists.txt +7 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/ogg_opus_encoder.cc +96 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/ogg_opus_encoder.h +53 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/Makefile.am +6 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/config_types.h +26 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/config_types.h.in +26 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/ogg.h +209 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/os_types.h +158 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus.h +981 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_custom.h +342 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_defines.h +799 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_multistream.h +660 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_projection.h +568 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_types.h +166 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/ogg_opus_encoder.cc +268 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/ogg_opus_encoder.h +115 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/opus_tools/opus_header.h +59 -0
- package/android/lc3Lib/src/main/cpp/liblc3/CMakeLists.txt +38 -0
- package/android/lc3Lib/src/main/cpp/liblc3/include/lc3.h +309 -0
- package/android/lc3Lib/src/main/cpp/liblc3/include/lc3_private.h +162 -0
- package/android/lc3Lib/src/main/cpp/liblc3/include/rnnoise.h +114 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/CMakeLists.txt +19 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/attdet.c +92 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/attdet.h +44 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bits.c +375 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bits.h +315 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bwdet.c +129 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bwdet.h +69 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/common.h +148 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/energy.c +70 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/energy.h +43 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/fastmath.h +158 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/lc3.c +702 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf.c +893 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf.h +111 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf_arm.h +506 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf_neon.h +281 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/makefile.mk +35 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct.c +452 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct.h +57 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct_neon.h +296 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/meson.build +46 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/plc.c +61 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/plc.h +57 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/sns.c +880 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/sns.h +103 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/spec.c +904 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/spec.h +119 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tables.c +3457 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tables.h +94 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tns.c +457 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tns.h +99 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3.cpp +159 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/_kiss_fft_guts.h +182 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/arch.h +261 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/celt_lpc.c +279 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/celt_lpc.h +59 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/common.h +48 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/compile.sh +3 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/denoise.c +646 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/kiss_fft.c +601 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/kiss_fft.h +203 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/opus_types.h +159 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/pitch.c +526 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/pitch.h +149 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn.c +178 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn.h +69 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_data.c +11051 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_data.h +34 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_reader.c +168 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_train.py +66 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/tansig_table.h +45 -0
- package/android/lc3Lib/src/main/java/com/mentra/lc3Lib/Lc3Cpp.java +38 -0
- package/android/lc3Lib/third_party/CMakeLists.txt +23 -0
- package/android/lc3Lib/third_party/CMakeLists_libogg.txt +18 -0
- package/android/lc3Lib/third_party/CMakeLists_libopus.txt +18 -0
- package/android/lc3Lib/third_party/CMakeLists_opus-tools.txt +23 -0
- package/android/lc3Lib/third_party/opus_tools/src/AUTHORS +5 -0
- package/android/lc3Lib/third_party/opus_tools/src/CMakeLists.txt +4 -0
- package/android/lc3Lib/third_party/opus_tools/src/COPYING +371 -0
- package/android/lc3Lib/third_party/opus_tools/src/ChangeLog +3 -0
- package/android/lc3Lib/third_party/opus_tools/src/Makefile.am +42 -0
- package/android/lc3Lib/third_party/opus_tools/src/Makefile.unix +23 -0
- package/android/lc3Lib/third_party/opus_tools/src/NEWS +0 -0
- package/android/lc3Lib/third_party/opus_tools/src/README +0 -0
- package/android/lc3Lib/third_party/opus_tools/src/autogen.sh +115 -0
- package/android/lc3Lib/third_party/opus_tools/src/configure.ac +293 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/arch.h +239 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/audio-in.c +1046 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/diag_range.c +245 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/diag_range.h +28 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/info_opus.c +320 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/info_opus.h +51 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/lpc.c +157 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/lpc.h +27 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opus_header.c +286 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opus_header.h +59 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusdec.c +884 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusenc.c +1021 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusenc.h +101 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusinfo.c +639 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusinfo.h +51 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/os_support.h +167 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/resample.c +1137 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/speex_resampler.h +344 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/stack_alloc.h +115 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wav_io.c +125 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wav_io.h +62 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wave_out.c +223 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wave_out.h +60 -0
- package/android/settings.gradle +1 -0
- package/android/src/main/AndroidManifest.xml +40 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +528 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +610 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +1616 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceStore.kt +314 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothModels.kt +1710 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +554 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/ObservableStore.kt +68 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/controllers/ControllerManager.kt +158 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/controllers/R1.kt +934 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/services/Foreground.kt +175 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/services/PhoneMic.kt +1109 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G1.java +3974 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G2.kt +3551 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Mach1.java +1327 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.java +6959 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraNex.kt +1655 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraosBle.java +53675 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +202 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Simulated.kt +224 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/STTTools.kt +340 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SherpaOnnxTranscriber.kt +465 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/VadGateSpeechPolicy.kt +221 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/AES.java +106 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/AudioSessionMonitor.kt +189 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/BitmapJavaUtils.java +169 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/BlePhotoUploadService.java +179 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/Constants.kt +44 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/G1Text.kt +436 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +29 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleUploadService.java +76 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/K900ProtocolUtils.java +791 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/MessageChunker.java +186 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/NexSGCUtils.kt +589 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/PhoneAudioMonitor.kt +303 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/SmartGlassesConnectionState.java +9 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/ByteUtilAudioPlayer.java +655 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/Lc3Player.java +441 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PCMAudioPlayer.java +431 -0
- package/android/src/main/res/values/strings.xml +4 -0
- package/app.plugin.js +1 -0
- package/build/BluetoothSdk.types.d.ts +498 -0
- package/build/BluetoothSdk.types.d.ts.map +1 -0
- package/build/BluetoothSdk.types.js +23 -0
- package/build/BluetoothSdk.types.js.map +1 -0
- package/build/BluetoothSdkModule.d.ts +71 -0
- package/build/BluetoothSdkModule.d.ts.map +1 -0
- package/build/BluetoothSdkModule.js +106 -0
- package/build/BluetoothSdkModule.js.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +5 -0
- package/build/index.js.map +1 -0
- package/expo-module.config.json +9 -0
- package/ios/BluetoothSdkModule.swift +665 -0
- package/ios/MentraBluetoothSDK.podspec +77 -0
- package/ios/Packages/CoreObjC/CoreObjC.xcodeproj/project.pbxproj +213 -0
- package/ios/Packages/CoreObjC/PcmConverter.h +22 -0
- package/ios/Packages/CoreObjC/PcmConverter.m +266 -0
- package/ios/Packages/CoreObjC/attdet.c +92 -0
- package/ios/Packages/CoreObjC/attdet.h +44 -0
- package/ios/Packages/CoreObjC/bits.c +375 -0
- package/ios/Packages/CoreObjC/bits.h +315 -0
- package/ios/Packages/CoreObjC/bwdet.c +129 -0
- package/ios/Packages/CoreObjC/bwdet.h +69 -0
- package/ios/Packages/CoreObjC/common.h +151 -0
- package/ios/Packages/CoreObjC/energy.c +70 -0
- package/ios/Packages/CoreObjC/energy.h +43 -0
- package/ios/Packages/CoreObjC/fastmath.h +158 -0
- package/ios/Packages/CoreObjC/lc3.c +704 -0
- package/ios/Packages/CoreObjC/lc3.h +313 -0
- package/ios/Packages/CoreObjC/lc3_cpp.h +283 -0
- package/ios/Packages/CoreObjC/lc3_private.h +163 -0
- package/ios/Packages/CoreObjC/ltpf.c +905 -0
- package/ios/Packages/CoreObjC/ltpf.h +111 -0
- package/ios/Packages/CoreObjC/ltpf_arm.h +506 -0
- package/ios/Packages/CoreObjC/ltpf_neon.h +281 -0
- package/ios/Packages/CoreObjC/makefile.mk +35 -0
- package/ios/Packages/CoreObjC/mdct.c +469 -0
- package/ios/Packages/CoreObjC/mdct.h +57 -0
- package/ios/Packages/CoreObjC/mdct_neon.h +296 -0
- package/ios/Packages/CoreObjC/meson.build +61 -0
- package/ios/Packages/CoreObjC/plc.c +61 -0
- package/ios/Packages/CoreObjC/plc.h +57 -0
- package/ios/Packages/CoreObjC/rnnoise.h +114 -0
- package/ios/Packages/CoreObjC/sns.c +880 -0
- package/ios/Packages/CoreObjC/sns.h +103 -0
- package/ios/Packages/CoreObjC/spec.c +907 -0
- package/ios/Packages/CoreObjC/spec.h +119 -0
- package/ios/Packages/CoreObjC/tables.c +3457 -0
- package/ios/Packages/CoreObjC/tables.h +94 -0
- package/ios/Packages/CoreObjC/tns.c +457 -0
- package/ios/Packages/CoreObjC/tns.h +99 -0
- package/ios/Packages/SherpaOnnx/Model/joiner.onnx +0 -0
- package/ios/Packages/SherpaOnnx/Model/tokens.txt +502 -0
- package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +1659 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Headers/cargs.h +162 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Headers/sherpa-onnx/c-api/c-api.h +1852 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Headers/sherpa-onnx/c-api/cxx-api.h +674 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Info.plist +44 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/libsherpa-onnx.a +0 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/sherpa-onnx.a +0 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/libsherpa-onnx.a +0 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/sherpa-onnx.a +0 -0
- package/ios/Packages/VAD/Common/VAD/VADQuality.swift +41 -0
- package/ios/Packages/VAD/Common/VAD/VADState.swift +26 -0
- package/ios/Packages/VAD/Common/VAD/VADStrategy.swift +29 -0
- package/ios/Packages/VAD/Common/VAD/VADType.swift +14 -0
- package/ios/Packages/VAD/Data/Configuration.swift +68 -0
- package/ios/Packages/VAD/Data/FrameSize.swift +39 -0
- package/ios/Packages/VAD/Data/Record.swift +13 -0
- package/ios/Packages/VAD/Data/Result.swift +22 -0
- package/ios/Packages/VAD/Data/SampleRate.swift +48 -0
- package/ios/Packages/VAD/Silero/Model/silero_vad.onnx +0 -0
- package/ios/Packages/VAD/Silero/SileroVAD.swift +284 -0
- package/ios/Packages/VAD/Silero/SileroVADStrategy.swift +64 -0
- package/ios/Packages/libbz2/module.modulemap +5 -0
- package/ios/Packages/libbz2/shim.h +1 -0
- package/ios/Source/Bridge.swift +353 -0
- package/ios/Source/Bridging-Header.h +16 -0
- package/ios/Source/DeviceManager.swift +1478 -0
- package/ios/Source/DeviceStore.swift +295 -0
- package/ios/Source/MentraBluetoothSDK.swift +2439 -0
- package/ios/Source/ObservableStore.swift +88 -0
- package/ios/Source/PrivacyInfo.xcprivacy +23 -0
- package/ios/Source/controllers/ControllerManager.swift +187 -0
- package/ios/Source/controllers/R1.swift +827 -0
- package/ios/Source/services/PhoneMic.swift +662 -0
- package/ios/Source/sgcs/Frame.swift +651 -0
- package/ios/Source/sgcs/G1.swift +2505 -0
- package/ios/Source/sgcs/G2.swift +3730 -0
- package/ios/Source/sgcs/Mach1.swift +543 -0
- package/ios/Source/sgcs/MentraLive.swift +4708 -0
- package/ios/Source/sgcs/MentraNex.swift +2479 -0
- package/ios/Source/sgcs/SGCManager.swift +243 -0
- package/ios/Source/sgcs/Simulated.swift +270 -0
- package/ios/Source/sgcs/mentraos_ble.pb.swift +3811 -0
- package/ios/Source/stt/STTTools.swift +154 -0
- package/ios/Source/stt/SherpaOnnxTranscriber.swift +401 -0
- package/ios/Source/utils/AudioSessionMonitor.swift +283 -0
- package/ios/Source/utils/Constants.swift +74 -0
- package/ios/Source/utils/Enums.swift +95 -0
- package/ios/Source/utils/G1Text.swift +2067 -0
- package/ios/Source/utils/JSCExperiment.swift +241 -0
- package/ios/Source/utils/MemoryMonitor.swift +44 -0
- package/ios/Source/utils/MessageChunker.swift +164 -0
- package/ios/Source/utils/Models.swift +135 -0
- package/ios/Source/utils/PhoneAudioMonitor.swift +226 -0
- package/ios/Source/utils/TarBz2Extractor.swift +206 -0
- package/package.json +78 -0
- package/plugin/build/index.d.ts +6 -0
- package/plugin/build/index.js +12 -0
- package/plugin/build/withAndroid.d.ts +4 -0
- package/plugin/build/withAndroid.js +80 -0
- package/plugin/build/withIos.d.ts +4 -0
- package/plugin/build/withIos.js +64 -0
- package/src/BluetoothSdk.types.ts +581 -0
- package/src/BluetoothSdkModule.ts +259 -0
- package/src/index.ts +4 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/* Copyright (C)2012 Xiph.Org Foundation
|
|
2
|
+
Copyright (C)2012 Gregory Maxwell
|
|
3
|
+
Copyright (C)2012 Jean-Marc Valin
|
|
4
|
+
File: diag_range.c
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions
|
|
8
|
+
are met:
|
|
9
|
+
|
|
10
|
+
- Redistributions of source code must retain the above copyright
|
|
11
|
+
notice, this list of conditions and the following disclaimer.
|
|
12
|
+
|
|
13
|
+
- Redistributions in binary form must reproduce the above copyright
|
|
14
|
+
notice, this list of conditions and the following disclaimer in the
|
|
15
|
+
documentation and/or other materials provided with the distribution.
|
|
16
|
+
|
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
18
|
+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
19
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
20
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
|
21
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
22
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
23
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
24
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
25
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
26
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
27
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
#ifdef HAVE_CONFIG_H
|
|
31
|
+
# include "config.h"
|
|
32
|
+
#endif
|
|
33
|
+
|
|
34
|
+
#ifdef _WIN32
|
|
35
|
+
#define I64FORMAT "I64d"
|
|
36
|
+
#define I64uFORMAT "I64u"
|
|
37
|
+
#else
|
|
38
|
+
#define I64FORMAT "lld"
|
|
39
|
+
#define I64uFORMAT "llu"
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
#include <stdio.h>
|
|
43
|
+
#include <opus.h>
|
|
44
|
+
#include "diag_range.h"
|
|
45
|
+
|
|
46
|
+
/*This is some non-exported code copied wholesale from libopus.
|
|
47
|
+
*Normal programs shouldn't need these functions, but we use them here
|
|
48
|
+
*to parse deep inside multichannel packets in order to get diagnostic
|
|
49
|
+
*data for save-range. If you're thinking about copying it and you aren't
|
|
50
|
+
*making an opus stream diagnostic tool, you're probably doing something
|
|
51
|
+
*wrong.*/
|
|
52
|
+
static int parse_size(const unsigned char *data, opus_int32 len, short *size)
|
|
53
|
+
{
|
|
54
|
+
if (len<1)
|
|
55
|
+
{
|
|
56
|
+
*size = -1;
|
|
57
|
+
return -1;
|
|
58
|
+
} else if (data[0]<252)
|
|
59
|
+
{
|
|
60
|
+
*size = data[0];
|
|
61
|
+
return 1;
|
|
62
|
+
} else if (len<2)
|
|
63
|
+
{
|
|
64
|
+
*size = -1;
|
|
65
|
+
return -1;
|
|
66
|
+
} else {
|
|
67
|
+
*size = 4*data[1] + data[0];
|
|
68
|
+
return 2;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static int opus_packet_parse_impl(const unsigned char *data, opus_int32 len,
|
|
73
|
+
int self_delimited, unsigned char *out_toc,
|
|
74
|
+
const unsigned char *frames[48], short size[48], int *payload_offset)
|
|
75
|
+
{
|
|
76
|
+
int i, bytes;
|
|
77
|
+
int count;
|
|
78
|
+
int cbr;
|
|
79
|
+
unsigned char ch, toc;
|
|
80
|
+
int framesize;
|
|
81
|
+
int last_size;
|
|
82
|
+
const unsigned char *data0 = data;
|
|
83
|
+
|
|
84
|
+
if (size==NULL)
|
|
85
|
+
return OPUS_BAD_ARG;
|
|
86
|
+
|
|
87
|
+
framesize = opus_packet_get_samples_per_frame(data, 48000);
|
|
88
|
+
|
|
89
|
+
cbr = 0;
|
|
90
|
+
toc = *data++;
|
|
91
|
+
len--;
|
|
92
|
+
last_size = len;
|
|
93
|
+
switch (toc&0x3)
|
|
94
|
+
{
|
|
95
|
+
/* One frame */
|
|
96
|
+
case 0:
|
|
97
|
+
count=1;
|
|
98
|
+
break;
|
|
99
|
+
/* Two CBR frames */
|
|
100
|
+
case 1:
|
|
101
|
+
count=2;
|
|
102
|
+
cbr = 1;
|
|
103
|
+
if (!self_delimited)
|
|
104
|
+
{
|
|
105
|
+
if (len&0x1)
|
|
106
|
+
return OPUS_INVALID_PACKET;
|
|
107
|
+
size[0] = last_size = len/2;
|
|
108
|
+
}
|
|
109
|
+
break;
|
|
110
|
+
/* Two VBR frames */
|
|
111
|
+
case 2:
|
|
112
|
+
count = 2;
|
|
113
|
+
bytes = parse_size(data, len, size);
|
|
114
|
+
len -= bytes;
|
|
115
|
+
if (size[0]<0 || size[0] > len)
|
|
116
|
+
return OPUS_INVALID_PACKET;
|
|
117
|
+
data += bytes;
|
|
118
|
+
last_size = len-size[0];
|
|
119
|
+
break;
|
|
120
|
+
/* Multiple CBR/VBR frames (from 0 to 120 ms) */
|
|
121
|
+
case 3:
|
|
122
|
+
if (len<1)
|
|
123
|
+
return OPUS_INVALID_PACKET;
|
|
124
|
+
/* Number of frames encoded in bits 0 to 5 */
|
|
125
|
+
ch = *data++;
|
|
126
|
+
count = ch&0x3F;
|
|
127
|
+
if (count <= 0 || framesize*count > 5760)
|
|
128
|
+
return OPUS_INVALID_PACKET;
|
|
129
|
+
len--;
|
|
130
|
+
/* Padding flag is bit 6 */
|
|
131
|
+
if (ch&0x40)
|
|
132
|
+
{
|
|
133
|
+
int padding=0;
|
|
134
|
+
int p;
|
|
135
|
+
do {
|
|
136
|
+
if (len<=0)
|
|
137
|
+
return OPUS_INVALID_PACKET;
|
|
138
|
+
p = *data++;
|
|
139
|
+
len--;
|
|
140
|
+
padding += p==255 ? 254: p;
|
|
141
|
+
} while (p==255);
|
|
142
|
+
len -= padding;
|
|
143
|
+
}
|
|
144
|
+
if (len<0)
|
|
145
|
+
return OPUS_INVALID_PACKET;
|
|
146
|
+
/* VBR flag is bit 7 */
|
|
147
|
+
cbr = !(ch&0x80);
|
|
148
|
+
if (!cbr)
|
|
149
|
+
{
|
|
150
|
+
/* VBR case */
|
|
151
|
+
last_size = len;
|
|
152
|
+
for (i=0;i<count-1;i++)
|
|
153
|
+
{
|
|
154
|
+
bytes = parse_size(data, len, size+i);
|
|
155
|
+
len -= bytes;
|
|
156
|
+
if (size[i]<0 || size[i] > len)
|
|
157
|
+
return OPUS_INVALID_PACKET;
|
|
158
|
+
data += bytes;
|
|
159
|
+
last_size -= bytes+size[i];
|
|
160
|
+
}
|
|
161
|
+
if (last_size<0)
|
|
162
|
+
return OPUS_INVALID_PACKET;
|
|
163
|
+
} else if (!self_delimited)
|
|
164
|
+
{
|
|
165
|
+
/* CBR case */
|
|
166
|
+
last_size = len/count;
|
|
167
|
+
if (last_size*count!=len)
|
|
168
|
+
return OPUS_INVALID_PACKET;
|
|
169
|
+
for (i=0;i<count-1;i++)
|
|
170
|
+
size[i] = last_size;
|
|
171
|
+
}
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
/* Self-delimited framing has an extra size for the last frame. */
|
|
175
|
+
if (self_delimited)
|
|
176
|
+
{
|
|
177
|
+
bytes = parse_size(data, len, size+count-1);
|
|
178
|
+
len -= bytes;
|
|
179
|
+
if (size[count-1]<0 || size[count-1] > len)
|
|
180
|
+
return OPUS_INVALID_PACKET;
|
|
181
|
+
data += bytes;
|
|
182
|
+
/* For CBR packets, apply the size to all the frames. */
|
|
183
|
+
if (cbr)
|
|
184
|
+
{
|
|
185
|
+
if (size[count-1]*count > len)
|
|
186
|
+
return OPUS_INVALID_PACKET;
|
|
187
|
+
for (i=0;i<count-1;i++)
|
|
188
|
+
size[i] = size[count-1];
|
|
189
|
+
} else if(size[count-1] > last_size)
|
|
190
|
+
return OPUS_INVALID_PACKET;
|
|
191
|
+
} else
|
|
192
|
+
{
|
|
193
|
+
/* Because it's not encoded explicitly, it's possible the size of the
|
|
194
|
+
last packet (or all the packets, for the CBR case) is larger than
|
|
195
|
+
1275. Reject them here.*/
|
|
196
|
+
if (last_size > 1275)
|
|
197
|
+
return OPUS_INVALID_PACKET;
|
|
198
|
+
size[count-1] = last_size;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
if (frames)
|
|
202
|
+
{
|
|
203
|
+
for (i=0;i<count;i++)
|
|
204
|
+
{
|
|
205
|
+
frames[i] = data;
|
|
206
|
+
data += size[i];
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (out_toc)
|
|
211
|
+
*out_toc = toc;
|
|
212
|
+
|
|
213
|
+
if (payload_offset)
|
|
214
|
+
*payload_offset = data-data0;
|
|
215
|
+
|
|
216
|
+
return count;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
void save_range(FILE *frange, int frame_size, unsigned char *packet, int nbBytes, opus_uint32 *rngs, int nb_streams){
|
|
220
|
+
int i, parsed_size;
|
|
221
|
+
const unsigned char *subpkt;
|
|
222
|
+
static const char *bw_strings[5]={"NB","MB","WB","SWB","FB"};
|
|
223
|
+
static const char *mode_strings[3]={"LP","HYB","MDCT"};
|
|
224
|
+
fprintf(frange,"%d, %d, ",frame_size,nbBytes);
|
|
225
|
+
subpkt=packet;
|
|
226
|
+
parsed_size=nbBytes;
|
|
227
|
+
for(i=0;i<nb_streams;i++){
|
|
228
|
+
int j,payload_offset,nf;
|
|
229
|
+
const unsigned char *frames[48];
|
|
230
|
+
unsigned char toc;
|
|
231
|
+
short size[48];
|
|
232
|
+
payload_offset=0;
|
|
233
|
+
nf=opus_packet_parse_impl(subpkt,parsed_size,i+1!=nb_streams,
|
|
234
|
+
&toc,frames,size,&payload_offset);
|
|
235
|
+
fprintf(frange,"[[%d",(int)(frames[0]-subpkt));
|
|
236
|
+
for(j=0;j<nf;j++)fprintf(frange,", %d",size[j]);
|
|
237
|
+
fprintf(frange,"], %s, %s, %c, %d",
|
|
238
|
+
mode_strings[((((subpkt[0]>>3)+48)&92)+4)>>5],
|
|
239
|
+
bw_strings[opus_packet_get_bandwidth(subpkt)-OPUS_BANDWIDTH_NARROWBAND],
|
|
240
|
+
subpkt[0]&4?'S':'M',opus_packet_get_samples_per_frame(subpkt,48000));
|
|
241
|
+
fprintf(frange,", %" I64uFORMAT "]%s",(unsigned long long)rngs[i],i+1==nb_streams?"\n":", ");
|
|
242
|
+
parsed_size-=payload_offset;
|
|
243
|
+
subpkt+=payload_offset;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/* Copyright (C)2012 Xiph.Org Foundation
|
|
2
|
+
File: diag_range.h
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions
|
|
6
|
+
are met:
|
|
7
|
+
|
|
8
|
+
- Redistributions of source code must retain the above copyright
|
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
- Redistributions in binary form must reproduce the above copyright
|
|
12
|
+
notice, this list of conditions and the following disclaimer in the
|
|
13
|
+
documentation and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
16
|
+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
17
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
18
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
|
19
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
20
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
21
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
22
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
23
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
24
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
25
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
void save_range(FILE *frange, int frame_size, unsigned char *packet, int nbBytes, opus_uint32 *rngs, int nb_streams);
|
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/* Copyright (C)2012 Gregory Maxwell
|
|
2
|
+
File: info_opus.c
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions
|
|
6
|
+
are met:
|
|
7
|
+
|
|
8
|
+
- Redistributions of source code must retain the above copyright
|
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
- Redistributions in binary form must reproduce the above copyright
|
|
12
|
+
notice, this list of conditions and the following disclaimer in the
|
|
13
|
+
documentation and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
16
|
+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
17
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
18
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
|
19
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
20
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
21
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
22
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
23
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
24
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
25
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
#ifdef HAVE_CONFIG_H
|
|
29
|
+
#include <config.h>
|
|
30
|
+
#endif
|
|
31
|
+
|
|
32
|
+
#include <stdlib.h>
|
|
33
|
+
#include <string.h>
|
|
34
|
+
|
|
35
|
+
#include <ogg/ogg.h>
|
|
36
|
+
|
|
37
|
+
#ifndef OPUSTOOLS
|
|
38
|
+
# include "ogginfo2.h"
|
|
39
|
+
#else
|
|
40
|
+
# include "opusinfo.h"
|
|
41
|
+
#endif
|
|
42
|
+
#include "opus_header.h"
|
|
43
|
+
#include "info_opus.h"
|
|
44
|
+
|
|
45
|
+
/* From libopus, src/opus_decode.c */
|
|
46
|
+
static int packet_get_samples_per_frame(const unsigned char *data, ogg_int32_t Fs)
|
|
47
|
+
{
|
|
48
|
+
int audiosize;
|
|
49
|
+
if (data[0]&0x80)
|
|
50
|
+
{
|
|
51
|
+
audiosize = ((data[0]>>3)&0x3);
|
|
52
|
+
audiosize = (Fs<<audiosize)/400;
|
|
53
|
+
} else if ((data[0]&0x60) == 0x60)
|
|
54
|
+
{
|
|
55
|
+
audiosize = (data[0]&0x08) ? Fs/50 : Fs/100;
|
|
56
|
+
} else {
|
|
57
|
+
audiosize = ((data[0]>>3)&0x3);
|
|
58
|
+
if (audiosize == 3)
|
|
59
|
+
audiosize = Fs*60/1000;
|
|
60
|
+
else
|
|
61
|
+
audiosize = (Fs<<audiosize)/100;
|
|
62
|
+
}
|
|
63
|
+
return audiosize;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* From libopus, src/opus_decode.c */
|
|
67
|
+
static int packet_get_nb_frames(const unsigned char packet[], ogg_int32_t len)
|
|
68
|
+
{
|
|
69
|
+
int count;
|
|
70
|
+
if (len<1)
|
|
71
|
+
return -1;
|
|
72
|
+
count = packet[0]&0x3;
|
|
73
|
+
if (count==0)
|
|
74
|
+
return 1;
|
|
75
|
+
else if (count!=3)
|
|
76
|
+
return 2;
|
|
77
|
+
else if (len<2)
|
|
78
|
+
return -4;
|
|
79
|
+
else
|
|
80
|
+
return packet[1]&0x3F;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
#define readle32(buf, base) (((buf[base+3]<<24)&0xff000000)| \
|
|
84
|
+
((buf[base+2]<<16)&0xff0000)| \
|
|
85
|
+
((buf[base+1]<<8)&0xff00)| \
|
|
86
|
+
(buf[base]&0xff))
|
|
87
|
+
|
|
88
|
+
void info_opus_process(stream_processor *stream, ogg_page *page )
|
|
89
|
+
{
|
|
90
|
+
ogg_packet packet;
|
|
91
|
+
ogg_int64_t page_samples=0;
|
|
92
|
+
misc_opus_info *inf = stream->data;
|
|
93
|
+
int header=0, packets=0;
|
|
94
|
+
int res;
|
|
95
|
+
|
|
96
|
+
ogg_stream_pagein(&stream->os, page);
|
|
97
|
+
if(inf->doneheaders < 2)
|
|
98
|
+
header = 1;
|
|
99
|
+
inf->last_eos = ogg_page_eos(page);
|
|
100
|
+
|
|
101
|
+
while(1) {
|
|
102
|
+
ogg_int32_t spp;
|
|
103
|
+
res = ogg_stream_packetout(&stream->os, &packet);
|
|
104
|
+
if(res < 0) {
|
|
105
|
+
oi_warn(_("WARNING: discontinuity in stream (%d)\n"), stream->num);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
else if (res == 0)
|
|
109
|
+
break;
|
|
110
|
+
|
|
111
|
+
packets++;
|
|
112
|
+
if(inf->doneheaders < 2) {
|
|
113
|
+
if(inf->doneheaders==0 && opus_header_parse(packet.packet,packet.bytes,&inf->oh)!=1) {
|
|
114
|
+
oi_warn(_("WARNING: Could not decode Opus header "
|
|
115
|
+
"packet %d - invalid Opus stream (%d)\n"),
|
|
116
|
+
inf->doneheaders, stream->num);
|
|
117
|
+
continue;
|
|
118
|
+
} else if (inf->doneheaders==0){
|
|
119
|
+
if(inf->oh.preskip<120)oi_warn(_("WARNING: Implausibly low preskip in Opus stream (%d)\n"),stream->num);
|
|
120
|
+
}
|
|
121
|
+
if(inf->doneheaders==1 && (packet.bytes<8 || memcmp(packet.packet, "OpusTags",8)!=0)) {
|
|
122
|
+
oi_warn(_("WARNING: Could not decode OpusTags header "
|
|
123
|
+
"packet %d - invalid Opus stream (%d)\n"),
|
|
124
|
+
inf->doneheaders, stream->num);
|
|
125
|
+
continue;
|
|
126
|
+
} else if (inf->doneheaders==1) {
|
|
127
|
+
char *tmp;
|
|
128
|
+
char *c=(char *)packet.packet;
|
|
129
|
+
int length, len, i, nb_fields;
|
|
130
|
+
|
|
131
|
+
length=packet.bytes;
|
|
132
|
+
if (length<(8+4+4)) {
|
|
133
|
+
oi_warn(_("Invalid/corrupted comments in stream %d\n"),stream->num);
|
|
134
|
+
continue;
|
|
135
|
+
}
|
|
136
|
+
c += 8;
|
|
137
|
+
len=readle32(c, 0);
|
|
138
|
+
c+=4;
|
|
139
|
+
if (len < 0 || len>(length-16)) {
|
|
140
|
+
oi_warn(_("Invalid/corrupted comments in stream %d\n"),stream->num);
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
tmp=calloc(len+1,1);
|
|
144
|
+
memcpy(tmp,c,len);
|
|
145
|
+
oi_info(_("Encoded with %s\n"),tmp);
|
|
146
|
+
free(tmp);
|
|
147
|
+
c+=len;
|
|
148
|
+
/*The -16 check above makes sure we can read this.*/
|
|
149
|
+
nb_fields=readle32(c, 0);
|
|
150
|
+
c+=4;
|
|
151
|
+
length-=16+len;
|
|
152
|
+
if (nb_fields < 0 || nb_fields>(length>>2)) {
|
|
153
|
+
oi_warn(_("Invalid/corrupted comments in stream %d\n"),stream->num);
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if(nb_fields)oi_info(_("User comments section follows...\n"));
|
|
157
|
+
for (i=0;i<nb_fields;i++) {
|
|
158
|
+
char *comment;
|
|
159
|
+
if (length<4) {
|
|
160
|
+
oi_warn(_("Invalid/corrupted comments in stream %d\n"),stream->num);
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
len=readle32(c, 0);
|
|
164
|
+
c+=4;
|
|
165
|
+
length-=4;
|
|
166
|
+
if (len < 0 || len>length) {
|
|
167
|
+
oi_warn(_("Invalid/corrupted comments in stream %d\n"),stream->num);
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
/*check_xiph_comment expects a null terminated comment*/
|
|
171
|
+
comment=malloc((len+1)*sizeof(char));
|
|
172
|
+
memcpy(comment,c,len);
|
|
173
|
+
comment[len]=0;
|
|
174
|
+
check_xiph_comment(stream, i, comment, len);
|
|
175
|
+
free(comment);
|
|
176
|
+
c+=len;
|
|
177
|
+
length-=len;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
inf->doneheaders++;
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if(packet.bytes>=2 && memcmp(packet.packet, "Op",2)==0) {
|
|
185
|
+
oi_warn(_("WARNING: Invalid packet or misplaced header in stream %d\n"),stream->num);
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if(packet.bytes<1) {
|
|
189
|
+
oi_warn(_("WARNING: Invalid zero byte packet in stream %d\n"),stream->num);
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
spp = packet_get_nb_frames(packet.packet,packet.bytes);
|
|
193
|
+
if(spp<1 || spp>48) {
|
|
194
|
+
oi_warn(_("WARNING: Invalid packet TOC in stream %d\n"),stream->num);
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
spp *= packet_get_samples_per_frame(packet.packet,48000);
|
|
198
|
+
if(spp<120 || spp>5760 || (spp%120)!=0) {
|
|
199
|
+
oi_warn(_("WARNING: Invalid packet TOC in stream %d\n"),stream->num);
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
inf->total_samples += spp;
|
|
203
|
+
page_samples += spp;
|
|
204
|
+
inf->total_packets++;
|
|
205
|
+
inf->last_packet_duration = spp;
|
|
206
|
+
if(inf->max_packet_duration<spp)inf->max_packet_duration=spp;
|
|
207
|
+
if(inf->min_packet_duration>spp)inf->min_packet_duration=spp;
|
|
208
|
+
if(inf->max_packet_bytes<packet.bytes)inf->max_packet_bytes=packet.bytes;
|
|
209
|
+
if(inf->min_packet_bytes>packet.bytes)inf->min_packet_bytes=packet.bytes;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if(!header) {
|
|
213
|
+
ogg_int64_t gp = ogg_page_granulepos(page);
|
|
214
|
+
if(gp > 0) {
|
|
215
|
+
if(gp < inf->lastgranulepos)
|
|
216
|
+
oi_warn(_("WARNING: granulepos in stream %d decreases from %"
|
|
217
|
+
I64FORMAT " to %" I64FORMAT "\n" ),
|
|
218
|
+
stream->num, inf->lastgranulepos, gp);
|
|
219
|
+
if(inf->lastgranulepos==0 && inf->firstgranule==-1) {
|
|
220
|
+
/*First timed page, now we can recover the start time.*/
|
|
221
|
+
inf->firstgranule = gp-inf->total_samples;
|
|
222
|
+
if(inf->firstgranule<0) {
|
|
223
|
+
/*There shouldn't be any negative samples after counting the samples in the page backwards
|
|
224
|
+
from the first GP, but if this is the last page of the stream there may need to be to trim.*/
|
|
225
|
+
if(!ogg_page_eos(page))oi_warn(_("WARNING: Samples with negative granpos in stream %d\n"),stream->num);
|
|
226
|
+
else inf->firstgranule=0;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if(inf->total_samples<gp-inf->firstgranule)oi_warn(_("WARNING: Sample count behind granule (%" I64FORMAT ">%" I64FORMAT ") in stream %d\n"),
|
|
230
|
+
(long long)inf->total_samples,(long long)(gp-inf->firstgranule),stream->num);
|
|
231
|
+
if(!ogg_page_eos(page) && (inf->total_samples>gp-inf->firstgranule))
|
|
232
|
+
oi_warn(_("WARNING: Sample count ahead of granule (%" I64FORMAT ">%" I64FORMAT ") in stream %d\n"),
|
|
233
|
+
(long long)inf->total_samples,(long long)(gp-inf->firstgranule),stream->num);
|
|
234
|
+
inf->lastlastgranulepos = inf->lastgranulepos;
|
|
235
|
+
inf->lastgranulepos = gp;
|
|
236
|
+
if(!packets)
|
|
237
|
+
oi_warn(_("WARNING: Page with positive granpos (%" I64FORMAT ") on a page with no completed packets in stream %d\n"),gp,stream->num);
|
|
238
|
+
}
|
|
239
|
+
else if(packets) {
|
|
240
|
+
/* Only do this if we saw at least one packet ending on this page.
|
|
241
|
+
* It's legal (though very unusual) to have no packets in a page at
|
|
242
|
+
* all - this is occasionally used to have an empty EOS page */
|
|
243
|
+
oi_warn(_("Negative or zero granulepos (%" I64FORMAT ") on Opus stream outside of headers. This file was created by a buggy encoder\n"), gp);
|
|
244
|
+
}
|
|
245
|
+
inf->overhead_bytes += page->header_len;
|
|
246
|
+
if(page_samples)inf->last_page_duration = page_samples;
|
|
247
|
+
if(inf->max_page_duration<page_samples)inf->max_page_duration=page_samples;
|
|
248
|
+
if(inf->min_page_duration>page_samples)inf->min_page_duration=page_samples;
|
|
249
|
+
inf->total_pages++;
|
|
250
|
+
} else {
|
|
251
|
+
/* Headers and metadata are pure overhead. */
|
|
252
|
+
inf->overhead_bytes += page->header_len + page->body_len;
|
|
253
|
+
}
|
|
254
|
+
inf->bytes += page->header_len + page->body_len;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
void info_opus_end(stream_processor *stream)
|
|
258
|
+
{
|
|
259
|
+
misc_opus_info *inf = stream->data;
|
|
260
|
+
|
|
261
|
+
oi_info(_("Opus stream %d:\n"),stream->num);
|
|
262
|
+
|
|
263
|
+
if(inf && inf->total_packets>0){
|
|
264
|
+
int i;
|
|
265
|
+
long minutes, seconds, milliseconds;
|
|
266
|
+
double time;
|
|
267
|
+
time = (inf->lastgranulepos-inf->firstgranule-inf->oh.preskip) / 48000.;
|
|
268
|
+
if(time<=0)time=0;
|
|
269
|
+
minutes = (long)(time) / 60;
|
|
270
|
+
seconds = (long)(time - minutes*60);
|
|
271
|
+
milliseconds = (long)((time - minutes*60 - seconds)*1000);
|
|
272
|
+
if(inf->lastgranulepos-inf->firstgranule<inf->oh.preskip)
|
|
273
|
+
oi_error(_("\tERROR: stream %d has a negative duration: %" I64FORMAT "-%" I64FORMAT "-%d=%" I64FORMAT "\n"),stream->num,
|
|
274
|
+
inf->lastgranulepos,inf->firstgranule,inf->oh.preskip,inf->lastgranulepos-inf->firstgranule-inf->oh.preskip);
|
|
275
|
+
if((inf->total_samples-inf->last_page_duration)>(inf->lastgranulepos-inf->firstgranule))
|
|
276
|
+
oi_error(_("\tERROR: stream %d has interior holes or more than one page of end trimming\n"),stream->num);
|
|
277
|
+
if(inf->last_eos &&( (inf->last_page_duration-inf->last_packet_duration)>(inf->lastgranulepos-inf->lastlastgranulepos)))
|
|
278
|
+
oi_warn(_("\tWARNING: stream %d has more than one packet of end trimming\n"),stream->num);
|
|
279
|
+
if(inf->max_page_duration>=240000)
|
|
280
|
+
oi_warn(_("\tWARNING: stream %d has high muxing delay\n"),stream->num);
|
|
281
|
+
oi_info(_("\tPre-skip: %d\n"),inf->oh.preskip);
|
|
282
|
+
oi_info(_("\tPlayback gain: %gdB\n"),inf->oh.gain/256.);
|
|
283
|
+
oi_info(_("\tChannels: %d\n"),inf->oh.channels);
|
|
284
|
+
if(inf->oh.input_sample_rate)oi_info(_("\tOriginal sample rate: %dHz\n"),inf->oh.input_sample_rate);
|
|
285
|
+
if(inf->oh.nb_streams>1)oi_info(_("\tStreams: %d, Coupled: %d\n"),inf->oh.nb_streams,inf->oh.nb_coupled);
|
|
286
|
+
if(inf->oh.channel_mapping>0) {
|
|
287
|
+
oi_info(_("\tChannel Mapping family: %d Map:"),inf->oh.channel_mapping);
|
|
288
|
+
for(i=0;i<inf->oh.channels;i++)oi_info("%s%d%s",i==0?" [":", ",inf->oh.stream_map[i],i==inf->oh.channels-1?"]\n":"");
|
|
289
|
+
}
|
|
290
|
+
if(inf->total_packets)oi_info(_("\tPacket duration: %6.1fms (max), %6.1fms (avg), %6.1fms (min)\n"),
|
|
291
|
+
inf->max_packet_duration/48.,inf->total_samples/(double)inf->total_packets/48.,inf->min_packet_duration/48.);
|
|
292
|
+
if(inf->total_pages)oi_info(_("\tPage duration: %8.1fms (max), %6.1fms (avg), %6.1fms (min)\n"),
|
|
293
|
+
inf->max_page_duration/48.,inf->total_samples/(double)inf->total_pages/48.,inf->min_page_duration/48.);
|
|
294
|
+
oi_info(_("\tTotal data length: %" I64FORMAT " bytes (overhead: %0.3g%%)\n"),inf->bytes,(double)inf->overhead_bytes/inf->bytes*100.);
|
|
295
|
+
oi_info(_("\tPlayback length: %ldm:%02ld.%03lds\n"), minutes, seconds, milliseconds);
|
|
296
|
+
oi_info(_("\tAverage bitrate: %0.4g kb/s, w/o overhead: %.04g kb/s%s\n"),time<=0?0:inf->bytes*8/time/1000.0,
|
|
297
|
+
time<=0?0:(inf->bytes-inf->overhead_bytes)*8/time/1000.0,
|
|
298
|
+
(inf->min_packet_duration==inf->max_packet_duration)&&(inf->min_packet_bytes==inf->max_packet_bytes)?" (hard-CBR)":"");
|
|
299
|
+
} else {
|
|
300
|
+
oi_warn(_("\tWARNING: stream %d is empty\n"),stream->num);
|
|
301
|
+
}
|
|
302
|
+
free(stream->data);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
void info_opus_start(stream_processor *stream)
|
|
306
|
+
{
|
|
307
|
+
misc_opus_info *oinfo;
|
|
308
|
+
|
|
309
|
+
stream->type = "opus";
|
|
310
|
+
stream->process_page = info_opus_process;
|
|
311
|
+
stream->process_end = info_opus_end;
|
|
312
|
+
|
|
313
|
+
stream->data = calloc(1, sizeof(misc_opus_info));
|
|
314
|
+
|
|
315
|
+
oinfo = stream->data;
|
|
316
|
+
oinfo->firstgranule=-1;
|
|
317
|
+
oinfo->min_packet_duration=5760;
|
|
318
|
+
oinfo->min_page_duration=5760*255;
|
|
319
|
+
oinfo->min_packet_bytes=2147483647;
|
|
320
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/* Copyright (C)2012 Gregory Maxwell
|
|
2
|
+
File: info_opus.h
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions
|
|
6
|
+
are met:
|
|
7
|
+
|
|
8
|
+
- Redistributions of source code must retain the above copyright
|
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
- Redistributions in binary form must reproduce the above copyright
|
|
12
|
+
notice, this list of conditions and the following disclaimer in the
|
|
13
|
+
documentation and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
16
|
+
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
17
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
18
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
|
19
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
20
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
21
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
22
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
23
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
24
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
25
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
typedef struct {
|
|
29
|
+
OpusHeader oh;
|
|
30
|
+
ogg_int64_t bytes;
|
|
31
|
+
ogg_int64_t overhead_bytes;
|
|
32
|
+
ogg_int64_t lastlastgranulepos;
|
|
33
|
+
ogg_int64_t lastgranulepos;
|
|
34
|
+
ogg_int64_t firstgranule;
|
|
35
|
+
ogg_int64_t total_samples;
|
|
36
|
+
ogg_int64_t total_packets;
|
|
37
|
+
ogg_int64_t total_pages;
|
|
38
|
+
ogg_int32_t last_packet_duration;
|
|
39
|
+
ogg_int32_t last_page_duration;
|
|
40
|
+
ogg_int32_t max_page_duration;
|
|
41
|
+
ogg_int32_t min_page_duration;
|
|
42
|
+
ogg_int32_t max_packet_duration;
|
|
43
|
+
ogg_int32_t min_packet_duration;
|
|
44
|
+
ogg_int32_t max_packet_bytes;
|
|
45
|
+
ogg_int32_t min_packet_bytes;
|
|
46
|
+
int last_eos;
|
|
47
|
+
|
|
48
|
+
int doneheaders;
|
|
49
|
+
} misc_opus_info;
|
|
50
|
+
|
|
51
|
+
void info_opus_start(stream_processor *stream);
|