⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 options.cpp

📁 采用公司系列的芯片
💻 CPP
字号:
/* * Copyright (C) 2005 WIS Technologies International Ltd. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and the associated README documentation file (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */// Option variables, modifiable from the command line:// Implementation#include "Options.hh"#include <GroupsockHelper.hh>#include <getopt.h>// Initialize option variables to default values:portNumBits rtspServerPortNum = 8554;char* streamDescription = strDup("RTSP/RTP stream from a WIS GO7007 encoder");UserAuthenticationDatabase* authDB = NULL;VideoFormat videoFormat = VFMT_MPEG4;int videoWidth = 640;int videoHeight = 480;int videoBitrate = 1500000;int videoIsPAL = 0;int videoInputDeviceNumber = 0;AudioFormat audioFormat = AFMT_PCM_RAW16;unsigned audioSamplingFrequency = 48000;int audioIsStereo = True;StreamingMode streamingMode = STREAMING_UNICAST;netAddressBits multicastAddress = 0;portNumBits videoRTPPortNum = 6000;portNumBits audioRTPPortNum = 6002;void checkArgs(UsageEnvironment& env, int argc, char** argv) {  while (1) {    int option_index = 0;    static struct option long_options[] = {      // videoFormat:      {"nv", 0, 0, 0},      {"mjpeg", 0, 0, 0},      {"mpeg1", 0, 0, 0},      {"mpeg2", 0, 0, 0},      {"mpeg4", 0, 0, 0},      // videoIsPAL:      {"pal", 0, 0, 0},      // audioFormat:      {"na", 0, 0, 0},      {"pcm", 0, 0, 0},      {"ulaw", 0, 0, 0},      {0, 0, 0, 0}    };    int c = getopt_long_only(argc, argv, "p:D:u:w:h:r:d:f:MmA:v:a:",			     long_options, &option_index);    if (c == -1) break;    switch (c) {    case 0: {      // Process 'long' options:      char const* option = long_options[option_index].name;      // videoFormat:      if (strcmp(option, "nv") == 0) videoFormat = VFMT_NONE;      else if (strcmp(option, "mjpeg") == 0) videoFormat = VFMT_MJPEG;      else if (strcmp(option, "mpeg1") == 0) videoFormat = VFMT_MPEG1;      else if (strcmp(option, "mpeg2") == 0) videoFormat = VFMT_MPEG2;      else if (strcmp(option, "mpeg4") == 0) videoFormat = VFMT_MPEG4;      // videoIsPAL:      else if (strcmp(option, "pal") == 0) videoIsPAL = 1;      // audioFormat:      else if (strcmp(option, "na") == 0) audioFormat = AFMT_NONE;      else if (strcmp(option, "pcm") == 0) audioFormat = AFMT_PCM_RAW16;      else if (strcmp(option, "ulaw") == 0) audioFormat = AFMT_PCM_ULAW;      break;    }      // rtspServerPortNum:    case 'p': {      int rtspServerPortNumArg;      if (sscanf(optarg, "%d", &rtspServerPortNumArg) == 1	  && rtspServerPortNumArg > 0 && rtspServerPortNumArg < 65536) {	rtspServerPortNum = rtspServerPortNumArg;      } else {	fprintf(stderr, "Invalid RTSP port num argument: %s\n", optarg);      }      break;    }      // streamDescription:    case 'D': {      streamDescription = strDup(optarg);      break;    }      // authDB:    case 'u': {      // Parse "optarg" for a colon, indicating username:password       char* username = optarg;      char* password;      for (password = optarg; *password != '\0'; ++password) {	if (*password == ':') {	  *password++ = '\0';	  break;	}      }      if (authDB == NULL) authDB = new UserAuthenticationDatabase(streamDescription);      authDB->addUserRecord(username, password);      break;    }      // videoWidth:    case 'w': {      int videoWidthArg;      if (sscanf(optarg, "%d", &videoWidthArg) == 1	  && videoWidthArg > 0) {	videoWidth = videoWidthArg;      } else {	fprintf(stderr, "Invalid video width argument: %s\n", optarg);      }      break;    }      // videoHeight:    case 'h': {      int videoHeightArg;      if (sscanf(optarg, "%d", &videoHeightArg) == 1	  && videoHeightArg > 0) {	videoHeight = videoHeightArg;      } else {	fprintf(stderr, "Invalid video height argument: %s\n", optarg);      }      break;    }      // videoBitrate:    case 'r': {      int videoBitrateArg;      if (sscanf(optarg, "%d", &videoBitrateArg) == 1	  && videoBitrateArg > 0) {	videoBitrate = videoBitrateArg;      } else {	fprintf(stderr, "Invalid video bitrate argument: %s\n", optarg);      }      break;    }      // videoInputDeviceNumber:    case 'd': {      int videoInputDeviceNumberArg;      if (sscanf(optarg, "%d", &videoInputDeviceNumberArg) == 1	  && videoInputDeviceNumberArg >= 0) {	videoInputDeviceNumber = videoInputDeviceNumberArg;      } else {	fprintf(stderr, "Invalid video input device number argument: %s\n", optarg);      }      break;    }      // audioSamplingFrequency:    case 'f': {      int audioSamplingFrequencyArg;      if (sscanf(optarg, "%d", &audioSamplingFrequencyArg) == 1	  && audioSamplingFrequencyArg > 0) {	audioSamplingFrequency = audioSamplingFrequencyArg;      } else {	fprintf(stderr, "Invalid audio sampling frerquency argument: %s\n", optarg);      }      break;    }      // audioIsStereo:    case 'M': {      audioIsStereo = 0;      break;    }      // streamingMode:    case 'm': {      streamingMode = STREAMING_MULTICAST_SSM;      break;    }      // multicastAddress:    case 'A': {      netAddressBits addr = our_inet_addr(optarg);      if (IsMulticastAddress(addr)) {	multicastAddress = addr;      } else {	fprintf(stderr, "Invalid multicast address: %s\n", optarg);      }      break;    }      // videoRTPPortNum:    case 'v': {      int videoRTPPortNumArg;      if (sscanf(optarg, "%d", &videoRTPPortNumArg) == 1	  && videoRTPPortNumArg > 0 && videoRTPPortNumArg < 65536	  && (videoRTPPortNumArg&1) == 0) {	videoRTPPortNum = videoRTPPortNumArg;      } else {	fprintf(stderr, "Invalid video RTP port num argument: %s", optarg);	if ((videoRTPPortNumArg&1) != 0) fprintf(stderr, " (must be even)");	fprintf(stderr, "\n");      }      break;    }      // audioRTPPortNum:    case 'a': {      int audioRTPPortNumArg;      if (sscanf(optarg, "%d", &audioRTPPortNumArg) == 1	  && audioRTPPortNumArg > 0 && audioRTPPortNumArg < 65536	  && (audioRTPPortNumArg&1) == 0) {	audioRTPPortNum = audioRTPPortNumArg;      } else {	fprintf(stderr, "Invalid audio RTP port num argument: %s", optarg);	if ((audioRTPPortNumArg&1) != 0) fprintf(stderr, " (must be even)");	fprintf(stderr, "\n");      }      break;    }    default: {      printf ("?? getopt returned character '%c' ??\n", c);    }    }  }  if (optind < argc) {    printf ("Warning: Ignoring non-option command-line arguments: ");    while (optind < argc)      printf ("%s ", argv[optind++]);    printf ("\n");  }  // Determine whether we're streaming multicast, and if so, what flavor:  if (streamingMode == STREAMING_MULTICAST_SSM) {    if (multicastAddress == 0) multicastAddress = chooseRandomIPv4SSMAddress(env);  } else if (multicastAddress != 0) {    streamingMode = STREAMING_MULTICAST_ASM;  } else streamingMode = STREAMING_UNICAST;}void reclaimArgs() {  delete authDB;  delete[] streamDescription;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -