📄 intf_ctrl.c
字号:
/***************************************************************************** * intf_ctrl.c: interface commands access to control functions * Library of functions common to all interfaces, allowing access to various * structures and settings. Interfaces should only use those functions * to read or write informations from other threads. * A control function must be declared in the `local prototypes' section (it's * type is fixed), and copied into the control_command array. Functions should * be listed in alphabetical order, so when `help' is called they are also * displayed in this order. * A control function can use any function of the program, but should respect * two points: first, it should not block, since if it does so, the whole * interface thread will hang and in particular miscelannous interface events * won't be handled. Secondly, it should send it's output messages exclusively * with intf_IntfMsg() function, except particularly critical messages which * can use over intf_*Msg() functions. * Control functions should return 0 (INTF_NO_ERROR) on success, or one of the * error codes defined in command.h. Custom error codes are allowed, but should * be positive. * More informations about parameters stand in `list of commands' section. ***************************************************************************** * Copyright (C) 1999, 2000 VideoLAN * * Authors: * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. *****************************************************************************//***************************************************************************** * Preamble *****************************************************************************/#include "defs.h"#include <sys/types.h> /* on BSD, uio.h needs types.h */#include <sys/stat.h> /* on BSD, fstat() needs stat.h */#include <sys/uio.h> /* "input.h" */#include <stdio.h> /* fprintf() */#include <stdlib.h> /* malloc(), free() */#include <unistd.h> /* close(), read() */#include <fcntl.h> /* open() *//* Common headers */#include "config.h"#include "common.h"#include "threads.h"#include "mtime.h"#include "debug.h"#include "plugins.h"#include "intf_msg.h"#include "input.h"#include "audio_output.h"#include "intf_cmd.h"#include "interface.h"#include "main.h"/* * Local prototypes */static int Demo ( int i_argc, intf_arg_t *p_argv );static int DisplayImage ( int i_argc, intf_arg_t *p_argv );static int Exec ( int i_argc, intf_arg_t *p_argv );static int Help ( int i_argc, intf_arg_t *p_argv );static int PlayAudio ( int i_argc, intf_arg_t *p_argv );static int PlayVideo ( int i_argc, intf_arg_t *p_argv );static int Quit ( int i_argc, intf_arg_t *p_argv );static int SelectPID ( int i_argc, intf_arg_t *p_argv );static int SpawnInput ( int i_argc, intf_arg_t *p_argv );#ifdef DEBUGstatic int Test ( int i_argc, intf_arg_t *p_argv );#endifstatic int Vlan ( int i_argc, intf_arg_t *p_argv );static int Psi ( int i_argc, intf_arg_t *p_argv );/* * List of commands. * This list is used by intf_ExecCommand function to find functions to * execute and prepare its arguments. It is terminated by an element which name * is a null pointer. intf_command_t is defined in command.h. * * Here is a description of a command description elements: * name is the name of the function, as it should be typed on command line, * function is a pointer to the control function, * format is an argument descriptor (see below), * summary is a text string displayed in regard of the command name when `help' * is called without parameters, and whith usage on syntax error, * usage is a short syntax indicator displayed with summary when the command * causes a syntax error, * help is a complete help about the command, displayed when `help' is called with * the command name as parameter. * * Format string is a list of ' ' separated strings, which have following * meanings: * s string argument * i integer argument * f float argument * ? optionnal argument * * argument can be repeated * name= named argument * Example: "channel=i? s*? i " means that any number of string arguments, * followed by a single mandatory integer argument are waited. A named argument, * which name is `channel' and must have an integer value can be optionnaly * specified at beginning. The last space is mandatory if there is at least one * element, since it acts as an item terminator. * Named arguments MUST be at the beginning of the format string, and in * alphabetic order, but their order on command line has no importance. * The format string can't have more than INTF_MAX_ARGS elements. */const intf_command_t control_command[] ={ { "demo", Demo, /* demo */ /* format: */ "", /* summary: */ "program demonstration", /* usage: */ "demo", /* help: */ "Start program capabilities demonstration." }, { "display", DisplayImage, /* display */ /* format: */ "s ", /* summary: */ "load and display an image", /* usage: */ "display <file>", /* help: */ "Load and display an image. Image format is automatically "\ "identified from file name extension." }, { "exec", Exec, /* exec */ /* format: */ "s ", /* summary: */ "execute a script file", /* usage: */ "exec <file>", /* help: */ "Load an execute a script." }, { "exit", Quit, /* exit (quit alias) */ /* format: */ "", /* summary: */ "quit program", /* usage: */ "exit", /* help: */ "see `quit'." }, { "help", Help, /* help */ /* format: */ "s? ", /* summary: */ "list all functions or print help about a specific function", /* usage: */ "help [command]", /* help: */ "If called without argument, list all available " \ " functions.\nIf a command name is provided as argument, displays a short "\ "inline help about the command.\n" }, { "play-audio", PlayAudio, /* play-audio */ /* format: */ "channels=i? rate=i? s ", /* summary: */ "play an audio file", /* usage: */ "play-audio [channels=1/2] [rate=r] <file>", /* help: */ "Load and play an audio file." }, { "play-video", PlayVideo, /* play-video */ /* format: */ "s ", /* summary: */ "play a video (.vlp) file", /* usage: */ "play-video <file>", /* help: */ "Load and play a video file." }, { "quit", Quit, /* quit */ /* format: */ "", /* summary: */ "quit program", /* usage: */ "quit", /* help: */ "Terminates the program execution... There is not much to"\ " say about it !" }, { "select-pid", SelectPID, /* select-pid */ /* format: */ "i i ", /* summary: */ "spawn a decoder thread for a specified PID", /* summary: */ "select-pid <input> <pid>", /* help: */ "Spawn a decoder thread for <pid>. The stream will be" \ " received by <input>." }, { "spawn-input", SpawnInput, /* spawn-input */ /* format: */ "method=i? filename=s? hostname=s? ip=s? port=i? vlan=i?", /* summary: */ "spawn an input thread", /* summary: */ "spawn-input [method=<method>]\n" \ "[filename=<file>|hostname=<hostname>|ip=<ip>]\n" \ "[port=<port>] [vlan=<vlan>]", /* help: */ "Spawn an input thread. Method is 10, 20, 21, 22, 32, "\ "hostname is the fully-qualified domain name, ip is a dotted-decimal address." },#ifdef DEBUG { "test", Test, /* test */ /* format: */ "i? ", /* summary: */ "crazy developper's test", /* usage: */ "depends on the last coder :-)", /* help: */ "`test' works only in DEBUG mode, and is provide for " \ "developpers as an easy way to test part of their code. If you don't know "\ "what it should do, just try !" },#endif { "vlan", Vlan, /* format: */ "intf=s? s i? ", /* summary: */ "vlan operations", /* usage: */ "vlan synchro\n" \ "vlan [intf=<interface>] request\n" \ "vlan [intf=<interface>] join <vlan>\n" \ "vlan [intf=<interface>] leave", /* help: */ "Perform various operations on vlans. 'synchro' resynchronize " \ "with the server. 'request' ask which is the current vlan (for the default "\ "interface or for a given one). 'join' and 'leave' try to change vlan." }, { "psi", Psi, /* format: */ "i ", /* summary: */ "Dump PSI tables", /* usage: */ "psi <input thread index>", /* help: */ "Display the PSI tables on the console. Warning: this is debug" \ "command, it can leads to pb since locks are not taken yet" }, { 0, 0, 0, 0, 0 } /* array terminator */};/* following functions are local *//***************************************************************************** * Demo: demo ***************************************************************************** * This function is provided to display a demo of program possibilities. *****************************************************************************/static int Demo( int i_argc, intf_arg_t *p_argv ){ intf_IntfMsg( COPYRIGHT_MESSAGE ); return( INTF_NO_ERROR );}/***************************************************************************** * Exec: execute a script ***************************************************************************** * This function load and execute a script. *****************************************************************************/static int Exec( int i_argc, intf_arg_t *p_argv ){ int i_err; /* error code */ i_err = intf_ExecScript( p_argv[1].psz_str ); return( i_err ? INTF_OTHER_ERROR : INTF_NO_ERROR );}/***************************************************************************** * DisplayImage: load and display an image (ok ?) ***************************************************************************** * Try to load an image identified by it's filename and displays it as a still * image using interface video heap. *****************************************************************************/static int DisplayImage( int i_argc, intf_arg_t *p_argv ){ /* XXX?? */ return( INTF_NO_ERROR );}/***************************************************************************** * Help: list all available commands (ok ?) ***************************************************************************** * This function print a list of available commands *****************************************************************************/static int Help( int i_argc, intf_arg_t *p_argv ){ int i_index; /* command index */ /* If called with an argument: look for the command and display it's help */ if( i_argc == 2 ) {fprintf( stderr, "maxx debug: coin\n" ); for( i_index = 0; control_command[i_index].psz_name && strcmp( control_command[i_index].psz_name, p_argv[1].psz_str ); i_index++ ) { ; }fprintf( stderr, "maxx debug: meuh\n" ); /* Command has been found in list */ if( control_command[i_index].psz_name ) {fprintf( stderr, "maxx debug: meow\n" ); intf_IntfMsg( control_command[i_index].psz_usage );fprintf( stderr, "maxx debug: blah\n" ); intf_IntfMsg( control_command[i_index].psz_help );fprintf( stderr, "maxx debug: blih\n" ); } /* Command is unknown */ else { intf_IntfMsg("help: don't know command `%s'", p_argv[1].psz_str); return( INTF_OTHER_ERROR ); } } /* If called without argument: print all commands help field */ else { for( i_index = 0; control_command[i_index].psz_name; i_index++ ) { intf_IntfMsg( "%s: %s", control_command[i_index].psz_name, control_command[i_index].psz_summary ); } } return( INTF_NO_ERROR );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -