@glassly/bluetooth-sdk 0.1.0-dev.26
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 +563 -0
- package/android/build.gradle +450 -0
- package/android/gradle.properties.example +9 -0
- package/android/lc3Lib/CMakeLists.txt +6 -0
- package/android/lc3Lib/build.gradle +212 -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/glassly/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 +4 -0
- package/android/silero/LICENSE.md +17 -0
- package/android/silero/build.gradle +50 -0
- package/android/silero/proguard-rules.pro +24 -0
- package/android/silero/src/androidTest/assets/hello.wav +0 -0
- package/android/silero/src/androidTest/java/com/konovalov/vad/silero/VadSileroTest.kt +79 -0
- package/android/silero/src/main/assets/LICENSE +21 -0
- package/android/silero/src/main/assets/silero_vad.onnx +0 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/Vad.kt +160 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/VadSilero.kt +449 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/FrameSize.kt +15 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/Mode.kt +14 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/SampleRate.kt +12 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/utils/AudioUtils.kt +47 -0
- package/android/silero/src/main/java/com/konovalov/vad/silero/utils/TensorMap.kt +41 -0
- package/android/silero/src/test/java/com/konovalov/vad/silero/utils/AudioUtilsTest.kt +44 -0
- package/android/src/main/AndroidManifest.xml +42 -0
- package/android/src/main/assets/G2Firmware/README.md +11 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdk.kt +2325 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdkAnalytics.kt +216 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdkDebug.kt +14 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdkDefaults.kt +7 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/BluetoothSdkModule.kt +1088 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/Bridge.kt +953 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/DeviceManager.kt +2528 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/DeviceStore.kt +360 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/GeneratedChangelogCatalog.kt +8 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/GeneratedReleaseMetadata.kt +11 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/LocalNetworkModule.kt +414 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/ObservableStore.kt +88 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/OtaManifest.kt +191 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/ReleaseChangelog.kt +61 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/ScopedNetworkReadiness.kt +17 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/audio/AudioModels.kt +144 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/camera/CameraModels.kt +486 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/connection/ConnectionModels.kt +78 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/controllers/ControllerManager.kt +158 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/controllers/R1.kt +937 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/debug/BleTraceLogger.kt +165 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/events/BluetoothEvents.kt +178 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/internal/MapParsing.kt +140 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/net/LocalIpv4.kt +57 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/otaserver/LocalOtaServer.kt +304 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/otaserver/OtaServerModule.kt +120 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/photoreceiver/LocalPhotoReceiverRegistry.java +108 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/photoreceiver/LocalPhotoUploadServer.kt +622 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/photoreceiver/PhotoReceiverModule.kt +156 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/requests/DisplayRequests.kt +56 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/services/Foreground.kt +272 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/services/PhoneMic.kt +1195 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/Ar99.java +2653 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/BesOtaHeartbeatGuard.kt +49 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/BesOtaProgressMapper.kt +27 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G1.kt +3878 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G1TextSanitizer.kt +38 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2.kt +6428 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2CfwClassification.kt +49 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2CfwRenderer.kt +1241 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2CfwTextureCache.kt +270 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2FlashProtocol.kt +291 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/G2Flasher.kt +411 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/GlasslyBle.java +43189 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/Mach1.kt +1280 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/MentraLive.kt +10817 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/MentraLiveL2capChannel.kt +274 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/MentraLivePairingAdvertisement.kt +54 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/MentraNex.kt +2011 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/Nimo.kt +2532 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/SGCManager.kt +470 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/Simulated.kt +228 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/Ar99OtaManager.java +566 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaByteUtils.java +18 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaCommandConstants.java +35 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaCrc32Util.java +13 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaGattTransport.java +11 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/sgcs/ar99/ota/OtaProtocol.java +92 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/speakerid/SpeakerIdEngine.kt +525 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/status/DeviceStatus.kt +669 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/status/RuntimeState.kt +201 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/status/WifiHotspotStatus.kt +189 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/streaming/StreamModels.kt +518 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/stt/STTTools.kt +391 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/stt/SherpaOnnxTranscriber.kt +518 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/stt/VadGateSpeechPolicy.kt +229 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/tts/TTSTools.kt +248 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/types/DeviceModels.kt +96 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/AES.java +106 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/AudioSessionMonitor.kt +189 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/AvifExifStripper.java +573 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/BitmapJavaUtils.java +169 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/BleJsonCompact.java +496 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/BlePhotoUploadService.java +677 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/BleWireProtocol.java +108 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/Constants.kt +46 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/G1Text.kt +436 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/HeifExifTagReader.java +199 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +29 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/IncidentLogBleUploadService.java +77 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/K900LengthCodec.java +115 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/K900ProtocolUtils.java +827 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/MessageChunkReassembler.java +228 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/MessageChunker.java +325 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/NexSGCUtils.kt +698 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/PhoneAudioMonitor.kt +348 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/SmartGlassesConnectionState.java +9 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/Ar99OpusPcmDecoder.java +398 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/ByteUtilAudioPlayer.java +655 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/Lc3Player.java +441 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/PCMAudioPlayer.java +431 -0
- package/android/src/main/java/com/glassly/bluetoothsdk/utils/audio/PcmStreamPlayer.kt +328 -0
- package/android/src/main/res/values/strings.xml +4 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/BluetoothSdkExceptionTest.kt +18 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/OtaManifestDowngradeTest.kt +86 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/OtaStartResponsePolicyTest.kt +30 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/ReleaseChangelogTest.kt +13 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/ScopedNetworkReadinessTest.kt +39 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/StreamStatusEventTest.kt +29 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/camera/PhotoRequestTest.kt +141 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/otaserver/LocalOtaServerTest.kt +82 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/photoreceiver/LocalPhotoReceiverRegistryTest.java +75 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/services/ForegroundServiceTypeTest.kt +69 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/Ar99AdvertisementMatcherTest.java +22 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/BesOtaHeartbeatGuardTest.kt +73 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/BesOtaProgressMapperTest.kt +67 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/EvenRleTest.kt +63 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G1TextSanitizerTest.kt +31 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G2CfwClassificationTest.kt +89 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G2CfwRendererTest.kt +344 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G2CfwTextureCacheTest.kt +200 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/G2FlashProtocolTest.kt +131 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/MentraLiveGattCharacteristicsTest.kt +39 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/MentraLivePairingAdvertisementParserTest.kt +133 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/sgcs/NimoProtocolTest.kt +333 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/AvifExifStripperTest.java +46 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/BinaryMessageChunkerTest.java +84 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/BleJsonCompactTest.java +319 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/BlePhotoUploadServiceTest.java +107 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/K900ProtocolUtilsEndiannessTest.java +172 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/K900ProtocolUtilsTest.java +24 -0
- package/android/src/test/java/com/glassly/bluetoothsdk/utils/PhoneAudioMonitorTest.kt +45 -0
- package/android/src/test/resources/avif_with_exif.avif +0 -0
- package/app.plugin.js +3 -0
- package/build/BluetoothSdk.types.d.ts +1354 -0
- package/build/BluetoothSdk.types.d.ts.map +1 -0
- package/build/BluetoothSdk.types.js +41 -0
- package/build/BluetoothSdk.types.js.map +1 -0
- package/build/_internal.d.ts +17 -0
- package/build/_internal.d.ts.map +1 -0
- package/build/_internal.js +16 -0
- package/build/_internal.js.map +1 -0
- package/build/_private/BluetoothSdkModule.d.ts +172 -0
- package/build/_private/BluetoothSdkModule.d.ts.map +1 -0
- package/build/_private/BluetoothSdkModule.js +300 -0
- package/build/_private/BluetoothSdkModule.js.map +1 -0
- package/build/_private/LocalNetworkModule.d.ts +38 -0
- package/build/_private/LocalNetworkModule.d.ts.map +1 -0
- package/build/_private/LocalNetworkModule.js +3 -0
- package/build/_private/LocalNetworkModule.js.map +1 -0
- package/build/_private/cameraRequestPayload.d.ts +4 -0
- package/build/_private/cameraRequestPayload.d.ts.map +1 -0
- package/build/_private/cameraRequestPayload.js +32 -0
- package/build/_private/cameraRequestPayload.js.map +1 -0
- package/build/_private/photoRequestPayload.d.ts +6 -0
- package/build/_private/photoRequestPayload.d.ts.map +1 -0
- package/build/_private/photoRequestPayload.js +86 -0
- package/build/_private/photoRequestPayload.js.map +1 -0
- package/build/_private/sdkOtaManifest.d.ts +11 -0
- package/build/_private/sdkOtaManifest.d.ts.map +1 -0
- package/build/_private/sdkOtaManifest.js +15 -0
- package/build/_private/sdkOtaManifest.js.map +1 -0
- package/build/changelogs.d.ts +7 -0
- package/build/changelogs.d.ts.map +1 -0
- package/build/changelogs.js +46 -0
- package/build/changelogs.js.map +1 -0
- package/build/debug.d.ts +3 -0
- package/build/debug.d.ts.map +1 -0
- package/build/debug.js +8 -0
- package/build/debug.js.map +1 -0
- package/build/generated/changelogCatalog.d.ts +9 -0
- package/build/generated/changelogCatalog.d.ts.map +1 -0
- package/build/generated/changelogCatalog.js +12 -0
- package/build/generated/changelogCatalog.js.map +1 -0
- package/build/generated/releaseMetadata.d.ts +12 -0
- package/build/generated/releaseMetadata.d.ts.map +1 -0
- package/build/generated/releaseMetadata.js +10 -0
- package/build/generated/releaseMetadata.js.map +1 -0
- package/build/index.d.ts +6 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +171 -0
- package/build/index.js.map +1 -0
- package/build/ota-server/OtaServer.types.d.ts +14 -0
- package/build/ota-server/OtaServer.types.d.ts.map +1 -0
- package/build/ota-server/OtaServer.types.js +2 -0
- package/build/ota-server/OtaServer.types.js.map +1 -0
- package/build/ota-server/OtaServerModule.d.ts +21 -0
- package/build/ota-server/OtaServerModule.d.ts.map +1 -0
- package/build/ota-server/OtaServerModule.js +3 -0
- package/build/ota-server/OtaServerModule.js.map +1 -0
- package/build/ota-server/OtaServerModule.web.d.ts +10 -0
- package/build/ota-server/OtaServerModule.web.d.ts.map +1 -0
- package/build/ota-server/OtaServerModule.web.js +12 -0
- package/build/ota-server/OtaServerModule.web.js.map +1 -0
- package/build/ota-server/index.d.ts +3 -0
- package/build/ota-server/index.d.ts.map +1 -0
- package/build/ota-server/index.js +3 -0
- package/build/ota-server/index.js.map +1 -0
- package/build/ota-transport/index.d.ts +67 -0
- package/build/ota-transport/index.d.ts.map +1 -0
- package/build/ota-transport/index.js +58 -0
- package/build/ota-transport/index.js.map +1 -0
- package/build/photo-receiver/PhotoReceiver.types.d.ts +18 -0
- package/build/photo-receiver/PhotoReceiver.types.d.ts.map +1 -0
- package/build/photo-receiver/PhotoReceiver.types.js +2 -0
- package/build/photo-receiver/PhotoReceiver.types.js.map +1 -0
- package/build/photo-receiver/PhotoReceiverModule.d.ts +10 -0
- package/build/photo-receiver/PhotoReceiverModule.d.ts.map +1 -0
- package/build/photo-receiver/PhotoReceiverModule.js +3 -0
- package/build/photo-receiver/PhotoReceiverModule.js.map +1 -0
- package/build/photo-receiver/PhotoReceiverModule.web.d.ts +10 -0
- package/build/photo-receiver/PhotoReceiverModule.web.d.ts.map +1 -0
- package/build/photo-receiver/PhotoReceiverModule.web.js +12 -0
- package/build/photo-receiver/PhotoReceiverModule.web.js.map +1 -0
- package/build/photo-receiver/index.d.ts +3 -0
- package/build/photo-receiver/index.d.ts.map +1 -0
- package/build/photo-receiver/index.js +3 -0
- package/build/photo-receiver/index.js.map +1 -0
- package/build/react/index.d.ts +5 -0
- package/build/react/index.d.ts.map +1 -0
- package/build/react/index.js +4 -0
- package/build/react/index.js.map +1 -0
- package/build/react/useBluetooth.d.ts +100 -0
- package/build/react/useBluetooth.d.ts.map +1 -0
- package/build/react/useBluetooth.js +167 -0
- package/build/react/useBluetooth.js.map +1 -0
- package/build/react/useBluetoothEvent.d.ts +6 -0
- package/build/react/useBluetoothEvent.d.ts.map +1 -0
- package/build/react/useBluetoothEvent.js +21 -0
- package/build/react/useBluetoothEvent.js.map +1 -0
- package/build/react/useBluetoothScan.d.ts +22 -0
- package/build/react/useBluetoothScan.d.ts.map +1 -0
- package/build/react/useBluetoothScan.js +135 -0
- package/build/react/useBluetoothScan.js.map +1 -0
- package/build/react/useBluetoothStatus.d.ts +16 -0
- package/build/react/useBluetoothStatus.d.ts.map +1 -0
- package/build/react/useBluetoothStatus.js +137 -0
- package/build/react/useBluetoothStatus.js.map +1 -0
- package/build/react/useGlassesConnection.d.ts +29 -0
- package/build/react/useGlassesConnection.d.ts.map +1 -0
- package/build/react/useGlassesConnection.js +153 -0
- package/build/react/useGlassesConnection.js.map +1 -0
- package/build/types/index.d.ts +3 -0
- package/build/types/index.d.ts.map +1 -0
- package/build/types/index.js +2 -0
- package/build/types/index.js.map +1 -0
- package/expo-module.config.json +14 -0
- package/ios/BackgroundOtaArtifactDownloader.swift +125 -0
- package/ios/BluetoothSdkModule.swift +1034 -0
- package/ios/GlasslyBluetoothSDK.podspec +106 -0
- package/ios/LocalIPv4.swift +150 -0
- package/ios/LocalOtaServer.swift +309 -0
- package/ios/LocalPhotoUploadServer.swift +754 -0
- package/ios/OtaServerModule.swift +147 -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/include/PcmConverter.h +22 -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 +2383 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Info.plist +48 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/Headers/sherpa-onnx/c-api/c-api.h +4689 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/Headers/sherpa-onnx/c-api/cxx-api.h +2036 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/libsherpa-onnx.a +0 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/Headers/sherpa-onnx/c-api/c-api.h +4689 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/Headers/sherpa-onnx/c-api/cxx-api.h +2036 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/libsherpa-onnx.a +0 -0
- package/ios/Packages/libbz2/module.modulemap +5 -0
- package/ios/Packages/libbz2/shim.h +1 -0
- package/ios/PhotoReceiverModule.swift +129 -0
- package/ios/Source/BluetoothSDK.swift +2303 -0
- package/ios/Source/BluetoothSDKDebug.swift +12 -0
- package/ios/Source/BluetoothSdkDefaults.swift +29 -0
- package/ios/Source/Bridge.swift +708 -0
- package/ios/Source/Bridging-Header.h +16 -0
- package/ios/Source/DeviceManager.swift +2109 -0
- package/ios/Source/DeviceStore.swift +336 -0
- package/ios/Source/GeneratedChangelogCatalog.swift +7 -0
- package/ios/Source/GeneratedReleaseMetadata.swift +11 -0
- package/ios/Source/ObservableStore.swift +118 -0
- package/ios/Source/OtaManifest.swift +211 -0
- package/ios/Source/PrivacyInfo.xcprivacy +23 -0
- package/ios/Source/ReleaseChangelog.swift +65 -0
- package/ios/Source/Resources/G2Firmware/README.md +10 -0
- package/ios/Source/audio/AudioModels.swift +178 -0
- package/ios/Source/audio/PcmStreamPlayer.swift +410 -0
- package/ios/Source/camera/CameraModels.swift +866 -0
- package/ios/Source/connection/ScanSession.swift +27 -0
- package/ios/Source/controllers/ControllerManager.swift +184 -0
- package/ios/Source/controllers/R1.swift +829 -0
- package/ios/Source/errors/BluetoothSdkError.swift +19 -0
- package/ios/Source/events/BluetoothEvents.swift +342 -0
- package/ios/Source/internal/BleTraceLogger.swift +192 -0
- package/ios/Source/internal/BluetoothAvailability.swift +78 -0
- package/ios/Source/internal/BluetoothSdkAnalytics.swift +199 -0
- package/ios/Source/internal/ValueParsing.swift +99 -0
- package/ios/Source/requests/DisplayRequests.swift +82 -0
- package/ios/Source/services/PhoneMic.swift +662 -0
- package/ios/Source/sgcs/Ar99.swift +2451 -0
- package/ios/Source/sgcs/Frame.swift +649 -0
- package/ios/Source/sgcs/G1.swift +2554 -0
- package/ios/Source/sgcs/G2.swift +6887 -0
- package/ios/Source/sgcs/G2CfwClassification.swift +43 -0
- package/ios/Source/sgcs/G2CfwRenderer.swift +1279 -0
- package/ios/Source/sgcs/G2CfwTextureCache.swift +233 -0
- package/ios/Source/sgcs/G2FlashProtocol.swift +312 -0
- package/ios/Source/sgcs/G2Flasher.swift +773 -0
- package/ios/Source/sgcs/Mach1.swift +541 -0
- package/ios/Source/sgcs/MentraLive.swift +7011 -0
- package/ios/Source/sgcs/MentraLiveL2capChannel.swift +183 -0
- package/ios/Source/sgcs/MentraLivePairingAdvertisement.swift +64 -0
- package/ios/Source/sgcs/MentraNex.swift +3221 -0
- package/ios/Source/sgcs/Nimo.swift +1886 -0
- package/ios/Source/sgcs/SGCManager.swift +608 -0
- package/ios/Source/sgcs/Simulated.swift +274 -0
- package/ios/Source/sgcs/ar99/ota/Ar99OtaManager.swift +637 -0
- package/ios/Source/sgcs/glassly_ble.pb.swift +4354 -0
- package/ios/Source/speakerid/SpeakerIdEngine.swift +573 -0
- package/ios/Source/status/DeviceStatus.swift +981 -0
- package/ios/Source/status/RuntimeState.swift +359 -0
- package/ios/Source/status/WifiHotspotStatus.swift +345 -0
- package/ios/Source/streaming/StreamModels.swift +693 -0
- package/ios/Source/stt/STTTools.swift +191 -0
- package/ios/Source/stt/SherpaOnnxTranscriber.swift +466 -0
- package/ios/Source/tts/TTSTools.swift +171 -0
- package/ios/Source/types/DeviceModels.swift +177 -0
- package/ios/Source/utils/AudioSessionMonitor.swift +283 -0
- package/ios/Source/utils/BinaryCodec.swift +61 -0
- package/ios/Source/utils/BleJsonCompact.swift +405 -0
- package/ios/Source/utils/BleWireProtocol.swift +92 -0
- package/ios/Source/utils/Constants.swift +78 -0
- package/ios/Source/utils/Enums.swift +95 -0
- package/ios/Source/utils/G1Text.swift +2096 -0
- package/ios/Source/utils/JSCExperiment.swift +241 -0
- package/ios/Source/utils/MemoryMonitor.swift +44 -0
- package/ios/Source/utils/MessageChunkReassembler.swift +190 -0
- package/ios/Source/utils/MessageChunker.swift +294 -0
- package/ios/Source/utils/Models.swift +135 -0
- package/ios/Source/utils/PhoneAudioMonitor.swift +230 -0
- package/ios/Source/utils/TarBz2Extractor.swift +257 -0
- package/ios/Tests/BluetoothSDKTests/G2CfwClassificationTests.swift +78 -0
- package/ios/Tests/BluetoothSDKTests/G2CfwRendererTests.swift +372 -0
- package/ios/Tests/BluetoothSDKTests/G2CfwTextureCacheTests.swift +162 -0
- package/ios/Tests/BluetoothSDKTests/G2FlashProtocolTests.swift +182 -0
- package/ios/Tests/MentraLivePairingAdvertisementTests.swift +160 -0
- package/ios/Tests/ReleaseChangelogTests.swift +13 -0
- package/package.json +129 -0
- package/plugin/build/index.d.ts +10 -0
- package/plugin/build/index.js +12 -0
- package/plugin/build/withAndroid.d.ts +3 -0
- package/plugin/build/withAndroid.js +190 -0
- package/plugin/build/withIos.d.ts +5 -0
- package/plugin/build/withIos.js +108 -0
- package/scripts/inject-ios-sdk-version.mjs +65 -0
- package/scripts/public-ota-api.test.mjs +37 -0
- package/scripts/verify-release-package.mjs +45 -0
- package/scripts/write-release-metadata.mjs +152 -0
- package/scripts/write-release-metadata.test.mjs +37 -0
- package/src/BluetoothSdk.types.ts +1623 -0
- package/src/_internal.ts +16 -0
- package/src/_private/BluetoothSdkModule.ts +684 -0
- package/src/_private/LocalNetworkModule.ts +50 -0
- package/src/_private/cameraRequestPayload.ts +34 -0
- package/src/_private/photoRequestPayload.ts +90 -0
- package/src/_private/sdkOtaManifest.ts +18 -0
- package/src/changelogs.ts +46 -0
- package/src/debug.ts +9 -0
- package/src/generated/changelogCatalog.ts +13 -0
- package/src/generated/releaseMetadata.ts +20 -0
- package/src/index.ts +321 -0
- package/src/ota-server/OtaServer.types.ts +10 -0
- package/src/ota-server/OtaServerModule.ts +23 -0
- package/src/ota-server/OtaServerModule.web.ts +17 -0
- package/src/ota-server/index.ts +2 -0
- package/src/ota-transport/index.ts +116 -0
- package/src/photo-receiver/PhotoReceiver.types.ts +20 -0
- package/src/photo-receiver/PhotoReceiverModule.ts +11 -0
- package/src/photo-receiver/PhotoReceiverModule.web.ts +17 -0
- package/src/photo-receiver/index.ts +2 -0
- package/src/react/index.ts +21 -0
- package/src/react/useBluetooth.ts +309 -0
- package/src/react/useBluetoothEvent.ts +35 -0
- package/src/react/useBluetoothScan.ts +173 -0
- package/src/react/useBluetoothStatus.ts +180 -0
- package/src/react/useGlassesConnection.ts +202 -0
- package/src/types/index.ts +12 -0
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
package com.glassly.bluetoothsdk.utils;
|
|
2
|
+
|
|
3
|
+
import java.io.ByteArrayOutputStream;
|
|
4
|
+
import java.io.IOException;
|
|
5
|
+
import java.nio.ByteBuffer;
|
|
6
|
+
import java.nio.ByteOrder;
|
|
7
|
+
import java.nio.charset.StandardCharsets;
|
|
8
|
+
import java.util.ArrayList;
|
|
9
|
+
import java.util.Arrays;
|
|
10
|
+
import java.util.List;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Removes the Exif metadata item from glasses BLE AVIF so {@link com.radzivon.bartoshyk.avif.coder.HeifCoder}
|
|
14
|
+
* can decode the image. EXIF is appended to {@code mdat} by the glasses encoder; libavif then fails if that
|
|
15
|
+
* trailer is present. IMU JSON must be read from the original bytes before stripping.
|
|
16
|
+
*/
|
|
17
|
+
final class AvifExifStripper {
|
|
18
|
+
private AvifExifStripper() {}
|
|
19
|
+
|
|
20
|
+
static byte[] stripForDecode(byte[] avif) throws IOException {
|
|
21
|
+
if (avif.length < 12) {
|
|
22
|
+
return avif;
|
|
23
|
+
}
|
|
24
|
+
// Primary path: parse meta tables, remove Exif item from iloc/iinf/iref, truncate mdat.
|
|
25
|
+
try {
|
|
26
|
+
byte[] cleaned = stripUsingMetaTables(avif);
|
|
27
|
+
if (cleaned.length < avif.length) {
|
|
28
|
+
return cleaned;
|
|
29
|
+
}
|
|
30
|
+
} catch (IOException | RuntimeException ignored) {
|
|
31
|
+
// Malformed BMFF can throw runtime parse errors (buffer/index); fall through to the
|
|
32
|
+
// marker-based fallback rather than letting the decode crash.
|
|
33
|
+
}
|
|
34
|
+
// Fallback: truncate mdat at the Exif\0\0 marker AND purge Exif from meta tables.
|
|
35
|
+
int exifMarker = lastExifMarkerOffset(avif);
|
|
36
|
+
if (exifMarker < 0) {
|
|
37
|
+
return avif;
|
|
38
|
+
}
|
|
39
|
+
return stripMdatTailAndMeta(avif, exifMarker);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Truncates mdat at the {@code Exif\0\0} byte position, then removes the Exif item from
|
|
44
|
+
* iloc/iinf/iref so HeifCoder does not try to seek to the now-absent data.
|
|
45
|
+
*/
|
|
46
|
+
private static byte[] stripMdatTailAndMeta(byte[] avif, int exifMarker) throws IOException {
|
|
47
|
+
List<BmffBox> top = parseTopLevel(avif);
|
|
48
|
+
BmffBox ftyp = require(top, "ftyp");
|
|
49
|
+
BmffBox meta = require(top, "meta");
|
|
50
|
+
BmffBox mdat = require(top, "mdat");
|
|
51
|
+
|
|
52
|
+
int fileOffset = 0;
|
|
53
|
+
for (BmffBox box : top) {
|
|
54
|
+
if ("mdat".equals(box.type)) {
|
|
55
|
+
int payloadStart = fileOffset + 8;
|
|
56
|
+
if (exifMarker >= payloadStart && exifMarker < payloadStart + box.payload.length) {
|
|
57
|
+
int newPayloadLen = exifMarker - payloadStart;
|
|
58
|
+
if (newPayloadLen <= 0) {
|
|
59
|
+
return avif;
|
|
60
|
+
}
|
|
61
|
+
byte[] newMdatPayload = Arrays.copyOf(box.payload, newPayloadLen);
|
|
62
|
+
byte[] metaPayload = normalizeMetaPayload(meta.payload);
|
|
63
|
+
int oldMetaBoxSize = meta.encodedSize();
|
|
64
|
+
// Best-effort: clean up Exif item refs from meta tables.
|
|
65
|
+
try {
|
|
66
|
+
MetaTables tables = parseMetaTables(metaPayload);
|
|
67
|
+
int exifItemId = findExifItemId(tables.iinfPayload);
|
|
68
|
+
if (exifItemId >= 0) {
|
|
69
|
+
byte[] newIloc = removeIlocEntry(tables.ilocPayload, exifItemId);
|
|
70
|
+
byte[] newIinf = removeIinfEntry(tables.iinfPayload, exifItemId);
|
|
71
|
+
byte[] newIref = removeCdscRefs(tables.irefPayload, exifItemId);
|
|
72
|
+
byte[] tempMetaPayload =
|
|
73
|
+
rebuildMeta(metaPayload, newIloc, newIinf, newIref);
|
|
74
|
+
int metaDelta =
|
|
75
|
+
new BmffBox("meta", tempMetaPayload).encodedSize()
|
|
76
|
+
- oldMetaBoxSize;
|
|
77
|
+
newIloc = shiftIlocExtentOffsets(newIloc, metaDelta);
|
|
78
|
+
metaPayload = rebuildMeta(metaPayload, newIloc, newIinf, newIref);
|
|
79
|
+
}
|
|
80
|
+
} catch (IOException ignored) {
|
|
81
|
+
}
|
|
82
|
+
ByteArrayOutputStream out = new ByteArrayOutputStream(avif.length);
|
|
83
|
+
ftyp.writeTo(out);
|
|
84
|
+
new BmffBox("meta", metaPayload).writeTo(out);
|
|
85
|
+
for (BmffBox other : top) {
|
|
86
|
+
if (!"ftyp".equals(other.type)
|
|
87
|
+
&& !"meta".equals(other.type)
|
|
88
|
+
&& !"mdat".equals(other.type)) {
|
|
89
|
+
other.writeTo(out);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
new BmffBox("mdat", newMdatPayload).writeTo(out);
|
|
93
|
+
return out.toByteArray();
|
|
94
|
+
}
|
|
95
|
+
return avif;
|
|
96
|
+
}
|
|
97
|
+
fileOffset += 8 + box.payload.length;
|
|
98
|
+
}
|
|
99
|
+
return avif;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private static byte[] stripUsingMetaTables(byte[] avif) throws IOException {
|
|
103
|
+
List<BmffBox> top = parseTopLevel(avif);
|
|
104
|
+
BmffBox ftyp = require(top, "ftyp");
|
|
105
|
+
BmffBox meta = require(top, "meta");
|
|
106
|
+
BmffBox mdat = require(top, "mdat");
|
|
107
|
+
|
|
108
|
+
byte[] metaPayload = normalizeMetaPayload(meta.payload);
|
|
109
|
+
MetaTables tables = parseMetaTables(metaPayload);
|
|
110
|
+
int exifItemId = findExifItemId(tables.iinfPayload);
|
|
111
|
+
if (exifItemId < 0) {
|
|
112
|
+
return avif;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
int exifLength = ilocItemLength(tables.ilocPayload, exifItemId);
|
|
116
|
+
if (exifLength <= 0 || mdat.payload.length < exifLength) {
|
|
117
|
+
return avif;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
int mdatPayloadStart = locateMdatPayloadStart(avif);
|
|
121
|
+
int exifFileOffset = ilocItemOffset(tables.ilocPayload, exifItemId);
|
|
122
|
+
int exifOffsetInMdat = exifFileOffset - mdatPayloadStart;
|
|
123
|
+
int newMdatPayloadLength;
|
|
124
|
+
if (exifOffsetInMdat >= 0 && exifOffsetInMdat + exifLength == mdat.payload.length) {
|
|
125
|
+
newMdatPayloadLength = exifOffsetInMdat;
|
|
126
|
+
} else if (mdat.payload.length >= exifLength) {
|
|
127
|
+
newMdatPayloadLength = mdat.payload.length - exifLength;
|
|
128
|
+
} else {
|
|
129
|
+
return avif;
|
|
130
|
+
}
|
|
131
|
+
byte[] newMdatPayload = Arrays.copyOf(mdat.payload, newMdatPayloadLength);
|
|
132
|
+
|
|
133
|
+
byte[] newIloc = removeIlocEntry(tables.ilocPayload, exifItemId);
|
|
134
|
+
byte[] newIinf = removeIinfEntry(tables.iinfPayload, exifItemId);
|
|
135
|
+
byte[] newIref = removeCdscRefs(tables.irefPayload, exifItemId);
|
|
136
|
+
byte[] tempMetaPayload = rebuildMeta(metaPayload, newIloc, newIinf, newIref);
|
|
137
|
+
int metaDelta = new BmffBox("meta", tempMetaPayload).encodedSize() - meta.encodedSize();
|
|
138
|
+
newIloc = shiftIlocExtentOffsets(newIloc, metaDelta);
|
|
139
|
+
byte[] newMetaPayload = rebuildMeta(metaPayload, newIloc, newIinf, newIref);
|
|
140
|
+
|
|
141
|
+
ByteArrayOutputStream out = new ByteArrayOutputStream(avif.length);
|
|
142
|
+
ftyp.writeTo(out);
|
|
143
|
+
new BmffBox("meta", newMetaPayload).writeTo(out);
|
|
144
|
+
for (BmffBox box : top) {
|
|
145
|
+
if (!"ftyp".equals(box.type) && !"meta".equals(box.type) && !"mdat".equals(box.type)) {
|
|
146
|
+
box.writeTo(out);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
new BmffBox("mdat", newMdatPayload).writeTo(out);
|
|
150
|
+
return out.toByteArray();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private static int lastExifMarkerOffset(byte[] data) {
|
|
154
|
+
byte[] marker = new byte[] {'E', 'x', 'i', 'f', 0, 0};
|
|
155
|
+
int last = -1;
|
|
156
|
+
outer:
|
|
157
|
+
for (int i = 0; i <= data.length - marker.length; i++) {
|
|
158
|
+
for (int j = 0; j < marker.length; j++) {
|
|
159
|
+
if (data[i + j] != marker[j]) {
|
|
160
|
+
continue outer;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
last = i;
|
|
164
|
+
}
|
|
165
|
+
return last;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** Older injector builds accidentally nested a full meta box inside meta payload. */
|
|
169
|
+
private static byte[] normalizeMetaPayload(byte[] metaPayload) {
|
|
170
|
+
if (metaPayload.length >= 8) {
|
|
171
|
+
String type = new String(metaPayload, 4, 4, StandardCharsets.ISO_8859_1);
|
|
172
|
+
if ("meta".equals(type)) {
|
|
173
|
+
int innerSize = u32(metaPayload, 0);
|
|
174
|
+
if (innerSize >= 8 && innerSize <= metaPayload.length) {
|
|
175
|
+
return Arrays.copyOfRange(metaPayload, 8, innerSize);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return metaPayload;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
private static int findExifItemId(byte[] iinfPayload) {
|
|
183
|
+
int offset = 6;
|
|
184
|
+
while (offset + 8 <= iinfPayload.length) {
|
|
185
|
+
int size = u32(iinfPayload, offset);
|
|
186
|
+
if (size < 8 || offset + size > iinfPayload.length) {
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
String type = new String(iinfPayload, offset + 4, 4, StandardCharsets.ISO_8859_1);
|
|
190
|
+
if ("infe".equals(type) && size >= 21) {
|
|
191
|
+
int version = iinfPayload[offset + 8] & 0xFF;
|
|
192
|
+
int id =
|
|
193
|
+
version >= 3
|
|
194
|
+
? ByteBuffer.wrap(iinfPayload, offset + 12, 4)
|
|
195
|
+
.order(ByteOrder.BIG_ENDIAN)
|
|
196
|
+
.getInt()
|
|
197
|
+
: u16(iinfPayload, offset + 12);
|
|
198
|
+
if (offset + 16 + 4 <= iinfPayload.length) {
|
|
199
|
+
String itemType =
|
|
200
|
+
new String(iinfPayload, offset + 16, 4, StandardCharsets.ISO_8859_1);
|
|
201
|
+
if ("Exif".equals(itemType)) {
|
|
202
|
+
return id;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
offset += size;
|
|
207
|
+
}
|
|
208
|
+
return -1;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
private static int locateMdatPayloadStart(byte[] file) throws IOException {
|
|
212
|
+
int offset = 0;
|
|
213
|
+
for (BmffBox box : parseTopLevel(file)) {
|
|
214
|
+
if ("mdat".equals(box.type)) {
|
|
215
|
+
return offset + 8;
|
|
216
|
+
}
|
|
217
|
+
offset += 8 + box.payload.length;
|
|
218
|
+
}
|
|
219
|
+
throw new IOException("mdat missing");
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private static int ilocItemOffset(byte[] ilocPayload, int itemId) throws IOException {
|
|
223
|
+
IlocLayout layout = parseIlocLayout(ilocPayload);
|
|
224
|
+
int itemCount = u16(ilocPayload, 6);
|
|
225
|
+
ByteBuffer buf = ByteBuffer.wrap(ilocPayload).order(ByteOrder.BIG_ENDIAN);
|
|
226
|
+
buf.position(8);
|
|
227
|
+
for (int i = 0; i < itemCount; i++) {
|
|
228
|
+
int id = buf.getShort() & 0xFFFF;
|
|
229
|
+
buf.getShort();
|
|
230
|
+
skipSized(buf, layout.baseOffsetSize);
|
|
231
|
+
int extentCount = buf.getShort() & 0xFFFF;
|
|
232
|
+
if (extentCount < 1) {
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
int offset = readSized(buf, layout.offsetSize);
|
|
236
|
+
skipSized(buf, layout.lengthSize);
|
|
237
|
+
for (int e = 1; e < extentCount; e++) {
|
|
238
|
+
skipSized(buf, layout.offsetSize);
|
|
239
|
+
skipSized(buf, layout.lengthSize);
|
|
240
|
+
}
|
|
241
|
+
if (id == itemId) {
|
|
242
|
+
return offset;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return -1;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
private static byte[] shiftIlocExtentOffsets(byte[] ilocPayload, int delta) throws IOException {
|
|
249
|
+
if (delta == 0) {
|
|
250
|
+
return ilocPayload;
|
|
251
|
+
}
|
|
252
|
+
byte[] copy = Arrays.copyOf(ilocPayload, ilocPayload.length);
|
|
253
|
+
IlocLayout layout = parseIlocLayout(copy);
|
|
254
|
+
ByteBuffer buf = ByteBuffer.wrap(copy).order(ByteOrder.BIG_ENDIAN);
|
|
255
|
+
int itemCount = u16(copy, 6);
|
|
256
|
+
buf.position(8);
|
|
257
|
+
for (int i = 0; i < itemCount; i++) {
|
|
258
|
+
buf.getShort();
|
|
259
|
+
buf.getShort();
|
|
260
|
+
skipSized(buf, layout.baseOffsetSize);
|
|
261
|
+
int extentCount = buf.getShort() & 0xFFFF;
|
|
262
|
+
for (int e = 0; e < extentCount; e++) {
|
|
263
|
+
int offset = readSized(buf, layout.offsetSize);
|
|
264
|
+
int length = readSized(buf, layout.lengthSize);
|
|
265
|
+
buf.position(buf.position() - layout.offsetSize - layout.lengthSize);
|
|
266
|
+
writeSized(buf, offset + delta, layout.offsetSize);
|
|
267
|
+
writeSized(buf, length, layout.lengthSize);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return copy;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
private static void writeSized(ByteBuffer buf, int value, int bytes) throws IOException {
|
|
274
|
+
switch (bytes) {
|
|
275
|
+
case 0:
|
|
276
|
+
break;
|
|
277
|
+
case 4:
|
|
278
|
+
buf.putInt(value);
|
|
279
|
+
break;
|
|
280
|
+
default:
|
|
281
|
+
throw new IOException("unsupported iloc field size " + bytes);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
private static int ilocItemLength(byte[] ilocPayload, int itemId) throws IOException {
|
|
286
|
+
IlocLayout layout = parseIlocLayout(ilocPayload);
|
|
287
|
+
int itemCount = u16(ilocPayload, 6);
|
|
288
|
+
ByteBuffer buf = ByteBuffer.wrap(ilocPayload).order(ByteOrder.BIG_ENDIAN);
|
|
289
|
+
buf.position(8);
|
|
290
|
+
for (int i = 0; i < itemCount; i++) {
|
|
291
|
+
int id = buf.getShort() & 0xFFFF;
|
|
292
|
+
buf.getShort();
|
|
293
|
+
skipSized(buf, layout.baseOffsetSize);
|
|
294
|
+
int extentCount = buf.getShort() & 0xFFFF;
|
|
295
|
+
int totalLength = 0;
|
|
296
|
+
for (int e = 0; e < extentCount; e++) {
|
|
297
|
+
skipSized(buf, layout.offsetSize);
|
|
298
|
+
totalLength += readSized(buf, layout.lengthSize);
|
|
299
|
+
}
|
|
300
|
+
if (id == itemId) {
|
|
301
|
+
return totalLength;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return -1;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
private static byte[] removeIlocEntry(byte[] ilocPayload, int removeId) throws IOException {
|
|
308
|
+
IlocLayout layout = parseIlocLayout(ilocPayload);
|
|
309
|
+
int itemCount = u16(ilocPayload, 6);
|
|
310
|
+
ByteBuffer buf = ByteBuffer.wrap(ilocPayload).order(ByteOrder.BIG_ENDIAN);
|
|
311
|
+
buf.position(8);
|
|
312
|
+
ByteArrayOutputStream kept = new ByteArrayOutputStream(ilocPayload.length);
|
|
313
|
+
int keptCount = 0;
|
|
314
|
+
for (int i = 0; i < itemCount; i++) {
|
|
315
|
+
int start = buf.position();
|
|
316
|
+
int id = buf.getShort() & 0xFFFF;
|
|
317
|
+
buf.getShort();
|
|
318
|
+
skipSized(buf, layout.baseOffsetSize);
|
|
319
|
+
int extentCount = buf.getShort() & 0xFFFF;
|
|
320
|
+
for (int e = 0; e < extentCount; e++) {
|
|
321
|
+
skipSized(buf, layout.offsetSize);
|
|
322
|
+
skipSized(buf, layout.lengthSize);
|
|
323
|
+
}
|
|
324
|
+
int end = buf.position();
|
|
325
|
+
if (id != removeId) {
|
|
326
|
+
kept.write(ilocPayload, start, end - start);
|
|
327
|
+
keptCount++;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
ByteArrayOutputStream out = new ByteArrayOutputStream(ilocPayload.length);
|
|
331
|
+
out.write(ilocPayload, 0, 6);
|
|
332
|
+
writeU16(out, keptCount);
|
|
333
|
+
kept.writeTo(out);
|
|
334
|
+
return out.toByteArray();
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
private static byte[] removeIinfEntry(byte[] iinfPayload, int removeId) throws IOException {
|
|
338
|
+
ByteArrayOutputStream entries = new ByteArrayOutputStream(iinfPayload.length);
|
|
339
|
+
int kept = 0;
|
|
340
|
+
int offset = 6;
|
|
341
|
+
while (offset + 8 <= iinfPayload.length) {
|
|
342
|
+
int size = u32(iinfPayload, offset);
|
|
343
|
+
if (size < 8 || offset + size > iinfPayload.length) {
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
boolean drop = false;
|
|
347
|
+
if ("infe".equals(new String(iinfPayload, offset + 4, 4, StandardCharsets.ISO_8859_1))
|
|
348
|
+
&& size >= 20) {
|
|
349
|
+
int version = iinfPayload[offset + 8] & 0xFF;
|
|
350
|
+
int id =
|
|
351
|
+
version >= 3
|
|
352
|
+
? ByteBuffer.wrap(iinfPayload, offset + 12, 4)
|
|
353
|
+
.order(ByteOrder.BIG_ENDIAN)
|
|
354
|
+
.getInt()
|
|
355
|
+
: u16(iinfPayload, offset + 12);
|
|
356
|
+
if (id == removeId) {
|
|
357
|
+
drop = true;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (!drop) {
|
|
361
|
+
entries.write(iinfPayload, offset, size);
|
|
362
|
+
kept++;
|
|
363
|
+
}
|
|
364
|
+
offset += size;
|
|
365
|
+
}
|
|
366
|
+
ByteArrayOutputStream out = new ByteArrayOutputStream(iinfPayload.length);
|
|
367
|
+
out.write(iinfPayload, 0, 4);
|
|
368
|
+
writeU16(out, kept);
|
|
369
|
+
entries.writeTo(out);
|
|
370
|
+
return out.toByteArray();
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
private static byte[] removeCdscRefs(byte[] irefPayload, int exifItemId) throws IOException {
|
|
374
|
+
ByteArrayOutputStream body = new ByteArrayOutputStream(irefPayload.length);
|
|
375
|
+
body.write(irefPayload, 0, 4);
|
|
376
|
+
int offset = 4;
|
|
377
|
+
while (offset + 8 <= irefPayload.length) {
|
|
378
|
+
int size = u32(irefPayload, offset);
|
|
379
|
+
if (size < 8 || offset + size > irefPayload.length) {
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
String type = new String(irefPayload, offset + 4, 4, StandardCharsets.ISO_8859_1);
|
|
383
|
+
if ("cdsc".equals(type) && size >= 14) {
|
|
384
|
+
int fromId = u16(irefPayload, offset + 8);
|
|
385
|
+
if (fromId != exifItemId) {
|
|
386
|
+
body.write(irefPayload, offset, size);
|
|
387
|
+
}
|
|
388
|
+
} else {
|
|
389
|
+
body.write(irefPayload, offset, size);
|
|
390
|
+
}
|
|
391
|
+
offset += size;
|
|
392
|
+
}
|
|
393
|
+
return body.toByteArray();
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
private static byte[] rebuildMeta(byte[] metaPayload, byte[] iloc, byte[] iinf, byte[] iref)
|
|
397
|
+
throws IOException {
|
|
398
|
+
ByteArrayOutputStream result = new ByteArrayOutputStream(metaPayload.length + 64);
|
|
399
|
+
result.write(metaPayload, 0, Math.min(4, metaPayload.length));
|
|
400
|
+
for (BmffBox child : parseMetaChildren(metaPayload)) {
|
|
401
|
+
byte[] payload;
|
|
402
|
+
switch (child.type) {
|
|
403
|
+
case "iloc":
|
|
404
|
+
payload = iloc;
|
|
405
|
+
break;
|
|
406
|
+
case "iinf":
|
|
407
|
+
payload = iinf;
|
|
408
|
+
break;
|
|
409
|
+
case "iref":
|
|
410
|
+
payload = iref;
|
|
411
|
+
break;
|
|
412
|
+
default:
|
|
413
|
+
payload = child.payload;
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
new BmffBox(child.type, payload).writeTo(result);
|
|
417
|
+
}
|
|
418
|
+
return result.toByteArray();
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
private static MetaTables parseMetaTables(byte[] metaPayload) throws IOException {
|
|
422
|
+
MetaTables tables = new MetaTables();
|
|
423
|
+
for (BmffBox child : parseMetaChildren(metaPayload)) {
|
|
424
|
+
switch (child.type) {
|
|
425
|
+
case "iloc":
|
|
426
|
+
tables.ilocPayload = child.payload;
|
|
427
|
+
break;
|
|
428
|
+
case "iinf":
|
|
429
|
+
tables.iinfPayload = child.payload;
|
|
430
|
+
break;
|
|
431
|
+
case "iref":
|
|
432
|
+
tables.irefPayload = child.payload;
|
|
433
|
+
break;
|
|
434
|
+
default:
|
|
435
|
+
break;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
if (tables.ilocPayload == null || tables.iinfPayload == null || tables.irefPayload == null) {
|
|
439
|
+
throw new IOException("meta missing iloc/iinf/iref");
|
|
440
|
+
}
|
|
441
|
+
return tables;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
private static IlocLayout parseIlocLayout(byte[] ilocPayload) throws IOException {
|
|
445
|
+
if (ilocPayload.length < 10) {
|
|
446
|
+
throw new IOException("iloc too small");
|
|
447
|
+
}
|
|
448
|
+
IlocLayout layout = new IlocLayout();
|
|
449
|
+
layout.offsetSize = (ilocPayload[4] >> 4) & 0xF;
|
|
450
|
+
layout.lengthSize = ilocPayload[4] & 0xF;
|
|
451
|
+
layout.baseOffsetSize = (ilocPayload[5] >> 4) & 0xF;
|
|
452
|
+
if (layout.offsetSize != 4 || layout.lengthSize != 4) {
|
|
453
|
+
throw new IOException("Unexpected iloc field sizes");
|
|
454
|
+
}
|
|
455
|
+
return layout;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
private static void skipSized(ByteBuffer buf, int bytes) {
|
|
459
|
+
buf.position(buf.position() + bytes);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
private static int readSized(ByteBuffer buf, int bytes) throws IOException {
|
|
463
|
+
switch (bytes) {
|
|
464
|
+
case 0:
|
|
465
|
+
return 0;
|
|
466
|
+
case 4:
|
|
467
|
+
return buf.getInt();
|
|
468
|
+
default:
|
|
469
|
+
throw new IOException("unsupported iloc field size " + bytes);
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
private static List<BmffBox> parseMetaChildren(byte[] metaPayload) {
|
|
474
|
+
if (metaPayload.length < 4) {
|
|
475
|
+
return List.of();
|
|
476
|
+
}
|
|
477
|
+
try {
|
|
478
|
+
return parseChildBoxes(metaPayload, 4, metaPayload.length);
|
|
479
|
+
} catch (IOException e) {
|
|
480
|
+
return List.of();
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
private static List<BmffBox> parseTopLevel(byte[] data) throws IOException {
|
|
485
|
+
return parseChildBoxes(data, 0, data.length);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
private static List<BmffBox> parseChildBoxes(byte[] data, int start, int end) throws IOException {
|
|
489
|
+
List<BmffBox> boxes = new ArrayList<>();
|
|
490
|
+
int offset = start;
|
|
491
|
+
while (offset + 8 <= end) {
|
|
492
|
+
int size = u32(data, offset);
|
|
493
|
+
String type = new String(data, offset + 4, 4, StandardCharsets.ISO_8859_1);
|
|
494
|
+
int header = 8;
|
|
495
|
+
if (size == 1) {
|
|
496
|
+
if (offset + 16 > end) {
|
|
497
|
+
break;
|
|
498
|
+
}
|
|
499
|
+
size = (int) ByteBuffer.wrap(data, offset + 8, 8).order(ByteOrder.BIG_ENDIAN).getLong();
|
|
500
|
+
header = 16;
|
|
501
|
+
} else if (size == 0) {
|
|
502
|
+
size = end - offset;
|
|
503
|
+
}
|
|
504
|
+
if (size < header || offset + size > end) {
|
|
505
|
+
throw new IOException("Invalid box " + type + " size=" + size + " @" + offset);
|
|
506
|
+
}
|
|
507
|
+
byte[] payload = Arrays.copyOfRange(data, offset + header, offset + size);
|
|
508
|
+
boxes.add(new BmffBox(type, payload));
|
|
509
|
+
offset += size;
|
|
510
|
+
}
|
|
511
|
+
return boxes;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
private static BmffBox require(List<BmffBox> boxes, String type) throws IOException {
|
|
515
|
+
for (BmffBox box : boxes) {
|
|
516
|
+
if (type.equals(box.type)) {
|
|
517
|
+
return box;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
throw new IOException("Missing box " + type);
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
private static int u16(byte[] data, int offset) {
|
|
524
|
+
return ((data[offset] & 0xFF) << 8) | (data[offset + 1] & 0xFF);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
private static int u32(byte[] data, int offset) {
|
|
528
|
+
return ((data[offset] & 0xFF) << 24)
|
|
529
|
+
| ((data[offset + 1] & 0xFF) << 16)
|
|
530
|
+
| ((data[offset + 2] & 0xFF) << 8)
|
|
531
|
+
| (data[offset + 3] & 0xFF);
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
private static void writeU16(ByteArrayOutputStream out, int value) throws IOException {
|
|
535
|
+
out.write((value >> 8) & 0xFF);
|
|
536
|
+
out.write(value & 0xFF);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
private static final class IlocLayout {
|
|
540
|
+
int offsetSize;
|
|
541
|
+
int lengthSize;
|
|
542
|
+
int baseOffsetSize;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
private static final class MetaTables {
|
|
546
|
+
byte[] ilocPayload;
|
|
547
|
+
byte[] iinfPayload;
|
|
548
|
+
byte[] irefPayload;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
private static final class BmffBox {
|
|
552
|
+
final String type;
|
|
553
|
+
final byte[] payload;
|
|
554
|
+
|
|
555
|
+
BmffBox(String type, byte[] payload) {
|
|
556
|
+
this.type = type;
|
|
557
|
+
this.payload = payload;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
int encodedSize() {
|
|
561
|
+
return 8 + payload.length;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
void writeTo(ByteArrayOutputStream out) throws IOException {
|
|
565
|
+
int total = 8 + payload.length;
|
|
566
|
+
ByteBuffer hdr = ByteBuffer.allocate(8).order(ByteOrder.BIG_ENDIAN);
|
|
567
|
+
hdr.putInt(total);
|
|
568
|
+
hdr.put(type.getBytes(StandardCharsets.ISO_8859_1), 0, 4);
|
|
569
|
+
out.write(hdr.array());
|
|
570
|
+
out.write(payload);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
}
|