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,533 @@
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_MASTER_VALUE_PARSER_H_
9
+ #define SRC_MASTER_VALUE_PARSER_H_
10
+
11
+ #include <cassert>
12
+ #include <cstdint>
13
+ #include <functional>
14
+ #include <string>
15
+ #include <type_traits>
16
+ #include <utility>
17
+ #include <vector>
18
+
19
+ #include "src/master_parser.h"
20
+ #include "src/recursive_parser.h"
21
+ #include "src/skip_callback.h"
22
+ #include "webm/callback.h"
23
+ #include "webm/element.h"
24
+ #include "webm/id.h"
25
+ #include "webm/reader.h"
26
+ #include "webm/status.h"
27
+
28
+ namespace webm {
29
+
30
+ // Parses Master elements from an EBML stream, storing child values in a
31
+ // structure of type T. This class differs from MasterParser in that
32
+ // MasterParser does not collect the parsed data into an object that can then be
33
+ // retrieved.
34
+ //
35
+ // For example, consider the following Foo object, which represents a master
36
+ // element that contains two booleans:
37
+ //
38
+ // struct Foo {
39
+ // Element<bool> bar;
40
+ // Element<bool> baz;
41
+ // };
42
+ //
43
+ // A FooParser implemented via MasterParser, like below, could be used to parse
44
+ // the master element and the boolean children, but the boolean values could not
45
+ // be retrieved from the parser.
46
+ //
47
+ // struct FooParser : public MasterParser {
48
+ // FooParser()
49
+ // : MasterParser({Id::kBar, new BoolParser}, // std::pair<*> types
50
+ // {Id::kBaz, new BoolParser}) {} // omitted for brevity.
51
+ // };
52
+ //
53
+ // However, if FooParser is implemented via MasterValueParser<Foo>, then the
54
+ // boolean values will be parsed into a Foo object that can be retrieved from
55
+ // FooParser via its value() and mutable_value() methods.
56
+ //
57
+ // struct FooParser : public MasterValueParser<Foo> {
58
+ // FooParser()
59
+ // : MasterValueParser(MakeChild<BoolParser>(Id::kBar, &Foo::bar),
60
+ // MakeChild<BoolParser>(Id::kBaz, &Foo::baz)) {}
61
+ // };
62
+ template <typename T>
63
+ class MasterValueParser : public ElementParser {
64
+ public:
65
+ Status Init(const ElementMetadata& metadata,
66
+ std::uint64_t max_size) override {
67
+ assert(metadata.size == kUnknownElementSize || metadata.size <= max_size);
68
+
69
+ PreInit();
70
+
71
+ const Status status = master_parser_.Init(metadata, max_size);
72
+ if (!status.completed_ok()) {
73
+ return status;
74
+ }
75
+
76
+ return status;
77
+ }
78
+
79
+ void InitAfterSeek(const Ancestory& child_ancestory,
80
+ const ElementMetadata& child_metadata) override {
81
+ PreInit();
82
+ started_done_ = true;
83
+ master_parser_.InitAfterSeek(child_ancestory, child_metadata);
84
+ }
85
+
86
+ Status Feed(Callback* callback, Reader* reader,
87
+ std::uint64_t* num_bytes_read) override {
88
+ assert(callback != nullptr);
89
+ assert(reader != nullptr);
90
+ assert(num_bytes_read != nullptr);
91
+
92
+ *num_bytes_read = 0;
93
+
94
+ if (!parse_complete_) {
95
+ // TODO(mjbshaw): just call Reader::Skip if element's size is known and
96
+ // action is skip.
97
+ SkipCallback skip_callback;
98
+ if (action_ == Action::kSkip) {
99
+ callback = &skip_callback;
100
+ }
101
+
102
+ Status status = master_parser_.Feed(callback, reader, num_bytes_read);
103
+ // Check if we've artificially injected an error code, and if so, switch
104
+ // into skipping mode.
105
+ if (status.code == Status::kSwitchToSkip) {
106
+ assert(started_done_);
107
+ assert(action_ == Action::kSkip);
108
+ callback = &skip_callback;
109
+ std::uint64_t local_num_bytes_read;
110
+ status = master_parser_.Feed(callback, reader, &local_num_bytes_read);
111
+ *num_bytes_read += local_num_bytes_read;
112
+ }
113
+ if (!status.completed_ok()) {
114
+ return status;
115
+ }
116
+ parse_complete_ = true;
117
+ }
118
+
119
+ if (!started_done_) {
120
+ Status status = OnParseStarted(callback, &action_);
121
+ if (!status.completed_ok()) {
122
+ return status;
123
+ }
124
+ started_done_ = true;
125
+ }
126
+
127
+ if (action_ != Action::kSkip) {
128
+ return OnParseCompleted(callback);
129
+ }
130
+
131
+ return Status(Status::kOkCompleted);
132
+ }
133
+
134
+ bool GetCachedMetadata(ElementMetadata* metadata) override {
135
+ return master_parser_.GetCachedMetadata(metadata);
136
+ }
137
+
138
+ bool WasSkipped() const override { return action_ == Action::kSkip; }
139
+
140
+ const T& value() const { return value_; }
141
+
142
+ T* mutable_value() { return &value_; }
143
+
144
+ protected:
145
+ // Users and subclasses are not meant to use the Tag* classes; they're an
146
+ // internal implementation detail.
147
+ // A tag that will cause the internal ChildParser to use the parsed child as a
148
+ // start event.
149
+ struct TagUseAsStart {};
150
+ // A tag that will cause the internal ChildParser to call OnChildParsed once
151
+ // it has been fully parsed.
152
+ struct TagNotifyOnParseComplete {};
153
+
154
+ // A factory that will create a std::pair<Id, std::unique_ptr<ElementParser>>.
155
+ // Users and subclasses are not meant to use this class directly, as it is an
156
+ // internal implementation detail of this class. Subclasses should use
157
+ // MakeChild instead of using this class directly.
158
+ template <typename Parser, typename Value, typename... Tags>
159
+ class SingleChildFactory {
160
+ public:
161
+ constexpr SingleChildFactory(Id id, Element<Value> T::* member)
162
+ : id_(id), member_(member) {}
163
+
164
+ // Builds a std::pair<Id, std::unique_ptr<ElementParser>>. The parent
165
+ // pointer must be a pointer to the MasterValueParser that is being
166
+ // constructed. The given value pointer must be the pointer to the fully
167
+ // constructed MasterValueParser::value_ object.
168
+ std::pair<Id, std::unique_ptr<ElementParser>> BuildParser(
169
+ MasterValueParser* parent, T* value) {
170
+ assert(parent != nullptr);
171
+ assert(value != nullptr);
172
+
173
+ Element<Value>* child_member = &(value->*member_);
174
+ auto lambda = [child_member](Parser* parser) {
175
+ child_member->Set(std::move(*parser->mutable_value()), true);
176
+ };
177
+ return {id_, MakeChildParser<Parser, Value, Tags...>(
178
+ parent, std::move(lambda), child_member)};
179
+ }
180
+
181
+ // If called, OnParseStarted will be called on the parent element when this
182
+ // particular element is encountered.
183
+ constexpr SingleChildFactory<Parser, Value, TagUseAsStart, Tags...>
184
+ UseAsStartEvent() const {
185
+ return {id_, member_};
186
+ }
187
+
188
+ // If called, OnChildParsed will be called on the parent element when this
189
+ // particular element is fully parsed.
190
+ constexpr SingleChildFactory<Parser, Value, TagNotifyOnParseComplete,
191
+ Tags...>
192
+ NotifyOnParseComplete() const {
193
+ return {id_, member_};
194
+ }
195
+
196
+ private:
197
+ Id id_;
198
+ Element<Value> T::* member_;
199
+ };
200
+
201
+ template <typename Parser, typename Value, typename... Tags>
202
+ class RepeatedChildFactory {
203
+ public:
204
+ constexpr RepeatedChildFactory(Id id,
205
+ std::vector<Element<Value>> T::* member)
206
+ : id_(id), member_(member) {}
207
+
208
+ // Builds a std::pair<Id, std::unique_ptr<ElementParser>>. The parent
209
+ // pointer must be a pointer to the MasterValueParser that is being
210
+ // constructed. The given value pointer must be the pointer to the fully
211
+ // constructed MasterValueParser::value_ object.
212
+ std::pair<Id, std::unique_ptr<ElementParser>> BuildParser(
213
+ MasterValueParser* parent, T* value) {
214
+ assert(parent != nullptr);
215
+ assert(value != nullptr);
216
+
217
+ std::vector<Element<Value>>* child_member = &(value->*member_);
218
+ auto lambda = [child_member](Parser* parser) {
219
+ if (child_member->size() == 1 && !child_member->front().is_present()) {
220
+ child_member->clear();
221
+ }
222
+ child_member->emplace_back(std::move(*parser->mutable_value()), true);
223
+ };
224
+ return {id_, MakeChildParser<Parser, Value, Tags...>(
225
+ parent, std::move(lambda), child_member)};
226
+ }
227
+
228
+ // If called, OnParseStarted will be called on the parent element when this
229
+ // particular element is encountered.
230
+ constexpr RepeatedChildFactory<Parser, Value, TagUseAsStart, Tags...>
231
+ UseAsStartEvent() const {
232
+ return {id_, member_};
233
+ }
234
+
235
+ // If called, OnChildParsed will be called on the parent element when this
236
+ // particular element is fully parsed.
237
+ constexpr RepeatedChildFactory<Parser, Value, TagNotifyOnParseComplete,
238
+ Tags...>
239
+ NotifyOnParseComplete() const {
240
+ return {id_, member_};
241
+ }
242
+
243
+ private:
244
+ Id id_;
245
+ std::vector<Element<Value>> T::* member_;
246
+ };
247
+
248
+ template <typename Parser, typename... Tags>
249
+ class RecursiveChildFactory {
250
+ public:
251
+ constexpr RecursiveChildFactory(Id id, std::vector<Element<T>> T::* member,
252
+ std::size_t max_recursion_depth)
253
+ : id_(id), member_(member), max_recursion_depth_(max_recursion_depth) {}
254
+
255
+ // Builds a std::pair<Id, std::unique_ptr<ElementParser>>. The parent
256
+ // pointer must be a pointer to the MasterValueParser that is being
257
+ // constructed. The given value pointer must be the pointer to the fully
258
+ // constructed MasterValueParser::value_ object.
259
+ std::pair<Id, std::unique_ptr<ElementParser>> BuildParser(
260
+ MasterValueParser* parent, T* value) {
261
+ assert(parent != nullptr);
262
+ assert(value != nullptr);
263
+
264
+ std::vector<Element<T>>* child_member = &(value->*member_);
265
+ auto lambda = [child_member](RecursiveParser<Parser>* parser) {
266
+ if (child_member->size() == 1 && !child_member->front().is_present()) {
267
+ child_member->clear();
268
+ }
269
+ child_member->emplace_back(std::move(*parser->mutable_value()), true);
270
+ };
271
+
272
+ return {id_, std::unique_ptr<ElementParser>(
273
+ new ChildParser<RecursiveParser<Parser>,
274
+ decltype(lambda), Tags...>(
275
+ parent, std::move(lambda), max_recursion_depth_))};
276
+ }
277
+
278
+ // If called, OnParseStarted will be called on the parent element when this
279
+ // particular element is encountered.
280
+ constexpr RecursiveChildFactory<Parser, TagUseAsStart, Tags...>
281
+ UseAsStartEvent() const {
282
+ return {id_, member_, max_recursion_depth_};
283
+ }
284
+
285
+ // If called, OnChildParsed will be called on the parent element when this
286
+ // particular element is fully parsed.
287
+ constexpr RecursiveChildFactory<Parser, TagNotifyOnParseComplete, Tags...>
288
+ NotifyOnParseComplete() const {
289
+ return {id_, member_, max_recursion_depth_};
290
+ }
291
+
292
+ private:
293
+ Id id_;
294
+ std::vector<Element<T>> T::* member_;
295
+ std::size_t max_recursion_depth_;
296
+ };
297
+
298
+ // Constructs a new parser. Each argument must be a *ChildFactory, constructed
299
+ // from the MakeChild method.
300
+ template <typename... Args>
301
+ explicit MasterValueParser(Args&&... args)
302
+ : master_parser_(args.BuildParser(this, &value_)...) {}
303
+
304
+ // Returns a factory that will produce a
305
+ // std::pair<Id, std::unique_ptr<ElementParser>>. When a child element of the
306
+ // given ID is encountered, a parser of type Parser will be used to parse it,
307
+ // and store its value in the member pointer when the parse is complete. The
308
+ // given default value will be used in the event that the child element has a
309
+ // zero size. This method is only meant to be used by subclasses to provide
310
+ // the necessary factories to the constructor.
311
+ template <typename Parser, typename Value>
312
+ static SingleChildFactory<Parser, Value> MakeChild(
313
+ Id id, Element<Value> T::* member) {
314
+ static_assert(std::is_base_of<ElementParser, Parser>::value,
315
+ "Parser must derive from ElementParser");
316
+ static_assert(!std::is_base_of<MasterValueParser<T>, Parser>::value,
317
+ "Recursive elements should be contained in a std::vector");
318
+ return SingleChildFactory<Parser, Value>(id, member);
319
+ }
320
+
321
+ template <typename Parser, typename Value>
322
+ static RepeatedChildFactory<Parser, Value> MakeChild(
323
+ Id id, std::vector<Element<Value>> T::* member) {
324
+ static_assert(std::is_base_of<ElementParser, Parser>::value,
325
+ "Parser must derive from ElementParser");
326
+ static_assert(!std::is_base_of<MasterValueParser<T>, Parser>::value,
327
+ "Recursive elements require a maximum recursion depth");
328
+ return RepeatedChildFactory<Parser, Value>(id, member);
329
+ }
330
+
331
+ template <typename Parser>
332
+ static RecursiveChildFactory<Parser> MakeChild(
333
+ Id id, std::vector<Element<T>> T::* member,
334
+ std::size_t max_recursion_depth) {
335
+ static_assert(std::is_base_of<MasterValueParser<T>, Parser>::value,
336
+ "Child must be recusrive to use maximum recursion depth");
337
+ return RecursiveChildFactory<Parser>(id, member, max_recursion_depth);
338
+ }
339
+
340
+ // Gets the metadata for this element, setting the EBML element ID to id. Only
341
+ // call after Init() has been called.
342
+ ElementMetadata metadata(Id id) const {
343
+ return {id, master_parser_.header_size(), master_parser_.size(),
344
+ master_parser_.position()};
345
+ }
346
+
347
+ // This method will be called once the element has been fully parsed, or a
348
+ // particular child element of interest (see UseAsStartEvent()) is
349
+ // encountered. By default it just sets *action to Action::kRead and returns
350
+ // Status::kOkCompleted. May be overridden (i.e. in order to call a Callback
351
+ // method). Returning anything other than Status::kOkCompleted will stop
352
+ // parsing and the status to be returned by Init or Feed (whichever originated
353
+ // the call to this method). In this case, resuming parsing will result in
354
+ // this method being called again.
355
+ virtual Status OnParseStarted(Callback* callback, Action* action) {
356
+ assert(callback != nullptr);
357
+ assert(action != nullptr);
358
+ *action = Action::kRead;
359
+ return Status(Status::kOkCompleted);
360
+ }
361
+
362
+ // This method is the companion to OnParseStarted, and will only be called
363
+ // after OnParseStarted has already been called and parsing has completed.
364
+ // This will not be called if OnParseStarted set the action to Action::kSkip.
365
+ // By default it just returns Status::kOkCompleted. Returning anything other
366
+ // than Status::kOkCompleted will stop parsing and the status to be returned
367
+ // by Init or Feed (whichever originated the call to this method). In this
368
+ // case, resuming parsing will result in this method being called again.
369
+ virtual Status OnParseCompleted(Callback* callback) {
370
+ assert(callback != nullptr);
371
+ return Status(Status::kOkCompleted);
372
+ }
373
+
374
+ // Returns true if the OnParseStarted method has already been called and has
375
+ // completed.
376
+ bool parse_started_event_completed() const { return started_done_; }
377
+
378
+ // Derived classes may manually call OnParseStarted before calling Feed, in
379
+ // which case this method should be called to inform this class that
380
+ // OnParseStarted has already been called and it should not be called again.
381
+ void set_parse_started_event_completed_with_action(Action action) {
382
+ assert(!started_done_);
383
+
384
+ action_ = action;
385
+ started_done_ = true;
386
+ }
387
+
388
+ // This method will be called for each child element that has been fully
389
+ // parsed for which NotifyOnParseComplete() was requested. The provided
390
+ // metadata is for the child element that has just completed parsing. By
391
+ // default this method does nothing.
392
+ virtual void OnChildParsed(const ElementMetadata& /* metadata */) {}
393
+
394
+ private:
395
+ T value_;
396
+ Action action_ = Action::kRead;
397
+ bool parse_complete_;
398
+ bool started_done_;
399
+ // master_parser_ must be after value_ to ensure correct initialization order.
400
+ MasterParser master_parser_;
401
+
402
+ const ElementMetadata& child_metadata() const {
403
+ return master_parser_.child_metadata();
404
+ }
405
+
406
+ // Helper struct that will be std::true_type if Tag is in Tags, or
407
+ // std::false_type otherwise.
408
+ template <typename Tag, typename... Tags>
409
+ struct HasTag;
410
+
411
+ // Base condition: Tags is empty, so it trivially does not contain Tag.
412
+ template <typename Tag>
413
+ struct HasTag<Tag> : std::false_type {};
414
+
415
+ // If the head of the Tags list is a different tag, skip it and check the
416
+ // remaining tags.
417
+ template <typename Tag, typename DifferentTag, typename... Tags>
418
+ struct HasTag<Tag, DifferentTag, Tags...> : HasTag<Tag, Tags...> {};
419
+
420
+ // If the head of the Tags list is the same as Tag, then we're done.
421
+ template <typename Tag, typename... Tags>
422
+ struct HasTag<Tag, Tag, Tags...> : std::true_type {};
423
+
424
+ template <typename Base, typename F, typename... Tags>
425
+ class ChildParser : public Base {
426
+ public:
427
+ using Base::WasSkipped;
428
+
429
+ template <typename... Args>
430
+ explicit ChildParser(MasterValueParser* parent, F consume_element_value,
431
+ Args&&... base_args)
432
+ : Base(std::forward<Args>(base_args)...),
433
+ parent_(parent),
434
+ consume_element_value_(std::move(consume_element_value)) {}
435
+
436
+ ChildParser() = delete;
437
+ ChildParser(const ChildParser&) = delete;
438
+ ChildParser& operator=(const ChildParser&) = delete;
439
+
440
+ Status Feed(Callback* callback, Reader* reader,
441
+ std::uint64_t* num_bytes_read) override {
442
+ *num_bytes_read = 0;
443
+
444
+ Status status = Prepare(callback);
445
+ if (!status.completed_ok()) {
446
+ return status;
447
+ }
448
+
449
+ status = Base::Feed(callback, reader, num_bytes_read);
450
+ if (status.completed_ok() && parent_->action_ != Action::kSkip &&
451
+ !WasSkipped()) {
452
+ consume_element_value_(this);
453
+ if (has_tag<TagNotifyOnParseComplete>()) {
454
+ parent_->OnChildParsed(parent_->child_metadata());
455
+ }
456
+ }
457
+ return status;
458
+ }
459
+
460
+ private:
461
+ MasterValueParser* parent_;
462
+ F consume_element_value_;
463
+
464
+ Status Prepare(Callback* callback) {
465
+ if (has_tag<TagUseAsStart>() && !parent_->started_done_) {
466
+ const Status status =
467
+ parent_->OnParseStarted(callback, &parent_->action_);
468
+ if (!status.completed_ok()) {
469
+ return status;
470
+ }
471
+ parent_->started_done_ = true;
472
+ if (parent_->action_ == Action::kSkip) {
473
+ return Status(Status::kSwitchToSkip);
474
+ }
475
+ }
476
+ return Status(Status::kOkCompleted);
477
+ }
478
+
479
+ template <typename Tag>
480
+ constexpr static bool has_tag() {
481
+ return MasterValueParser::HasTag<Tag, Tags...>::value;
482
+ }
483
+ };
484
+
485
+ // Returns a std::unique_ptr<ElementParser> that points to a ChildParser
486
+ // when the Parser's constructor does not take a Value parameter.
487
+ template <typename Parser, typename Value, typename... Tags, typename F>
488
+ static typename std::enable_if<!std::is_constructible<Parser, Value>::value,
489
+ std::unique_ptr<ElementParser>>::type
490
+ MakeChildParser(MasterValueParser* parent, F consume_element_value, ...) {
491
+ return std::unique_ptr<ElementParser>(new ChildParser<Parser, F, Tags...>(
492
+ parent, std::move(consume_element_value)));
493
+ }
494
+
495
+ // Returns a std::unique_ptr<ElementParser> that points to a ChildParser
496
+ // when the Parser's constructor does take a Value parameter.
497
+ template <typename Parser, typename Value, typename... Tags, typename F>
498
+ static typename std::enable_if<std::is_constructible<Parser, Value>::value,
499
+ std::unique_ptr<ElementParser>>::type
500
+ MakeChildParser(MasterValueParser* parent, F consume_element_value,
501
+ const Element<Value>* default_value) {
502
+ return std::unique_ptr<ElementParser>(new ChildParser<Parser, F, Tags...>(
503
+ parent, std::move(consume_element_value), default_value->value()));
504
+ }
505
+
506
+ // Returns a std::unique_ptr<ElementParser> that points to a ChildParser
507
+ // when the Parser's constructor does take a Value parameter.
508
+ template <typename Parser, typename Value, typename... Tags, typename F>
509
+ static typename std::enable_if<std::is_constructible<Parser, Value>::value,
510
+ std::unique_ptr<ElementParser>>::type
511
+ MakeChildParser(MasterValueParser* parent, F consume_element_value,
512
+ const std::vector<Element<Value>>* member) {
513
+ Value default_value{};
514
+ if (!member->empty()) {
515
+ default_value = member->front().value();
516
+ }
517
+ return std::unique_ptr<ElementParser>(new ChildParser<Parser, F, Tags...>(
518
+ parent, std::move(consume_element_value), std::move(default_value)));
519
+ }
520
+
521
+ // Initializes object state. Call immediately before initializing
522
+ // master_parser_.
523
+ void PreInit() {
524
+ value_ = {};
525
+ action_ = Action::kRead;
526
+ parse_complete_ = false;
527
+ started_done_ = false;
528
+ }
529
+ };
530
+
531
+ } // namespace webm
532
+
533
+ #endif // SRC_MASTER_VALUE_PARSER_H_
@@ -0,0 +1,57 @@
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_MASTERING_METADATA_PARSER_H_
9
+ #define SRC_MASTERING_METADATA_PARSER_H_
10
+
11
+ #include "src/float_parser.h"
12
+ #include "src/master_value_parser.h"
13
+ #include "webm/dom_types.h"
14
+ #include "webm/id.h"
15
+
16
+ namespace webm {
17
+
18
+ // Spec reference:
19
+ // http://matroska.org/technical/specs/index.html#MasteringMetadata
20
+ // http://www.webmproject.org/docs/container/#MasteringMetadata
21
+ class MasteringMetadataParser : public MasterValueParser<MasteringMetadata> {
22
+ public:
23
+ MasteringMetadataParser()
24
+ : MasterValueParser<MasteringMetadata>(
25
+ MakeChild<FloatParser>(
26
+ Id::kPrimaryRChromaticityX,
27
+ &MasteringMetadata::primary_r_chromaticity_x),
28
+ MakeChild<FloatParser>(
29
+ Id::kPrimaryRChromaticityY,
30
+ &MasteringMetadata::primary_r_chromaticity_y),
31
+ MakeChild<FloatParser>(
32
+ Id::kPrimaryGChromaticityX,
33
+ &MasteringMetadata::primary_g_chromaticity_x),
34
+ MakeChild<FloatParser>(
35
+ Id::kPrimaryGChromaticityY,
36
+ &MasteringMetadata::primary_g_chromaticity_y),
37
+ MakeChild<FloatParser>(
38
+ Id::kPrimaryBChromaticityX,
39
+ &MasteringMetadata::primary_b_chromaticity_x),
40
+ MakeChild<FloatParser>(
41
+ Id::kPrimaryBChromaticityY,
42
+ &MasteringMetadata::primary_b_chromaticity_y),
43
+ MakeChild<FloatParser>(
44
+ Id::kWhitePointChromaticityX,
45
+ &MasteringMetadata::white_point_chromaticity_x),
46
+ MakeChild<FloatParser>(
47
+ Id::kWhitePointChromaticityY,
48
+ &MasteringMetadata::white_point_chromaticity_y),
49
+ MakeChild<FloatParser>(Id::kLuminanceMax,
50
+ &MasteringMetadata::luminance_max),
51
+ MakeChild<FloatParser>(Id::kLuminanceMin,
52
+ &MasteringMetadata::luminance_min)) {}
53
+ };
54
+
55
+ } // namespace webm
56
+
57
+ #endif // SRC_MASTERING_METADATA_PARSER_H_
@@ -0,0 +1,34 @@
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_PARSER_H_
9
+ #define SRC_PARSER_H_
10
+
11
+ #include "webm/callback.h"
12
+ #include "webm/reader.h"
13
+ #include "webm/status.h"
14
+
15
+ namespace webm {
16
+
17
+ class Parser {
18
+ public:
19
+ virtual ~Parser() = default;
20
+
21
+ // Feeds data into the parser, with the number of bytes read from the reader
22
+ // returned in num_bytes_read. Returns Status::kOkCompleted when parsing is
23
+ // complete, or an appropriate error code if the data is malformed and cannot
24
+ // be parsed. Otherwise, the status of Reader::Read is returned if only a
25
+ // partial parse could be done because the reader couldn't immediately provide
26
+ // all the needed data. reader and num_bytes_read must not be null. Do not
27
+ // call again once the parse is complete.
28
+ virtual Status Feed(Callback* callback, Reader* reader,
29
+ std::uint64_t* num_bytes_read) = 0;
30
+ };
31
+
32
+ } // namespace webm
33
+
34
+ #endif // SRC_PARSER_H_
@@ -0,0 +1,34 @@
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/parser_utils.h"
9
+
10
+ #include <cassert>
11
+ #include <cstdint>
12
+
13
+ #include "webm/reader.h"
14
+ #include "webm/status.h"
15
+
16
+ namespace webm {
17
+
18
+ Status ReadByte(Reader* reader, std::uint8_t* byte) {
19
+ assert(reader != nullptr);
20
+ assert(byte != nullptr);
21
+
22
+ std::uint64_t num_bytes_read;
23
+ const Status status = reader->Read(1, byte, &num_bytes_read);
24
+
25
+ if (!status.completed_ok()) {
26
+ assert(num_bytes_read == 0);
27
+ } else {
28
+ assert(num_bytes_read == 1);
29
+ }
30
+
31
+ return status;
32
+ }
33
+
34
+ } // namespace webm