Improved stream handling

parent 2f8799ad
Pipeline #1311 passed with stage
in 11 minutes and 7 seconds
......@@ -190,9 +190,18 @@ Semaphore opus-block-sem
[: opus-blocks back> ;] opus-block-sem c-section
opus-task ?dup-IF wake THEN ;
[IFDEF] pulse-exec##
: stream@ ( -- stream )
idx-block $@ $10 u> IF
idx-channels c@ 1 = >r
mono-play stereo-play r> select
ELSE drop 0 THEN ;
[THEN]
: opus-go ( -- )
opus-task ?dup-IF wake ELSE opus-block-task THEN ;
: start-play ( -- )
0 to idx-pos# 0 to play-pos#
opus-task ?dup-IF wake ELSE opus-block-task THEN
0 to idx-pos# 0 to play-pos# opus-go
[IFDEF] pulse-exec##
idx-block $@ $10 u> IF
idx-channels c@ 1 = >r
......@@ -208,24 +217,24 @@ Semaphore opus-block-sem
: pause-play ( -- )
[IFDEF] pulse-exec##
idx-block $@ $10 u> IF
idx-channels c@ 1 = >r
mono-play stereo-play r> select ?dup-IF
pause-stream
THEN
ELSE drop THEN
stream@ ?dup-IF ['] pause-stream pulse-exec# THEN
opus-task ?dup-IF halt THEN
[THEN] ;
: resume-play ( -- )
[IFDEF] pulse-exec##
idx-block $@ $10 u> IF
idx-channels c@ 1 = >r
mono-play stereo-play r> select ?dup-IF
resume-stream
THEN
ELSE drop THEN
stream@ ?dup-IF opus-go ['] resume-stream pulse-exec# THEN
[THEN] ;
: discard-opus-blocks ( -- )
[: opus-blocks get-stack 0 ?DO { | w^ buf } buf $free LOOP
opus-blocks $free ;]
opus-block-sem c-section ;
: open-play ( addr-play u addr-idx u -- )
opus-task ?dup-IF halt discard-opus-blocks THEN
[IFDEF] pulse-exec#
stream@ ?dup-IF ['] flush-stream pulse-exec# THEN
[THEN]
idx-block $slurp-file
play-block $slurp-file \ r/o open-file throw to play-file
start-play ;
......
......@@ -53,6 +53,7 @@ $Variable request-queue
' execute pa_context_subscribe_cb_t: Constant pa-context-subscribe-cb
' execute pa_context_success_cb_t: Constant pa-context-success-cb
' execute pa_stream_request_cb_t: Constant pa-stream-request-cb
' execute pa_stream_success_cb_t: Constant pa-stream-success-cb
:noname cell- free throw ; pa_free_cb_t: Constant pa-free-cb
0 Value pa-ready
......@@ -145,6 +146,20 @@ Variable def-output$
PA_SUBSCRIPTION_EVENT_SERVER of >server-info endof
endcase ;
: ?requests ( -- )
\G check if requests have completed
requests@ 0 ?DO
dup pa_operation_get_state
PA_OPERATION_RUNNING = IF >request ELSE drop THEN
LOOP ;
: requests| ( -- )
\G block until all requests are done
BEGIN
request-queue $@len ~~ WHILE { | w^ retval }
pa-ml 1 retval pa_mainloop_iterate ?pa-ior
?requests
REPEAT ;
: pulse-init ( -- )
stacksize4 NewTask4 to pa-task
pa-task activate debug-out debug-vector ! nothrow
......@@ -159,10 +174,7 @@ Variable def-output$
BEGIN
?events { | w^ retval }
pa-ml 1 retval pa_mainloop_iterate ?pa-ior
requests@ 0 ?DO
dup pa_operation_get_state
PA_OPERATION_RUNNING = IF >request ELSE drop THEN
LOOP
?requests
AGAIN ;] catch ?dup-IF DoError THEN ;
event: :>exec ( xt -- ) execute ;
......@@ -234,9 +246,13 @@ Defer write-record
n @ IF pa_stream_drop ?pa-ior THEN ;
: pause-stream ( stream -- )
1 0 0 pa_stream_cork ?pa-ior ;
1 0 0 pa_stream_cork >request ;
: resume-stream ( stream -- )
0 0 0 pa_stream_cork ?pa-ior ;
0 0 0 pa_stream_cork >request ;
: flush-stream ( stream -- )
pa-stream-success-cb [: drop pause-stream ;] pa_stream_flush >request ;
: drain-stream ( stream -- )
pa-stream-success-cb [: drop pause-stream ;] pa_stream_drain >request ;
: read-stream { stream bytes xt: read-record -- }
read-record { w^ buf }
BEGIN buf $@len bytes u< WHILE
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment