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.
Files changed (283) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +903 -2
  3. package/THIRD_PARTY_NOTICES.md +30 -0
  4. package/android/av1/build.gradle +67 -0
  5. package/android/av1/consumer-rules.pro +4 -0
  6. package/android/av1/src/main/cpp/Av1Codec_jni.cpp +8 -0
  7. package/android/av1/src/main/cpp/CMakeLists.txt +34 -0
  8. package/android/av1/src/main/java/dev/mediacache/alphavideo/av1/Av1Codec.java +21 -0
  9. package/android/build.gradle +85 -0
  10. package/android/consumer-rules.pro +2 -0
  11. package/android/gradle.properties +1 -0
  12. package/android/publish.gradle +82 -0
  13. package/android/settings.gradle +5 -0
  14. package/android/src/main/AndroidManifest.xml +1 -0
  15. package/android/src/main/cpp/CMakeLists.txt +59 -0
  16. package/android/src/main/java/dev/mediacache/alphavideo/AlphaVideoCodecs.java +73 -0
  17. package/android/src/main/java/dev/mediacache/alphavideo/AlphaVideoView.java +1966 -0
  18. package/android/src/main/java/dev/mediacache/alphavideo/BufferedDualStreamPlayer.java +978 -0
  19. package/android/src/main/java/dev/mediacache/alphavideo/Fetcher.java +37 -0
  20. package/android/src/main/java/dev/mediacache/alphavideo/HttpFetcher.java +156 -0
  21. package/android/src/main/java/dev/mediacache/alphavideo/MediaCodecColor.java +47 -0
  22. package/android/src/main/java/dev/mediacache/alphavideo/MediaCodecDecoders.java +135 -0
  23. package/android/src/main/java/dev/mediacache/alphavideo/RangeSourceLink.java +54 -0
  24. package/android/src/main/java/dev/mediacache/alphavideo/SourceReader.java +174 -0
  25. package/android/src/main/java/dev/mediacache/alphavideo/SurfaceTextureVideoDecoder.java +802 -0
  26. package/android/src/main/java/dev/mediacache/alphavideo/WebMAlphaPlayerNative.java +95 -0
  27. package/android/src/main/java/dev/mediacache/alphavideo/WebMFrame.java +54 -0
  28. package/android/src/main/java/dev/mediacache/alphavideo/WebMSource.java +160 -0
  29. package/android/src/rangesource/java/dev/mediacache/alphavideo/AppDataSource.java +50 -0
  30. package/android/vpx/build.gradle +67 -0
  31. package/android/vpx/consumer-rules.pro +4 -0
  32. package/android/vpx/src/main/cpp/CMakeLists.txt +34 -0
  33. package/android/vpx/src/main/cpp/VpxCodec_jni.cpp +8 -0
  34. package/android/vpx/src/main/java/dev/mediacache/alphavideo/vpx/VpxCodec.java +21 -0
  35. package/codecs/av1/Dav1dDecoderPlugin.cpp +157 -0
  36. package/codecs/av1/Dav1dDecoderPlugin.h +17 -0
  37. package/codecs/vpx/VpxDecoderPlugin.cpp +103 -0
  38. package/codecs/vpx/VpxDecoderPlugin.h +17 -0
  39. package/cpp/AlphaDemuxer.cpp +984 -0
  40. package/cpp/AlphaDemuxer.h +123 -0
  41. package/cpp/AlphaVideoDecoderPlugin.h +84 -0
  42. package/cpp/Av1SequenceHeader.cpp +175 -0
  43. package/cpp/Av1SequenceHeader.h +25 -0
  44. package/cpp/ByteSource.cpp +116 -0
  45. package/cpp/ByteSource.h +59 -0
  46. package/cpp/RangeSourceClient.h +40 -0
  47. package/cpp/VideoDecoder.cpp +157 -0
  48. package/cpp/VideoDecoder.h +83 -0
  49. package/cpp/WebMAlphaPlayer.cpp +1666 -0
  50. package/cpp/WebMAlphaPlayer.h +389 -0
  51. package/cpp/WebMAlphaPlayer_jni.cpp +1380 -0
  52. package/cpp/YuvToRgb.cpp +39 -0
  53. package/cpp/YuvToRgb.h +40 -0
  54. package/ios/Sources/AlphaVideo/AlphaVideoCodecs.mm +63 -0
  55. package/ios/Sources/AlphaVideo/AlphaVideoInternal.h +70 -0
  56. package/ios/Sources/AlphaVideo/AlphaVideoPlayer.mm +994 -0
  57. package/ios/Sources/AlphaVideo/AlphaVideoSource.mm +476 -0
  58. package/ios/Sources/AlphaVideo/AlphaVideoView.mm +374 -0
  59. package/ios/Sources/AlphaVideo/include/AlphaVideo.h +303 -0
  60. package/ios/Sources/AlphaVideoAV1/AlphaVideoAV1Codec.mm +16 -0
  61. package/ios/Sources/AlphaVideoAV1/include/AlphaVideoAV1.h +18 -0
  62. package/ios/Sources/AlphaVideoVPX/AlphaVideoVPXCodec.mm +16 -0
  63. package/ios/Sources/AlphaVideoVPX/include/AlphaVideoVPX.h +17 -0
  64. package/lib/commonjs/AlphaVideoView.js +187 -0
  65. package/lib/commonjs/AlphaVideoView.js.map +1 -0
  66. package/lib/commonjs/AlphaVideoViewNativeComponent.js +47 -0
  67. package/lib/commonjs/AlphaVideoViewNativeComponent.js.map +1 -0
  68. package/lib/commonjs/AlphaVideoViewNativeComponent.web.js +11 -0
  69. package/lib/commonjs/AlphaVideoViewNativeComponent.web.js.map +1 -0
  70. package/lib/commonjs/NativeAlphaVideoModule.js +10 -0
  71. package/lib/commonjs/NativeAlphaVideoModule.js.map +1 -0
  72. package/lib/commonjs/NativeAlphaVideoModule.web.js +9 -0
  73. package/lib/commonjs/NativeAlphaVideoModule.web.js.map +1 -0
  74. package/lib/commonjs/WebPlayer.js +12 -0
  75. package/lib/commonjs/WebPlayer.js.map +1 -0
  76. package/lib/commonjs/WebPlayer.web.js +92 -0
  77. package/lib/commonjs/WebPlayer.web.js.map +1 -0
  78. package/lib/commonjs/index.js +124 -0
  79. package/lib/commonjs/index.js.map +1 -0
  80. package/lib/module/AlphaVideoView.js +187 -0
  81. package/lib/module/AlphaVideoView.js.map +1 -0
  82. package/lib/module/AlphaVideoViewNativeComponent.js +47 -0
  83. package/lib/module/AlphaVideoViewNativeComponent.js.map +1 -0
  84. package/lib/module/AlphaVideoViewNativeComponent.web.js +11 -0
  85. package/lib/module/AlphaVideoViewNativeComponent.web.js.map +1 -0
  86. package/lib/module/NativeAlphaVideoModule.js +10 -0
  87. package/lib/module/NativeAlphaVideoModule.js.map +1 -0
  88. package/lib/module/NativeAlphaVideoModule.web.js +9 -0
  89. package/lib/module/NativeAlphaVideoModule.web.js.map +1 -0
  90. package/lib/module/WebPlayer.js +12 -0
  91. package/lib/module/WebPlayer.js.map +1 -0
  92. package/lib/module/WebPlayer.web.js +92 -0
  93. package/lib/module/WebPlayer.web.js.map +1 -0
  94. package/lib/module/index.js +124 -0
  95. package/lib/module/index.js.map +1 -0
  96. package/lib/typescript/react-native/src/AlphaVideoView.d.ts +189 -0
  97. package/lib/typescript/react-native/src/AlphaVideoView.d.ts.map +1 -0
  98. package/lib/typescript/react-native/src/AlphaVideoViewNativeComponent.d.ts +109 -0
  99. package/lib/typescript/react-native/src/AlphaVideoViewNativeComponent.d.ts.map +1 -0
  100. package/lib/typescript/react-native/src/AlphaVideoViewNativeComponent.web.d.ts +5 -0
  101. package/lib/typescript/react-native/src/AlphaVideoViewNativeComponent.web.d.ts.map +1 -0
  102. package/lib/typescript/react-native/src/NativeAlphaVideoModule.d.ts +21 -0
  103. package/lib/typescript/react-native/src/NativeAlphaVideoModule.d.ts.map +1 -0
  104. package/lib/typescript/react-native/src/NativeAlphaVideoModule.web.d.ts +3 -0
  105. package/lib/typescript/react-native/src/NativeAlphaVideoModule.web.d.ts.map +1 -0
  106. package/lib/typescript/react-native/src/WebPlayer.d.ts +3 -0
  107. package/lib/typescript/react-native/src/WebPlayer.d.ts.map +1 -0
  108. package/lib/typescript/react-native/src/WebPlayer.web.d.ts +9 -0
  109. package/lib/typescript/react-native/src/WebPlayer.web.d.ts.map +1 -0
  110. package/lib/typescript/react-native/src/index.d.ts +77 -0
  111. package/lib/typescript/react-native/src/index.d.ts.map +1 -0
  112. package/licenses/dav1d-COPYING.txt +23 -0
  113. package/licenses/libvpx-LICENSE.txt +31 -0
  114. package/licenses/libvpx-PATENTS.txt +23 -0
  115. package/licenses/libwebm-LICENSE.txt +30 -0
  116. package/licenses/libwebm-PATENTS.txt +23 -0
  117. package/package.json +150 -4
  118. package/prebuilt/android/arm64-v8a/lib/libdav1d.a +0 -0
  119. package/prebuilt/android/arm64-v8a/lib/libvpx.a +0 -0
  120. package/prebuilt/android/armeabi-v7a/lib/libdav1d.a +0 -0
  121. package/prebuilt/android/armeabi-v7a/lib/libvpx.a +0 -0
  122. package/prebuilt/android/x86_64/lib/libdav1d.a +0 -0
  123. package/prebuilt/android/x86_64/lib/libvpx.a +0 -0
  124. package/prebuilt/include/dav1d/common.h +94 -0
  125. package/prebuilt/include/dav1d/data.h +117 -0
  126. package/prebuilt/include/dav1d/dav1d.h +329 -0
  127. package/prebuilt/include/dav1d/headers.h +440 -0
  128. package/prebuilt/include/dav1d/picture.h +157 -0
  129. package/prebuilt/include/dav1d/version.h +50 -0
  130. package/prebuilt/include/vpx/vp8.h +136 -0
  131. package/prebuilt/include/vpx/vp8dx.h +228 -0
  132. package/prebuilt/include/vpx/vpx_codec.h +475 -0
  133. package/prebuilt/include/vpx/vpx_decoder.h +365 -0
  134. package/prebuilt/include/vpx/vpx_frame_buffer.h +83 -0
  135. package/prebuilt/include/vpx/vpx_image.h +209 -0
  136. package/prebuilt/include/vpx/vpx_integer.h +40 -0
  137. package/prebuilt/ios/lib/libdav1d.a +0 -0
  138. package/prebuilt/ios/lib/libvpx.a +0 -0
  139. package/prebuilt/ios-simulator/include/dav1d/common.h +94 -0
  140. package/prebuilt/ios-simulator/include/dav1d/data.h +117 -0
  141. package/prebuilt/ios-simulator/include/dav1d/dav1d.h +329 -0
  142. package/prebuilt/ios-simulator/include/dav1d/headers.h +440 -0
  143. package/prebuilt/ios-simulator/include/dav1d/picture.h +157 -0
  144. package/prebuilt/ios-simulator/include/dav1d/version.h +50 -0
  145. package/prebuilt/ios-simulator/include/vpx/vp8.h +136 -0
  146. package/prebuilt/ios-simulator/include/vpx/vp8dx.h +228 -0
  147. package/prebuilt/ios-simulator/include/vpx/vpx_codec.h +475 -0
  148. package/prebuilt/ios-simulator/include/vpx/vpx_decoder.h +365 -0
  149. package/prebuilt/ios-simulator/include/vpx/vpx_frame_buffer.h +83 -0
  150. package/prebuilt/ios-simulator/include/vpx/vpx_image.h +209 -0
  151. package/prebuilt/ios-simulator/include/vpx/vpx_integer.h +40 -0
  152. package/prebuilt/ios-simulator/lib/libdav1d.a +0 -0
  153. package/prebuilt/ios-simulator/lib/libvpx.a +0 -0
  154. package/react-native/android/CMakeLists.txt +14 -0
  155. package/react-native/android/build.gradle +110 -0
  156. package/react-native/android/src/main/AndroidManifest.xml +1 -0
  157. package/react-native/android/src/main/java/dev/mediacache/alphavideo/reactnative/AlphaVideoModule.java +102 -0
  158. package/react-native/android/src/main/java/dev/mediacache/alphavideo/reactnative/AlphaVideoPackage.java +50 -0
  159. package/react-native/android/src/main/java/dev/mediacache/alphavideo/reactnative/AlphaVideoViewManager.java +317 -0
  160. package/react-native/android/src/newarch/java/dev/mediacache/alphavideo/reactnative/AlphaVideoModuleSpec.java +10 -0
  161. package/react-native/android/src/newarch/java/dev/mediacache/alphavideo/reactnative/AlphaVideoViewManagerSpec.java +23 -0
  162. package/react-native/android/src/norangesource/java/dev/mediacache/alphavideo/AppDataSource.java +15 -0
  163. package/react-native/android/src/oldarch/java/dev/mediacache/alphavideo/reactnative/AlphaVideoModuleSpec.java +30 -0
  164. package/react-native/android/src/oldarch/java/dev/mediacache/alphavideo/reactnative/AlphaVideoViewManagerSpec.java +61 -0
  165. package/react-native/ios/RNAlphaVideoViewComponentView.mm +173 -0
  166. package/react-native/ios/RNAlphaVideoViewManager.mm +147 -0
  167. package/react-native/src/AlphaVideoView.tsx +329 -0
  168. package/react-native/src/AlphaVideoViewNativeComponent.ts +132 -0
  169. package/react-native/src/AlphaVideoViewNativeComponent.web.ts +5 -0
  170. package/react-native/src/NativeAlphaVideoModule.ts +22 -0
  171. package/react-native/src/NativeAlphaVideoModule.web.ts +2 -0
  172. package/react-native/src/WebPlayer.tsx +7 -0
  173. package/react-native/src/WebPlayer.web.tsx +60 -0
  174. package/react-native/src/index.tsx +144 -0
  175. package/react-native-alpha-video.podspec +99 -0
  176. package/react-native.config.js +12 -0
  177. package/scripts/build_codecs_android.sh +246 -0
  178. package/scripts/build_codecs_ios.sh +31 -0
  179. package/scripts/build_codecs_ios_device.sh +210 -0
  180. package/scripts/build_codecs_ios_simulator.sh +256 -0
  181. package/scripts/build_wasm.sh +230 -0
  182. package/scripts/build_xcframework.sh +49 -0
  183. package/scripts/fetch-prebuilt.sh +48 -0
  184. package/scripts/package_release.sh +107 -0
  185. package/scripts/publish-android.sh +85 -0
  186. package/scripts/vendor_range_source.sh +47 -0
  187. package/third_party/libwebm/AUTHORS.TXT +5 -0
  188. package/third_party/libwebm/LICENSE.TXT +30 -0
  189. package/third_party/libwebm/PATENTS.TXT +23 -0
  190. package/third_party/libwebm/README.md +7 -0
  191. package/third_party/libwebm/webm_parser/include/webm/buffer_reader.h +138 -0
  192. package/third_party/libwebm/webm_parser/include/webm/callback.h +363 -0
  193. package/third_party/libwebm/webm_parser/include/webm/dom_types.h +1781 -0
  194. package/third_party/libwebm/webm_parser/include/webm/element.h +208 -0
  195. package/third_party/libwebm/webm_parser/include/webm/file_reader.h +103 -0
  196. package/third_party/libwebm/webm_parser/include/webm/id.h +1085 -0
  197. package/third_party/libwebm/webm_parser/include/webm/istream_reader.h +99 -0
  198. package/third_party/libwebm/webm_parser/include/webm/reader.h +94 -0
  199. package/third_party/libwebm/webm_parser/include/webm/status.h +166 -0
  200. package/third_party/libwebm/webm_parser/include/webm/webm_parser.h +133 -0
  201. package/third_party/libwebm/webm_parser/src/ancestory.cc +334 -0
  202. package/third_party/libwebm/webm_parser/src/ancestory.h +83 -0
  203. package/third_party/libwebm/webm_parser/src/audio_parser.h +84 -0
  204. package/third_party/libwebm/webm_parser/src/bit_utils.cc +26 -0
  205. package/third_party/libwebm/webm_parser/src/bit_utils.h +24 -0
  206. package/third_party/libwebm/webm_parser/src/block_additions_parser.h +30 -0
  207. package/third_party/libwebm/webm_parser/src/block_group_parser.h +71 -0
  208. package/third_party/libwebm/webm_parser/src/block_header_parser.cc +76 -0
  209. package/third_party/libwebm/webm_parser/src/block_header_parser.h +65 -0
  210. package/third_party/libwebm/webm_parser/src/block_more_parser.h +32 -0
  211. package/third_party/libwebm/webm_parser/src/block_parser.cc +285 -0
  212. package/third_party/libwebm/webm_parser/src/block_parser.h +126 -0
  213. package/third_party/libwebm/webm_parser/src/bool_parser.h +95 -0
  214. package/third_party/libwebm/webm_parser/src/buffer_reader.cc +110 -0
  215. package/third_party/libwebm/webm_parser/src/byte_parser.h +144 -0
  216. package/third_party/libwebm/webm_parser/src/callback.cc +155 -0
  217. package/third_party/libwebm/webm_parser/src/chapter_atom_parser.h +42 -0
  218. package/third_party/libwebm/webm_parser/src/chapter_display_parser.h +34 -0
  219. package/third_party/libwebm/webm_parser/src/chapters_parser.h +28 -0
  220. package/third_party/libwebm/webm_parser/src/cluster_parser.h +48 -0
  221. package/third_party/libwebm/webm_parser/src/colour_parser.h +55 -0
  222. package/third_party/libwebm/webm_parser/src/content_enc_aes_settings_parser.h +32 -0
  223. package/third_party/libwebm/webm_parser/src/content_encoding_parser.h +38 -0
  224. package/third_party/libwebm/webm_parser/src/content_encodings_parser.h +30 -0
  225. package/third_party/libwebm/webm_parser/src/content_encryption_parser.h +37 -0
  226. package/third_party/libwebm/webm_parser/src/cue_point_parser.h +38 -0
  227. package/third_party/libwebm/webm_parser/src/cue_track_positions_parser.h +39 -0
  228. package/third_party/libwebm/webm_parser/src/cues_parser.h +27 -0
  229. package/third_party/libwebm/webm_parser/src/date_parser.cc +72 -0
  230. package/third_party/libwebm/webm_parser/src/date_parser.h +64 -0
  231. package/third_party/libwebm/webm_parser/src/ebml_parser.h +48 -0
  232. package/third_party/libwebm/webm_parser/src/edition_entry_parser.h +35 -0
  233. package/third_party/libwebm/webm_parser/src/element_parser.h +102 -0
  234. package/third_party/libwebm/webm_parser/src/file_reader.cc +142 -0
  235. package/third_party/libwebm/webm_parser/src/float_parser.cc +77 -0
  236. package/third_party/libwebm/webm_parser/src/float_parser.h +65 -0
  237. package/third_party/libwebm/webm_parser/src/id_element_parser.cc +49 -0
  238. package/third_party/libwebm/webm_parser/src/id_element_parser.h +56 -0
  239. package/third_party/libwebm/webm_parser/src/id_parser.cc +75 -0
  240. package/third_party/libwebm/webm_parser/src/id_parser.h +45 -0
  241. package/third_party/libwebm/webm_parser/src/info_parser.h +44 -0
  242. package/third_party/libwebm/webm_parser/src/int_parser.h +121 -0
  243. package/third_party/libwebm/webm_parser/src/istream_reader.cc +133 -0
  244. package/third_party/libwebm/webm_parser/src/master_parser.cc +298 -0
  245. package/third_party/libwebm/webm_parser/src/master_parser.h +230 -0
  246. package/third_party/libwebm/webm_parser/src/master_value_parser.h +533 -0
  247. package/third_party/libwebm/webm_parser/src/mastering_metadata_parser.h +57 -0
  248. package/third_party/libwebm/webm_parser/src/parser.h +34 -0
  249. package/third_party/libwebm/webm_parser/src/parser_utils.cc +34 -0
  250. package/third_party/libwebm/webm_parser/src/parser_utils.h +64 -0
  251. package/third_party/libwebm/webm_parser/src/projection_parser.h +40 -0
  252. package/third_party/libwebm/webm_parser/src/recursive_parser.h +93 -0
  253. package/third_party/libwebm/webm_parser/src/seek_head_parser.h +27 -0
  254. package/third_party/libwebm/webm_parser/src/seek_parser.h +37 -0
  255. package/third_party/libwebm/webm_parser/src/segment_parser.cc +86 -0
  256. package/third_party/libwebm/webm_parser/src/segment_parser.h +53 -0
  257. package/third_party/libwebm/webm_parser/src/simple_tag_parser.h +37 -0
  258. package/third_party/libwebm/webm_parser/src/size_parser.cc +56 -0
  259. package/third_party/libwebm/webm_parser/src/size_parser.h +43 -0
  260. package/third_party/libwebm/webm_parser/src/skip_callback.h +63 -0
  261. package/third_party/libwebm/webm_parser/src/skip_parser.cc +59 -0
  262. package/third_party/libwebm/webm_parser/src/skip_parser.h +35 -0
  263. package/third_party/libwebm/webm_parser/src/slices_parser.h +30 -0
  264. package/third_party/libwebm/webm_parser/src/tag_parser.h +37 -0
  265. package/third_party/libwebm/webm_parser/src/tags_parser.h +27 -0
  266. package/third_party/libwebm/webm_parser/src/targets_parser.h +35 -0
  267. package/third_party/libwebm/webm_parser/src/time_slice_parser.h +30 -0
  268. package/third_party/libwebm/webm_parser/src/track_entry_parser.h +65 -0
  269. package/third_party/libwebm/webm_parser/src/tracks_parser.h +27 -0
  270. package/third_party/libwebm/webm_parser/src/unknown_parser.cc +49 -0
  271. package/third_party/libwebm/webm_parser/src/unknown_parser.h +38 -0
  272. package/third_party/libwebm/webm_parser/src/var_int_parser.cc +71 -0
  273. package/third_party/libwebm/webm_parser/src/var_int_parser.h +56 -0
  274. package/third_party/libwebm/webm_parser/src/video_parser.h +122 -0
  275. package/third_party/libwebm/webm_parser/src/virtual_block_parser.cc +72 -0
  276. package/third_party/libwebm/webm_parser/src/virtual_block_parser.h +69 -0
  277. package/third_party/libwebm/webm_parser/src/void_parser.cc +49 -0
  278. package/third_party/libwebm/webm_parser/src/void_parser.h +41 -0
  279. package/third_party/libwebm/webm_parser/src/webm_parser.cc +282 -0
  280. package/third_party/range-source/LICENSE +21 -0
  281. package/third_party/range-source/README.md +8 -0
  282. package/third_party/range-source/include/range_source.h +395 -0
  283. package/third_party/range-source/include/range_source_download.h +309 -0
@@ -0,0 +1,99 @@
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 INCLUDE_WEBM_ISTREAM_READER_H_
9
+ #define INCLUDE_WEBM_ISTREAM_READER_H_
10
+
11
+ #include <cstdint>
12
+ #include <cstdlib>
13
+ #include <istream>
14
+ #include <memory>
15
+ #include <type_traits>
16
+
17
+ #include "./reader.h"
18
+ #include "./status.h"
19
+
20
+ /**
21
+ \file
22
+ A `Reader` implementation that reads from a `std::istream`.
23
+ */
24
+
25
+ namespace webm {
26
+
27
+ /**
28
+ A `Reader` implementation that can read from `std::istream`-based resources.
29
+ */
30
+ class IstreamReader : public Reader {
31
+ public:
32
+ /**
33
+ Constructs a new, empty reader.
34
+ */
35
+ IstreamReader() = default;
36
+
37
+ /**
38
+ Constructs a new reader, using the provided `std::istream` as the data
39
+ source.
40
+
41
+ Ownership of the stream is taken, and it will be moved into a new internal
42
+ instance.
43
+
44
+ \param istream The stream to use as a data source. Must be an rvalue
45
+ reference derived from `std::istream`.
46
+ */
47
+ template <typename T>
48
+ explicit IstreamReader(T&& istream) : istream_(new T(std::move(istream))) {}
49
+
50
+ /**
51
+ Constructs a new reader by moving the provided reader into the new reader.
52
+
53
+ \param other The source reader to move. After moving, it will be reset to an
54
+ empty stream.
55
+ */
56
+ IstreamReader(IstreamReader&& other);
57
+
58
+ /**
59
+ Moves the provided reader into this reader.
60
+
61
+ \param other The source reader to move. After moving, it will be reset to an
62
+ empty stream. May be equal to `*this`, in which case this is a no-op.
63
+ \return `*this`.
64
+ */
65
+ IstreamReader& operator=(IstreamReader&& other);
66
+
67
+ Status Read(std::size_t num_to_read, std::uint8_t* buffer,
68
+ std::uint64_t* num_actually_read) override;
69
+
70
+ Status Skip(std::uint64_t num_to_skip,
71
+ std::uint64_t* num_actually_skipped) override;
72
+
73
+ std::uint64_t Position() const override;
74
+
75
+ /**
76
+ Constructs a new reader and its data source in place.
77
+
78
+ `T` must be derived from `std::istream` and constructible from the provided
79
+ arguments.
80
+
81
+ \param args Arguments that will be forwarded to the `T`'s constructor.
82
+ \return A new `IstreamReader` backed by the underlying data source equivalent
83
+ to `T(std::forward<Args>(args)...`.
84
+ */
85
+ template <typename T, typename... Args>
86
+ static IstreamReader Emplace(Args&&... args) {
87
+ IstreamReader reader;
88
+ reader.istream_.reset(new T(std::forward<Args>(args)...));
89
+ return reader;
90
+ }
91
+
92
+ private:
93
+ std::unique_ptr<std::istream> istream_;
94
+ std::uint64_t position_ = 0;
95
+ };
96
+
97
+ } // namespace webm
98
+
99
+ #endif // INCLUDE_WEBM_ISTREAM_READER_H_
@@ -0,0 +1,94 @@
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 INCLUDE_WEBM_READER_H_
9
+ #define INCLUDE_WEBM_READER_H_
10
+
11
+ #include <cstddef>
12
+ #include <cstdint>
13
+
14
+ #include "./status.h"
15
+
16
+ /**
17
+ \file
18
+ An interface that acts as a data source for the parser to read from.
19
+ */
20
+
21
+ namespace webm {
22
+
23
+ /**
24
+ \addtogroup PUBLIC_API
25
+ @{
26
+ */
27
+
28
+ /**
29
+ A generic interface for reading from a data source.
30
+
31
+ Throwing an exception from the member functions is permitted, though if the
32
+ exception will be caught and parsing resumed, then the reader should not
33
+ advance its position before throwing the exception.
34
+ */
35
+ class Reader {
36
+ public:
37
+ virtual ~Reader() = default;
38
+
39
+ /**
40
+ Reads data from the source and advances the reader's position by the number
41
+ of bytes read.
42
+
43
+ Short reads are permitted, as is reading no data.
44
+
45
+ \param num_to_read The number of bytes that should be read. Must not be 0.
46
+ \param buffer The buffer to store the read bytes. Must be large enough to
47
+ store at least `num_to_read` bytes. Must not be null.
48
+ \param[out] num_actually_read The number of bytes that were actually read is
49
+ stored in this integer. Must not be null.
50
+ \return `Status::kOkCompleted` if `num_to_read` bytes were read.
51
+ `Status::kOkPartial` if the number of bytes read is > 0 and < `num_to_read`.
52
+ If no bytes are read, then some status other than `Status::kOkCompleted` and
53
+ `Status::kOkPartial` must be returned and `num_actually_read` must be set to
54
+ 0.
55
+ */
56
+ virtual Status Read(std::size_t num_to_read, std::uint8_t* buffer,
57
+ std::uint64_t* num_actually_read) = 0;
58
+
59
+ /**
60
+ Skips data from the source and advances the reader's position by the number
61
+ of bytes skipped.
62
+
63
+ Short skips are permitted, as is skipping no data. This is similar to the
64
+ `Read()` method, but does not store data in an output buffer.
65
+
66
+ \param num_to_skip The number of bytes that should be skipped. Must not be 0.
67
+ \param[out] num_actually_skipped The number of bytes that were actually
68
+ skipped is stored in this integer. Must not be null.
69
+ \return `Status::kOkCompleted` if `num_to_skip` bytes were skipped.
70
+ `Status::kOkPartial` if the number of bytes skipped is > 0 and <
71
+ `num_to_skip`. If no bytes are skipped, then some status other than
72
+ `Status::kOkCompleted` and `Status::kOkPartial` must be returned and
73
+ `num_actually_skipped` must be set to 0.
74
+ */
75
+ virtual Status Skip(std::uint64_t num_to_skip,
76
+ std::uint64_t* num_actually_skipped) = 0;
77
+
78
+ /**
79
+ Gets the Reader's current absolute byte position in the stream.
80
+
81
+ Implementations don't necessarily need to start from 0 (which might be the
82
+ case if parsing is starting in the middle of a data source). The value
83
+ `kUnknownElementPosition` must not be returned.
84
+ */
85
+ virtual std::uint64_t Position() const = 0;
86
+ };
87
+
88
+ /**
89
+ @}
90
+ */
91
+
92
+ } // namespace webm
93
+
94
+ #endif // INCLUDE_WEBM_READER_H_
@@ -0,0 +1,166 @@
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 INCLUDE_WEBM_STATUS_H_
9
+ #define INCLUDE_WEBM_STATUS_H_
10
+
11
+ #include <cstdint>
12
+
13
+ /**
14
+ \file
15
+ Status information that represents success, failure, etc. for operations
16
+ throughout the API.
17
+ */
18
+
19
+ namespace webm {
20
+
21
+ /**
22
+ \addtogroup PUBLIC_API
23
+ @{
24
+ */
25
+
26
+ /**
27
+ An object used to represent the resulting status of various operations,
28
+ indicating success, failure, or some other result.
29
+ */
30
+ struct Status {
31
+ /**
32
+ A list of generic status codes used by the parser. Users are encouraged to
33
+ reuse these values as needed in the derivations of `Callback`. These values
34
+ will always be <= 0.
35
+ */
36
+ enum Code : std::int32_t {
37
+ // General status codes. Range: 0 to -1024.
38
+ /**
39
+ The operation successfully completed.
40
+ */
41
+ kOkCompleted = 0,
42
+
43
+ /**
44
+ The operation was successful but only partially completed (for example, a
45
+ read that resulted in fewer bytes than requested).
46
+ */
47
+ kOkPartial = -1,
48
+
49
+ /**
50
+ The operation would block, and should be tried again later.
51
+ */
52
+ kWouldBlock = -2,
53
+
54
+ /**
55
+ More data was requested but the file has ended.
56
+ */
57
+ kEndOfFile = -3,
58
+
59
+ /**
60
+ The reader was unable to seek to the requested location.
61
+ */
62
+ kSeekFailed = -4,
63
+
64
+ // Parsing errors. Range: -1025 to -2048.
65
+ /**
66
+ An element's ID is malformed.
67
+ */
68
+ kInvalidElementId = -1025,
69
+
70
+ /**
71
+ An element's size is malformed.
72
+ */
73
+ kInvalidElementSize = -1026,
74
+
75
+ /**
76
+ An unknown element has unknown size.
77
+ */
78
+ kIndefiniteUnknownElement = -1027,
79
+
80
+ /**
81
+ A child element overflowed the parent element's bounds.
82
+ */
83
+ kElementOverflow = -1028,
84
+
85
+ /**
86
+ An element's size exceeds the system's memory limits.
87
+ */
88
+ kNotEnoughMemory = -1029,
89
+
90
+ /**
91
+ An element's value is illegal/malformed.
92
+ */
93
+ kInvalidElementValue = -1030,
94
+
95
+ /**
96
+ A recursive element was so deeply nested that exceeded the parser's limit.
97
+ */
98
+ kExceededRecursionDepthLimit = -1031,
99
+
100
+ // The following codes are internal-only and should not be used by users.
101
+ // Additionally, these codes should never be returned to the user; doing so
102
+ // is considered a bug.
103
+ /**
104
+ \internal Parsing should switch from reading to skipping elements.
105
+ */
106
+ kSwitchToSkip = INT32_MIN,
107
+ };
108
+
109
+ /**
110
+ Status codes <= 0 are reserved by the parsing library. User error codes
111
+ should be positive (> 0). Users are encouraged to use codes from the `Code`
112
+ enum, but may use a positive error code if some application-specific error is
113
+ encountered.
114
+ */
115
+ std::int32_t code;
116
+
117
+ Status() = default;
118
+ Status(const Status&) = default;
119
+ Status(Status&&) = default;
120
+ Status& operator=(const Status&) = default;
121
+ Status& operator=(Status&&) = default;
122
+
123
+ /**
124
+ Creates a new `Status` object with the given status code.
125
+
126
+ \param code The status code which will be used to set the `code` member.
127
+ */
128
+ constexpr explicit Status(Code code) : code(code) {}
129
+
130
+ /**
131
+ Creates a new `Status` object with the given status code.
132
+
133
+ \param code The status code which will be used to set the `code` member.
134
+ */
135
+ constexpr explicit Status(std::int32_t code) : code(code) {}
136
+
137
+ /**
138
+ Returns true if the status code is either `kOkCompleted` or `kOkPartial`.
139
+ Provided for convenience.
140
+ */
141
+ constexpr bool ok() const {
142
+ return code == kOkCompleted || code == kOkPartial;
143
+ }
144
+
145
+ /**
146
+ Returns true if the status code is `kOkCompleted`. Provided for convenience.
147
+ */
148
+ constexpr bool completed_ok() const { return code == kOkCompleted; }
149
+
150
+ /**
151
+ Returns true if the status is considered a parsing error. Parsing errors
152
+ represent unrecoverable errors due to malformed data. Only status codes in
153
+ the range -2048 to -1025 (inclusive) are considered parsing errors.
154
+ */
155
+ constexpr bool is_parsing_error() const {
156
+ return -2048 <= code && code <= -1025;
157
+ }
158
+ };
159
+
160
+ /**
161
+ @}
162
+ */
163
+
164
+ } // namespace webm
165
+
166
+ #endif // INCLUDE_WEBM_STATUS_H_
@@ -0,0 +1,133 @@
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 INCLUDE_WEBM_WEBM_PARSER_H_
9
+ #define INCLUDE_WEBM_WEBM_PARSER_H_
10
+
11
+ #include <memory>
12
+
13
+ #include "./callback.h"
14
+ #include "./reader.h"
15
+ #include "./status.h"
16
+
17
+ /**
18
+ \file
19
+ The main parser class for parsing WebM files.
20
+ */
21
+
22
+ namespace webm {
23
+
24
+ /**
25
+ \defgroup PUBLIC_API Public API
26
+ Public types and header files intended for use by users.
27
+ */
28
+
29
+ /**
30
+ \addtogroup PUBLIC_API
31
+ @{
32
+ */
33
+
34
+ /**
35
+ Incrementally parses a WebM document encoded in a byte stream.
36
+
37
+ It is expected that the parsing will begin at the start of the WebM
38
+ file/document. Otherwise, the `DidSeek()` method should be used to inform the
39
+ parser that reading may not necessarily begin at the beginning of the document
40
+ and the parser should be prepared to handle data at an arbitrary point in the
41
+ document.
42
+
43
+ WebM files are mostly a subset of Matroska, with a few small modifications.
44
+ Matroska is a format built on top of EBML.
45
+ */
46
+ // Spec references:
47
+ // http://www.webmproject.org/docs/container/
48
+ // https://matroska.org/technical/specs/index.html
49
+ // https://github.com/Matroska-Org/ebml-specification/blob/master/specification.markdown
50
+ class WebmParser {
51
+ public:
52
+ /**
53
+ Constructs the object and prepares it for parsing.
54
+ */
55
+ WebmParser();
56
+
57
+ /*
58
+ Cleans up the parser. No further cleanup is required from the user.
59
+ */
60
+ ~WebmParser();
61
+
62
+ // Non-copyable and non-movable.
63
+ WebmParser(const WebmParser&) = delete;
64
+ WebmParser& operator=(const WebmParser&) = delete;
65
+
66
+ /**
67
+ Resets the parser after a seek was performed on the reader, which prepares
68
+ the parser for starting at an arbitrary point in the stream.
69
+
70
+ The seek must be to the start of an element (that is, it can't be any random
71
+ byte) or parsing will fail.
72
+ */
73
+ void DidSeek();
74
+
75
+ /**
76
+ Feeds data into the parser from the provided reader.
77
+
78
+ If a parsing error code has been returned (which indicates a malformed
79
+ document), calling Feed() again will just result in the same error; parsing
80
+ has already failed at that point and further progress can't be made.
81
+
82
+ \param callback The callback which receives parsing events. No internal
83
+ references are maintained to `callback`, so it may be modified or freed after
84
+ this method returns.
85
+ \param reader The reader the parser will use to request data. No internal
86
+ references are maintained to `reader`, so it may be modified or freed after
87
+ this method returns.
88
+ \return `Status::kOkCompleted` when parsing completes successfully.
89
+ `Status::kOkPartial` or another non-parsing error code (see status.h for
90
+ error codes classified as parsing errors) will be returned if parsing has
91
+ only partially completed, and Feed() should be called again to resume
92
+ parsing.
93
+ */
94
+ Status Feed(Callback* callback, Reader* reader);
95
+
96
+ /**
97
+ Swaps this parser and the provided parser.
98
+
99
+ \param other The parser to swap values/states with. Must not be null.
100
+ */
101
+ void Swap(WebmParser* other);
102
+
103
+ private:
104
+ // This header can only rely on sources in the public API.
105
+ class DocumentParser;
106
+
107
+ // The internal implementation of the parser.
108
+ std::unique_ptr<DocumentParser> parser_;
109
+
110
+ // The status of the parser, used to prevent further progress if an
111
+ // unrecoverable parsing error has already been encountered.
112
+ Status parsing_status_ = Status(Status::kOkPartial);
113
+ };
114
+
115
+ /**
116
+ Swaps the two parsers.
117
+
118
+ This is provided so code can use argument dependent lookup in an idiomatic way
119
+ when swapping (especially since `std::swap` won't work since the parser is
120
+ non-movable).
121
+
122
+ \param left The first parser to swap.
123
+ \param right The second parser to swap.
124
+ */
125
+ void swap(WebmParser& left, WebmParser& right);
126
+
127
+ /**
128
+ @}
129
+ */
130
+
131
+ } // namespace webm
132
+
133
+ #endif // INCLUDE_WEBM_WEBM_PARSER_H_