react-native-alpha-video 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +903 -2
- package/THIRD_PARTY_NOTICES.md +30 -0
- package/android/av1/build.gradle +67 -0
- package/android/av1/consumer-rules.pro +4 -0
- package/android/av1/src/main/cpp/Av1Codec_jni.cpp +8 -0
- package/android/av1/src/main/cpp/CMakeLists.txt +34 -0
- package/android/av1/src/main/java/dev/mediacache/alphavideo/av1/Av1Codec.java +21 -0
- package/android/build.gradle +85 -0
- package/android/consumer-rules.pro +2 -0
- package/android/gradle.properties +1 -0
- package/android/publish.gradle +82 -0
- package/android/settings.gradle +5 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/cpp/CMakeLists.txt +59 -0
- package/android/src/main/java/dev/mediacache/alphavideo/AlphaVideoCodecs.java +73 -0
- package/android/src/main/java/dev/mediacache/alphavideo/AlphaVideoView.java +1966 -0
- package/android/src/main/java/dev/mediacache/alphavideo/BufferedDualStreamPlayer.java +978 -0
- package/android/src/main/java/dev/mediacache/alphavideo/Fetcher.java +37 -0
- package/android/src/main/java/dev/mediacache/alphavideo/HttpFetcher.java +156 -0
- package/android/src/main/java/dev/mediacache/alphavideo/MediaCodecColor.java +47 -0
- package/android/src/main/java/dev/mediacache/alphavideo/MediaCodecDecoders.java +135 -0
- package/android/src/main/java/dev/mediacache/alphavideo/RangeSourceLink.java +54 -0
- package/android/src/main/java/dev/mediacache/alphavideo/SourceReader.java +174 -0
- package/android/src/main/java/dev/mediacache/alphavideo/SurfaceTextureVideoDecoder.java +802 -0
- package/android/src/main/java/dev/mediacache/alphavideo/WebMAlphaPlayerNative.java +95 -0
- package/android/src/main/java/dev/mediacache/alphavideo/WebMFrame.java +54 -0
- package/android/src/main/java/dev/mediacache/alphavideo/WebMSource.java +160 -0
- package/android/src/rangesource/java/dev/mediacache/alphavideo/AppDataSource.java +50 -0
- package/android/vpx/build.gradle +67 -0
- package/android/vpx/consumer-rules.pro +4 -0
- package/android/vpx/src/main/cpp/CMakeLists.txt +34 -0
- package/android/vpx/src/main/cpp/VpxCodec_jni.cpp +8 -0
- package/android/vpx/src/main/java/dev/mediacache/alphavideo/vpx/VpxCodec.java +21 -0
- package/codecs/av1/Dav1dDecoderPlugin.cpp +157 -0
- package/codecs/av1/Dav1dDecoderPlugin.h +17 -0
- package/codecs/vpx/VpxDecoderPlugin.cpp +103 -0
- package/codecs/vpx/VpxDecoderPlugin.h +17 -0
- package/cpp/AlphaDemuxer.cpp +984 -0
- package/cpp/AlphaDemuxer.h +123 -0
- package/cpp/AlphaVideoDecoderPlugin.h +84 -0
- package/cpp/Av1SequenceHeader.cpp +175 -0
- package/cpp/Av1SequenceHeader.h +25 -0
- package/cpp/ByteSource.cpp +116 -0
- package/cpp/ByteSource.h +59 -0
- package/cpp/RangeSourceClient.h +40 -0
- package/cpp/VideoDecoder.cpp +157 -0
- package/cpp/VideoDecoder.h +83 -0
- package/cpp/WebMAlphaPlayer.cpp +1666 -0
- package/cpp/WebMAlphaPlayer.h +389 -0
- package/cpp/WebMAlphaPlayer_jni.cpp +1380 -0
- package/cpp/YuvToRgb.cpp +39 -0
- package/cpp/YuvToRgb.h +40 -0
- package/ios/Sources/AlphaVideo/AlphaVideoCodecs.mm +63 -0
- package/ios/Sources/AlphaVideo/AlphaVideoInternal.h +70 -0
- package/ios/Sources/AlphaVideo/AlphaVideoPlayer.mm +994 -0
- package/ios/Sources/AlphaVideo/AlphaVideoSource.mm +476 -0
- package/ios/Sources/AlphaVideo/AlphaVideoView.mm +374 -0
- package/ios/Sources/AlphaVideo/include/AlphaVideo.h +303 -0
- package/ios/Sources/AlphaVideoAV1/AlphaVideoAV1Codec.mm +16 -0
- package/ios/Sources/AlphaVideoAV1/include/AlphaVideoAV1.h +18 -0
- package/ios/Sources/AlphaVideoVPX/AlphaVideoVPXCodec.mm +16 -0
- package/ios/Sources/AlphaVideoVPX/include/AlphaVideoVPX.h +17 -0
- package/lib/commonjs/AlphaVideoView.js +187 -0
- package/lib/commonjs/AlphaVideoView.js.map +1 -0
- package/lib/commonjs/AlphaVideoViewNativeComponent.js +47 -0
- package/lib/commonjs/AlphaVideoViewNativeComponent.js.map +1 -0
- package/lib/commonjs/AlphaVideoViewNativeComponent.web.js +11 -0
- package/lib/commonjs/AlphaVideoViewNativeComponent.web.js.map +1 -0
- package/lib/commonjs/NativeAlphaVideoModule.js +10 -0
- package/lib/commonjs/NativeAlphaVideoModule.js.map +1 -0
- package/lib/commonjs/NativeAlphaVideoModule.web.js +9 -0
- package/lib/commonjs/NativeAlphaVideoModule.web.js.map +1 -0
- package/lib/commonjs/WebPlayer.js +12 -0
- package/lib/commonjs/WebPlayer.js.map +1 -0
- package/lib/commonjs/WebPlayer.web.js +92 -0
- package/lib/commonjs/WebPlayer.web.js.map +1 -0
- package/lib/commonjs/index.js +124 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/AlphaVideoView.js +187 -0
- package/lib/module/AlphaVideoView.js.map +1 -0
- package/lib/module/AlphaVideoViewNativeComponent.js +47 -0
- package/lib/module/AlphaVideoViewNativeComponent.js.map +1 -0
- package/lib/module/AlphaVideoViewNativeComponent.web.js +11 -0
- package/lib/module/AlphaVideoViewNativeComponent.web.js.map +1 -0
- package/lib/module/NativeAlphaVideoModule.js +10 -0
- package/lib/module/NativeAlphaVideoModule.js.map +1 -0
- package/lib/module/NativeAlphaVideoModule.web.js +9 -0
- package/lib/module/NativeAlphaVideoModule.web.js.map +1 -0
- package/lib/module/WebPlayer.js +12 -0
- package/lib/module/WebPlayer.js.map +1 -0
- package/lib/module/WebPlayer.web.js +92 -0
- package/lib/module/WebPlayer.web.js.map +1 -0
- package/lib/module/index.js +124 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/react-native/src/AlphaVideoView.d.ts +189 -0
- package/lib/typescript/react-native/src/AlphaVideoView.d.ts.map +1 -0
- package/lib/typescript/react-native/src/AlphaVideoViewNativeComponent.d.ts +109 -0
- package/lib/typescript/react-native/src/AlphaVideoViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/react-native/src/AlphaVideoViewNativeComponent.web.d.ts +5 -0
- package/lib/typescript/react-native/src/AlphaVideoViewNativeComponent.web.d.ts.map +1 -0
- package/lib/typescript/react-native/src/NativeAlphaVideoModule.d.ts +21 -0
- package/lib/typescript/react-native/src/NativeAlphaVideoModule.d.ts.map +1 -0
- package/lib/typescript/react-native/src/NativeAlphaVideoModule.web.d.ts +3 -0
- package/lib/typescript/react-native/src/NativeAlphaVideoModule.web.d.ts.map +1 -0
- package/lib/typescript/react-native/src/WebPlayer.d.ts +3 -0
- package/lib/typescript/react-native/src/WebPlayer.d.ts.map +1 -0
- package/lib/typescript/react-native/src/WebPlayer.web.d.ts +9 -0
- package/lib/typescript/react-native/src/WebPlayer.web.d.ts.map +1 -0
- package/lib/typescript/react-native/src/index.d.ts +77 -0
- package/lib/typescript/react-native/src/index.d.ts.map +1 -0
- package/licenses/dav1d-COPYING.txt +23 -0
- package/licenses/libvpx-LICENSE.txt +31 -0
- package/licenses/libvpx-PATENTS.txt +23 -0
- package/licenses/libwebm-LICENSE.txt +30 -0
- package/licenses/libwebm-PATENTS.txt +23 -0
- package/package.json +150 -4
- package/prebuilt/android/arm64-v8a/lib/libdav1d.a +0 -0
- package/prebuilt/android/arm64-v8a/lib/libvpx.a +0 -0
- package/prebuilt/android/armeabi-v7a/lib/libdav1d.a +0 -0
- package/prebuilt/android/armeabi-v7a/lib/libvpx.a +0 -0
- package/prebuilt/android/x86_64/lib/libdav1d.a +0 -0
- package/prebuilt/android/x86_64/lib/libvpx.a +0 -0
- package/prebuilt/include/dav1d/common.h +94 -0
- package/prebuilt/include/dav1d/data.h +117 -0
- package/prebuilt/include/dav1d/dav1d.h +329 -0
- package/prebuilt/include/dav1d/headers.h +440 -0
- package/prebuilt/include/dav1d/picture.h +157 -0
- package/prebuilt/include/dav1d/version.h +50 -0
- package/prebuilt/include/vpx/vp8.h +136 -0
- package/prebuilt/include/vpx/vp8dx.h +228 -0
- package/prebuilt/include/vpx/vpx_codec.h +475 -0
- package/prebuilt/include/vpx/vpx_decoder.h +365 -0
- package/prebuilt/include/vpx/vpx_frame_buffer.h +83 -0
- package/prebuilt/include/vpx/vpx_image.h +209 -0
- package/prebuilt/include/vpx/vpx_integer.h +40 -0
- package/prebuilt/ios/lib/libdav1d.a +0 -0
- package/prebuilt/ios/lib/libvpx.a +0 -0
- package/prebuilt/ios-simulator/include/dav1d/common.h +94 -0
- package/prebuilt/ios-simulator/include/dav1d/data.h +117 -0
- package/prebuilt/ios-simulator/include/dav1d/dav1d.h +329 -0
- package/prebuilt/ios-simulator/include/dav1d/headers.h +440 -0
- package/prebuilt/ios-simulator/include/dav1d/picture.h +157 -0
- package/prebuilt/ios-simulator/include/dav1d/version.h +50 -0
- package/prebuilt/ios-simulator/include/vpx/vp8.h +136 -0
- package/prebuilt/ios-simulator/include/vpx/vp8dx.h +228 -0
- package/prebuilt/ios-simulator/include/vpx/vpx_codec.h +475 -0
- package/prebuilt/ios-simulator/include/vpx/vpx_decoder.h +365 -0
- package/prebuilt/ios-simulator/include/vpx/vpx_frame_buffer.h +83 -0
- package/prebuilt/ios-simulator/include/vpx/vpx_image.h +209 -0
- package/prebuilt/ios-simulator/include/vpx/vpx_integer.h +40 -0
- package/prebuilt/ios-simulator/lib/libdav1d.a +0 -0
- package/prebuilt/ios-simulator/lib/libvpx.a +0 -0
- package/react-native/android/CMakeLists.txt +14 -0
- package/react-native/android/build.gradle +110 -0
- package/react-native/android/src/main/AndroidManifest.xml +1 -0
- package/react-native/android/src/main/java/dev/mediacache/alphavideo/reactnative/AlphaVideoModule.java +102 -0
- package/react-native/android/src/main/java/dev/mediacache/alphavideo/reactnative/AlphaVideoPackage.java +50 -0
- package/react-native/android/src/main/java/dev/mediacache/alphavideo/reactnative/AlphaVideoViewManager.java +317 -0
- package/react-native/android/src/newarch/java/dev/mediacache/alphavideo/reactnative/AlphaVideoModuleSpec.java +10 -0
- package/react-native/android/src/newarch/java/dev/mediacache/alphavideo/reactnative/AlphaVideoViewManagerSpec.java +23 -0
- package/react-native/android/src/norangesource/java/dev/mediacache/alphavideo/AppDataSource.java +15 -0
- package/react-native/android/src/oldarch/java/dev/mediacache/alphavideo/reactnative/AlphaVideoModuleSpec.java +30 -0
- package/react-native/android/src/oldarch/java/dev/mediacache/alphavideo/reactnative/AlphaVideoViewManagerSpec.java +61 -0
- package/react-native/ios/RNAlphaVideoViewComponentView.mm +173 -0
- package/react-native/ios/RNAlphaVideoViewManager.mm +147 -0
- package/react-native/src/AlphaVideoView.tsx +329 -0
- package/react-native/src/AlphaVideoViewNativeComponent.ts +132 -0
- package/react-native/src/AlphaVideoViewNativeComponent.web.ts +5 -0
- package/react-native/src/NativeAlphaVideoModule.ts +22 -0
- package/react-native/src/NativeAlphaVideoModule.web.ts +2 -0
- package/react-native/src/WebPlayer.tsx +7 -0
- package/react-native/src/WebPlayer.web.tsx +60 -0
- package/react-native/src/index.tsx +144 -0
- package/react-native-alpha-video.podspec +99 -0
- package/react-native.config.js +12 -0
- package/scripts/build_codecs_android.sh +246 -0
- package/scripts/build_codecs_ios.sh +31 -0
- package/scripts/build_codecs_ios_device.sh +210 -0
- package/scripts/build_codecs_ios_simulator.sh +256 -0
- package/scripts/build_wasm.sh +230 -0
- package/scripts/build_xcframework.sh +49 -0
- package/scripts/fetch-prebuilt.sh +48 -0
- package/scripts/package_release.sh +107 -0
- package/scripts/publish-android.sh +85 -0
- package/scripts/vendor_range_source.sh +47 -0
- package/third_party/libwebm/AUTHORS.TXT +5 -0
- package/third_party/libwebm/LICENSE.TXT +30 -0
- package/third_party/libwebm/PATENTS.TXT +23 -0
- package/third_party/libwebm/README.md +7 -0
- package/third_party/libwebm/webm_parser/include/webm/buffer_reader.h +138 -0
- package/third_party/libwebm/webm_parser/include/webm/callback.h +363 -0
- package/third_party/libwebm/webm_parser/include/webm/dom_types.h +1781 -0
- package/third_party/libwebm/webm_parser/include/webm/element.h +208 -0
- package/third_party/libwebm/webm_parser/include/webm/file_reader.h +103 -0
- package/third_party/libwebm/webm_parser/include/webm/id.h +1085 -0
- package/third_party/libwebm/webm_parser/include/webm/istream_reader.h +99 -0
- package/third_party/libwebm/webm_parser/include/webm/reader.h +94 -0
- package/third_party/libwebm/webm_parser/include/webm/status.h +166 -0
- package/third_party/libwebm/webm_parser/include/webm/webm_parser.h +133 -0
- package/third_party/libwebm/webm_parser/src/ancestory.cc +334 -0
- package/third_party/libwebm/webm_parser/src/ancestory.h +83 -0
- package/third_party/libwebm/webm_parser/src/audio_parser.h +84 -0
- package/third_party/libwebm/webm_parser/src/bit_utils.cc +26 -0
- package/third_party/libwebm/webm_parser/src/bit_utils.h +24 -0
- package/third_party/libwebm/webm_parser/src/block_additions_parser.h +30 -0
- package/third_party/libwebm/webm_parser/src/block_group_parser.h +71 -0
- package/third_party/libwebm/webm_parser/src/block_header_parser.cc +76 -0
- package/third_party/libwebm/webm_parser/src/block_header_parser.h +65 -0
- package/third_party/libwebm/webm_parser/src/block_more_parser.h +32 -0
- package/third_party/libwebm/webm_parser/src/block_parser.cc +285 -0
- package/third_party/libwebm/webm_parser/src/block_parser.h +126 -0
- package/third_party/libwebm/webm_parser/src/bool_parser.h +95 -0
- package/third_party/libwebm/webm_parser/src/buffer_reader.cc +110 -0
- package/third_party/libwebm/webm_parser/src/byte_parser.h +144 -0
- package/third_party/libwebm/webm_parser/src/callback.cc +155 -0
- package/third_party/libwebm/webm_parser/src/chapter_atom_parser.h +42 -0
- package/third_party/libwebm/webm_parser/src/chapter_display_parser.h +34 -0
- package/third_party/libwebm/webm_parser/src/chapters_parser.h +28 -0
- package/third_party/libwebm/webm_parser/src/cluster_parser.h +48 -0
- package/third_party/libwebm/webm_parser/src/colour_parser.h +55 -0
- package/third_party/libwebm/webm_parser/src/content_enc_aes_settings_parser.h +32 -0
- package/third_party/libwebm/webm_parser/src/content_encoding_parser.h +38 -0
- package/third_party/libwebm/webm_parser/src/content_encodings_parser.h +30 -0
- package/third_party/libwebm/webm_parser/src/content_encryption_parser.h +37 -0
- package/third_party/libwebm/webm_parser/src/cue_point_parser.h +38 -0
- package/third_party/libwebm/webm_parser/src/cue_track_positions_parser.h +39 -0
- package/third_party/libwebm/webm_parser/src/cues_parser.h +27 -0
- package/third_party/libwebm/webm_parser/src/date_parser.cc +72 -0
- package/third_party/libwebm/webm_parser/src/date_parser.h +64 -0
- package/third_party/libwebm/webm_parser/src/ebml_parser.h +48 -0
- package/third_party/libwebm/webm_parser/src/edition_entry_parser.h +35 -0
- package/third_party/libwebm/webm_parser/src/element_parser.h +102 -0
- package/third_party/libwebm/webm_parser/src/file_reader.cc +142 -0
- package/third_party/libwebm/webm_parser/src/float_parser.cc +77 -0
- package/third_party/libwebm/webm_parser/src/float_parser.h +65 -0
- package/third_party/libwebm/webm_parser/src/id_element_parser.cc +49 -0
- package/third_party/libwebm/webm_parser/src/id_element_parser.h +56 -0
- package/third_party/libwebm/webm_parser/src/id_parser.cc +75 -0
- package/third_party/libwebm/webm_parser/src/id_parser.h +45 -0
- package/third_party/libwebm/webm_parser/src/info_parser.h +44 -0
- package/third_party/libwebm/webm_parser/src/int_parser.h +121 -0
- package/third_party/libwebm/webm_parser/src/istream_reader.cc +133 -0
- package/third_party/libwebm/webm_parser/src/master_parser.cc +298 -0
- package/third_party/libwebm/webm_parser/src/master_parser.h +230 -0
- package/third_party/libwebm/webm_parser/src/master_value_parser.h +533 -0
- package/third_party/libwebm/webm_parser/src/mastering_metadata_parser.h +57 -0
- package/third_party/libwebm/webm_parser/src/parser.h +34 -0
- package/third_party/libwebm/webm_parser/src/parser_utils.cc +34 -0
- package/third_party/libwebm/webm_parser/src/parser_utils.h +64 -0
- package/third_party/libwebm/webm_parser/src/projection_parser.h +40 -0
- package/third_party/libwebm/webm_parser/src/recursive_parser.h +93 -0
- package/third_party/libwebm/webm_parser/src/seek_head_parser.h +27 -0
- package/third_party/libwebm/webm_parser/src/seek_parser.h +37 -0
- package/third_party/libwebm/webm_parser/src/segment_parser.cc +86 -0
- package/third_party/libwebm/webm_parser/src/segment_parser.h +53 -0
- package/third_party/libwebm/webm_parser/src/simple_tag_parser.h +37 -0
- package/third_party/libwebm/webm_parser/src/size_parser.cc +56 -0
- package/third_party/libwebm/webm_parser/src/size_parser.h +43 -0
- package/third_party/libwebm/webm_parser/src/skip_callback.h +63 -0
- package/third_party/libwebm/webm_parser/src/skip_parser.cc +59 -0
- package/third_party/libwebm/webm_parser/src/skip_parser.h +35 -0
- package/third_party/libwebm/webm_parser/src/slices_parser.h +30 -0
- package/third_party/libwebm/webm_parser/src/tag_parser.h +37 -0
- package/third_party/libwebm/webm_parser/src/tags_parser.h +27 -0
- package/third_party/libwebm/webm_parser/src/targets_parser.h +35 -0
- package/third_party/libwebm/webm_parser/src/time_slice_parser.h +30 -0
- package/third_party/libwebm/webm_parser/src/track_entry_parser.h +65 -0
- package/third_party/libwebm/webm_parser/src/tracks_parser.h +27 -0
- package/third_party/libwebm/webm_parser/src/unknown_parser.cc +49 -0
- package/third_party/libwebm/webm_parser/src/unknown_parser.h +38 -0
- package/third_party/libwebm/webm_parser/src/var_int_parser.cc +71 -0
- package/third_party/libwebm/webm_parser/src/var_int_parser.h +56 -0
- package/third_party/libwebm/webm_parser/src/video_parser.h +122 -0
- package/third_party/libwebm/webm_parser/src/virtual_block_parser.cc +72 -0
- package/third_party/libwebm/webm_parser/src/virtual_block_parser.h +69 -0
- package/third_party/libwebm/webm_parser/src/void_parser.cc +49 -0
- package/third_party/libwebm/webm_parser/src/void_parser.h +41 -0
- package/third_party/libwebm/webm_parser/src/webm_parser.cc +282 -0
- package/third_party/range-source/LICENSE +21 -0
- package/third_party/range-source/README.md +8 -0
- package/third_party/range-source/include/range_source.h +395 -0
- package/third_party/range-source/include/range_source_download.h +309 -0
package/cpp/YuvToRgb.cpp
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#include "YuvToRgb.h"
|
|
2
|
+
|
|
3
|
+
namespace webm {
|
|
4
|
+
|
|
5
|
+
YuvToRgb yuvToRgbFor(int colorRange, int colorSpace, int width, int height) {
|
|
6
|
+
// Luma and chroma weights of the matrix
|
|
7
|
+
double kr = 0.299, kb = 0.114; // BT.601
|
|
8
|
+
bool sd = width <= 720 && height <= 576;
|
|
9
|
+
if (colorSpace == kMatrixBt709 || (colorSpace == kMatrixUnspecified && !sd)) {
|
|
10
|
+
kr = 0.2126; kb = 0.0722;
|
|
11
|
+
} else if (colorSpace == kMatrixBt2020Ncl || colorSpace == kMatrixBt2020Cl) {
|
|
12
|
+
kr = 0.2627; kb = 0.0593;
|
|
13
|
+
}
|
|
14
|
+
const double kg = 1.0 - kr - kb;
|
|
15
|
+
const double rv = 2 * (1 - kr);
|
|
16
|
+
const double bu = 2 * (1 - kb);
|
|
17
|
+
const double gu = 2 * kb * (1 - kb) / kg;
|
|
18
|
+
const double gv = 2 * kr * (1 - kr) / kg;
|
|
19
|
+
|
|
20
|
+
// Y' = ys * (y - yo), U' = cs * (u - co), from the 0..1 texture samples
|
|
21
|
+
const bool full = colorRange == kRangeFull;
|
|
22
|
+
const double ys = full ? 1.0 : 255.0 / 219.0, yo = full ? 0.0 : 16.0 / 255.0;
|
|
23
|
+
const double cs = full ? 1.0 : 255.0 / 224.0, co = 128.0 / 255.0;
|
|
24
|
+
|
|
25
|
+
// Rows R, G, B of [y u v 1], stored column-major
|
|
26
|
+
const double rows[3][4] = {
|
|
27
|
+
{ys, 0, rv * cs, -ys * yo - rv * cs * co},
|
|
28
|
+
{ys, -gu * cs, -gv * cs, -ys * yo + (gu + gv) * cs * co},
|
|
29
|
+
{ys, bu * cs, 0, -ys * yo - bu * cs * co},
|
|
30
|
+
};
|
|
31
|
+
YuvToRgb out{};
|
|
32
|
+
for (int col = 0; col < 4; col++) {
|
|
33
|
+
for (int row = 0; row < 3; row++) out.m[col * 4 + row] = static_cast<float>(rows[row][col]);
|
|
34
|
+
}
|
|
35
|
+
out.m[15] = 1;
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
} // namespace webm
|
package/cpp/YuvToRgb.h
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
namespace webm {
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Colour ranges and matrices, numbered as FFmpeg's AVColorRange and AVColorSpace. The matrix
|
|
7
|
+
* numbers are ISO/IEC 23091-2's (H.273), as in WebM's Colour element and AV1's sequence header.
|
|
8
|
+
* Android's Java code and the web's TypeScript use the same numbers.
|
|
9
|
+
*/
|
|
10
|
+
enum ColorRange { kRangeUnspecified = 0, kRangeLimited = 1, kRangeFull = 2 };
|
|
11
|
+
enum ColorMatrix {
|
|
12
|
+
kMatrixRgb = 0,
|
|
13
|
+
kMatrixBt709 = 1,
|
|
14
|
+
kMatrixUnspecified = 2,
|
|
15
|
+
kMatrixReserved = 3,
|
|
16
|
+
kMatrixBt470bg = 5,
|
|
17
|
+
kMatrixSmpte170m = 6,
|
|
18
|
+
kMatrixSmpte240m = 7,
|
|
19
|
+
kMatrixBt2020Ncl = 9,
|
|
20
|
+
kMatrixBt2020Cl = 10,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* YUV to RGB for the shaders: rgb = m * (y, u, v, 1), with y, u and v the texture samples
|
|
25
|
+
* (0..1) and the result in 0..1 before clamping. Column-major, as GLSL's mat4 and Metal's
|
|
26
|
+
* float4x4 take it.
|
|
27
|
+
*/
|
|
28
|
+
struct YuvToRgb {
|
|
29
|
+
float m[16];
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The conversion for a clip's ColorRange and ColorMatrix. An unspecified range is limited
|
|
34
|
+
* (16-235), which VP9 and AV1 video almost always is. An unspecified matrix is BT.601 up to
|
|
35
|
+
* 720x576 and BT.709 above, Android's default for untagged video, so the software path matches
|
|
36
|
+
* MediaCodec's.
|
|
37
|
+
*/
|
|
38
|
+
YuvToRgb yuvToRgbFor(int colorRange, int colorSpace, int width, int height);
|
|
39
|
+
|
|
40
|
+
} // namespace webm
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AlphaVideoCodecs.mm
|
|
3
|
+
* Finds the linked codec modules by class name and registers their decoders with the C++ core.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#import "AlphaVideoInternal.h"
|
|
7
|
+
#include "VideoDecoder.h"
|
|
8
|
+
#include "WebMAlphaPlayer.h"
|
|
9
|
+
|
|
10
|
+
NSString *const AlphaVideoErrorNoDecoder = @(webm::WebMAlphaPlayer::kErrorNoDecoder);
|
|
11
|
+
|
|
12
|
+
typedef const void *(*AlphaVideoPluginListGetter)(id, SEL);
|
|
13
|
+
|
|
14
|
+
@implementation AlphaVideoCodecs
|
|
15
|
+
|
|
16
|
+
+ (void)discover {
|
|
17
|
+
static dispatch_once_t once;
|
|
18
|
+
dispatch_once(&once, ^{
|
|
19
|
+
// Each module's class has +pluginList, its AlphaVideoDecoderPluginList (AlphaVideoVPX.h,
|
|
20
|
+
// AlphaVideoAV1.h). Static pods link with -ObjC and SwiftPM links source targets as
|
|
21
|
+
// object files, so a linked module's class is in the app though nothing references it.
|
|
22
|
+
for (NSString *name in @[ @"AlphaVideoVPXCodec", @"AlphaVideoAV1Codec" ]) {
|
|
23
|
+
Class module = NSClassFromString(name);
|
|
24
|
+
SEL selector = NSSelectorFromString(@"pluginList");
|
|
25
|
+
if (!module || ![module respondsToSelector:selector]) continue;
|
|
26
|
+
auto getter = (AlphaVideoPluginListGetter)[module methodForSelector:selector];
|
|
27
|
+
NSError *error;
|
|
28
|
+
if (![self registerList:getter(module, selector) error:&error]) {
|
|
29
|
+
NSLog(@"AlphaVideo: %@: %@", name, error.localizedDescription);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
+ (BOOL)registerList:(const void *)pluginList error:(NSError **)error {
|
|
36
|
+
std::string message = "No plugin list";
|
|
37
|
+
if (pluginList &&
|
|
38
|
+
webm::registerDecoderPlugins(reinterpret_cast<AlphaVideoDecoderPluginList>(const_cast<void *>(pluginList)), &message)) {
|
|
39
|
+
return YES;
|
|
40
|
+
}
|
|
41
|
+
if (error) {
|
|
42
|
+
*error = [NSError errorWithDomain:@"AlphaVideo"
|
|
43
|
+
code:1
|
|
44
|
+
userInfo:@{NSLocalizedDescriptionKey : @(message.c_str())}];
|
|
45
|
+
}
|
|
46
|
+
return NO;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
+ (BOOL)registerPluginList:(const void *)pluginList error:(NSError **)error {
|
|
50
|
+
[self discover];
|
|
51
|
+
return [self registerList:pluginList error:error];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
+ (NSArray<NSString *> *)softwareDecoders {
|
|
55
|
+
[self discover];
|
|
56
|
+
NSMutableArray<NSString *> *decoders = [NSMutableArray array];
|
|
57
|
+
for (const std::string &decoder : webm::registeredDecoders()) {
|
|
58
|
+
[decoders addObject:@(decoder.c_str())];
|
|
59
|
+
}
|
|
60
|
+
return decoders;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AlphaVideoInternal.h
|
|
3
|
+
* Shared by the library's own files; not part of the public API.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
#import "AlphaVideo.h"
|
|
7
|
+
|
|
8
|
+
#ifdef __cplusplus
|
|
9
|
+
#include <memory>
|
|
10
|
+
#include "RangeSourceClient.h"
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
14
|
+
|
|
15
|
+
#ifdef __cplusplus
|
|
16
|
+
/** The range-source add-on's table, or NULL without it. */
|
|
17
|
+
const RangeSourcePlugin *_Nullable AlphaVideoRangeSourcePlugin(void);
|
|
18
|
+
#endif
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A native reader over a URL or a data source, fetching on its own thread. With the range-source
|
|
22
|
+
* add-on, it reads by range, through blocks in memory and an optional store. Without it, the
|
|
23
|
+
* basic input: a URL downloaded whole into a temporary file, read as it arrives. Closes once the
|
|
24
|
+
* last holder (the view, a player) lets go.
|
|
25
|
+
*/
|
|
26
|
+
@interface AlphaVideoSourceReader : NSObject
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Opens the source at 0 to learn its size and version, unless the store holds it whole. Blocks
|
|
30
|
+
* on the network, so not on the main queue.
|
|
31
|
+
*
|
|
32
|
+
* @param dataSource the name of a data source registered with the add-on's RangeDataSources; nil
|
|
33
|
+
* for the built-in URLSession fetcher (http and https only)
|
|
34
|
+
* @param storage "disk", "memory" or "none"; with the add-on
|
|
35
|
+
* @param key what the store calls the file; with the add-on
|
|
36
|
+
*/
|
|
37
|
+
+ (nullable instancetype)openURL:(NSURL *)url
|
|
38
|
+
dataSource:(nullable NSString *)dataSource
|
|
39
|
+
headers:(NSDictionary<NSString *, NSString *> *)headers
|
|
40
|
+
storage:(NSString *)storage
|
|
41
|
+
key:(NSString *)key
|
|
42
|
+
maxStorageBytes:(int64_t)maxStorageBytes
|
|
43
|
+
error:(NSString *_Nullable *_Nullable)error;
|
|
44
|
+
|
|
45
|
+
/** Reads the whole file into the store. Blocks; NO with `error` set if it fails. */
|
|
46
|
+
- (BOOL)fetchAll:(NSString *_Nullable *_Nullable)error;
|
|
47
|
+
|
|
48
|
+
#ifdef __cplusplus
|
|
49
|
+
@property (nonatomic, readonly) std::shared_ptr<webm::SourceReader> rangeReader;
|
|
50
|
+
#endif
|
|
51
|
+
|
|
52
|
+
@end
|
|
53
|
+
|
|
54
|
+
@interface AlphaVideoPlayer (SourceReader)
|
|
55
|
+
- (BOOL)loadFromReader:(AlphaVideoSourceReader *)reader;
|
|
56
|
+
@end
|
|
57
|
+
|
|
58
|
+
@interface AlphaVideoMetalView (SourceReader)
|
|
59
|
+
- (BOOL)loadFromReader:(AlphaVideoSourceReader *)reader;
|
|
60
|
+
@end
|
|
61
|
+
|
|
62
|
+
@interface AlphaVideoCodecs ()
|
|
63
|
+
/** Registers the linked codec modules, once. Before a player opens a file. */
|
|
64
|
+
+ (void)discover;
|
|
65
|
+
@end
|
|
66
|
+
|
|
67
|
+
/** The file an asset://, file:// or absolute-path source names; nil for anything else. */
|
|
68
|
+
NSString *_Nullable AlphaVideoLocalPathForSource(NSString *uri);
|
|
69
|
+
|
|
70
|
+
NS_ASSUME_NONNULL_END
|