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,76 @@
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/block_header_parser.h"
9
+
10
+ #include <cassert>
11
+ #include <cstdint>
12
+
13
+ #include "src/parser_utils.h"
14
+
15
+ namespace webm {
16
+
17
+ // Spec reference:
18
+ // http://matroska.org/technical/specs/index.html#block_structure
19
+ // http://matroska.org/technical/specs/index.html#simpleblock_structure
20
+ // http://matroska.org/technical/specs/index.html#block_virtual
21
+ Status BlockHeaderParser::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
+
27
+ *num_bytes_read = 0;
28
+
29
+ Status status;
30
+ std::uint64_t local_num_bytes_read;
31
+
32
+ while (true) {
33
+ switch (state_) {
34
+ case State::kReadingTrackNumber: {
35
+ status = uint_parser_.Feed(callback, reader, &local_num_bytes_read);
36
+ *num_bytes_read += local_num_bytes_read;
37
+ if (!status.completed_ok()) {
38
+ return status;
39
+ }
40
+ value_.track_number = uint_parser_.value();
41
+ state_ = State::kReadingTimecode;
42
+ continue;
43
+ }
44
+
45
+ case State::kReadingTimecode: {
46
+ status =
47
+ AccumulateIntegerBytes(timecode_bytes_remaining_, reader,
48
+ &value_.timecode, &local_num_bytes_read);
49
+ *num_bytes_read += local_num_bytes_read;
50
+ timecode_bytes_remaining_ -= static_cast<int>(local_num_bytes_read);
51
+ if (!status.completed_ok()) {
52
+ return status;
53
+ }
54
+ state_ = State::kReadingFlags;
55
+ continue;
56
+ }
57
+
58
+ case State::kReadingFlags: {
59
+ assert(timecode_bytes_remaining_ == 0);
60
+ status = ReadByte(reader, &value_.flags);
61
+ if (!status.completed_ok()) {
62
+ return status;
63
+ }
64
+ ++*num_bytes_read;
65
+ state_ = State::kDone;
66
+ continue;
67
+ }
68
+
69
+ case State::kDone: {
70
+ return Status(Status::kOkCompleted);
71
+ }
72
+ }
73
+ }
74
+ }
75
+
76
+ } // 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_BLOCK_HEADER_PARSER_H_
9
+ #define SRC_BLOCK_HEADER_PARSER_H_
10
+
11
+ #include <cassert>
12
+ #include <cstdint>
13
+
14
+ #include "src/parser.h"
15
+ #include "src/var_int_parser.h"
16
+ #include "webm/callback.h"
17
+ #include "webm/reader.h"
18
+ #include "webm/status.h"
19
+
20
+ namespace webm {
21
+
22
+ struct BlockHeader {
23
+ std::uint64_t track_number;
24
+ std::int16_t timecode;
25
+ std::uint8_t flags;
26
+
27
+ bool operator==(const BlockHeader& other) const {
28
+ return track_number == other.track_number && timecode == other.timecode &&
29
+ flags == other.flags;
30
+ }
31
+ };
32
+
33
+ class BlockHeaderParser : public Parser {
34
+ public:
35
+ Status Feed(Callback* callback, Reader* reader,
36
+ std::uint64_t* num_bytes_read) override;
37
+
38
+ // Gets the parsed block header information. This must not be called until the
39
+ // parse has been successfully completed.
40
+ const BlockHeader& value() const {
41
+ assert(state_ == State::kDone);
42
+ return value_;
43
+ }
44
+
45
+ private:
46
+ BlockHeader value_;
47
+
48
+ VarIntParser uint_parser_;
49
+
50
+ int timecode_bytes_remaining_ = 2;
51
+
52
+ enum class State {
53
+ /* clang-format off */
54
+ // State Transitions to state When
55
+ kReadingTrackNumber, // kReadingTimecode track parsed
56
+ kReadingTimecode, // kReadingFlags timecode parsed
57
+ kReadingFlags, // kDone flags parsed
58
+ kDone, // No transitions from here (must call Init)
59
+ /* clang-format on */
60
+ } state_ = State::kReadingTrackNumber;
61
+ };
62
+
63
+ } // namespace webm
64
+
65
+ #endif // SRC_BLOCK_HEADER_PARSER_H_
@@ -0,0 +1,32 @@
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_BLOCK_MORE_PARSER_H_
9
+ #define SRC_BLOCK_MORE_PARSER_H_
10
+
11
+ #include "src/byte_parser.h"
12
+ #include "src/int_parser.h"
13
+ #include "src/master_value_parser.h"
14
+ #include "webm/dom_types.h"
15
+ #include "webm/id.h"
16
+
17
+ namespace webm {
18
+
19
+ // Spec reference:
20
+ // http://matroska.org/technical/specs/index.html#BlockMore
21
+ // http://www.webmproject.org/docs/container/#BlockMore
22
+ class BlockMoreParser : public MasterValueParser<BlockMore> {
23
+ public:
24
+ BlockMoreParser()
25
+ : MasterValueParser<BlockMore>(
26
+ MakeChild<UnsignedIntParser>(Id::kBlockAddId, &BlockMore::id),
27
+ MakeChild<BinaryParser>(Id::kBlockAdditional, &BlockMore::data)) {}
28
+ };
29
+
30
+ } // namespace webm
31
+
32
+ #endif // SRC_BLOCK_MORE_PARSER_H_
@@ -0,0 +1,285 @@
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/block_parser.h"
9
+
10
+ #include <cassert>
11
+ #include <cstdint>
12
+ #include <numeric>
13
+ #include <type_traits>
14
+ #include <vector>
15
+
16
+ #include "src/parser_utils.h"
17
+ #include "webm/element.h"
18
+
19
+ namespace webm {
20
+
21
+ namespace {
22
+
23
+ // The ParseBasicBlockFlags functions parse extra flag bits into the block,
24
+ // depending on the type of block that is being parsed.
25
+ void ParseBasicBlockFlags(std::uint8_t /* flags */, Block* /* block */) {
26
+ // Block has no extra flags that aren't already handled.
27
+ }
28
+
29
+ void ParseBasicBlockFlags(std::uint8_t flags, SimpleBlock* block) {
30
+ block->is_key_frame = (0x80 & flags) != 0;
31
+ block->is_discardable = (0x01 & flags) != 0;
32
+ }
33
+
34
+ // The BasicBlockBegin functions call the Callback event handler and get the
35
+ // correct action for the parser, depending on the type of block that is being
36
+ // parsed.
37
+ Status BasicBlockBegin(const ElementMetadata& metadata, const Block& block,
38
+ Callback* callback, Action* action) {
39
+ return callback->OnBlockBegin(metadata, block, action);
40
+ }
41
+
42
+ Status BasicBlockBegin(const ElementMetadata& metadata,
43
+ const SimpleBlock& block, Callback* callback,
44
+ Action* action) {
45
+ return callback->OnSimpleBlockBegin(metadata, block, action);
46
+ }
47
+
48
+ // The BasicBlockEnd functions call the Callback event handler depending on the
49
+ // type of block that is being parsed.
50
+ Status BasicBlockEnd(const ElementMetadata& metadata, const Block& block,
51
+ Callback* callback) {
52
+ return callback->OnBlockEnd(metadata, block);
53
+ }
54
+
55
+ Status BasicBlockEnd(const ElementMetadata& metadata, const SimpleBlock& block,
56
+ Callback* callback) {
57
+ return callback->OnSimpleBlockEnd(metadata, block);
58
+ }
59
+
60
+ } // namespace
61
+
62
+ template <typename T>
63
+ Status BasicBlockParser<T>::Init(const ElementMetadata& metadata,
64
+ std::uint64_t max_size) {
65
+ assert(metadata.size == kUnknownElementSize || metadata.size <= max_size);
66
+
67
+ if (metadata.size == kUnknownElementSize || metadata.size < 5) {
68
+ return Status(Status::kInvalidElementSize);
69
+ }
70
+
71
+ *this = {};
72
+ frame_metadata_.parent_element = metadata;
73
+
74
+ return Status(Status::kOkCompleted);
75
+ }
76
+
77
+ template <typename T>
78
+ Status BasicBlockParser<T>::Feed(Callback* callback, Reader* reader,
79
+ std::uint64_t* num_bytes_read) {
80
+ assert(callback != nullptr);
81
+ assert(reader != nullptr);
82
+ assert(num_bytes_read != nullptr);
83
+
84
+ *num_bytes_read = 0;
85
+
86
+ Status status;
87
+ std::uint64_t local_num_bytes_read;
88
+
89
+ while (true) {
90
+ switch (state_) {
91
+ case State::kReadingHeader: {
92
+ status = header_parser_.Feed(callback, reader, &local_num_bytes_read);
93
+ *num_bytes_read += local_num_bytes_read;
94
+ header_bytes_read_ += local_num_bytes_read;
95
+ if (!status.completed_ok()) {
96
+ return status;
97
+ }
98
+ value_.track_number = header_parser_.value().track_number;
99
+ value_.timecode = header_parser_.value().timecode;
100
+
101
+ std::uint8_t flags = header_parser_.value().flags;
102
+ value_.is_visible = (0x08 & flags) == 0;
103
+ value_.lacing = static_cast<Lacing>(flags & 0x06);
104
+ ParseBasicBlockFlags(flags, &value_);
105
+
106
+ if (value_.lacing == Lacing::kNone) {
107
+ value_.num_frames = 1;
108
+ state_ = State::kGettingAction;
109
+ } else {
110
+ state_ = State::kReadingLaceCount;
111
+ }
112
+ continue;
113
+ }
114
+
115
+ case State::kReadingLaceCount: {
116
+ assert(lace_sizes_.empty());
117
+ std::uint8_t lace_count;
118
+ status = ReadByte(reader, &lace_count);
119
+ if (!status.completed_ok()) {
120
+ return status;
121
+ }
122
+ ++*num_bytes_read;
123
+ ++header_bytes_read_;
124
+ // Lace count is stored as (count - 1).
125
+ value_.num_frames = lace_count + 1;
126
+ state_ = State::kGettingAction;
127
+ continue;
128
+ }
129
+
130
+ case State::kGettingAction: {
131
+ Action action = Action::kRead;
132
+ status = BasicBlockBegin(frame_metadata_.parent_element, value_,
133
+ callback, &action);
134
+ if (!status.completed_ok()) {
135
+ return status;
136
+ }
137
+ if (action == Action::kSkip) {
138
+ state_ = State::kSkipping;
139
+ } else if (value_.lacing == Lacing::kNone || value_.num_frames == 1) {
140
+ state_ = State::kValidatingSize;
141
+ } else if (value_.lacing == Lacing::kXiph) {
142
+ state_ = State::kReadingXiphLaceSizes;
143
+ } else if (value_.lacing == Lacing::kEbml) {
144
+ state_ = State::kReadingFirstEbmlLaceSize;
145
+ } else {
146
+ state_ = State::kCalculatingFixedLaceSizes;
147
+ }
148
+ continue;
149
+ }
150
+
151
+ case State::kReadingXiphLaceSizes:
152
+ assert(value_.num_frames > 0);
153
+ while (static_cast<int>(lace_sizes_.size()) < value_.num_frames - 1) {
154
+ std::uint8_t byte;
155
+ do {
156
+ status = ReadByte(reader, &byte);
157
+ if (!status.completed_ok()) {
158
+ return status;
159
+ }
160
+ ++*num_bytes_read;
161
+ ++header_bytes_read_;
162
+ xiph_lace_size_ += byte;
163
+ } while (byte == 255);
164
+
165
+ lace_sizes_.push_back(xiph_lace_size_);
166
+ xiph_lace_size_ = 0;
167
+ }
168
+ state_ = State::kValidatingSize;
169
+ continue;
170
+
171
+ case State::kReadingFirstEbmlLaceSize:
172
+ assert(value_.num_frames > 0);
173
+ assert(lace_sizes_.empty());
174
+ status = uint_parser_.Feed(callback, reader, &local_num_bytes_read);
175
+ *num_bytes_read += local_num_bytes_read;
176
+ header_bytes_read_ += local_num_bytes_read;
177
+ if (!status.completed_ok()) {
178
+ return status;
179
+ }
180
+ lace_sizes_.push_back(uint_parser_.value());
181
+ uint_parser_ = {};
182
+ state_ = State::kReadingEbmlLaceSizes;
183
+ continue;
184
+
185
+ case State::kReadingEbmlLaceSizes:
186
+ assert(value_.num_frames > 0);
187
+ assert(!lace_sizes_.empty());
188
+ while (static_cast<int>(lace_sizes_.size()) < value_.num_frames - 1) {
189
+ status = uint_parser_.Feed(callback, reader, &local_num_bytes_read);
190
+ *num_bytes_read += local_num_bytes_read;
191
+ header_bytes_read_ += local_num_bytes_read;
192
+ if (!status.completed_ok()) {
193
+ return status;
194
+ }
195
+ constexpr std::uint64_t one = 1; // Prettier than a static_cast.
196
+ std::uint64_t offset =
197
+ (one << (uint_parser_.encoded_length() * 7 - 1)) - 1;
198
+ lace_sizes_.push_back(lace_sizes_.back() + uint_parser_.value() -
199
+ offset);
200
+ uint_parser_ = {};
201
+ }
202
+ state_ = State::kValidatingSize;
203
+ continue;
204
+
205
+ case State::kCalculatingFixedLaceSizes: {
206
+ assert(value_.num_frames > 0);
207
+ assert(lace_sizes_.empty());
208
+ if (header_bytes_read_ >= frame_metadata_.parent_element.size) {
209
+ return Status(Status::kInvalidElementValue);
210
+ }
211
+ std::uint64_t laced_data_size =
212
+ frame_metadata_.parent_element.size - header_bytes_read_;
213
+ std::uint64_t frame_size = laced_data_size / value_.num_frames;
214
+ if (laced_data_size % value_.num_frames != 0) {
215
+ return Status(Status::kInvalidElementValue);
216
+ }
217
+ lace_sizes_.resize(value_.num_frames, frame_size);
218
+ frame_metadata_.position =
219
+ frame_metadata_.parent_element.position + header_bytes_read_;
220
+ frame_metadata_.size = frame_size;
221
+ state_ = State::kReadingFrames;
222
+ continue;
223
+ }
224
+
225
+ case State::kValidatingSize: {
226
+ std::uint64_t sum = std::accumulate(
227
+ lace_sizes_.begin(), lace_sizes_.end(), header_bytes_read_);
228
+ if (sum >= frame_metadata_.parent_element.size) {
229
+ return Status(Status::kInvalidElementValue);
230
+ }
231
+ lace_sizes_.push_back(frame_metadata_.parent_element.size - sum);
232
+ frame_metadata_.position = frame_metadata_.parent_element.position +
233
+ frame_metadata_.parent_element.header_size +
234
+ header_bytes_read_;
235
+ frame_metadata_.size = lace_sizes_[0];
236
+ state_ = State::kReadingFrames;
237
+ continue;
238
+ }
239
+
240
+ case State::kSkipping:
241
+ do {
242
+ // Skip the remaining part of the header and all of the frames.
243
+ status = reader->Skip(
244
+ frame_metadata_.parent_element.size - header_bytes_read_,
245
+ &local_num_bytes_read);
246
+ *num_bytes_read += local_num_bytes_read;
247
+ header_bytes_read_ += local_num_bytes_read;
248
+ } while (status.code == Status::kOkPartial);
249
+ return status;
250
+
251
+ case State::kReadingFrames:
252
+ assert(value_.num_frames > 0);
253
+ assert(static_cast<int>(lace_sizes_.size()) == value_.num_frames);
254
+ for (; current_lace_ < lace_sizes_.size(); ++current_lace_) {
255
+ const std::uint64_t original = lace_sizes_[current_lace_];
256
+ status = callback->OnFrame(frame_metadata_, reader,
257
+ &lace_sizes_[current_lace_]);
258
+ *num_bytes_read += original - lace_sizes_[current_lace_];
259
+ if (!status.completed_ok()) {
260
+ return status;
261
+ }
262
+ assert(lace_sizes_[current_lace_] == 0);
263
+ if (current_lace_ + 1 < lace_sizes_.size()) {
264
+ frame_metadata_.position += frame_metadata_.size;
265
+ frame_metadata_.size = lace_sizes_[current_lace_ + 1];
266
+ }
267
+ }
268
+ state_ = State::kDone;
269
+ continue;
270
+
271
+ case State::kDone:
272
+ return BasicBlockEnd(frame_metadata_.parent_element, value_, callback);
273
+ }
274
+ }
275
+ }
276
+
277
+ template <typename T>
278
+ bool BasicBlockParser<T>::WasSkipped() const {
279
+ return state_ == State::kSkipping;
280
+ }
281
+
282
+ template class BasicBlockParser<Block>;
283
+ template class BasicBlockParser<SimpleBlock>;
284
+
285
+ } // namespace webm
@@ -0,0 +1,126 @@
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_BLOCK_PARSER_H_
9
+ #define SRC_BLOCK_PARSER_H_
10
+
11
+ #include <cassert>
12
+ #include <cstdint>
13
+ #include <type_traits>
14
+ #include <vector>
15
+
16
+ #include "src/block_header_parser.h"
17
+ #include "src/element_parser.h"
18
+ #include "src/var_int_parser.h"
19
+ #include "webm/callback.h"
20
+ #include "webm/dom_types.h"
21
+ #include "webm/element.h"
22
+ #include "webm/reader.h"
23
+ #include "webm/status.h"
24
+
25
+ namespace webm {
26
+
27
+ // Parses Block and SimpleBlock elements. It is recommended to use the
28
+ // BlockParser and SimpleBlockParser aliases.
29
+ // Spec reference:
30
+ // http://matroska.org/technical/specs/index.html#Block
31
+ // http://matroska.org/technical/specs/index.html#SimpleBlock
32
+ // http://www.webmproject.org/docs/container/#SimpleBlock
33
+ // http://www.webmproject.org/docs/container/#Block
34
+ // http://matroska.org/technical/specs/index.html#block_structure
35
+ // http://matroska.org/technical/specs/index.html#simpleblock_structure
36
+ template <typename T>
37
+ class BasicBlockParser : public ElementParser {
38
+ static_assert(std::is_same<T, Block>::value ||
39
+ std::is_same<T, SimpleBlock>::value,
40
+ "T must be Block or SimpleBlock");
41
+
42
+ public:
43
+ Status Init(const ElementMetadata& metadata, std::uint64_t max_size) override;
44
+
45
+ Status Feed(Callback* callback, Reader* reader,
46
+ std::uint64_t* num_bytes_read) override;
47
+
48
+ bool WasSkipped() const override;
49
+
50
+ // Gets the parsed block header information. The frames are not included. This
51
+ // must not be called until the parse has been successfully completed.
52
+ const T& value() const {
53
+ assert(state_ == State::kDone);
54
+ return value_;
55
+ }
56
+
57
+ // Gets the parsed block header information. The frames are not included. This
58
+ // must not be called until the parse has been successfully completed.
59
+ T* mutable_value() {
60
+ assert(state_ == State::kDone);
61
+ return &value_;
62
+ }
63
+
64
+ private:
65
+ // The number of header bytes read (header meaning everything before the
66
+ // frames).
67
+ std::uint64_t header_bytes_read_ = 0;
68
+
69
+ // The parsed header value for the element.
70
+ T value_{};
71
+
72
+ // Metadata for the frame that is currently being read.
73
+ FrameMetadata frame_metadata_;
74
+
75
+ // Parser for parsing header metadata that is common between Block and
76
+ // SimpleBlock.
77
+ BlockHeaderParser header_parser_;
78
+
79
+ // Parser for parsing unsigned EBML variable-sized integers.
80
+ VarIntParser uint_parser_;
81
+
82
+ // The current lace size when parsing Xiph lace sizes.
83
+ std::uint64_t xiph_lace_size_ = 0;
84
+
85
+ // Lace (frame) sizes, where each entry represents the size of a frame.
86
+ std::vector<std::uint64_t> lace_sizes_;
87
+
88
+ // The current index into lace_sizes_ for the current frame being read.
89
+ std::size_t current_lace_ = 0;
90
+
91
+ // Parsing states for the finite-state machine.
92
+ enum class State {
93
+ /* clang-format off */
94
+ // State Transitions to state When
95
+ kReadingHeader, // kGettingAction no lacing
96
+ // kReadingLaceCount yes lacing
97
+ kReadingLaceCount, // kGettingAction no errors
98
+ kGettingAction, // kSkipping action == skip
99
+ // kValidatingSize no lacing
100
+ // kReadingXiphLaceSizes xiph lacing
101
+ // kReadingFirstEbmlLaceSize ebml lacing
102
+ // kCalculatingFixedLaceSizes fixed lacing
103
+ kReadingXiphLaceSizes, // kValidatingSize all sizes read
104
+ kReadingFirstEbmlLaceSize, // kReadingEbmlLaceSizes first size read
105
+ kReadingEbmlLaceSizes, // kValidatingSize all sizes read
106
+ kCalculatingFixedLaceSizes, // kReadingFrames no errors
107
+ kValidatingSize, // kReadingFrames no errors
108
+ kSkipping, // No transitions from here (must call Init)
109
+ kReadingFrames, // kDone all frames read
110
+ kDone, // No transitions from here (must call Init)
111
+ /* clang-format on */
112
+ };
113
+
114
+ // The current state of the parser.
115
+ State state_ = State::kReadingHeader;
116
+ };
117
+
118
+ extern template class BasicBlockParser<Block>;
119
+ extern template class BasicBlockParser<SimpleBlock>;
120
+
121
+ using BlockParser = BasicBlockParser<Block>;
122
+ using SimpleBlockParser = BasicBlockParser<SimpleBlock>;
123
+
124
+ } // namespace webm
125
+
126
+ #endif // SRC_BLOCK_PARSER_H_
@@ -0,0 +1,95 @@
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_BOOL_PARSER_H_
9
+ #define SRC_BOOL_PARSER_H_
10
+
11
+ #include <cassert>
12
+ #include <cstdint>
13
+
14
+ #include "src/element_parser.h"
15
+ #include "src/parser_utils.h"
16
+ #include "webm/callback.h"
17
+ #include "webm/element.h"
18
+ #include "webm/reader.h"
19
+ #include "webm/status.h"
20
+
21
+ namespace webm {
22
+
23
+ // Parses a boolean from a byte stream. EBML does not have a boolean type, but
24
+ // the Matroska spec defines some unsigned integer elements that have a range of
25
+ // [0, 1]. The BoolParser parses these unsigned integer elements into
26
+ // true/false, and reports a Status::kInvalidElementValue error if the integer
27
+ // is outside of its permitted range.
28
+ class BoolParser : public ElementParser {
29
+ public:
30
+ explicit BoolParser(bool default_value = false)
31
+ : default_value_(default_value) {}
32
+
33
+ Status Init(const ElementMetadata& metadata,
34
+ std::uint64_t max_size) override {
35
+ assert(metadata.size == kUnknownElementSize || metadata.size <= max_size);
36
+
37
+ // Booleans are really just unsigned integers with a range limit of 0-1.
38
+ // Unsigned integers can't be encoded with more than 8 bytes.
39
+ if (metadata.size > 8) {
40
+ return Status(Status::kInvalidElementSize);
41
+ }
42
+
43
+ size_ = num_bytes_remaining_ = static_cast<int>(metadata.size);
44
+ value_ = default_value_;
45
+
46
+ return Status(Status::kOkCompleted);
47
+ }
48
+
49
+ Status Feed(Callback* callback, Reader* reader,
50
+ std::uint64_t* num_bytes_read) override {
51
+ assert(callback != nullptr);
52
+ assert(reader != nullptr);
53
+ assert(num_bytes_read != nullptr);
54
+
55
+ std::uint64_t uint_value = 0;
56
+ const Status status = AccumulateIntegerBytes(num_bytes_remaining_, reader,
57
+ &uint_value, num_bytes_read);
58
+ num_bytes_remaining_ -= static_cast<int>(*num_bytes_read);
59
+
60
+ // Only the last byte should have a value, and it should only be 0 or 1.
61
+ if ((num_bytes_remaining_ != 0 && uint_value != 0) || uint_value > 1) {
62
+ return Status(Status::kInvalidElementValue);
63
+ }
64
+
65
+ if (size_ > 0) {
66
+ value_ = uint_value == 1;
67
+ }
68
+
69
+ return status;
70
+ }
71
+
72
+ // Gets the parsed bool. This must not be called until the parse had been
73
+ // successfully completed.
74
+ bool value() const {
75
+ assert(num_bytes_remaining_ == 0);
76
+ return value_;
77
+ }
78
+
79
+ // Gets the parsed bool. This must not be called until the parse had been
80
+ // successfully completed.
81
+ bool* mutable_value() {
82
+ assert(num_bytes_remaining_ == 0);
83
+ return &value_;
84
+ }
85
+
86
+ private:
87
+ bool value_;
88
+ bool default_value_;
89
+ int num_bytes_remaining_ = -1;
90
+ int size_;
91
+ };
92
+
93
+ } // namespace webm
94
+
95
+ #endif // SRC_BOOL_PARSER_H_