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

📄 main.cc

📁 这个软件的功能同我上次传的那个avifile.也是linux上的一个用于多媒体应用的源码。
💻 CC
📖 第 1 页 / 共 3 页
字号:
	{		cropped_label = crop_whitespace(mixer_labels[i]);		if (!strcasecmp(mixdev, cropped_label))			{			found_label = 1;			free(cropped_label);			break;		}		free(cropped_label);		cropped_label = NULL;	}	if (!found_label)	{		close(mixer);		return set_error("Could not find mixer device.");	}			if (!(available_devs & (1 << i)))	{		close(mixer);		return set_error("Selected mixer device is not a valid recording device.");	}	if (!(available_recdevs & (1 << i)))	{		ostringstream s;		s << "WARNING: " << dev << ":" << mixdev << " is not a recording device.";		vcr_notice(s);	}		unsigned int		recdevs;	//ioctl(mixer, MIXER_READ(SOUND_MIXER_RECSRC), &recdevs);	recdevs = (1 << (unsigned int)i);	ioctl(mixer, MIXER_WRITE(SOUND_MIXER_RECSRC), &recdevs);	//now, set the volume.	//TODO: UNMUTE	unsigned int		mixvolume = (volume & 0xff) + ((volume & 0xff) << 8);	ioctl(mixer, MIXER_WRITE(i), &mixvolume);	close(mixer);	return 1;}/* Gets the 'channel' and 'fine' settings for the preset from the xawtv, * calculates the frequency using those 2 values, and sets the tuner. */shortset_tuner_frequency(const char *preset){	char		*cname = cfg_get_str(preset, "channel");	int		fine = cfg_get_int(preset, "fine");		if (!cname || !strcmp(cname, "none"))		return 0;	int		channel = lookup_channel(cname);	if (channel < 0)		return 0;	int freq = get_freq(channel);		if (freq < 0)		return 0;		freq += fine;	v4l->setFreq(freq);	v4l->setChannelNorm(normID); //always do that after changing tuner/channel	return 1;}intget_codec_index(int fourcc){	avm::vector<const CodecInfo*>::const_iterator it;	avm::vector<const CodecInfo*> codecList;	int i = 0;	CodecInfo::Get(codecList);	for (it = codecList.begin(); it != codecList.end(); it++)	{		if ((*it)->fourcc == (unsigned)fourcc)			return i;		i++;	}	return -1;}//TODO: It ignores fourcc currently..shortset_attribute(int fourcc, const char *attr, const char *val){	int retval = 0;	avm::vector<AttributeInfo>::const_iterator it;	int idx = get_codec_index(fourcc);	if (idx < 0)		return 0;	avm::vector<const CodecInfo*> codecList;	CodecInfo::Get(codecList);	avm::vector<AttributeInfo> encinfo = codecList[idx]->encoder_info;	for (it = encinfo.begin(); it != encinfo.end(); it++)	{		if (strcasecmp(attr, it->GetName()))			continue; //wrong attribute.		switch(it->kind)		{		case AttributeInfo::Integer:			SetCodecAttr(*(codecList[idx]), it->GetName(), atoi(val));			break;		case AttributeInfo::String:			SetCodecAttr(*(codecList[idx]), it->GetName(), val);			break;		case AttributeInfo::Select:			SetCodecAttr(*(codecList[idx]), it->GetName(), val);			break;		case AttributeInfo::Float:		default:			break;		}		retval = 1;		break;	}	return retval;}shortset_attributes(int fourcc){	int i;	for (i = 0; i < attr_count; i++)	{		if (!set_attribute(fourcc, attributes[i].name, attributes[i].val))			return 0;	}	return 1;}shortset_freqtab(const char *f){	int		i = 0;	short		found_tab = 0;		while (chanlist_names[i].nr != -1)	{		if (!strcmp(chanlist_names[i].str, f)) //freqtab found		{			chantab = int(chanlist_names[i].nr);			chanlist = chanlists[chantab].list;			chancount = chanlists[chantab].count;			found_tab = 1;			break;		}		i++;	}	return found_tab;}shortset_window_size(){	// check window	int vidres = 0;		while (restable[vidres].res != videores && restable[vidres].res != WNONE)		vidres++;	if (restable[vidres].res == videores)	{		if (window.x == -1)		{			char bla[100];			sprintf(bla, "Setting window size to %i x %i\n",				restable[vidres].width, restable[vidres].height);			vcr_debug(bla);			window.x = 0;			window.y = 0;			window.width = restable[vidres].width;			window.height = restable[vidres].height;		}					if ( (window.x + window.width > restable[vidres].width)			|| (window.y + window.height > restable[vidres].height)			|| window.width == 0 || window.height == 0 )		{			cerr << "Invalid capture window size (" << window.width << " x " <<				window.height << ") at offset (X,Y)=(" << window.x << ", " <<				window.y << ")! Must be bigger than 0x0 and smaller than the " <<				"original window (which is " << restable[vidres].width << " x " <<				restable[vidres].height << "." << endl;			return 0;		}	}	else //should never happen!	{		cerr << "Unknown video resolution. But you shouldn't see this." << endl;		return 0;		}	return 1;}intis_valid_preset(const char *p){	if (!p)		return 0;	int		found_preset = 0;	char **list;	for (list = cfg_list_sections(); *list != NULL; list++)	{		if (			!strcmp(*list, "defaults") ||			!strcmp(*list, "global") ||			!strcmp(*list, "launch") ||			strcasecmp(*list, p) ||			cfg_get_str(p, "codec") //existing section, but it's a codec preset			)			continue;		found_preset = 1;		break;	}	vcr_debug("Found valid preset.\n");	return found_preset;}intis_valid_codec_preset(const char *p){	if (!p)		return 0;	int		found_preset = 0;	char **list;	for (list = cfg_list_sections(); *list != NULL; list++)	{		if (			!strcmp(*list, "defaults") ||			!strcmp(*list, "global") ||			!strcmp(*list, "launch") ||			strcasecmp(*list, p) ||			!cfg_get_str(p, "codec")			)			continue;		found_preset = 1;		break;	}	vcr_debug("Found valid codec preset.\n");	return found_preset;}/* returns -1 if inputsource does not exist. * Otherwise, the inputsource's ID (for v4l->setChannel()) */intis_valid_inputsource(const char *src){	if (!src) //default to television		src = "Television";		int		i,	 	nrsources = v4l->capCapChannelC();	int		found_channel = -1;	for (i = 0; i < nrsources; i++)	{		if (!strcasecmp(v4l->capChannelName(i), src))		{			found_channel = i;		}	}	return found_channel;}/* read codec preset settings from config file */voidread_codec_presets(const char *p){	const char *tmpstr;	int tmpint;	float tmpfloat;	//since we always read a new codec, reset the attributes now.	clear_attributes();	if (attributes_str)	{		free(attributes_str);		attributes_str = NULL;	}	if ( (tmpstr = cfg_get_str(p, "codec")) )	{		if (codec_name)			free(codec_name);		codec_name = strdup(tmpstr);	}	if ( (tmpstr = cfg_get_str(p, "attributes")) )	{		if (attributes_str)			free(attributes_str);		attributes_str = strdup(tmpstr);	}	if ( (tmpint = cfg_get_int(p, "keyframes")) > -1 )		keyframes = tmpint;		if ((tmpint = cfg_get_int(p, "resolution")) > -1)		resolution = tmpint;	if ( (tmpint = cfg_get_int(p, "quality")) > -1 )		quality = tmpint;	if ((tmpstr = cfg_get_str(p, "audiomode")))	{		if (audio_mode)			free(audio_mode);		audio_mode = strdup(tmpstr);	}	if ( (tmpint = cfg_get_int(p, "audiofrequency")) > -1 )		audio_freq = tmpint;	if ( (tmpint = cfg_get_int(p, "audiosamplesize")) > -1 )		audio_size = tmpint; // 8 or 16	if ( (tmpfloat = cfg_get_float(p, "framerate")) > -1 )		fps = tmpfloat;	if ( (tmpint = cfg_get_int(p, "audiobitrate")) > -1 )		audio_bitrate = tmpint;	if (!window_str && (tmpstr = cfg_get_str(p, "window")))	{		if (window_str)		{			free(window_str);			window_str = NULL;		}		window_str = strdup(tmpstr);	}	if ( (tmpint = cfg_get_int(p, "splitsize"))  ) //can be -1 !		splitsize = tmpint;	if (splitsize < -1)		splitsize = -1;}/* parses argument to 'w' / 'window' */shortparse_window_string(){	int winval[4];	int count = 0;		vcr_debug("Scanning window string\n");		char 		*my_str = window_str;	while ( count < 4 && sscanf(my_str, "%i", &(winval[count]) ) )	{		bool cuted = false;		char bla[strlen(my_str)+100];		sprintf(bla, "	-> to value: %i\n", winval[count]);		vcr_debug(bla);		for (unsigned int i=0; i < strlen(my_str); i++)		{			if (tolower(my_str[i]) == ',')			{				unsigned int i2=0;				unsigned int old_length = strlen(my_str);				vcr_debug("  found _,_ - copy for next turn\n");						i++; //don't copy the ","				while (i+i2 < old_length+1) // +1 to copy post \0				{					my_str[i2] = my_str[i+i2];					i2++;				}				i = strlen(my_str);				cuted = true;			}		}		count++;		if (!cuted)			my_str [0] = 0;		sprintf(bla, "	%i - for next turn %s\n", count, my_str);		vcr_debug(bla);	}		if (count != 4 || strlen(my_str) > 0)		return 0;		free(my_str);	window_str = NULL;	my_str = NULL;		window.x = winval [0];	window.y = winval [1];	window.width = winval [2];	window.height = winval [3];		vcr_debug("END\n");	return 1;}/* Side effect: mangles argv */voidparse_arguments(int argc, char *argv[]){	int		c,		long_index;	static struct option long_options[] = 		{			{ "codec-attribute", 1, 0, 'a' },			{ "audiobitrate", 1, 0, 'b' },			{ "codec", 1, 0, 'c' },			{ "debug", 0, 0, 'd' },			{ "framerate", 1, 0, 'F' },			{ "config-file", 1, 0, 'f' },			{ "grabdevice", 1, 0, 'g' },			{ "help", 0, 0, 'h' },			{ "keyframes", 1, 0, 'k' },			{ "audiomode", 1, 0, 'm' },			{ "codec-preset", 1, 0, 'P' },			{ "preset", 1, 0, 'p' },			{ "quality", 1, 0, 'q' },			{ "resolution", 1, 0, 'r' },			{ "rectime", 1, 0, 't' },			{ "splitsize", 1, 0, 'S' },			{ "source", 1, 0, 's' },			{ "verbose", 0, 0, 'v' },			{ "window", 1, 0, 'w' },			{ 0, 0, 0, 0 }		};			while(1)	{		c = getopt_long_only(argc, argv, "a:b:c:d::F:f:g:hk:m:P:p:q:r:s:S:t:vw:",			long_options, &long_index);		if (c == EOF)			break;		switch(c)		{		case ':':		case '?':			usage();			end_program(1);			break;		case 'b': /* audiocompression */			if (!strcasecmp(optarg, "list"))			{				list_audiobitrates();				end_program(0);			}			audio_bitrate = atoi(optarg);				break;		case 'a': /* codec attributes */			if (codec_name && !strcasecmp(optarg, "list"))			{				int fourcc = is_valid_codec(codec_name);				if (fourcc != -1)				{					list_attributes(fourcc);					end_program(0);				}				else				{					cerr << "error: The codec name you have specified is invalid." <<						endl;					list_codecs();					end_program(1);				}			}			if (!add_attribute(optarg))			{				cerr << "error: invalid args to -a." << endl;				end_program(1);			}			break;		case 'c': /* codec */			if (!strcasecmp(optarg, "list"))			{				list_codecs();				end_program(0);			}			if (codec_name)				free(codec_name);			codec_name = strdup(optarg);			break;		case 'd': /* debug */			if (optarg)			{				if (debugfile)					free(debugfile);				debugfile = strdup(optarg);			}			want_debug = 1;			break;		case 'F': /* framerate */			fps = atoi(optarg);			break;		case 'f': /* config-file */			if (config_file)				free(config_file);			config_file = strdup(optarg);			break;		case 'g': /* grabber device */			if (grabdevice)				free(grabdevice);			grabdevice = strdup(optarg);			break;		case 'h': /* help */			usage();			end_program(0);		case 'k': /* keyframes */			keyframes = atoi(optarg);			break;		case 'm': /* audiomode */			audio_mode = strdup(optarg);			break;		case 'P': /* codec preset */			if (codec_preset)				free(codec_preset);			codec_preset = strdup(optarg);			break;		case 'p': /* tuner preset (taken from xawtv config file) */			if (preset)				free(preset);			preset = strdup(optarg);			break;		case 'q': /* quality */			quality = atoi(optarg);			break; 		case 'r': /* resolution */			if (!strcasecmp(optarg, "list"))			{				list_resolutions();				end_program(0);			}      resolution = atoi(optarg); 			break;		case 'S': /* splitsize */			splitsize = atoi(optarg);			break;		case 's': /* input source */			if (!strcasecmp(optarg, "list"))			{				list_sources();				end_program(0);			}			if (input_source)				free(input_source);			input_source = strdup(optarg);			break;		case 't': /* recording time */		{			if (rectime_str)				free(rectime_str);			rectime_str = strdup(optarg);		}			break;		case 'v': //verbose			verbose = 1;			break;		case 'w': /* window */			window_str = strdup(optarg);			break; 		break;		default:			usage();			end_program(1);		}	}	if (argc - optind > 1)	{		cerr << "Too many file arguments given." << endl;		end_program(1);	}		if (optind < argc) /* remaining argument = filename */	{					if (filename)			free(filename);		filename = strdup(argv[optind]);	}}/* called after reading config file & parsing cmdline args */voidverify_globals(){	int temp = 0;	if (codec_preset)	{		if (!is_valid_codec_preset(codec_preset))		{			cerr << "Invalid codec preset given." << endl;			list_codec_presets();			end_program(1);		}		else		{			vcr_notice("Reading codec preset.");			read_codec_presets(codec_preset);		}	}	if (!quality)		quality = 95;	if (quality < 1 || quality > 100)	{		cerr << "Quality out of range (range is 1..100, default 95)" << endl;		end_program(1);	}	if (!resolution)		resolution = 384;	if (!set_resolution(resolution))	{		cerr << "Invalid resolution given." << endl;		list_resolutions();		end_program(1);	}	//set channel *before* norm, and audio after norm/channel	if ((temp = is_valid_inputsource(input_source)) < 0)	{			cerr << "Invalid input source given." << endl;			list_sources();			end_program(1);	}	else		v4l->setChannel(temp);	if (norm && (temp = is_valid_norm(norm)) < 0)	{		cerr << "Invalid norm given!" << endl;		list_norms();		end_program(1);	}	else if (norm)		normID = temp;	if (normID < 0)		normID = 0; //default to PAL	v4l->setChannelNorm(normID);	if (!audio_freq)		audio_freq = 44;	switch(audio_freq)	{	case 44: soundfreq = F44; break;	case 22: soundfreq = F22; break;	case 11: soundfreq = F11; break;	default:		cerr << "Audio frequency not one of 44,22 or 11." << endl;		end_program(1);	}	if (!audio_size)		audio_size = 16;	switch(audio_size)	{	case 8: samplesize = S8; break;	case 16: samplesize = S16; break;	default:		cerr << "Audio sample size is neither 16 or 8." << endl;

⌨️ 快捷键说明

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