codemirror-lang-liquidsoap 0.2.9 → 0.3.1

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 (418) hide show
  1. package/dist/cli.js +2 -2
  2. package/dist/index.js +2 -2
  3. package/package.json +4 -3
  4. package/src/cli.ts +0 -0
  5. package/src/liquidsoap.grammar +1 -1
  6. package/src/parser.js +1 -1
  7. package/tests/liquidsoap/.github/alpine/APKBUILD-minimal.in +1 -1
  8. package/tests/liquidsoap/.github/alpine/APKBUILD.in +1 -1
  9. package/tests/liquidsoap/.github/alpine/liquidsoap.pre-install +0 -0
  10. package/tests/liquidsoap/.github/debian/rules +1 -1
  11. package/tests/liquidsoap/.github/debian/rules-minimal +1 -1
  12. package/tests/liquidsoap/.github/opam/liquidsoap-core-windows.opam +4 -3
  13. package/tests/liquidsoap/.github/opam/packages/ffmpeg-av-windows/ffmpeg-av-windows.1.2.0/opam +38 -0
  14. package/tests/liquidsoap/.github/opam/packages/ffmpeg-avcodec-windows/ffmpeg-avcodec-windows.1.2.0/opam +37 -0
  15. package/tests/liquidsoap/.github/opam/packages/ffmpeg-avdevice-windows/ffmpeg-avdevice-windows.1.2.0/opam +37 -0
  16. package/tests/liquidsoap/.github/opam/packages/ffmpeg-avfilter-windows/ffmpeg-avfilter-windows.1.2.0/opam +37 -0
  17. package/tests/liquidsoap/.github/opam/packages/ffmpeg-avutil-windows/ffmpeg-avutil-windows.1.2.0/opam +37 -0
  18. package/tests/liquidsoap/.github/opam/packages/ffmpeg-swresample-windows/ffmpeg-swresample-windows.1.2.0/opam +38 -0
  19. package/tests/liquidsoap/.github/opam/packages/ffmpeg-swscale-windows/ffmpeg-swscale-windows.1.2.0/opam +37 -0
  20. package/tests/liquidsoap/.github/opam/packages/ffmpeg-windows/ffmpeg-windows.1.2.0/opam +35 -0
  21. package/tests/liquidsoap/.github/scripts/add-local-opam-packages.sh +0 -0
  22. package/tests/liquidsoap/.github/scripts/build-apk.sh +0 -0
  23. package/tests/liquidsoap/.github/scripts/build-deb.sh +0 -0
  24. package/tests/liquidsoap/.github/scripts/build-details.sh +1 -1
  25. package/tests/liquidsoap/.github/scripts/build-doc.sh +0 -0
  26. package/tests/liquidsoap/.github/scripts/build-docker-alpine.sh +0 -0
  27. package/tests/liquidsoap/.github/scripts/build-docker.sh +0 -0
  28. package/tests/liquidsoap/.github/scripts/build-posix.sh +16 -13
  29. package/tests/liquidsoap/.github/scripts/build-website.sh +0 -0
  30. package/tests/liquidsoap/.github/scripts/build-win32.sh +0 -0
  31. package/tests/liquidsoap/.github/scripts/checkout-deps.sh +0 -0
  32. package/tests/liquidsoap/.github/scripts/export-metrics.sh +0 -0
  33. package/tests/liquidsoap/.github/scripts/push-docker.sh +0 -0
  34. package/tests/liquidsoap/.github/scripts/stats-posix.sh +0 -0
  35. package/tests/liquidsoap/.github/scripts/test-posix.sh +0 -0
  36. package/tests/liquidsoap/.github/workflows/ci.yml +10 -1
  37. package/tests/liquidsoap/.pre-commit-config.yaml +1 -1
  38. package/tests/liquidsoap/CHANGES.md +101 -1
  39. package/tests/liquidsoap/README.md +1 -1
  40. package/tests/liquidsoap/ROADMAP.md +28 -26
  41. package/tests/liquidsoap/doc/content/cookbook.md +46 -3
  42. package/tests/liquidsoap/doc/content/database.md +126 -0
  43. package/tests/liquidsoap/doc/content/documentation.md +1 -0
  44. package/tests/liquidsoap/doc/content/encoding_formats.md +6 -7
  45. package/tests/liquidsoap/doc/content/ffmpeg_encoder.md +20 -0
  46. package/tests/liquidsoap/doc/content/hls_output.md +27 -2
  47. package/tests/liquidsoap/doc/content/index.md +1 -1
  48. package/tests/liquidsoap/doc/content/liq/basic-radio.liq +14 -6
  49. package/tests/liquidsoap/doc/content/liq/check +0 -0
  50. package/tests/liquidsoap/doc/content/liq/liquidsoap +0 -0
  51. package/tests/liquidsoap/doc/content/liq/medialib.sqlite.liq +4 -0
  52. package/tests/liquidsoap/doc/content/liq/on2-if2.liq +5 -2
  53. package/tests/liquidsoap/doc/content/liq/on2-initial.liq +10 -5
  54. package/tests/liquidsoap/doc/content/liq/on2-replaygain.liq +13 -4
  55. package/tests/liquidsoap/doc/content/liq/on2-volume.liq +4 -2
  56. package/tests/liquidsoap/doc/content/liq/playlists.liq +2 -1
  57. package/tests/liquidsoap/doc/content/liq/radiopi.liq +2 -6
  58. package/tests/liquidsoap/doc/content/liq/source-cue.liq +26 -0
  59. package/tests/liquidsoap/doc/content/liq/space_overhead.liq +0 -0
  60. package/tests/liquidsoap/doc/content/liq/split-cue.liq +7 -8
  61. package/tests/liquidsoap/doc/content/liq/sqlite.liq +120 -0
  62. package/tests/liquidsoap/doc/content/liq/video-in-video.liq +2 -0
  63. package/tests/liquidsoap/doc/content/migrating.md +12 -0
  64. package/tests/liquidsoap/doc/content/on2_part2.md +1 -1
  65. package/tests/liquidsoap/doc/content/playlist_parsers.md +2 -10
  66. package/tests/liquidsoap/doc/content/seek.md +1 -20
  67. package/tests/liquidsoap/doc/dune.inc +655 -0
  68. package/tests/liquidsoap/dune-project +8 -5
  69. package/tests/liquidsoap/liquidsoap +0 -0
  70. package/tests/liquidsoap/liquidsoap-core.opam +6 -4
  71. package/tests/liquidsoap/src/core/builtins/builtins_ffmpeg_bitstream_filters.ml +100 -128
  72. package/tests/liquidsoap/src/core/builtins/builtins_ffmpeg_decoder.ml +10 -11
  73. package/tests/liquidsoap/src/core/builtins/builtins_ffmpeg_encoder.ml +14 -15
  74. package/tests/liquidsoap/src/core/builtins/builtins_ffmpeg_filters.ml +33 -3
  75. package/tests/liquidsoap/src/core/builtins/builtins_files.ml +64 -12
  76. package/tests/liquidsoap/src/core/builtins/builtins_optionals.ml +0 -1
  77. package/tests/liquidsoap/src/core/builtins/builtins_prometheus.ml +4 -4
  78. package/tests/liquidsoap/src/core/builtins/builtins_request.ml +16 -1
  79. package/tests/liquidsoap/src/core/builtins/builtins_resolvers.ml +1 -1
  80. package/tests/liquidsoap/src/core/builtins/builtins_settings.ml +12 -2
  81. package/tests/liquidsoap/src/core/builtins/builtins_socket.ml +17 -4
  82. package/tests/liquidsoap/src/core/builtins/builtins_source.ml +17 -7
  83. package/tests/liquidsoap/src/core/builtins/builtins_sqlite.ml +362 -0
  84. package/tests/liquidsoap/src/core/builtins/builtins_ssl.ml +18 -9
  85. package/tests/liquidsoap/src/core/builtins/builtins_tls.ml +38 -27
  86. package/tests/liquidsoap/src/core/clock.ml +1 -1
  87. package/tests/liquidsoap/src/core/clock.mli +1 -1
  88. package/tests/liquidsoap/src/core/conversions/conversion.ml +4 -38
  89. package/tests/liquidsoap/src/core/conversions/mean.ml +12 -14
  90. package/tests/liquidsoap/src/core/conversions/stereo.ml +4 -4
  91. package/tests/liquidsoap/src/core/conversions/swap.ml +8 -23
  92. package/tests/liquidsoap/src/core/decoder/aac_decoder.ml +3 -3
  93. package/tests/liquidsoap/src/core/decoder/decoder.ml +134 -129
  94. package/tests/liquidsoap/src/core/decoder/decoder.mli +11 -4
  95. package/tests/liquidsoap/src/core/decoder/decoder_utils.ml +8 -9
  96. package/tests/liquidsoap/src/core/decoder/decoder_utils.mli +2 -2
  97. package/tests/liquidsoap/src/core/decoder/external_decoder.ml +7 -5
  98. package/tests/liquidsoap/src/core/decoder/ffmpeg_copy_decoder.ml +1 -1
  99. package/tests/liquidsoap/src/core/decoder/ffmpeg_decoder.ml +138 -60
  100. package/tests/liquidsoap/src/core/decoder/ffmpeg_decoder_common.ml +10 -0
  101. package/tests/liquidsoap/src/core/decoder/ffmpeg_internal_decoder.ml +1 -2
  102. package/tests/liquidsoap/src/core/decoder/ffmpeg_raw_decoder.ml +1 -1
  103. package/tests/liquidsoap/src/core/decoder/flac_metadata_plug.ml +3 -3
  104. package/tests/liquidsoap/src/core/decoder/gstreamer_decoder.ml +1 -2
  105. package/tests/liquidsoap/src/core/decoder/id3_plug.ml +3 -3
  106. package/tests/liquidsoap/src/core/decoder/image/sdlimage_decoder.ml +3 -3
  107. package/tests/liquidsoap/src/core/decoder/image_decoder.ml +25 -23
  108. package/tests/liquidsoap/src/core/decoder/image_plug.ml +3 -3
  109. package/tests/liquidsoap/src/core/decoder/liq_flac_decoder.ml +10 -11
  110. package/tests/liquidsoap/src/core/decoder/liq_ogg_decoder.ml +5 -5
  111. package/tests/liquidsoap/src/core/decoder/mad_decoder.ml +6 -7
  112. package/tests/liquidsoap/src/core/decoder/midi_decoder.ml +10 -10
  113. package/tests/liquidsoap/src/core/decoder/ogg_metadata_plug.ml +3 -3
  114. package/tests/liquidsoap/src/core/decoder/srt_decoder.ml +23 -15
  115. package/tests/liquidsoap/src/core/decoder/taglib_plug.ml +3 -3
  116. package/tests/liquidsoap/src/core/decoder/text/video_text_sdl.ml +12 -7
  117. package/tests/liquidsoap/src/core/decoder/video_plug.ml +3 -3
  118. package/tests/liquidsoap/src/core/dune +19 -22
  119. package/tests/liquidsoap/src/core/encoder/encoder.ml +1 -1
  120. package/tests/liquidsoap/src/core/encoder/encoder.mli +1 -1
  121. package/tests/liquidsoap/src/core/encoder/encoder_formats.ml +6 -0
  122. package/tests/liquidsoap/src/core/encoder/encoder_utils.ml +66 -0
  123. package/tests/liquidsoap/src/core/encoder/encoders/avi_encoder.ml +38 -39
  124. package/tests/liquidsoap/src/core/encoder/encoders/fdkaac_encoder.ml +1 -1
  125. package/tests/liquidsoap/src/core/encoder/encoders/ffmpeg_copy_encoder.ml +26 -24
  126. package/tests/liquidsoap/src/core/encoder/encoders/ffmpeg_encoder.ml +24 -6
  127. package/tests/liquidsoap/src/core/encoder/encoders/ffmpeg_encoder_common.ml +52 -45
  128. package/tests/liquidsoap/src/core/encoder/encoders/ffmpeg_internal_encoder.ml +55 -34
  129. package/tests/liquidsoap/src/core/encoder/encoders/gstreamer_encoder.ml +27 -22
  130. package/tests/liquidsoap/src/core/encoder/encoders/lame_encoder.ml +5 -4
  131. package/tests/liquidsoap/src/core/encoder/encoders/ogg_encoder.ml +14 -7
  132. package/tests/liquidsoap/src/core/encoder/encoders/shine_encoder.ml +4 -5
  133. package/tests/liquidsoap/src/core/encoder/formats/ffmpeg_format.ml +9 -0
  134. package/tests/liquidsoap/src/core/encoder/lang/lang_ffmpeg.ml +13 -10
  135. package/tests/liquidsoap/src/core/encoder/lang_encoder.ml +1 -1
  136. package/tests/liquidsoap/src/core/harbor/harbor.ml +7 -2
  137. package/tests/liquidsoap/src/core/harbor/harbor_base.ml +7 -3
  138. package/tests/liquidsoap/src/core/io/alsa_io.ml +8 -5
  139. package/tests/liquidsoap/src/core/io/ffmpeg_filter_io.ml +9 -14
  140. package/tests/liquidsoap/src/core/io/ffmpeg_io.ml +23 -24
  141. package/tests/liquidsoap/src/core/io/gstreamer_io.ml +24 -20
  142. package/tests/liquidsoap/src/core/io/oss_io.ml +7 -5
  143. package/tests/liquidsoap/src/core/io/portaudio_io.ml +7 -5
  144. package/tests/liquidsoap/src/core/io/pulseaudio_io.ml +8 -7
  145. package/tests/liquidsoap/src/core/io/srt_io.ml +115 -114
  146. package/tests/liquidsoap/src/core/io/udp_io.ml +6 -3
  147. package/tests/liquidsoap/src/core/lang.mli +3 -0
  148. package/tests/liquidsoap/src/core/lang_source.ml +23 -9
  149. package/tests/liquidsoap/src/core/ogg_formats/opus_encoder.ml +1 -1
  150. package/tests/liquidsoap/src/core/operators/accelerate.ml +10 -23
  151. package/tests/liquidsoap/src/core/operators/add.ml +131 -122
  152. package/tests/liquidsoap/src/core/operators/amplify.ml +36 -27
  153. package/tests/liquidsoap/src/core/operators/available.ml +20 -8
  154. package/tests/liquidsoap/src/core/operators/biquad_filter.ml +8 -8
  155. package/tests/liquidsoap/src/core/operators/chord.ml +7 -9
  156. package/tests/liquidsoap/src/core/operators/clip.ml +7 -7
  157. package/tests/liquidsoap/src/core/operators/comb.ml +7 -8
  158. package/tests/liquidsoap/src/core/operators/compand.ml +9 -9
  159. package/tests/liquidsoap/src/core/operators/compress.ml +15 -10
  160. package/tests/liquidsoap/src/core/operators/compress_exp.ml +8 -9
  161. package/tests/liquidsoap/src/core/operators/cross.ml +180 -247
  162. package/tests/liquidsoap/src/core/operators/defer.ml +8 -18
  163. package/tests/liquidsoap/src/core/operators/delay.ml +10 -18
  164. package/tests/liquidsoap/src/core/operators/delay_line.ml +9 -8
  165. package/tests/liquidsoap/src/core/operators/dtmf.ml +18 -16
  166. package/tests/liquidsoap/src/core/operators/dyn_op.ml +66 -63
  167. package/tests/liquidsoap/src/core/operators/echo.ml +8 -7
  168. package/tests/liquidsoap/src/core/operators/filter.ml +8 -8
  169. package/tests/liquidsoap/src/core/operators/filter_rc.ml +11 -10
  170. package/tests/liquidsoap/src/core/operators/fir_filter.ml +8 -7
  171. package/tests/liquidsoap/src/core/operators/flanger.ml +9 -8
  172. package/tests/liquidsoap/src/core/operators/frei0r_op.ml +113 -91
  173. package/tests/liquidsoap/src/core/operators/gate.ml +9 -8
  174. package/tests/liquidsoap/src/core/operators/iir_filter.ml +7 -7
  175. package/tests/liquidsoap/src/core/operators/insert_metadata.ml +29 -54
  176. package/tests/liquidsoap/src/core/operators/ladspa_op.ml +38 -36
  177. package/tests/liquidsoap/src/core/operators/lilv_op.ml +44 -44
  178. package/tests/liquidsoap/src/core/operators/lufs.ml +8 -8
  179. package/tests/liquidsoap/src/core/operators/map_metadata.ml +23 -20
  180. package/tests/liquidsoap/src/core/operators/map_op.ml +6 -7
  181. package/tests/liquidsoap/src/core/operators/max_duration.ml +21 -20
  182. package/tests/liquidsoap/src/core/operators/midi_routing.ml +13 -9
  183. package/tests/liquidsoap/src/core/operators/ms_stereo.ml +13 -15
  184. package/tests/liquidsoap/src/core/operators/muxer.ml +30 -101
  185. package/tests/liquidsoap/src/core/operators/noblank.ml +26 -48
  186. package/tests/liquidsoap/src/core/operators/normalize.ml +13 -9
  187. package/tests/liquidsoap/src/core/operators/on_end.ml +25 -12
  188. package/tests/liquidsoap/src/core/operators/on_frame.ml +9 -9
  189. package/tests/liquidsoap/src/core/operators/on_metadata.ml +9 -10
  190. package/tests/liquidsoap/src/core/operators/on_offset.ml +20 -13
  191. package/tests/liquidsoap/src/core/operators/on_track.ml +7 -10
  192. package/tests/liquidsoap/src/core/operators/pan.ml +7 -8
  193. package/tests/liquidsoap/src/core/operators/pipe.ml +14 -17
  194. package/tests/liquidsoap/src/core/operators/pitch.ml +7 -5
  195. package/tests/liquidsoap/src/core/operators/replaygain_op.ml +6 -6
  196. package/tests/liquidsoap/src/core/operators/resample.ml +7 -6
  197. package/tests/liquidsoap/src/core/operators/rms_smooth.ml +8 -8
  198. package/tests/liquidsoap/src/core/operators/sequence.ml +48 -58
  199. package/tests/liquidsoap/src/core/operators/soundtouch_op.ml +12 -12
  200. package/tests/liquidsoap/src/core/operators/st_bpm.ml +8 -7
  201. package/tests/liquidsoap/src/core/operators/stereotool_op.ml +5 -7
  202. package/tests/liquidsoap/src/core/operators/still_frame.ml +13 -10
  203. package/tests/liquidsoap/src/core/operators/switch.ml +128 -168
  204. package/tests/liquidsoap/src/core/operators/time_warp.ml +44 -103
  205. package/tests/liquidsoap/src/core/operators/track/merge_metadata.ml +31 -48
  206. package/tests/liquidsoap/src/core/operators/track_map.ml +6 -32
  207. package/tests/liquidsoap/src/core/operators/video_effects.ml +48 -13
  208. package/tests/liquidsoap/src/core/operators/video_fade.ml +69 -57
  209. package/tests/liquidsoap/src/core/operators/window_op.ml +8 -8
  210. package/tests/liquidsoap/src/core/outputs/graphics_out.ml +11 -8
  211. package/tests/liquidsoap/src/core/outputs/harbor_output.ml +3 -3
  212. package/tests/liquidsoap/src/core/outputs/hls_output.ml +203 -116
  213. package/tests/liquidsoap/src/core/outputs/icecast2.ml +31 -5
  214. package/tests/liquidsoap/src/core/outputs/output.ml +27 -31
  215. package/tests/liquidsoap/src/core/outputs/output.mli +4 -5
  216. package/tests/liquidsoap/src/core/outputs/pipe_output.ml +19 -8
  217. package/tests/liquidsoap/src/core/outputs/sdl_out.ml +12 -9
  218. package/tests/liquidsoap/src/core/playlist_parser.ml +2 -6
  219. package/tests/liquidsoap/src/core/request.ml +84 -36
  220. package/tests/liquidsoap/src/core/request.mli +11 -8
  221. package/tests/liquidsoap/src/core/source.ml +343 -181
  222. package/tests/liquidsoap/src/core/source.mli +147 -33
  223. package/tests/liquidsoap/src/core/sources/alsa_in.ml +4 -6
  224. package/tests/liquidsoap/src/core/sources/audio_gen.ml +23 -22
  225. package/tests/liquidsoap/src/core/sources/bjack_in.ml +7 -5
  226. package/tests/liquidsoap/src/core/sources/blank.ml +55 -36
  227. package/tests/liquidsoap/src/core/sources/debug_sources.ml +2 -2
  228. package/tests/liquidsoap/src/core/sources/external_input_video.ml +2 -3
  229. package/tests/liquidsoap/src/core/sources/generated.ml +25 -47
  230. package/tests/liquidsoap/src/core/sources/harbor_input.ml +7 -9
  231. package/tests/liquidsoap/src/core/sources/latest_metadata.ml +1 -2
  232. package/tests/liquidsoap/src/core/sources/noise.ml +38 -27
  233. package/tests/liquidsoap/src/core/sources/request_dynamic.ml +181 -198
  234. package/tests/liquidsoap/src/core/sources/synthesized.ml +36 -23
  235. package/tests/liquidsoap/src/core/sources/video_board.ml +8 -10
  236. package/tests/liquidsoap/src/core/sources/video_testsrc.ml +9 -11
  237. package/tests/liquidsoap/src/core/sources/video_text.ml +8 -11
  238. package/tests/liquidsoap/src/core/stream/aFrame.ml +0 -32
  239. package/tests/liquidsoap/src/core/stream/aFrame.mli +2 -46
  240. package/tests/liquidsoap/src/core/stream/content.ml +96 -11
  241. package/tests/liquidsoap/src/core/stream/content.mli +32 -22
  242. package/tests/liquidsoap/src/core/stream/content_audio.ml +8 -4
  243. package/tests/liquidsoap/src/core/stream/content_base.ml +24 -35
  244. package/tests/liquidsoap/src/core/stream/content_midi.ml +0 -1
  245. package/tests/liquidsoap/src/core/stream/content_pcm_base.ml +0 -1
  246. package/tests/liquidsoap/src/core/stream/content_timed.ml +15 -1
  247. package/tests/liquidsoap/src/core/stream/content_video.ml +91 -30
  248. package/tests/liquidsoap/src/core/stream/ffmpeg_content_base.ml +0 -49
  249. package/tests/liquidsoap/src/core/stream/ffmpeg_copy_content.ml +2 -1
  250. package/tests/liquidsoap/src/core/stream/ffmpeg_raw_content.ml +2 -1
  251. package/tests/liquidsoap/src/core/stream/frame.ml +67 -118
  252. package/tests/liquidsoap/src/core/stream/frame.mli +49 -43
  253. package/tests/liquidsoap/src/core/stream/frame_base.ml +20 -32
  254. package/tests/liquidsoap/src/core/stream/frame_settings.ml +13 -36
  255. package/tests/liquidsoap/src/core/stream/generator.ml +47 -140
  256. package/tests/liquidsoap/src/core/stream/generator.mli +6 -13
  257. package/tests/liquidsoap/src/core/stream/mFrame.ml +0 -12
  258. package/tests/liquidsoap/src/core/stream/mFrame.mli +0 -19
  259. package/tests/liquidsoap/src/core/stream/metadata_base.ml +75 -0
  260. package/tests/liquidsoap/src/core/stream/vFrame.ml +0 -16
  261. package/tests/liquidsoap/src/core/stream/vFrame.mli +1 -35
  262. package/tests/liquidsoap/src/core/synth/dssi_op.ml +19 -20
  263. package/tests/liquidsoap/src/core/synth/keyboard.ml +6 -10
  264. package/tests/liquidsoap/src/core/synth/keyboard_sdl.ml +5 -11
  265. package/tests/liquidsoap/src/core/synth/synth_op.ml +11 -10
  266. package/tests/liquidsoap/src/core/tools/http.ml +40 -6
  267. package/tests/liquidsoap/src/core/tools/http.mli +21 -3
  268. package/tests/liquidsoap/src/core/tools/liq_posix_time.ml +3 -1
  269. package/tests/liquidsoap/src/core/tools/producer_consumer.ml +7 -18
  270. package/tests/liquidsoap/src/core/tools/server.ml +1 -1
  271. package/tests/liquidsoap/src/core/tools/server_builtins.ml +1 -1
  272. package/tests/liquidsoap/src/core/tools/start_stop.ml +2 -6
  273. package/tests/liquidsoap/src/core/tools/tutils.ml +1 -1
  274. package/tests/liquidsoap/src/core/track.ml +1 -2
  275. package/tests/liquidsoap/src/core/visualization/midimeter.ml +7 -5
  276. package/tests/liquidsoap/src/core/visualization/video_volume.ml +55 -68
  277. package/tests/liquidsoap/src/core/visualization/vis_volume.ml +1 -1
  278. package/tests/liquidsoap/src/js/index.html +4 -4
  279. package/tests/liquidsoap/src/{core/builtins/builtins_magic.ml → lang/active_value.ml} +16 -12
  280. package/tests/liquidsoap/src/lang/active_value.mli +33 -0
  281. package/tests/liquidsoap/src/lang/builtins_math.ml +7 -6
  282. package/tests/liquidsoap/src/lang/dune +1 -0
  283. package/tests/liquidsoap/src/lang/environment.ml +3 -1
  284. package/tests/liquidsoap/src/lang/evaluation.ml +13 -2
  285. package/tests/liquidsoap/src/lang/lang.mli +3 -0
  286. package/tests/liquidsoap/src/lang/lang_core.ml +13 -6
  287. package/tests/liquidsoap/src/lang/lexer.ml +2 -0
  288. package/tests/liquidsoap/src/lang/methods.ml +1 -0
  289. package/tests/liquidsoap/src/lang/methods.mli +1 -0
  290. package/tests/liquidsoap/src/lang/modules.ml +1 -0
  291. package/tests/liquidsoap/src/lang/parser_helper.ml +10 -1
  292. package/tests/liquidsoap/src/lang/parser_helper.mli +8 -1
  293. package/tests/liquidsoap/src/lang/term/parsed_term.ml +2 -0
  294. package/tests/liquidsoap/src/lang/term/runtime_term.ml +6 -1
  295. package/tests/liquidsoap/src/lang/term/term_base.ml +128 -74
  296. package/tests/liquidsoap/src/lang/term/term_reducer.ml +69 -3
  297. package/tests/liquidsoap/src/lang/term.ml +0 -47
  298. package/tests/liquidsoap/src/lang/type.ml +17 -1
  299. package/tests/liquidsoap/src/lang/type.mli +1 -0
  300. package/tests/liquidsoap/src/lang/types/type_base.ml +1 -1
  301. package/tests/liquidsoap/src/lang/utils.ml +1 -0
  302. package/tests/liquidsoap/src/lang/value.ml +16 -2
  303. package/tests/liquidsoap/src/libs/error.liq +16 -0
  304. package/tests/liquidsoap/src/libs/extra/deprecations.liq +18 -0
  305. package/tests/liquidsoap/src/libs/extra/metadata.liq +101 -0
  306. package/tests/liquidsoap/src/libs/extra/openai.liq +152 -0
  307. package/tests/liquidsoap/src/libs/extra/server.liq +39 -25
  308. package/tests/liquidsoap/src/libs/extra/source.liq +188 -0
  309. package/tests/liquidsoap/src/libs/fades.liq +92 -46
  310. package/tests/liquidsoap/src/libs/file.liq +71 -5
  311. package/tests/liquidsoap/src/libs/medialib.liq +384 -2
  312. package/tests/liquidsoap/src/libs/metadata.liq +1 -9
  313. package/tests/liquidsoap/src/libs/playlist.liq +224 -141
  314. package/tests/liquidsoap/src/libs/request.liq +112 -84
  315. package/tests/liquidsoap/src/libs/server.liq +12 -0
  316. package/tests/liquidsoap/src/libs/source.liq +24 -3
  317. package/tests/liquidsoap/src/libs/sqlite.liq +164 -0
  318. package/tests/liquidsoap/src/libs/stdlib.liq +4 -0
  319. package/tests/liquidsoap/src/libs/string.liq +35 -1
  320. package/tests/liquidsoap/src/libs/utils.liq +8 -0
  321. package/tests/liquidsoap/src/libs/video.liq +2 -1
  322. package/tests/liquidsoap/src/runtime/build_config.ml +1 -1
  323. package/tests/liquidsoap/src/runtime/main.ml +1 -1
  324. package/tests/liquidsoap/src/tooling/parsed_json.ml +4 -0
  325. package/tests/liquidsoap/tests/core/content_test.ml +32 -20
  326. package/tests/liquidsoap/tests/core/decoder_test.ml +4 -4
  327. package/tests/liquidsoap/tests/core/ffmpeg_quality.ml +2 -0
  328. package/tests/liquidsoap/tests/core/frame_test.ml +0 -35
  329. package/tests/liquidsoap/tests/core/generator_test.ml +4 -4
  330. package/tests/liquidsoap/tests/core/more_types.ml +2 -0
  331. package/tests/liquidsoap/tests/core/output_encoded_test.ml +7 -5
  332. package/tests/liquidsoap/tests/core/output_test.ml +6 -11
  333. package/tests/liquidsoap/tests/core/stream_decoder_test.ml +3 -4
  334. package/tests/liquidsoap/tests/failures/ctype.liq +0 -0
  335. package/tests/liquidsoap/tests/failures/error.liq +0 -0
  336. package/tests/liquidsoap/tests/failures/record-invalid-member1.liq +0 -0
  337. package/tests/liquidsoap/tests/failures/record-invalid-member2.liq +0 -0
  338. package/tests/liquidsoap/tests/failures/ref.liq +0 -0
  339. package/tests/liquidsoap/tests/fixme/GH1170.liq +0 -0
  340. package/tests/liquidsoap/tests/fixme/cross2.liq +0 -0
  341. package/tests/liquidsoap/tests/fixme/cross3.liq +0 -0
  342. package/tests/liquidsoap/tests/fixme/sequence-1.liq +0 -0
  343. package/tests/liquidsoap/tests/language/bool.liq +1 -12
  344. package/tests/liquidsoap/tests/language/dune.inc +12 -0
  345. package/tests/liquidsoap/tests/language/file.liq +7 -2
  346. package/tests/liquidsoap/tests/language/functions.liq +2 -13
  347. package/tests/liquidsoap/tests/language/interactive.liq +5 -16
  348. package/tests/liquidsoap/tests/language/list.liq +73 -78
  349. package/tests/liquidsoap/tests/language/loop.liq +6 -18
  350. package/tests/liquidsoap/tests/language/mem_usage.liq +0 -1
  351. package/tests/liquidsoap/tests/language/metadata.liq +9 -13
  352. package/tests/liquidsoap/tests/language/null.liq +8 -12
  353. package/tests/liquidsoap/tests/language/number.liq +10 -0
  354. package/tests/liquidsoap/tests/language/pp.liq +8 -20
  355. package/tests/liquidsoap/tests/language/predicate.liq +6 -18
  356. package/tests/liquidsoap/tests/language/ref.liq +3 -15
  357. package/tests/liquidsoap/tests/language/regexp.liq +14 -25
  358. package/tests/liquidsoap/tests/language/sqlite.liq +96 -0
  359. package/tests/liquidsoap/tests/language/stdlib.liq +7 -20
  360. package/tests/liquidsoap/tests/language/string.liq +7 -0
  361. package/tests/liquidsoap/tests/media/dune.inc +39 -0
  362. package/tests/liquidsoap/tests/media/encoder_audio_only.liq.in +1 -1
  363. package/tests/liquidsoap/tests/media/encoder_audio_video.liq.in +1 -1
  364. package/tests/liquidsoap/tests/media/encoder_multitrack.liq.in +1 -1
  365. package/tests/liquidsoap/tests/media/encoder_video_only.liq.in +1 -1
  366. package/tests/liquidsoap/tests/media/ffmpeg_bitstream_filter.liq +94 -0
  367. package/tests/liquidsoap/tests/media/ffmpeg_complex_filter.liq +1 -1
  368. package/tests/liquidsoap/tests/media/ffmpeg_filter.liq +3 -9
  369. package/tests/liquidsoap/tests/media/ffmpeg_raw_hls.liq +15 -12
  370. package/tests/liquidsoap/tests/media/ffmpeg_transparency_filter.liq +3 -9
  371. package/tests/liquidsoap/tests/media/gen_dune.ml +1 -0
  372. package/tests/liquidsoap/tests/media/mk_encoder_test.sh +0 -0
  373. package/tests/liquidsoap/tests/media/mk_stream_test.sh +0 -0
  374. package/tests/liquidsoap/tests/media/multitrack.liq +21 -1
  375. package/tests/liquidsoap/tests/media/stream_audio.liq.in +0 -0
  376. package/tests/liquidsoap/tests/media/stream_video.liq.in +0 -0
  377. package/tests/liquidsoap/tests/performance/erathostenes.liq +0 -0
  378. package/tests/liquidsoap/tests/performance/memory.liq +0 -0
  379. package/tests/liquidsoap/tests/performance/small-record.liq +0 -0
  380. package/tests/liquidsoap/tests/regression/GH1327.liq +8 -0
  381. package/tests/liquidsoap/tests/regression/GH3316.liq +2 -0
  382. package/tests/liquidsoap/tests/regression/GH3645.liq +16 -0
  383. package/tests/liquidsoap/tests/regression/GH3675.liq +37 -0
  384. package/tests/liquidsoap/tests/regression/LS354-2.liq +11 -3
  385. package/tests/liquidsoap/tests/regression/dune.inc +45 -14
  386. package/tests/liquidsoap/tests/regression/track_sensitive.liq +17 -0
  387. package/tests/liquidsoap/tests/regression/unified-pcm-types.aac +0 -0
  388. package/tests/liquidsoap/tests/regression/unified-pcm-types.liq +3 -0
  389. package/tests/liquidsoap/tests/run_test.ml +7 -3
  390. package/tests/liquidsoap/tests/streams/195.liq +4 -1
  391. package/tests/liquidsoap/tests/streams/cross-override.liq +12 -4
  392. package/tests/liquidsoap/tests/streams/cross-persist-override.liq +12 -4
  393. package/tests/liquidsoap/tests/streams/cross.liq +1 -1
  394. package/tests/liquidsoap/tests/streams/crossfade.liq +11 -24
  395. package/tests/liquidsoap/tests/streams/cue-cut.liq +16 -0
  396. package/tests/liquidsoap/tests/streams/dtmf.liq +3 -0
  397. package/tests/liquidsoap/tests/streams/dtmf_pcm_s16.liq +4 -0
  398. package/tests/liquidsoap/tests/streams/dune.inc +145 -0
  399. package/tests/liquidsoap/tests/streams/fades-persistent-override.liq +7 -2
  400. package/tests/liquidsoap/tests/streams/hls_discontinuity.liq +68 -0
  401. package/tests/liquidsoap/tests/streams/hls_id3v2.liq +76 -4
  402. package/tests/liquidsoap/tests/streams/hls_large_frame.liq +31 -0
  403. package/tests/liquidsoap/tests/streams/merge_metadata.liq +2 -4
  404. package/tests/liquidsoap/tests/streams/no-cue-cut.liq +22 -0
  405. package/tests/liquidsoap/tests/streams/random.liq +4 -4
  406. package/tests/liquidsoap/tests/streams/rotate.liq +44 -21
  407. package/tests/liquidsoap/tests/streams/sharing.liq +5 -0
  408. package/tests/liquidsoap/tests/streams/source-cue.liq +134 -0
  409. package/tests/liquidsoap/tests/streams/srt_raw_pcm.liq +5 -0
  410. package/tests/liquidsoap/tests/test.liq +1 -2
  411. package/tests/run.sh +0 -0
  412. package/tests/liquidsoap/.github/opam/packages/duppy/duppy.0.9.3/opam +0 -37
  413. package/tests/liquidsoap/.github/opam/packages/ssl/ssl.0.7.0/opam +0 -40
  414. package/tests/liquidsoap/src/core/liqmagic.disabled.ml +0 -2
  415. package/tests/liquidsoap/src/core/liqmagic.enabled.ml +0 -3
  416. package/tests/liquidsoap/src/core/liqmagic.mli +0 -4
  417. package/tests/liquidsoap/src/core/operators/cuepoint.ml +0 -216
  418. package/tests/liquidsoap/tests/regression/GH3121.liq +0 -16
@@ -21,6 +21,7 @@
21
21
  *****************************************************************************)
22
22
 
23
23
  open Liquidsoap_lang.Error
24
+ open Mm
24
25
 
25
26
  (** In this module we define the central streaming concepts: sources, active
26
27
  sources and clocks.
@@ -50,6 +51,11 @@ module Pcre = Re.Pcre
50
51
  since those are structural, not nominal like a variant type.) *)
51
52
  type source_t = [ `Fallible | `Infallible ]
52
53
 
54
+ exception Unavailable
55
+
56
+ type streaming_state =
57
+ [ `Unavailable | `Ready of unit -> unit | `Done of Frame.t ]
58
+
53
59
  (** {1 Proto clocks}
54
60
 
55
61
  Roughly describe what a clock is, and build a notion of clock variable
@@ -283,12 +289,11 @@ type watcher = {
283
289
  clock_sync_mode:clock_sync_mode ->
284
290
  unit;
285
291
  sleep : unit -> unit;
286
- get_frame :
292
+ generate_frame :
287
293
  start_time:float ->
288
294
  end_time:float ->
289
- start_position:int ->
290
- end_position:int ->
291
- is_partial:bool ->
295
+ length:int ->
296
+ has_track_mark:bool ->
292
297
  metadata:metadata ->
293
298
  unit;
294
299
  before_output : unit -> unit;
@@ -441,10 +446,6 @@ class virtual operator ?pos ?(name = "src") sources =
441
446
  when it's not used any more, and decide whether the source should run in
442
447
  caching mode.
443
448
 
444
- A source may be accessed by several sources, and must switch to caching
445
- mode when it may be accessed by more than one source, in order to ensure
446
- consistency of the delivered stream chunk.
447
-
448
449
  Before that a source P accesses another source S it must activate it. The
449
450
  An activation is identified by the path to the source which required it.
450
451
  It is possible that two identical activations are done, and they should
@@ -455,37 +456,8 @@ class virtual operator ?pos ?(name = "src") sources =
455
456
 
456
457
  val mutable caching = false
457
458
  val mutable activations : operator list list = []
458
-
459
- method private update_caching_mode =
460
- let string_of activations =
461
- String.concat ", "
462
- (List.map
463
- (fun l -> String.concat ":" (List.map (fun s -> s#id) l))
464
- activations)
465
- in
466
- self#log#debug "Activations changed: static=[%s]." (string_of activations);
467
-
468
- (* Decide whether caching mode is needed, and why *)
469
- match
470
- if self#is_active then Some "active source"
471
- else (
472
- match activations with
473
- | [] | _ :: [] -> None
474
- | _ -> Some "two static activations")
475
- with
476
- | None ->
477
- if caching then (
478
- caching <- false;
479
- self#log#debug "Disabling caching mode.")
480
- | Some msg ->
481
- if not caching then (
482
- caching <- true;
483
- self#log#debug "Enabling caching mode: %s." msg)
484
-
485
459
  val mutable on_wake_up = []
486
-
487
- method on_wake_up =
488
- self#mutexify (fun fn -> on_wake_up <- on_wake_up @ [fn])
460
+ method on_wake_up fn = on_wake_up <- fn :: on_wake_up
489
461
 
490
462
  initializer
491
463
  self#on_wake_up (fun () ->
@@ -510,11 +482,10 @@ class virtual operator ?pos ?(name = "src") sources =
510
482
  (Frame.string_of_content_type self#content_type);
511
483
  self#wake_up activation;
512
484
  List.iter (fun fn -> fn ()) on_wake_up);
513
- activations <- activation :: activations;
514
- self#update_caching_mode
485
+ activations <- activation :: activations
515
486
 
516
487
  val mutable on_sleep = []
517
- method on_sleep = self#mutexify (fun fn -> on_sleep <- on_sleep @ [fn])
488
+ method on_sleep fn = on_sleep <- fn :: on_sleep
518
489
 
519
490
  initializer
520
491
  self#on_sleep (fun () -> self#iter_watchers (fun w -> w.sleep ()))
@@ -533,7 +504,6 @@ class virtual operator ?pos ?(name = "src") sources =
533
504
  | h :: tl -> remove (h :: acc) tl
534
505
  in
535
506
  activations <- remove [] activations;
536
- self#update_caching_mode;
537
507
  if activations = [] then (
538
508
  source_log#info "Source %s gets down." id;
539
509
  self#sleep;
@@ -556,8 +526,8 @@ class virtual operator ?pos ?(name = "src") sources =
556
526
 
557
527
  (** Streaming *)
558
528
 
559
- (* Number of frames left in the current track: -1 means Infinity, time unit
560
- is the frame. *)
529
+ (* Number of maste ticks left in the current track: -1 means unknown, time unit
530
+ is master tick. *)
561
531
  method virtual remaining : int
562
532
  val mutable elapsed = 0
563
533
  method elapsed = elapsed
@@ -574,36 +544,118 @@ class virtual operator ?pos ?(name = "src") sources =
574
544
  if (s :> < seek : int -> int >) == (self :> < seek : int -> int >) then 0
575
545
  else s#seek n
576
546
 
577
- (* Underlying source implementation for [is_ready].
578
- should return [true] when the source can produce
579
- fresh data. *)
580
- method virtual private _is_ready : ?frame:Frame.t -> unit -> bool
547
+ method virtual private can_generate_frame : bool
548
+ method virtual private generate_frame : Frame.t
549
+ val mutable streaming_state : streaming_state = `Unavailable
550
+
551
+ method is_ready =
552
+ if not content_type_computation_allowed then false
553
+ else (
554
+ self#has_ticked;
555
+ match streaming_state with `Ready _ | `Done _ -> true | _ -> false)
556
+
557
+ val mutable _cache = None
558
+
559
+ method private cache =
560
+ match _cache with None -> self#empty_frame | Some c -> c
561
+
562
+ val mutable consumed = 0
563
+
564
+ (* This is the implementation of the main streaming logic. *)
565
+ initializer
566
+ self#on_before_output (fun () ->
567
+ consumed <- 0;
568
+ let cache = self#cache in
569
+ let cache_pos = Frame.position cache in
570
+ let size = Lazy.force Frame.size in
571
+ if cache_pos > 0 || self#can_generate_frame then
572
+ streaming_state <-
573
+ `Ready
574
+ (fun () ->
575
+ let buf =
576
+ if cache_pos < size then
577
+ Frame.append cache self#instrumented_generate_frame
578
+ else cache
579
+ in
580
+ let buf_pos = Frame.position buf in
581
+ let buf =
582
+ if size < buf_pos then (
583
+ _cache <-
584
+ Some
585
+ (Frame.chunk ~start:size ~stop:(buf_pos - size) buf);
586
+ Frame.slice buf size)
587
+ else buf
588
+ in
589
+ streaming_state <- `Done buf)
590
+ else streaming_state <- `Unavailable);
581
591
 
582
- method is_ready ?frame () =
583
- match frame with
584
- | None -> self#_is_ready ?frame ()
585
- | Some frame ->
586
- (caching && Frame.position frame < Frame.position self#memo)
587
- || self#_is_ready ~frame ()
592
+ self#on_after_output (fun () ->
593
+ match (streaming_state, consumed) with
594
+ | `Done buf, 0 -> _cache <- Some buf
595
+ | `Done buf, n ->
596
+ let pos = Frame.position buf in
597
+ assert (n <= pos);
598
+ if pos = n then _cache <- None
599
+ else _cache <- Some (Frame.chunk ~start:n ~stop:(pos - n) buf)
600
+ | _ -> ())
601
+
602
+ method peek_frame =
603
+ self#has_ticked;
604
+ match streaming_state with
605
+ | `Unavailable ->
606
+ log#critical "source called while not ready!";
607
+ raise Unavailable
608
+ | `Ready fn ->
609
+ fn ();
610
+ self#peek_frame
611
+ | `Done data -> data
612
+
613
+ method get_partial_frame cb =
614
+ let data = cb self#peek_frame in
615
+ consumed <- max consumed (Frame.position data);
616
+ data
617
+
618
+ method get_frame = self#get_partial_frame (fun f -> f)
619
+
620
+ method get_mutable_content field =
621
+ let content = Frame.get self#get_frame field in
622
+ (* Optimization is disabled for now. *)
623
+ Content.copy content
624
+
625
+ method get_mutable_frame field =
626
+ Frame.set self#get_frame field (self#get_mutable_content field)
627
+
628
+ method set_frame_data
629
+ : 'a.
630
+ Frame.field ->
631
+ (?offset:int -> ?length:int -> 'a -> Content.data) ->
632
+ 'a ->
633
+ Frame.t =
634
+ fun field lift data -> Frame.set_data self#get_frame field lift data
635
+
636
+ method private split_frame frame =
637
+ match Frame.track_marks frame with
638
+ | 0 :: _ -> (self#empty_frame, Some frame)
639
+ | p :: _ ->
640
+ ( Frame.slice frame p,
641
+ Some (Frame.chunk ~start:p ~stop:(Frame.position frame) frame) )
642
+ | [] -> (frame, None)
643
+
644
+ method frame_has_track_mark = Frame.has_track_marks self#get_frame
645
+
646
+ method frame_track_mark =
647
+ match Frame.track_marks self#get_frame with
648
+ | pos :: _ -> Some pos
649
+ | _ -> None
650
+
651
+ method frame_metadata = Frame.get_all_metadata self#get_frame
652
+ method frame_position = Frame.position self#get_frame
653
+ method frame_audio_position = Frame.audio_of_main self#frame_position
588
654
 
589
655
  (* If possible, end the current track.
590
656
  Typically, that signal is just re-routed, or makes the next file
591
657
  to be played if there's anything like a file. *)
592
658
  method virtual abort_track : unit
593
-
594
- (* In caching mode, remember what has been given during the current
595
- tick. The generation is deferred until we actually have computed the kind
596
- by unfication. *)
597
- val mutable memo = None
598
-
599
- method memo =
600
- match memo with
601
- | Some memo -> memo
602
- | None ->
603
- let m = Frame.create self#content_type in
604
- memo <- Some m;
605
- m
606
-
607
659
  val mutable buffer = None
608
660
 
609
661
  method buffer =
@@ -616,58 +668,137 @@ class virtual operator ?pos ?(name = "src") sources =
616
668
  buffer <- Some buf;
617
669
  buf
618
670
 
619
- val mutable last_metadata = None
620
- method last_metadata = self#mutexify (fun () -> last_metadata) ()
621
- val mutable on_metadata : (Frame.metadata -> unit) list = []
671
+ val mutable empty_frame = None
672
+
673
+ method empty_frame =
674
+ match empty_frame with
675
+ | Some frame -> frame
676
+ | None ->
677
+ let f = Frame.create ~length:0 self#content_type in
678
+ empty_frame <- Some f;
679
+ f
622
680
 
623
- method on_metadata =
624
- self#mutexify (fun fn -> on_metadata <- on_metadata @ [fn])
681
+ method end_of_track = Frame.add_track_mark self#empty_frame 0
682
+ val mutable last_metadata = None
683
+ method last_metadata = last_metadata
684
+ val mutable on_metadata : (Frame.metadata -> unit) List.t = []
685
+ method on_metadata fn = on_metadata <- fn :: on_metadata
686
+ val mutable on_track_called = false
687
+ initializer self#on_before_output (fun () -> on_track_called <- false)
688
+ val mutable on_track : (Frame.metadata -> unit) List.t = []
689
+ method on_track fn = on_track <- fn :: on_track
690
+
691
+ method private set_last_metadata buf =
692
+ match List.rev (Frame.get_all_metadata buf) with
693
+ | (_, m) :: _ -> last_metadata <- Some m
694
+ | _ -> ()
695
+
696
+ method private execute_on_track buf =
697
+ if not on_track_called then (
698
+ on_track_called <- true;
699
+ self#set_last_metadata buf;
700
+ let m = Option.value ~default:Frame.Metadata.empty last_metadata in
701
+ self#log#debug "calling on_track handlers..";
702
+ List.iter (fun fn -> fn m) on_track)
703
+
704
+ val mutable last_images = Hashtbl.create 0
705
+
706
+ method last_image field =
707
+ match Hashtbl.find_opt last_images field with
708
+ | Some i -> i
709
+ | None ->
710
+ let width, height = self#video_dimensions in
711
+ let i = Video.Canvas.Image.create width height in
712
+ Hashtbl.replace last_images field i;
713
+ i
625
714
 
626
- val mutable on_track : (Frame.metadata -> unit) list = []
715
+ method private set_last_image ~field img =
716
+ Hashtbl.replace last_images field img
627
717
 
628
- (* We want to notify of new tracks on the next call after a
629
- partial frame. *)
630
- val mutable was_partial = true
631
- method on_track = self#mutexify (fun fn -> on_track <- on_track @ [fn])
718
+ val mutable video_generators = Hashtbl.create 0
632
719
 
633
- method private instrumented_get_frame buf =
720
+ method private video_generator ~priv field =
721
+ match Hashtbl.find_opt video_generators (priv, field) with
722
+ | Some g -> g
723
+ | None ->
724
+ let params =
725
+ Content.Video.get_params
726
+ (Frame.Fields.find field self#content_type)
727
+ in
728
+ let g = Content.Video.make_generator params in
729
+ Hashtbl.add video_generators (priv, field) g;
730
+ g
731
+
732
+ method private internal_generate_video ?create ~priv ~field length =
733
+ Content.Video.generate ?create (self#video_generator ~priv field) length
734
+
735
+ method private generate_video = self#internal_generate_video ~priv:false
736
+
737
+ method private nearest_image ~pos ~last_image buf =
738
+ let nearest =
739
+ List.fold_left
740
+ (fun current (p, img) ->
741
+ match current with
742
+ | Some (p', _) when abs (p' - pos) < abs (p - pos) -> current
743
+ | _ -> Some (p, img))
744
+ None buf.Content.Video.data
745
+ in
746
+ match nearest with Some (_, img) -> img | None -> last_image
747
+
748
+ method private normalize_video ~field content =
749
+ let buf = Content.Video.get_data content in
750
+ let data = buf.Content.Video.data in
751
+ let last_image =
752
+ match List.rev data with
753
+ | (_, img) :: _ ->
754
+ self#set_last_image ~field img;
755
+ img
756
+ | [] -> self#last_image field
757
+ in
758
+ Content.Video.lift_data
759
+ (self#internal_generate_video ~field ~priv:true
760
+ ~create:(fun ~pos ~width:_ ~height:_ () ->
761
+ self#nearest_image ~pos ~last_image buf)
762
+ (Content.length content))
763
+
764
+ method private normalize_video_content =
765
+ Frame.Fields.mapi (fun field content ->
766
+ if
767
+ Content.Video.is_data content
768
+ && Frame.Fields.mem field self#content_type
769
+ then self#normalize_video ~field content
770
+ else content)
771
+
772
+ method private instrumented_generate_frame =
634
773
  let start_time = Unix.gettimeofday () in
635
- let start_position = Frame.position buf in
636
- self#get_frame buf;
774
+ let buf = self#normalize_video_content self#generate_frame in
637
775
  let end_time = Unix.gettimeofday () in
638
- let end_position = Frame.position buf in
639
- let is_partial = Frame.is_partial buf in
640
- if is_partial then elapsed <- 0
641
- else elapsed <- elapsed + end_position - start_position;
642
- let metadata =
643
- List.filter
644
- (fun (pos, _) -> start_position <= pos)
645
- (Frame.get_all_metadata buf)
776
+ let length = Frame.position buf in
777
+ let track_marks = Frame.track_marks buf in
778
+ let buf =
779
+ match track_marks with
780
+ | p :: _ :: _ ->
781
+ self#log#important
782
+ "Source created multiple tracks in a single frame! Sub-frame \
783
+ tracks are not supported and are merged into a single one..";
784
+ Frame.add_track_mark (Frame.drop_track_marks buf) p
785
+ | _ -> buf
646
786
  in
787
+ let has_track_mark = track_marks <> [] in
788
+ if has_track_mark then elapsed <- 0 else elapsed <- elapsed + length;
789
+ let metadata = Frame.get_all_metadata buf in
647
790
  let on_metadata = self#mutexify (fun () -> on_metadata) () in
648
791
  List.iter
649
792
  (fun (i, m) ->
650
- self#log#debug "Got metadata at position %d: calling handlers..." i;
793
+ self#log#debug
794
+ "generate_frame: got metadata at position %d: calling handlers..." i;
651
795
  List.iter (fun fn -> fn m) on_metadata)
652
796
  metadata;
653
- (match List.rev metadata with
654
- | (_, m) :: _ -> self#mutexify (fun () -> last_metadata <- Some m) ()
655
- | [] -> ());
656
- self#mutexify
657
- (fun () ->
658
- if was_partial then (
659
- was_partial <- false;
660
- let m =
661
- match Frame.get_metadata buf start_position with
662
- | None -> Frame.Metadata.empty
663
- | Some m -> m
664
- in
665
- List.iter (fun fn -> fn m) on_track);
666
- was_partial <- is_partial)
667
- ();
797
+ if has_track_mark then self#execute_on_track buf;
668
798
  self#iter_watchers (fun w ->
669
- w.get_frame ~start_time ~start_position ~end_time ~end_position
670
- ~is_partial ~metadata)
799
+ w.generate_frame ~start_time ~end_time ~length ~has_track_mark
800
+ ~metadata);
801
+ buf
671
802
 
672
803
  (* Set to [true] when we're inside an output cycle. *)
673
804
  val mutable in_output = false
@@ -683,13 +814,12 @@ class virtual operator ?pos ?(name = "src") sources =
683
814
  List.iter (fun fn -> fn ()) on_before_output;
684
815
  in_output <- true
685
816
 
686
- val mutable on_output = []
817
+ val mutable on_output : (unit -> unit) List.t = []
687
818
  method on_output fn = on_output <- fn :: on_output
688
819
  val mutable on_after_output = []
689
820
  method on_after_output fn = on_after_output <- fn :: on_after_output
690
821
 
691
822
  initializer
692
- self#on_after_output (fun () -> Frame.clear self#memo);
693
823
  self#on_after_output (fun () ->
694
824
  self#iter_watchers (fun w -> w.after_output ()))
695
825
 
@@ -699,79 +829,14 @@ class virtual operator ?pos ?(name = "src") sources =
699
829
  in_output <- false
700
830
 
701
831
  method private has_ticked =
702
- if not in_output then (
703
- in_output <- true;
704
- self#before_output;
705
- match deref clock with
706
- | Known c ->
832
+ match deref clock with
833
+ | Known c ->
834
+ if not in_output then (
835
+ in_output <- true;
836
+ self#before_output;
707
837
  c#on_output (fun () -> List.iter (fun fn -> fn ()) on_output);
708
- c#on_after_output (fun () -> self#after_output)
709
- | _ -> assert false)
710
-
711
- (* [#get buf] completes the frame with the next data in the stream.
712
- Depending on whether caching is enabled or not,
713
- it calls [#get_frame] directly or tries to get data from the cache frame,
714
- filling it if needed.
715
- Any source calling [other_source#get should] thus take care of clearing
716
- the cache of the other source ([#advance]) at the end of the output
717
- round ([#after_output]). *)
718
- method get buf =
719
- assert (Frame.is_partial buf);
720
- self#has_ticked;
721
-
722
- (* In some cases we can't avoid #get being called on a non-ready
723
- source, for example:
724
- - A starts pumping B, stops in the middle of the track
725
- - B finishes its track, becomes unavailable
726
- - A starts streaming again, needs to receive an EOT before
727
- having to worry about availability.
728
-
729
- Another important example is crossfade, if e.g. a transition
730
- returns a failling source.
731
-
732
- So we add special cases where, instead of calling #get_frame, we
733
- call silent_end_track to properly end a track by inserting a break.
734
-
735
- This makes the whole protocol a bit sloppy as it weakens constraints
736
- tying #is_ready and #get, preventing the detection of "bad" calls
737
- of #get without prior check of #is_ready.
738
-
739
- This fix makes it really important to keep #is_ready = true during a
740
- track, otherwise the track will be ended without the source noticing! *)
741
- let silent_end_track () = Frame.add_break buf (Frame.position buf) in
742
- if not caching then
743
- if not (self#_is_ready ~frame:buf ()) then silent_end_track ()
744
- else (
745
- let b = Frame.breaks buf in
746
- self#instrumented_get_frame buf;
747
- if List.length b + 1 > List.length (Frame.breaks buf) then (
748
- self#log#severe "#get_frame added too many breaks!";
749
- assert false);
750
- if List.length b + 1 < List.length (Frame.breaks buf) then (
751
- self#log#severe
752
- "#get_frame returned a buffer without enough breaks!";
753
- assert false))
754
- else (
755
- let memo = self#memo in
756
- try Frame.get_chunk buf memo
757
- with Frame.No_chunk ->
758
- if not (self#_is_ready ~frame:buf ()) then silent_end_track ()
759
- else (
760
- (* [memo] has nothing new for [buf]. Feed [memo] and try again *)
761
- let b = Frame.breaks memo in
762
- let p = Frame.position memo in
763
- self#instrumented_get_frame memo;
764
- if List.length b + 1 <> List.length (Frame.breaks memo) then (
765
- self#log#severe "#get_frame didn't add exactly one break!";
766
- assert false)
767
- else if Frame.is_partial buf then
768
- if p < Frame.position memo then self#get buf
769
- else Frame.add_break buf (Frame.position buf)))
770
-
771
- (* That's the way the source produces audio data.
772
- It cannot be called directly, but [#get] should be used instead, for
773
- dealing with caching if needed. *)
774
- method virtual private get_frame : Frame.t -> unit
838
+ c#on_after_output (fun () -> self#after_output))
839
+ | _ -> ()
775
840
  end
776
841
 
777
842
  (** Entry-point sources, which need to actively perform some task. *)
@@ -809,6 +874,103 @@ class virtual active_source ?pos ?name () =
809
874
  inherit active_operator ?pos ?name []
810
875
  end
811
876
 
877
+ (* Reselect type. This drives the choice of next source.
878
+ In cases where the underlying source returns the same
879
+ choice after calling [get_source], we need to refuse
880
+ that source unless if can continue filling up the frame
881
+ that is being worked on. This what [`After_position]
882
+ captures. *)
883
+ type reselect = [ `Ok | `Force | `After_position of int ]
884
+
885
+ class virtual generate_from_multiple_sources ~merge ~track_sensitive () =
886
+ object (self)
887
+ method virtual get_source : reselect:reselect -> unit -> source option
888
+ method virtual split_frame : Frame.t -> Frame.t * Frame.t option
889
+ method virtual empty_frame : Frame.t
890
+ method virtual private execute_on_track : Frame.t -> unit
891
+ method virtual private set_last_metadata : Frame.t -> unit
892
+ method virtual log : Log.t
893
+
894
+ method private can_generate_frame =
895
+ match
896
+ self#get_source
897
+ ~reselect:(if track_sensitive () then `Ok else `Force)
898
+ ()
899
+ with
900
+ | Some s -> s#is_ready
901
+ | None -> false
902
+
903
+ val mutable current_source = None
904
+
905
+ method private begin_track buf =
906
+ if merge () then Frame.drop_track_marks buf
907
+ else (
908
+ self#execute_on_track buf;
909
+ Frame.add_track_mark buf 0)
910
+
911
+ method private can_reselect ~(reselect : reselect) (s : source) =
912
+ s#is_ready
913
+ &&
914
+ match reselect with
915
+ | `Ok -> true
916
+ | `Force -> false
917
+ | `After_position p -> p < Frame.position s#get_frame
918
+
919
+ method private continue_frame s =
920
+ s#get_partial_frame (fun frame ->
921
+ match self#split_frame frame with
922
+ | buf, Some next_track when Frame.position buf = 0 -> (
923
+ match current_source with
924
+ | Some s' when s == s' -> self#empty_frame
925
+ | _ -> self#begin_track next_track)
926
+ | buf, _ -> buf)
927
+
928
+ method private generate_frame =
929
+ let s = Option.get (self#get_source ~reselect:`Ok ()) in
930
+ assert s#is_ready;
931
+ let buf = self#continue_frame s in
932
+ let size = Lazy.force Frame.size in
933
+ let rec f ~last_source ~last_chunk buf =
934
+ let pos = Frame.position buf in
935
+ let last_chunk_pos = Frame.position last_chunk in
936
+ self#set_last_metadata last_chunk;
937
+ if pos < size then (
938
+ let rem = size - pos in
939
+ match
940
+ self#get_source ~reselect:(`After_position last_chunk_pos) ()
941
+ with
942
+ | Some s' when last_source == s' ->
943
+ let remainder =
944
+ s#get_partial_frame (fun frame ->
945
+ Frame.slice frame (last_chunk_pos + rem))
946
+ in
947
+ let new_track =
948
+ Frame.chunk ~start:last_chunk_pos
949
+ ~stop:(Frame.position remainder) remainder
950
+ in
951
+ f ~last_source:s ~last_chunk:remainder
952
+ (Frame.append buf (self#begin_track new_track))
953
+ | Some s ->
954
+ assert s#is_ready;
955
+ let new_track =
956
+ s#get_partial_frame (fun frame ->
957
+ match self#split_frame frame with
958
+ | buf, _ when Frame.position buf = 0 ->
959
+ Frame.slice frame rem
960
+ | buf, _ ->
961
+ Frame.slice frame
962
+ (min (Frame.position buf) size - pos))
963
+ in
964
+ f ~last_source:s ~last_chunk:new_track
965
+ (Frame.append buf (self#begin_track new_track))
966
+ | _ -> (last_source, buf))
967
+ else (last_source, buf)
968
+ in
969
+ let last_source, buf = f ~last_source:s ~last_chunk:buf buf in
970
+ current_source <- Some last_source;
971
+ buf
972
+ end
973
+
812
974
  (** Specialized shortcuts *)
813
975
 
814
976
  type clock_variable = active_source var