@@ -5296,11 +5296,37 @@ struct cmd_list_ctx {
5296
5296
int num_sub ;
5297
5297
};
5298
5298
5299
+ static bool substitute_args (struct MPContext * ctx , struct mp_cmd * cmd ,
5300
+ struct mpv_node * replace )
5301
+ {
5302
+ if (!cmd -> receive_pipe )
5303
+ return true;
5304
+
5305
+ // TODO: allow more types?
5306
+ if (replace -> format != MPV_FORMAT_STRING )
5307
+ return false;
5308
+
5309
+ for (int i = 0 ; i < cmd -> nargs ; ++ i ) {
5310
+ if (!cmd -> args [i ].substitute )
5311
+ continue ;
5312
+ int r = m_option_parse (ctx -> log , cmd -> args [i ].type , bstr0 (cmd -> name ),
5313
+ bstr0 (replace -> u .string ), & cmd -> args [i ].v );
5314
+ if (r < 0 )
5315
+ return false;
5316
+ }
5317
+ return true;
5318
+ }
5319
+
5299
5320
static void continue_cmd_list (struct cmd_list_ctx * list );
5300
5321
5301
5322
static void on_cmd_list_sub_completion (struct mp_cmd_ctx * cmd )
5302
5323
{
5303
5324
struct cmd_list_ctx * list = cmd -> on_completion_priv ;
5325
+ if (cmd -> cmd -> receive_pipe )
5326
+ mpv_free_node_contents (& list -> parent -> previous_result );
5327
+
5328
+ if (cmd -> cmd -> queue_next && cmd -> cmd -> queue_next -> receive_pipe )
5329
+ list -> parent -> previous_result = cmd -> result ;
5304
5330
5305
5331
if (list -> current_valid && mp_thread_id_equal (list -> current_tid , mp_thread_current_id ())) {
5306
5332
list -> completed_recursive = true;
@@ -5327,6 +5353,11 @@ static void continue_cmd_list(struct cmd_list_ctx *list)
5327
5353
list -> current_valid = true;
5328
5354
list -> current_tid = mp_thread_current_id ();
5329
5355
5356
+ if (!substitute_args (list -> mpctx , sub , & list -> parent -> previous_result )) {
5357
+ MP_ERR (list -> mpctx , "Pipe input for command '%s' could not be parse.\n" , sub -> name );
5358
+ talloc_free (sub );
5359
+ continue ;
5360
+ }
5330
5361
run_command (list -> mpctx , sub , NULL , on_cmd_list_sub_completion , list );
5331
5362
5332
5363
list -> current_valid = false;
@@ -5376,7 +5407,8 @@ void mp_cmd_ctx_complete(struct mp_cmd_ctx *cmd)
5376
5407
cmd -> on_completion (cmd );
5377
5408
if (cmd -> abort )
5378
5409
mp_abort_remove (cmd -> mpctx , cmd -> abort );
5379
- mpv_free_node_contents (& cmd -> result );
5410
+ if (!cmd -> cmd -> queue_next || !cmd -> cmd -> queue_next -> receive_pipe )
5411
+ mpv_free_node_contents (& cmd -> result );
5380
5412
talloc_free (cmd );
5381
5413
}
5382
5414
@@ -5440,6 +5472,11 @@ void run_command(struct MPContext *mpctx, struct mp_cmd *cmd,
5440
5472
mp_abort_add (mpctx , ctx -> abort );
5441
5473
}
5442
5474
5475
+ if (ctx -> on_completion_priv ) {
5476
+ struct cmd_list_ctx * list = ctx -> on_completion_priv ;
5477
+ ctx -> previous_result = list -> parent -> previous_result ;
5478
+ }
5479
+
5443
5480
struct MPOpts * opts = mpctx -> opts ;
5444
5481
ctx -> on_osd = cmd -> flags & MP_ON_OSD_FLAGS ;
5445
5482
bool auto_osd = ctx -> on_osd == MP_ON_OSD_AUTO ;
0 commit comments