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
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Copyright (c) 2016 The WebM project authors. All Rights Reserved.
|
|
2
|
+
//
|
|
3
|
+
// Use of this source code is governed by a BSD-style license
|
|
4
|
+
// that can be found in the LICENSE file in the root of the source
|
|
5
|
+
// tree. An additional intellectual property rights grant can be found
|
|
6
|
+
// in the file PATENTS. All contributing project authors may
|
|
7
|
+
// be found in the AUTHORS file in the root of the source tree.
|
|
8
|
+
#include "webm/file_reader.h"
|
|
9
|
+
|
|
10
|
+
#include <cassert>
|
|
11
|
+
#include <cstdint>
|
|
12
|
+
#include <cstdio>
|
|
13
|
+
#include <cstdlib>
|
|
14
|
+
#include <limits>
|
|
15
|
+
#include <memory>
|
|
16
|
+
|
|
17
|
+
#include "webm/status.h"
|
|
18
|
+
|
|
19
|
+
#ifdef _MSC_VER
|
|
20
|
+
#define FSEEK_(stream, offset, whence) _fseeki64(stream, offset, whence)
|
|
21
|
+
#elif defined(_WIN32)
|
|
22
|
+
#define FSEEK_(stream, offset, whence) \
|
|
23
|
+
fseeko64(stream, static_cast<off_t>(offset), whence)
|
|
24
|
+
#elif _POSIX_C_SOURCE >= 200112L
|
|
25
|
+
#define FSEEK_(stream, offset, whence) \
|
|
26
|
+
fseeko(stream, static_cast<off_t>(offset), whence)
|
|
27
|
+
#else
|
|
28
|
+
#define FSEEK_(stream, offset, whence) \
|
|
29
|
+
std::fseek(stream, static_cast<long>(offset), whence)
|
|
30
|
+
#endif
|
|
31
|
+
|
|
32
|
+
namespace webm {
|
|
33
|
+
|
|
34
|
+
FileReader::FileReader(FILE* file) : file_(file) { assert(file); }
|
|
35
|
+
|
|
36
|
+
FileReader::FileReader(FileReader&& other)
|
|
37
|
+
: file_(std::move(other.file_)), position_(other.position_) {
|
|
38
|
+
other.position_ = 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
FileReader& FileReader::operator=(FileReader&& other) {
|
|
42
|
+
if (this != &other) {
|
|
43
|
+
file_ = std::move(other.file_);
|
|
44
|
+
position_ = other.position_;
|
|
45
|
+
other.position_ = 0;
|
|
46
|
+
}
|
|
47
|
+
return *this;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
Status FileReader::Read(std::size_t num_to_read, std::uint8_t* buffer,
|
|
51
|
+
std::uint64_t* num_actually_read) {
|
|
52
|
+
assert(num_to_read > 0);
|
|
53
|
+
assert(buffer != nullptr);
|
|
54
|
+
assert(num_actually_read != nullptr);
|
|
55
|
+
|
|
56
|
+
if (file_ == nullptr) {
|
|
57
|
+
*num_actually_read = 0;
|
|
58
|
+
return Status(Status::kEndOfFile);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
std::size_t actual =
|
|
62
|
+
std::fread(static_cast<void*>(buffer), 1, num_to_read, file_.get());
|
|
63
|
+
*num_actually_read = static_cast<std::uint64_t>(actual);
|
|
64
|
+
position_ += *num_actually_read;
|
|
65
|
+
|
|
66
|
+
if (actual == 0) {
|
|
67
|
+
return Status(Status::kEndOfFile);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (actual == num_to_read) {
|
|
71
|
+
return Status(Status::kOkCompleted);
|
|
72
|
+
} else {
|
|
73
|
+
return Status(Status::kOkPartial);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
Status FileReader::Skip(std::uint64_t num_to_skip,
|
|
78
|
+
std::uint64_t* num_actually_skipped) {
|
|
79
|
+
assert(num_to_skip > 0);
|
|
80
|
+
assert(num_actually_skipped != nullptr);
|
|
81
|
+
|
|
82
|
+
*num_actually_skipped = 0;
|
|
83
|
+
|
|
84
|
+
if (file_ == nullptr) {
|
|
85
|
+
return Status(Status::kEndOfFile);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Try seeking forward first.
|
|
89
|
+
long seek_offset = std::numeric_limits<long>::max(); // NOLINT
|
|
90
|
+
if (num_to_skip < static_cast<unsigned long>(seek_offset)) { // NOLINT
|
|
91
|
+
seek_offset = static_cast<long>(num_to_skip); // NOLINT
|
|
92
|
+
}
|
|
93
|
+
if (!FSEEK_(file_.get(), seek_offset, SEEK_CUR)) {
|
|
94
|
+
*num_actually_skipped = static_cast<std::uint64_t>(seek_offset);
|
|
95
|
+
position_ += static_cast<std::uint64_t>(seek_offset);
|
|
96
|
+
if (static_cast<unsigned long>(seek_offset) == num_to_skip) { // NOLINT
|
|
97
|
+
return Status(Status::kOkCompleted);
|
|
98
|
+
} else {
|
|
99
|
+
return Status(Status::kOkPartial);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
std::clearerr(file_.get());
|
|
103
|
+
|
|
104
|
+
// Seeking doesn't work on things like pipes, so if seeking failed then fall
|
|
105
|
+
// back to reading the data into a junk buffer.
|
|
106
|
+
std::size_t actual = 0;
|
|
107
|
+
do {
|
|
108
|
+
std::uint8_t junk[1024];
|
|
109
|
+
std::size_t num_to_read = sizeof(junk);
|
|
110
|
+
if (num_to_skip < num_to_read) {
|
|
111
|
+
num_to_read = static_cast<std::size_t>(num_to_skip);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
std::size_t actual =
|
|
115
|
+
std::fread(static_cast<void*>(junk), 1, num_to_read, file_.get());
|
|
116
|
+
*num_actually_skipped += static_cast<std::uint64_t>(actual);
|
|
117
|
+
position_ += static_cast<std::uint64_t>(actual);
|
|
118
|
+
num_to_skip -= static_cast<std::uint64_t>(actual);
|
|
119
|
+
} while (actual > 0 && num_to_skip > 0);
|
|
120
|
+
|
|
121
|
+
if (*num_actually_skipped == 0) {
|
|
122
|
+
return Status(Status::kEndOfFile);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (num_to_skip == 0) {
|
|
126
|
+
return Status(Status::kOkCompleted);
|
|
127
|
+
} else {
|
|
128
|
+
return Status(Status::kOkPartial);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
Status FileReader::Seek(std::uint64_t seek_position) {
|
|
133
|
+
if (FSEEK_(file_.get(), seek_position, SEEK_SET)) {
|
|
134
|
+
return Status(Status::kSeekFailed);
|
|
135
|
+
}
|
|
136
|
+
position_ = seek_position;
|
|
137
|
+
return Status(Status::kOkCompleted);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
std::uint64_t FileReader::Position() const { return position_; }
|
|
141
|
+
|
|
142
|
+
} // namespace webm
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Copyright (c) 2016 The WebM project authors. All Rights Reserved.
|
|
2
|
+
//
|
|
3
|
+
// Use of this source code is governed by a BSD-style license
|
|
4
|
+
// that can be found in the LICENSE file in the root of the source
|
|
5
|
+
// tree. An additional intellectual property rights grant can be found
|
|
6
|
+
// in the file PATENTS. All contributing project authors may
|
|
7
|
+
// be found in the AUTHORS file in the root of the source tree.
|
|
8
|
+
#include "src/float_parser.h"
|
|
9
|
+
|
|
10
|
+
#include <cassert>
|
|
11
|
+
#include <cstdint>
|
|
12
|
+
#include <cstring>
|
|
13
|
+
#include <limits>
|
|
14
|
+
|
|
15
|
+
#include "src/parser_utils.h"
|
|
16
|
+
#include "webm/element.h"
|
|
17
|
+
#include "webm/reader.h"
|
|
18
|
+
#include "webm/status.h"
|
|
19
|
+
|
|
20
|
+
namespace webm {
|
|
21
|
+
|
|
22
|
+
FloatParser::FloatParser(double default_value)
|
|
23
|
+
: default_value_(default_value) {}
|
|
24
|
+
|
|
25
|
+
Status FloatParser::Init(const ElementMetadata& metadata,
|
|
26
|
+
std::uint64_t max_size) {
|
|
27
|
+
assert(metadata.size == kUnknownElementSize || metadata.size <= max_size);
|
|
28
|
+
|
|
29
|
+
if (metadata.size == 0) {
|
|
30
|
+
value_ = default_value_;
|
|
31
|
+
} else if (metadata.size == 4 || metadata.size == 8) {
|
|
32
|
+
uint64_value_ = 0;
|
|
33
|
+
} else {
|
|
34
|
+
return Status(Status::kInvalidElementSize);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
num_bytes_remaining_ = static_cast<int>(metadata.size);
|
|
38
|
+
use_32_bits_ = metadata.size == 4;
|
|
39
|
+
|
|
40
|
+
return Status(Status::kOkCompleted);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
Status FloatParser::Feed(Callback* callback, Reader* reader,
|
|
44
|
+
std::uint64_t* num_bytes_read) {
|
|
45
|
+
assert(callback != nullptr);
|
|
46
|
+
assert(reader != nullptr);
|
|
47
|
+
assert(num_bytes_read != nullptr);
|
|
48
|
+
|
|
49
|
+
if (num_bytes_remaining_ == 0) {
|
|
50
|
+
return Status(Status::kOkCompleted);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const Status status = AccumulateIntegerBytes(num_bytes_remaining_, reader,
|
|
54
|
+
&uint64_value_, num_bytes_read);
|
|
55
|
+
num_bytes_remaining_ -= static_cast<int>(*num_bytes_read);
|
|
56
|
+
|
|
57
|
+
if (num_bytes_remaining_ == 0) {
|
|
58
|
+
if (use_32_bits_) {
|
|
59
|
+
static_assert(std::numeric_limits<float>::is_iec559,
|
|
60
|
+
"Your compiler does not support 32-bit IEC 559/IEEE 754 "
|
|
61
|
+
"floating point types");
|
|
62
|
+
std::uint32_t uint32_value = static_cast<std::uint32_t>(uint64_value_);
|
|
63
|
+
float float32_value;
|
|
64
|
+
std::memcpy(&float32_value, &uint32_value, 4);
|
|
65
|
+
value_ = float32_value;
|
|
66
|
+
} else {
|
|
67
|
+
static_assert(std::numeric_limits<double>::is_iec559,
|
|
68
|
+
"Your compiler does not support 64-bit IEC 559/IEEE 754 "
|
|
69
|
+
"floating point types");
|
|
70
|
+
std::memcpy(&value_, &uint64_value_, 8);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return status;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
} // namespace webm
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Copyright (c) 2016 The WebM project authors. All Rights Reserved.
|
|
2
|
+
//
|
|
3
|
+
// Use of this source code is governed by a BSD-style license
|
|
4
|
+
// that can be found in the LICENSE file in the root of the source
|
|
5
|
+
// tree. An additional intellectual property rights grant can be found
|
|
6
|
+
// in the file PATENTS. All contributing project authors may
|
|
7
|
+
// be found in the AUTHORS file in the root of the source tree.
|
|
8
|
+
#ifndef SRC_FLOAT_PARSER_H_
|
|
9
|
+
#define SRC_FLOAT_PARSER_H_
|
|
10
|
+
|
|
11
|
+
#include <cassert>
|
|
12
|
+
#include <cstdint>
|
|
13
|
+
|
|
14
|
+
#include "src/element_parser.h"
|
|
15
|
+
#include "webm/callback.h"
|
|
16
|
+
#include "webm/element.h"
|
|
17
|
+
#include "webm/reader.h"
|
|
18
|
+
#include "webm/status.h"
|
|
19
|
+
|
|
20
|
+
namespace webm {
|
|
21
|
+
|
|
22
|
+
// Parses an EBML float from a byte stream.
|
|
23
|
+
class FloatParser : public ElementParser {
|
|
24
|
+
public:
|
|
25
|
+
// Constructs a new parser which will use the given default_value as the
|
|
26
|
+
// value for the element if its size is zero. Defaults to the value zero (as
|
|
27
|
+
// the EBML spec indicates).
|
|
28
|
+
explicit FloatParser(double default_value = 0.0);
|
|
29
|
+
|
|
30
|
+
FloatParser(FloatParser&&) = default;
|
|
31
|
+
FloatParser& operator=(FloatParser&&) = default;
|
|
32
|
+
|
|
33
|
+
FloatParser(const FloatParser&) = delete;
|
|
34
|
+
FloatParser& operator=(const FloatParser&) = delete;
|
|
35
|
+
|
|
36
|
+
Status Init(const ElementMetadata& metadata, std::uint64_t max_size) override;
|
|
37
|
+
|
|
38
|
+
Status Feed(Callback* callback, Reader* reader,
|
|
39
|
+
std::uint64_t* num_bytes_read) override;
|
|
40
|
+
|
|
41
|
+
// Gets the parsed float. This must not be called until the parse had been
|
|
42
|
+
// successfully completed.
|
|
43
|
+
double value() const {
|
|
44
|
+
assert(num_bytes_remaining_ == 0);
|
|
45
|
+
return value_;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Gets the parsed float. This must not be called until the parse had been
|
|
49
|
+
// successfully completed.
|
|
50
|
+
double* mutable_value() {
|
|
51
|
+
assert(num_bytes_remaining_ == 0);
|
|
52
|
+
return &value_;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private:
|
|
56
|
+
double value_;
|
|
57
|
+
double default_value_;
|
|
58
|
+
std::uint64_t uint64_value_;
|
|
59
|
+
int num_bytes_remaining_ = -1;
|
|
60
|
+
bool use_32_bits_;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
} // namespace webm
|
|
64
|
+
|
|
65
|
+
#endif // SRC_FLOAT_PARSER_H_
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Copyright (c) 2016 The WebM project authors. All Rights Reserved.
|
|
2
|
+
//
|
|
3
|
+
// Use of this source code is governed by a BSD-style license
|
|
4
|
+
// that can be found in the LICENSE file in the root of the source
|
|
5
|
+
// tree. An additional intellectual property rights grant can be found
|
|
6
|
+
// in the file PATENTS. All contributing project authors may
|
|
7
|
+
// be found in the AUTHORS file in the root of the source tree.
|
|
8
|
+
#include "src/id_element_parser.h"
|
|
9
|
+
|
|
10
|
+
#include <cassert>
|
|
11
|
+
#include <cstdint>
|
|
12
|
+
|
|
13
|
+
#include "src/element_parser.h"
|
|
14
|
+
#include "src/parser_utils.h"
|
|
15
|
+
#include "webm/callback.h"
|
|
16
|
+
#include "webm/element.h"
|
|
17
|
+
#include "webm/reader.h"
|
|
18
|
+
#include "webm/status.h"
|
|
19
|
+
|
|
20
|
+
namespace webm {
|
|
21
|
+
|
|
22
|
+
Status IdElementParser::Init(const ElementMetadata& metadata,
|
|
23
|
+
std::uint64_t max_size) {
|
|
24
|
+
assert(metadata.size == kUnknownElementSize || metadata.size <= max_size);
|
|
25
|
+
|
|
26
|
+
if (metadata.size == 0 || metadata.size > 4) {
|
|
27
|
+
return Status(Status::kInvalidElementSize);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
num_bytes_remaining_ = static_cast<int>(metadata.size);
|
|
31
|
+
value_ = static_cast<Id>(0);
|
|
32
|
+
|
|
33
|
+
return Status(Status::kOkCompleted);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
Status IdElementParser::Feed(Callback* callback, Reader* reader,
|
|
37
|
+
std::uint64_t* num_bytes_read) {
|
|
38
|
+
assert(callback != nullptr);
|
|
39
|
+
assert(reader != nullptr);
|
|
40
|
+
assert(num_bytes_read != nullptr);
|
|
41
|
+
|
|
42
|
+
const Status status = AccumulateIntegerBytes(num_bytes_remaining_, reader,
|
|
43
|
+
&value_, num_bytes_read);
|
|
44
|
+
num_bytes_remaining_ -= static_cast<int>(*num_bytes_read);
|
|
45
|
+
|
|
46
|
+
return status;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
} // namespace webm
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Copyright (c) 2016 The WebM project authors. All Rights Reserved.
|
|
2
|
+
//
|
|
3
|
+
// Use of this source code is governed by a BSD-style license
|
|
4
|
+
// that can be found in the LICENSE file in the root of the source
|
|
5
|
+
// tree. An additional intellectual property rights grant can be found
|
|
6
|
+
// in the file PATENTS. All contributing project authors may
|
|
7
|
+
// be found in the AUTHORS file in the root of the source tree.
|
|
8
|
+
#ifndef SRC_ID_ELEMENT_PARSER_H_
|
|
9
|
+
#define SRC_ID_ELEMENT_PARSER_H_
|
|
10
|
+
|
|
11
|
+
#include <cstdint>
|
|
12
|
+
|
|
13
|
+
#include "src/element_parser.h"
|
|
14
|
+
#include "webm/callback.h"
|
|
15
|
+
#include "webm/reader.h"
|
|
16
|
+
#include "webm/status.h"
|
|
17
|
+
|
|
18
|
+
namespace webm {
|
|
19
|
+
|
|
20
|
+
class IdElementParser : public ElementParser {
|
|
21
|
+
public:
|
|
22
|
+
IdElementParser() = default;
|
|
23
|
+
|
|
24
|
+
IdElementParser(IdElementParser&&) = default;
|
|
25
|
+
IdElementParser& operator=(IdElementParser&&) = default;
|
|
26
|
+
|
|
27
|
+
IdElementParser(const IdElementParser&) = delete;
|
|
28
|
+
IdElementParser& operator=(const IdElementParser&) = delete;
|
|
29
|
+
|
|
30
|
+
Status Init(const ElementMetadata& metadata, std::uint64_t max_size) override;
|
|
31
|
+
|
|
32
|
+
Status Feed(Callback* callback, Reader* reader,
|
|
33
|
+
std::uint64_t* num_bytes_read) override;
|
|
34
|
+
|
|
35
|
+
// Gets the parsed Id. This must not be called until the parse had been
|
|
36
|
+
// successfully completed.
|
|
37
|
+
Id value() const {
|
|
38
|
+
assert(num_bytes_remaining_ == 0);
|
|
39
|
+
return value_;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Gets the parsed Id. This must not be called until the parse had been
|
|
43
|
+
// successfully completed.
|
|
44
|
+
Id* mutable_value() {
|
|
45
|
+
assert(num_bytes_remaining_ == 0);
|
|
46
|
+
return &value_;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private:
|
|
50
|
+
Id value_;
|
|
51
|
+
int num_bytes_remaining_ = -1;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
} // namespace webm
|
|
55
|
+
|
|
56
|
+
#endif // SRC_ID_ELEMENT_PARSER_H_
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Copyright (c) 2016 The WebM project authors. All Rights Reserved.
|
|
2
|
+
//
|
|
3
|
+
// Use of this source code is governed by a BSD-style license
|
|
4
|
+
// that can be found in the LICENSE file in the root of the source
|
|
5
|
+
// tree. An additional intellectual property rights grant can be found
|
|
6
|
+
// in the file PATENTS. All contributing project authors may
|
|
7
|
+
// be found in the AUTHORS file in the root of the source tree.
|
|
8
|
+
#include "src/id_parser.h"
|
|
9
|
+
|
|
10
|
+
#include <cassert>
|
|
11
|
+
#include <cstdint>
|
|
12
|
+
|
|
13
|
+
#include "src/bit_utils.h"
|
|
14
|
+
#include "src/parser_utils.h"
|
|
15
|
+
#include "webm/id.h"
|
|
16
|
+
#include "webm/reader.h"
|
|
17
|
+
#include "webm/status.h"
|
|
18
|
+
|
|
19
|
+
namespace webm {
|
|
20
|
+
|
|
21
|
+
Status IdParser::Feed(Callback* callback, Reader* reader,
|
|
22
|
+
std::uint64_t* num_bytes_read) {
|
|
23
|
+
assert(callback != nullptr);
|
|
24
|
+
assert(reader != nullptr);
|
|
25
|
+
assert(num_bytes_read != nullptr);
|
|
26
|
+
assert(num_bytes_remaining_ != 0);
|
|
27
|
+
|
|
28
|
+
*num_bytes_read = 0;
|
|
29
|
+
|
|
30
|
+
// Spec references:
|
|
31
|
+
// http://matroska.org/technical/specs/index.html#EBML_ex
|
|
32
|
+
// https://github.com/Matroska-Org/ebml-specification/blob/master/specification.markdown#variable-size-integer
|
|
33
|
+
// https://github.com/Matroska-Org/ebml-specification/blob/master/specification.markdown#element-id
|
|
34
|
+
|
|
35
|
+
// IDs are encoded like so (big-endian):
|
|
36
|
+
// 0b1xxx xxxx
|
|
37
|
+
// 0b01xx xxxx xxxx xxxx
|
|
38
|
+
// 0b001x xxxx xxxx xxxx xxxx xxxx
|
|
39
|
+
// 0b0001 xxxx xxxx xxxx xxxx xxxx xxxx xxxx
|
|
40
|
+
|
|
41
|
+
if (num_bytes_remaining_ == -1) {
|
|
42
|
+
std::uint8_t first_byte;
|
|
43
|
+
const Status status = ReadByte(reader, &first_byte);
|
|
44
|
+
if (!status.completed_ok()) {
|
|
45
|
+
return status;
|
|
46
|
+
}
|
|
47
|
+
++*num_bytes_read;
|
|
48
|
+
|
|
49
|
+
// The marker bit is the first 1-bit. It indicates the length of the ID.
|
|
50
|
+
// If there is no marker bit in the first half-octet, this isn't a valid
|
|
51
|
+
// ID, since IDs can't be more than 4 octets in MKV/WebM.
|
|
52
|
+
if (!(first_byte & 0xf0)) {
|
|
53
|
+
return Status(Status::kInvalidElementId);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
num_bytes_remaining_ = CountLeadingZeros(first_byte);
|
|
57
|
+
|
|
58
|
+
id_ = static_cast<Id>(first_byte);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
std::uint64_t local_num_bytes_read;
|
|
62
|
+
const Status status = AccumulateIntegerBytes(num_bytes_remaining_, reader,
|
|
63
|
+
&id_, &local_num_bytes_read);
|
|
64
|
+
*num_bytes_read += local_num_bytes_read;
|
|
65
|
+
num_bytes_remaining_ -= static_cast<int>(local_num_bytes_read);
|
|
66
|
+
|
|
67
|
+
return status;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
Id IdParser::id() const {
|
|
71
|
+
assert(num_bytes_remaining_ == 0);
|
|
72
|
+
return id_;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
} // namespace webm
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Copyright (c) 2016 The WebM project authors. All Rights Reserved.
|
|
2
|
+
//
|
|
3
|
+
// Use of this source code is governed by a BSD-style license
|
|
4
|
+
// that can be found in the LICENSE file in the root of the source
|
|
5
|
+
// tree. An additional intellectual property rights grant can be found
|
|
6
|
+
// in the file PATENTS. All contributing project authors may
|
|
7
|
+
// be found in the AUTHORS file in the root of the source tree.
|
|
8
|
+
#ifndef SRC_ID_PARSER_H_
|
|
9
|
+
#define SRC_ID_PARSER_H_
|
|
10
|
+
|
|
11
|
+
#include <cstdint>
|
|
12
|
+
|
|
13
|
+
#include "src/parser.h"
|
|
14
|
+
#include "webm/callback.h"
|
|
15
|
+
#include "webm/id.h"
|
|
16
|
+
#include "webm/reader.h"
|
|
17
|
+
#include "webm/status.h"
|
|
18
|
+
|
|
19
|
+
namespace webm {
|
|
20
|
+
|
|
21
|
+
// Parses an EBML ID from a byte stream.
|
|
22
|
+
class IdParser : public Parser {
|
|
23
|
+
public:
|
|
24
|
+
IdParser() = default;
|
|
25
|
+
IdParser(IdParser&&) = default;
|
|
26
|
+
IdParser& operator=(IdParser&&) = default;
|
|
27
|
+
|
|
28
|
+
IdParser(const IdParser&) = delete;
|
|
29
|
+
IdParser& operator=(const IdParser&) = delete;
|
|
30
|
+
|
|
31
|
+
Status Feed(Callback* callback, Reader* reader,
|
|
32
|
+
std::uint64_t* num_bytes_read) override;
|
|
33
|
+
|
|
34
|
+
// Gets the parsed ID. This must not be called until the parse had been
|
|
35
|
+
// successfully completed.
|
|
36
|
+
Id id() const;
|
|
37
|
+
|
|
38
|
+
private:
|
|
39
|
+
int num_bytes_remaining_ = -1;
|
|
40
|
+
Id id_;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
} // namespace webm
|
|
44
|
+
|
|
45
|
+
#endif // SRC_ID_PARSER_H_
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Copyright (c) 2016 The WebM project authors. All Rights Reserved.
|
|
2
|
+
//
|
|
3
|
+
// Use of this source code is governed by a BSD-style license
|
|
4
|
+
// that can be found in the LICENSE file in the root of the source
|
|
5
|
+
// tree. An additional intellectual property rights grant can be found
|
|
6
|
+
// in the file PATENTS. All contributing project authors may
|
|
7
|
+
// be found in the AUTHORS file in the root of the source tree.
|
|
8
|
+
#ifndef SRC_INFO_PARSER_H_
|
|
9
|
+
#define SRC_INFO_PARSER_H_
|
|
10
|
+
|
|
11
|
+
#include "src/byte_parser.h"
|
|
12
|
+
#include "src/date_parser.h"
|
|
13
|
+
#include "src/float_parser.h"
|
|
14
|
+
#include "src/int_parser.h"
|
|
15
|
+
#include "src/master_value_parser.h"
|
|
16
|
+
#include "webm/dom_types.h"
|
|
17
|
+
#include "webm/id.h"
|
|
18
|
+
|
|
19
|
+
namespace webm {
|
|
20
|
+
|
|
21
|
+
// Spec reference:
|
|
22
|
+
// http://matroska.org/technical/specs/index.html#Info
|
|
23
|
+
// http://www.webmproject.org/docs/container/#Info
|
|
24
|
+
class InfoParser : public MasterValueParser<Info> {
|
|
25
|
+
public:
|
|
26
|
+
InfoParser()
|
|
27
|
+
: MasterValueParser<Info>(
|
|
28
|
+
MakeChild<UnsignedIntParser>(Id::kTimecodeScale,
|
|
29
|
+
&Info::timecode_scale),
|
|
30
|
+
MakeChild<FloatParser>(Id::kDuration, &Info::duration),
|
|
31
|
+
MakeChild<DateParser>(Id::kDateUtc, &Info::date_utc),
|
|
32
|
+
MakeChild<StringParser>(Id::kTitle, &Info::title),
|
|
33
|
+
MakeChild<StringParser>(Id::kMuxingApp, &Info::muxing_app),
|
|
34
|
+
MakeChild<StringParser>(Id::kWritingApp, &Info::writing_app)) {}
|
|
35
|
+
|
|
36
|
+
protected:
|
|
37
|
+
Status OnParseCompleted(Callback* callback) override {
|
|
38
|
+
return callback->OnInfo(metadata(Id::kInfo), value());
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
} // namespace webm
|
|
43
|
+
|
|
44
|
+
#endif // SRC_INFO_PARSER_H_
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// Copyright (c) 2016 The WebM project authors. All Rights Reserved.
|
|
2
|
+
//
|
|
3
|
+
// Use of this source code is governed by a BSD-style license
|
|
4
|
+
// that can be found in the LICENSE file in the root of the source
|
|
5
|
+
// tree. An additional intellectual property rights grant can be found
|
|
6
|
+
// in the file PATENTS. All contributing project authors may
|
|
7
|
+
// be found in the AUTHORS file in the root of the source tree.
|
|
8
|
+
#ifndef SRC_INT_PARSER_H_
|
|
9
|
+
#define SRC_INT_PARSER_H_
|
|
10
|
+
|
|
11
|
+
#include <cassert>
|
|
12
|
+
#include <cstdint>
|
|
13
|
+
#include <limits>
|
|
14
|
+
#include <type_traits>
|
|
15
|
+
|
|
16
|
+
#include "src/element_parser.h"
|
|
17
|
+
#include "src/parser_utils.h"
|
|
18
|
+
#include "webm/callback.h"
|
|
19
|
+
#include "webm/element.h"
|
|
20
|
+
#include "webm/reader.h"
|
|
21
|
+
#include "webm/status.h"
|
|
22
|
+
|
|
23
|
+
namespace webm {
|
|
24
|
+
|
|
25
|
+
// Parses an EBML signed/unsigned int from a byte stream.
|
|
26
|
+
// Spec reference:
|
|
27
|
+
// http://matroska.org/technical/specs/index.html#EBML_ex
|
|
28
|
+
// https://github.com/Matroska-Org/ebml-specification/blob/master/specification.markdown#element-data-size
|
|
29
|
+
// https://github.com/Matroska-Org/ebml-specification/blob/master/specification.markdown#ebml-element-types
|
|
30
|
+
template <typename T>
|
|
31
|
+
class IntParser : public ElementParser {
|
|
32
|
+
public:
|
|
33
|
+
static_assert(
|
|
34
|
+
std::is_same<T, std::int64_t>::value ||
|
|
35
|
+
std::is_same<T, std::uint64_t>::value ||
|
|
36
|
+
(std::is_enum<T>::value && sizeof(T) == 8),
|
|
37
|
+
"T must be either std::int64_t, std::uint64_t, or a 64-bit enum");
|
|
38
|
+
|
|
39
|
+
// Constructs a new parser which will use the given default_value as the
|
|
40
|
+
// value for the element if its size is zero. Defaults to the value zero (as
|
|
41
|
+
// the EBML spec indicates).
|
|
42
|
+
explicit IntParser(T default_value = {}) : default_value_(default_value) {}
|
|
43
|
+
|
|
44
|
+
IntParser(IntParser&&) = default;
|
|
45
|
+
IntParser& operator=(IntParser&&) = default;
|
|
46
|
+
|
|
47
|
+
IntParser(const IntParser&) = delete;
|
|
48
|
+
IntParser& operator=(const IntParser&) = delete;
|
|
49
|
+
|
|
50
|
+
Status Init(const ElementMetadata& metadata,
|
|
51
|
+
std::uint64_t max_size) override {
|
|
52
|
+
assert(metadata.size == kUnknownElementSize || metadata.size <= max_size);
|
|
53
|
+
|
|
54
|
+
// Matroska requires integers to be 0-8 bytes in size.
|
|
55
|
+
if (metadata.size > 8) {
|
|
56
|
+
return Status(Status::kInvalidElementSize);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
size_ = num_bytes_remaining_ = static_cast<int>(metadata.size);
|
|
60
|
+
|
|
61
|
+
if (metadata.size == 0) {
|
|
62
|
+
value_ = default_value_;
|
|
63
|
+
} else {
|
|
64
|
+
value_ = {};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return Status(Status::kOkCompleted);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
Status Feed(Callback* callback, Reader* reader,
|
|
71
|
+
std::uint64_t* num_bytes_read) override {
|
|
72
|
+
assert(callback != nullptr);
|
|
73
|
+
assert(reader != nullptr);
|
|
74
|
+
assert(num_bytes_read != nullptr);
|
|
75
|
+
|
|
76
|
+
const Status status = AccumulateIntegerBytes(num_bytes_remaining_, reader,
|
|
77
|
+
&value_, num_bytes_read);
|
|
78
|
+
num_bytes_remaining_ -= static_cast<int>(*num_bytes_read);
|
|
79
|
+
|
|
80
|
+
// Sign extend the integer if it's a negative value. EBML allows for
|
|
81
|
+
// negative integers to drop superfluous sign bytes (i.e. -1 can be encoded
|
|
82
|
+
// as 0xFF instead of 0xFFFFFFFFFFFFFFFF).
|
|
83
|
+
if (std::is_signed<T>::value && num_bytes_remaining_ == 0 && size_ > 0) {
|
|
84
|
+
std::uint64_t sign_bits = std::numeric_limits<std::uint64_t>::max()
|
|
85
|
+
<< (8 * size_ - 1);
|
|
86
|
+
std::uint64_t unsigned_value = static_cast<std::uint64_t>(value_);
|
|
87
|
+
if (unsigned_value & sign_bits) {
|
|
88
|
+
value_ = static_cast<T>(unsigned_value | sign_bits);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return status;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Gets the parsed int. This must not be called until the parse had been
|
|
96
|
+
// successfully completed.
|
|
97
|
+
T value() const {
|
|
98
|
+
assert(num_bytes_remaining_ == 0);
|
|
99
|
+
return value_;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Gets the parsed int. This must not be called until the parse had been
|
|
103
|
+
// successfully completed.
|
|
104
|
+
T* mutable_value() {
|
|
105
|
+
assert(num_bytes_remaining_ == 0);
|
|
106
|
+
return &value_;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
private:
|
|
110
|
+
T value_;
|
|
111
|
+
T default_value_;
|
|
112
|
+
int num_bytes_remaining_ = -1;
|
|
113
|
+
int size_;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
using SignedIntParser = IntParser<std::int64_t>;
|
|
117
|
+
using UnsignedIntParser = IntParser<std::uint64_t>;
|
|
118
|
+
|
|
119
|
+
} // namespace webm
|
|
120
|
+
|
|
121
|
+
#endif // SRC_INT_PARSER_H_
|