@@ -136,25 +136,6 @@ static void qe_close(void *f, phi_track *t)
136136 if (e -> trk == t ) {
137137 e -> trk = NULL ;
138138
139- if (e -> q && !e -> q -> conf .conversion && !e -> pub .meta_priority ) {
140- int mod = (META_LEN (& e -> pub .meta ) || META_LEN (& t -> meta )); // empty meta == not modified
141- if (META_LEN (& t -> meta )) {
142- fflock_lock ((fflock * )& e -> pub .lock ); // UI thread may read or write `conf.meta` at this moment
143- core -> metaif -> destroy (& e -> pub .meta );
144- e -> pub .meta = t -> meta ; // Remember the tags we read from file in this track
145- fflock_unlock ((fflock * )& e -> pub .lock );
146- meta_zero (& t -> meta );
147- }
148-
149- if (t -> audio .total != ~0ULL && t -> audio .format .rate ) {
150- uint64 duration_msec = samples_to_msec (t -> audio .total , t -> audio .format .rate );
151- e -> pub .length_sec = duration_msec / 1000 ;
152- }
153-
154- if (mod )
155- q_modified (e -> q );
156- }
157-
158139 if (e -> expand || t -> meta_reading )
159140 core -> track -> stop (t );
160141 }
@@ -193,6 +174,45 @@ static const phi_filter phi_queue_guard = {
193174 "queue-guard"
194175};
195176
177+
178+ static int qagt_process (void * f , phi_track * t )
179+ {
180+ struct q_entry * e = t -> qent ;
181+
182+ // 't->meta' currently contains the metadata read from file
183+
184+ if (META_LEN (& e -> pub .meta ) && e -> pub .meta_priority )
185+ core -> metaif -> copy (& t -> meta , & e -> pub .meta , PHI_META_REPLACE ); // Copy tags from .cue, e.g. `TITLE value`
186+
187+ if (t -> meta_changed && !e -> pub .meta_priority ) {
188+
189+ if (t -> audio .total != ~0ULL && t -> audio .format .rate )
190+ e -> pub .length_sec = samples_to_msec (t -> audio .total , t -> audio .format .rate ) / 1000 ;
191+
192+ if (META_LEN (& e -> pub .meta ) || META_LEN (& t -> meta )) { // empty meta == not modified
193+ fflock_lock ((fflock * )& e -> pub .lock ); // UI thread may read or write `meta` at this moment
194+ core -> metaif -> destroy (& e -> pub .meta );
195+ core -> metaif -> copy (& e -> pub .meta , & t -> meta , 0 ); // Remember the tags we read from file
196+ fflock_unlock ((fflock * )& e -> pub .lock );
197+ q_modified (e -> q );
198+ }
199+ }
200+
201+ if (META_LEN (& e -> q -> conf .tconf .meta ))
202+ core -> metaif -> copy (& t -> meta , & e -> q -> conf .tconf .meta , PHI_META_REPLACE ); // Copy tags from user, e.g. `convert -m title=...`
203+
204+ // 't->meta' contains the aggregated metadata from user + from .cue + from file
205+
206+ t -> data_out = t -> data_in ;
207+ return !(t -> chain_flags & PHI_FFIRST ) ? PHI_OK : PHI_DONE ;
208+ }
209+
210+ static const phi_filter queue_agent = {
211+ NULL , NULL , qagt_process ,
212+ "queue-agent"
213+ };
214+
215+
196216static int qe_play (struct q_entry * e )
197217{
198218 if (e -> expand ) {
@@ -215,13 +235,15 @@ static int qe_play(struct q_entry *e)
215235 && !track -> filter (t , e -> q -> conf .first_filter , 0 ))
216236 goto err ;
217237
238+ track -> filter (t , & phi_queue_guard , 0 );
239+ track -> filter (t , core -> mod ("core.auto-input" ), 0 );
240+
218241 if (e -> q -> conf .conversion ) {
219- if (!track -> filter (t , & phi_queue_guard , 0 )
220- || !track -> filter (t , core -> mod ("core.auto-input" ), 0 )
221- || !track -> filter (t , core -> mod ("format.detect" ), 0 )
242+ if (!track -> filter (t , core -> mod ("format.detect" ), 0 )
222243 || !track -> filter (t , core -> mod ("afilter.until" ), 0 )
223244 || (c .afilter .danorm
224245 && !track -> filter (t , core -> mod ("af-danorm.f" ), 0 ))
246+ || !track -> filter (t , & queue_agent , 0 )
225247 || !track -> filter (t , ui_if , 0 )
226248 || (c .afilter .gain_db
227249 && !track -> filter (t , core -> mod ("afilter.gain" ), 0 ))
@@ -232,10 +254,9 @@ static int qe_play(struct q_entry *e)
232254 t -> output .allow_async = 1 ;
233255
234256 } else if (e -> q -> conf .analyze ) {
235- if (!track -> filter (t , & phi_queue_guard , 0 )
236- || !track -> filter (t , core -> mod ("core.auto-input" ), 0 )
237- || !track -> filter (t , core -> mod ("format.detect" ), 0 )
257+ if (!track -> filter (t , core -> mod ("format.detect" ), 0 )
238258 || !track -> filter (t , core -> mod ("afilter.until" ), 0 )
259+ || !track -> filter (t , & queue_agent , 0 )
239260 || !track -> filter (t , ui_if , 0 )
240261 || ((c .afilter .peaks_info
241262 || c .afilter .loudness_summary )
@@ -247,12 +268,11 @@ static int qe_play(struct q_entry *e)
247268 goto err ;
248269
249270 } else {
250- if (!track -> filter (t , & phi_queue_guard , 0 )
251- || !track -> filter (t , core -> mod ("core.auto-input" ), 0 )
252- || (c .tee && !c .tee_output
271+ if ((c .tee && !c .tee_output
253272 && !track -> filter (t , core -> mod ("core.tee" ), 0 ))
254273 || !track -> filter (t , core -> mod ("format.detect" ), 0 )
255274 || !track -> filter (t , core -> mod ("afilter.until" ), 0 )
275+ || !track -> filter (t , & queue_agent , 0 )
256276 || !track -> filter (t , ui_if , 0 )
257277 || (c .afilter .rg_normalizer
258278 && !track -> filter (t , core -> mod ("afilter.rg-norm" ), 0 ))
@@ -270,11 +290,6 @@ static int qe_play(struct q_entry *e)
270290 goto err ;
271291 }
272292
273- if (META_LEN (& e -> q -> conf .tconf .meta ))
274- core -> metaif -> copy (& t -> meta , & e -> q -> conf .tconf .meta , 0 ); // from user
275- if (META_LEN (& e -> pub .meta ) && e -> pub .meta_priority )
276- core -> metaif -> copy (& t -> meta , & e -> pub .meta , (META_LEN (& e -> q -> conf .tconf .meta )) ? PHI_META_UNIQUE : 0 ); // from .cue
277-
278293 e -> trk = t ;
279294 e -> used ++ ;
280295 e -> q -> active_n ++ ;
0 commit comments