@@ -74,10 +74,10 @@ export class Audio {
7474 #gain = new Signal < GainNode | undefined > ( undefined ) ;
7575 readonly root : Getter < AudioNode | undefined > = this . #gain;
7676
77+ #track = new Moq . TrackProducer ( "audio" , 1 ) ;
7778 #group?: Moq . GroupProducer ;
7879 #groupTimestamp = 0 ;
7980
80- #id = 0 ;
8181 #signals = new Effect ( ) ;
8282
8383 constructor ( broadcast : Moq . BroadcastProducer , props ?: AudioProps ) {
@@ -165,11 +165,10 @@ export class Audio {
165165 const worklet = effect . get ( this . #worklet) ;
166166 if ( ! worklet ) return ;
167167
168- const track = new Moq . TrackProducer ( `audio-${ this . #id++ } ` , 1 ) ;
169- effect . cleanup ( ( ) => track . close ( ) ) ;
170-
171- this . broadcast . insertTrack ( track . consume ( ) ) ;
172- effect . cleanup ( ( ) => this . broadcast . removeTrack ( track . name ) ) ;
168+ this . broadcast . insertTrack ( this . #track. consume ( ) ) ;
169+ effect . cleanup ( ( ) => {
170+ this . broadcast . removeTrack ( this . #track. name ) ;
171+ } ) ;
173172
174173 const settings = media . getSettings ( ) as AudioTrackSettings ;
175174
@@ -178,8 +177,8 @@ export class Audio {
178177
179178 const catalog : Catalog . Audio = {
180179 track : {
181- name : track . name ,
182- priority : u8 ( track . priority ) ,
180+ name : this . # track. name ,
181+ priority : u8 ( this . # track. priority ) ,
183182 } ,
184183 config : {
185184 // TODO get codec and description from decoderConfig
@@ -203,7 +202,7 @@ export class Audio {
203202
204203 if ( ! this . #group || frame . timestamp - this . #groupTimestamp >= 1000 * this . maxLatency ) {
205204 this . #group?. close ( ) ;
206- this . #group = track . appendGroup ( ) ;
205+ this . #group = this . # track. appendGroup ( ) ;
207206 this . #groupTimestamp = frame . timestamp ;
208207 }
209208
@@ -214,11 +213,17 @@ export class Audio {
214213 this . #group?. abort ( err ) ;
215214 this . #group = undefined ;
216215
217- track . abort ( err ) ;
216+ this . # track. abort ( err ) ;
218217 } ,
219218 } ) ;
220219 effect . cleanup ( ( ) => encoder . close ( ) ) ;
221220
221+ effect . cleanup ( ( ) => {
222+ this . #group?. close ( ) ;
223+ this . #group = undefined ;
224+ this . #groupTimestamp = 0 ;
225+ } ) ;
226+
222227 const config = catalog . config ;
223228
224229 encoder . configure ( {
@@ -256,5 +261,6 @@ export class Audio {
256261 close ( ) {
257262 this . #signals. close ( ) ;
258263 this . captions . close ( ) ;
264+ this . #track. close ( ) ;
259265 }
260266}
0 commit comments