Skip to content

Commit ffe3bdd

Browse files
committed
Allow to change blank duration in-track.
1 parent 54874c2 commit ffe3bdd

File tree

1 file changed

+43
-47
lines changed

1 file changed

+43
-47
lines changed

src/core/sources/blank.ml

+43-47
Original file line numberDiff line numberDiff line change
@@ -24,68 +24,64 @@ open Mm
2424
open Source
2525

2626
class blank duration =
27-
let ticks () =
28-
let d = duration () in
29-
if d < 0. then -1 else Frame.main_of_seconds d
30-
in
3127
object (self)
3228
inherit source ~name:"blank" ()
3329

34-
(** Remaining time, -1 for infinity. *)
35-
val mutable remaining = None
30+
val position : [ `New_track | `Elapsed of int ] Atomic.t =
31+
Atomic.make (`Elapsed 0)
3632

3733
method remaining =
38-
match remaining with
39-
| Some r -> r
40-
| None ->
41-
let r = ticks () in
42-
remaining <- Some r;
43-
r
34+
match (Atomic.get position, duration ()) with
35+
| `New_track, _ -> 0
36+
| `Elapsed _, d when d < 0. -> -1
37+
| `Elapsed e, d -> max 0 (Frame.main_of_seconds d - e)
4438

4539
method stype = `Infallible
4640
method private _is_ready ?frame:_ _ = true
4741
method self_sync = (`Static, false)
4842
method! seek x = x
4943
method seek_source = (self :> Source.source)
50-
method abort_track = remaining <- Some 0
44+
method abort_track = Atomic.set position `New_track
5145

5246
method get_frame ab =
53-
let position = Frame.position ab in
54-
let rem = self#remaining in
55-
let length =
56-
if rem < 0 then Lazy.force Frame.size - position
57-
else min rem (Lazy.force Frame.size - position)
58-
in
59-
let audio_pos = Frame.audio_of_main position in
60-
let audio_len = Frame.audio_of_main length in
61-
let video_pos = Frame.video_of_main position in
62-
let video_len = Frame.video_of_main length in
47+
match (Atomic.get position, self#remaining) with
48+
| `New_track, _ -> Frame.add_break ab (Frame.position ab)
49+
| `Elapsed elapsed, rem ->
50+
let pos = Frame.position ab in
51+
let length =
52+
if rem < 0 then Lazy.force Frame.size - pos
53+
else min rem (Lazy.force Frame.size - pos)
54+
in
55+
let audio_pos = Frame.audio_of_main pos in
56+
let audio_len = Frame.audio_of_main length in
57+
let video_pos = Frame.video_of_main pos in
58+
let video_len = Frame.video_of_main length in
6359

64-
Frame.Fields.iter
65-
(fun field typ ->
66-
match typ with
67-
| _ when Content.Audio.is_format typ ->
68-
Audio.clear
69-
(Content.Audio.get_data (Frame.get ab field))
70-
audio_pos audio_len
71-
| _ when Content_pcm_s16.is_format typ ->
72-
Content_pcm_s16.clear
73-
(Content_pcm_s16.get_data (Frame.get ab field))
74-
audio_pos audio_len
75-
| _ when Content_pcm_f32.is_format typ ->
76-
Content_pcm_f32.clear
77-
(Content_pcm_f32.get_data (Frame.get ab field))
78-
audio_pos audio_len
79-
| _ when Content.Video.is_format typ ->
80-
Video.Canvas.blank
81-
(Content.Video.get_data (Frame.get ab field))
82-
video_pos video_len
83-
| _ -> failwith "Invalid content type!")
84-
self#content_type;
60+
Frame.Fields.iter
61+
(fun field typ ->
62+
match typ with
63+
| _ when Content.Audio.is_format typ ->
64+
Audio.clear
65+
(Content.Audio.get_data (Frame.get ab field))
66+
audio_pos audio_len
67+
| _ when Content_pcm_s16.is_format typ ->
68+
Content_pcm_s16.clear
69+
(Content_pcm_s16.get_data (Frame.get ab field))
70+
audio_pos audio_len
71+
| _ when Content_pcm_f32.is_format typ ->
72+
Content_pcm_f32.clear
73+
(Content_pcm_f32.get_data (Frame.get ab field))
74+
audio_pos audio_len
75+
| _ when Content.Video.is_format typ ->
76+
Video.Canvas.blank
77+
(Content.Video.get_data (Frame.get ab field))
78+
video_pos video_len
79+
| _ -> failwith "Invalid content type!")
80+
self#content_type;
8581

86-
Frame.add_break ab (position + length);
87-
if Frame.is_partial ab then remaining <- None
88-
else if rem > 0 then remaining <- Some (rem - length)
82+
Frame.add_break ab (pos + length);
83+
Atomic.set position
84+
(`Elapsed (if Frame.is_partial ab then 0 else elapsed + length))
8985
end
9086

9187
let blank =

0 commit comments

Comments
 (0)