src/libtsduck/plugin/tsInputSwitcherArgs.cpp
bool ts::InputSwitcherArgs::loadArgs(DuckContext& duck, Args& args)
{
    appName = args.appName();
    fastSwitch = args.present(u"fast-switch");
    delayedSwitch = args.present(u"delayed-switch");
    terminate = args.present(u"terminate");
    cycleCount = args.intValue<size_t>(u"cycle", args.present(u"infinite") ? 0 : 1);
    monitor = args.present(u"monitor");
    bufferedPackets = args.intValue<size_t>(u"buffer-packets", DEFAULT_BUFFERED_PACKETS);
    maxInputPackets = std::min(args.intValue<size_t>(u"max-input-packets", DEFAULT_MAX_INPUT_PACKETS), bufferedPackets / 2);
    maxOutputPackets = args.intValue<size_t>(u"max-output-packets", DEFAULT_MAX_OUTPUT_PACKETS);
    const UString remoteName(args.value(u"remote"));
    reusePort = !args.present(u"no-reuse-port");
    sockBuffer = args.intValue<size_t>(u"udp-buffer-size");
    firstInput = args.intValue<size_t>(u"first-input", 0);
    primaryInput = args.intValue<size_t>(u"primary-input", NPOS);
    receiveTimeout = args.intValue<MilliSecond>(u"receive-timeout", primaryInput >= inputs.size() ? 0 : DEFAULT_RECEIVE_TIMEOUT);

    // Check conflicting modes.
    if (args.present(u"cycle") + args.present(u"infinite") + args.present(u"terminate") > 1) {
        args.error(u"options --cycle, --infinite and --terminate are mutually exclusive");
    }
    if (fastSwitch && delayedSwitch) {
        args.error(u"options --delayed-switch and --fast-switch are mutually exclusive");
    }

    // Resolve remote control name.
    if (!remoteName.empty() && remoteServer.resolve(remoteName, args) && !remoteServer.hasPort()) {
        args.error(u"missing UDP port number in --remote");
    }

    // Resolve all allowed remote.
    UStringVector remotes;
    args.getValues(remotes, u"allow");
    allowedRemote.clear();
    for (auto it = remotes.begin(); it != remotes.end(); ++it) {
        const IPAddress addr(*it, args);
        if (addr.hasAddress()) {
            allowedRemote.insert(addr);
        }
    }

    // Load all plugin descriptions. Default output is the standard output file.
    ArgsWithPlugins* pargs = dynamic_cast<ArgsWithPlugins*>(&args);
    if (pargs != nullptr) {
        pargs->getPlugins(inputs, INPUT_PLUGIN);
        pargs->getPlugin(output, OUTPUT_PLUGIN, u"file");
    }
    else {
        inputs.clear();
        output.set(u"file");
    }
    if (inputs.empty()) {
        // If no input plugin is used, used only standard input.
        inputs.push_back(PluginOptions(u"file"));
    }

    // Check validity of input indexes.
    if (firstInput >= inputs.size()) {
        args.error(u"invalid input index for --first-input %d", {firstInput});
    }

    if (primaryInput != NPOS && primaryInput >= inputs.size()) {
        args.error(u"invalid input index for --primary-input %d", {primaryInput});
    }

    return args.valid();
}
//----------------------------------------------------------------------------
// Load arguments from command line.
//----------------------------------------------------------------------------
Load arguments from command line.
Load arguments from command line .
bool ts::InputSwitcherArgs::loadArgs(DuckContext& duck, Args& args)
{
    appName = args.appName();
    fastSwitch = args.present(u"fast-switch");
    delayedSwitch = args.present(u"delayed-switch");
    terminate = args.present(u"terminate");
    cycleCount = args.intValue<size_t>(u"cycle", args.present(u"infinite") ? 0 : 1);
    monitor = args.present(u"monitor");
    bufferedPackets = args.intValue<size_t>(u"buffer-packets", DEFAULT_BUFFERED_PACKETS);
    maxInputPackets = std::min(args.intValue<size_t>(u"max-input-packets", DEFAULT_MAX_INPUT_PACKETS), bufferedPackets / 2);
    maxOutputPackets = args.intValue<size_t>(u"max-output-packets", DEFAULT_MAX_OUTPUT_PACKETS);
    const UString remoteName(args.value(u"remote"));
    reusePort = !args.present(u"no-reuse-port");
    sockBuffer = args.intValue<size_t>(u"udp-buffer-size");
    firstInput = args.intValue<size_t>(u"first-input", 0);
    primaryInput = args.intValue<size_t>(u"primary-input", NPOS);
    receiveTimeout = args.intValue<MilliSecond>(u"receive-timeout", primaryInput >= inputs.size() ? 0 : DEFAULT_RECEIVE_TIMEOUT);
    if (args.present(u"cycle") + args.present(u"infinite") + args.present(u"terminate") > 1) {
        args.error(u"options --cycle, --infinite and --terminate are mutually exclusive");
    }
    if (fastSwitch && delayedSwitch) {
        args.error(u"options --delayed-switch and --fast-switch are mutually exclusive");
    }
    if (!remoteName.empty() && remoteServer.resolve(remoteName, args) && !remoteServer.hasPort()) {
        args.error(u"missing UDP port number in --remote");
    }
    UStringVector remotes;
    args.getValues(remotes, u"allow");
    allowedRemote.clear();
    for (auto it = remotes.begin(); it != remotes.end(); ++it) {
        const IPAddress addr(*it, args);
        if (addr.hasAddress()) {
            allowedRemote.insert(addr);
        }
    }
    ArgsWithPlugins* pargs = dynamic_cast<ArgsWithPlugins*>(&args);
    if (pargs != nullptr) {
        pargs->getPlugins(inputs, INPUT_PLUGIN);
        pargs->getPlugin(output, OUTPUT_PLUGIN, u"file");
    }
    else {
        inputs.clear();
        output.set(u"file");
    }
    if (inputs.empty()) {
        inputs.push_back(PluginOptions(u"file"));
    }
    if (firstInput >= inputs.size()) {
        args.error(u"invalid input index for --first-input %d", {firstInput});
    }
    if (primaryInput != NPOS && primaryInput >= inputs.size()) {
        args.error(u"invalid input index for --primary-input %d", {primaryInput});
    }
    return args.valid();
}
bool ts :: InputSwitcherArgs :: loadArgs ( DuckContext & duck , Args & args ) { appName = args . appName ( ) ; fastSwitch = args . present ( u" " ) ; delayedSwitch = args . present ( u" " ) ; terminate = args . present ( u" " ) ; cycleCount = args . intValue < size_t > ( u" " , args . present ( u" " ) ? 0 : 1 ) ; monitor = args . present ( u" " ) ; bufferedPackets = args . intValue < size_t > ( u" " , DEFAULT_BUFFERED_PACKETS ) ; maxInputPackets = std :: min ( args . intValue < size_t > ( u" " , DEFAULT_MAX_INPUT_PACKETS ) , bufferedPackets / 2 ) ; maxOutputPackets = args . intValue < size_t > ( u" " , DEFAULT_MAX_OUTPUT_PACKETS ) ; const UString remoteName ( args . value ( u" " ) ) ; reusePort = ! args . present ( u" " ) ; sockBuffer = args . intValue < size_t > ( u" " ) ; firstInput = args . intValue < size_t > ( u" " , 0 ) ; primaryInput = args . intValue < size_t > ( u" " , NPOS ) ; receiveTimeout = args . intValue < MilliSecond > ( u" " , primaryInput >= inputs . size ( ) ? 0 : DEFAULT_RECEIVE_TIMEOUT ) ; if ( args . present ( u" " ) + args . present ( u" " ) + args . present ( u" " ) > 1 ) { args . error ( u" " ) ; } if ( fastSwitch && delayedSwitch ) { args . error ( u" " ) ; } if ( ! remoteName . empty ( ) && remoteServer . resolve ( remoteName , args ) && ! remoteServer . hasPort ( ) ) { args . error ( u" " ) ; } UStringVector remotes ; args . getValues ( remotes , u" " ) ; allowedRemote . clear ( ) ; for ( auto it = remotes . begin ( ) ; it != remotes . end ( ) ; ++ it ) { const IPAddress addr ( * it , args ) ; if ( addr . hasAddress ( ) ) { allowedRemote . insert ( addr ) ; } } ArgsWithPlugins * pargs = dynamic_cast < ArgsWithPlugins * > ( & args ) ; if ( pargs != nullptr ) { pargs -> getPlugins ( inputs , INPUT_PLUGIN ) ; pargs -> getPlugin ( output , OUTPUT_PLUGIN , u" " ) ; } else { inputs . clear ( ) ; output . set ( u" " ) ; } if ( inputs . empty ( ) ) { inputs . push_back ( PluginOptions ( u" " ) ) ; } if ( firstInput >= inputs . size ( ) ) { args . error ( u" " , { firstInput } ) ; } if ( primaryInput != NPOS && primaryInput >= inputs . size ( ) ) { args . error ( u" " , { primaryInput } ) ; } return args . valid ( ) ; }
Load arguments from command line.
Load arguments from command line .
// Check conflicting modes. // Resolve remote control name. // Resolve all allowed remote. // Load all plugin descriptions. Default output is the standard output file. // If no input plugin is used, used only standard input. // Check validity of input indexes.