示例#1
0
AString ADVBConfig::ReplaceTerms(const AString& user, const AString& subitem, const AString& _str) const
{
	AString str = _str;
	int p1, p2;

	while (((p1 = str.Pos("{conf:")) >= 0) && ((p2 = str.Pos("}", p1)) >= 0)) {
		AString item = GetUserSubItemConfigItem(user, subitem, str.Mid(p1 + 6, p2 - p1 - 6));

		str = str.Left(p1) + item + str.Mid(p2 + 1);
	}

	return str;
}
示例#2
0
bool ADVBConfig::ReadReplacementsFile(std::vector<REPLACEMENT>& replacements, const AString& filename) const
{
	AStdFile fp;
	bool success = false;

	if (fp.open(filename)) {
		AString line;

		//printf("Reading replacements file '%s':", filename.str());

		while (line.ReadLn(fp) >= 0) {
			int p = 0;

			if ((line.Word(0)[0] != ';') && ((p = line.Pos("=")) >= 0)) {
				REPLACEMENT repl = {
					line.Left(p).Word(0).DeQuotify(),
					line.Mid(p + 1).Word(0).DeQuotify(),
				};

				//printf("Replacement: '%s' -> '%s'", repl.search.str(), repl.replace.str());

				replacements.push_back(repl);
			}
		}

		fp.close();

		success = true;
	}
	else logit("Failed to open replacements file '%s'", filename.str());

	return success;
}
示例#3
0
ADVBConfig::ADVBConfig() : config(AString(DEFAULTCONFDIR).CatPath("dvb"), false),
						   defaults(20, &AString::DeleteString),
						   webresponse(false)
{
	static const struct {
		const char *name;
		const char *value;
	} __defaults[] = {
		{"prehandle",  		 	"2"},
		{"posthandle", 		 	"3"},
		{"pri", 	   		 	"0"},
		{"dir",              	""},
		{"h264crf",      	 	"17"},
		{"maxvideorate", 	 	"2000k"},
		{"aacbitrate", 	 	 	"160k"},
		{"mp3bitrate", 	 	 	"160k"},
		{"copyvideo", 	 	 	"-vcodec copy"},
		{"copyaudio", 	 	 	"-acodec copy"},
		{"mp3audio",  	 	 	"-acodec mp3 -b:a {conf:mp3bitrate}"},
		{"h264preset",   	 	"veryfast"},
		{"h264bufsize",  	 	"3000k"},
		{"videodeinterlace", 	"yadif"},
		{"videofilter",  	 	"-filter:v {conf:videodeinterlace}"},
		{"filters",		 	 	"{conf:videofilter} {conf:audiofilter}"},
		{"encodeflags",	 	 	"-movflags +faststart"},
		{"h264video", 	 	 	"-vcodec libx264 -preset {conf:h264preset} -crf {conf:h264crf} -maxrate {conf:maxvideorate} -bufsize {conf:h264bufsize} {conf:encodeflags} {conf:filters}"},
		{"aacaudio",  	 	 	"-acodec libfdk_aac -b:a {conf:aacbitrate}"},
		{"encodecopy",   	 	"{conf:copyvideo} {conf:mp3audio}"},
		{"encodeh264",   	 	"{conf:h264video} {conf:aacaudio}"},
		{"encodeargs",   	 	"{conf:encodeh264}"},
		{"encodeaudioonlyargs", "{conf:mp3audio}"},
	};
	uint_t i;

	for (i = 0; i < NUMBEROF(__defaults); i++) {
		defaults.Insert(__defaults[i].name, (uptr_t)new AString(__defaults[i].value));
	}

	CreateDirectory(GetConfigDir());
	CreateDirectory(GetDataDir());
	CreateDirectory(GetLogDir());
	CreateDirectory(GetRecordingsStorageDir());
	CreateDirectory(GetRecordingsDir());
	CreateDirectory(GetTempDir());

	if (CommitScheduling()) {
		AList   users;
		AString dir;

		ListUsers(users);

		const AString *user = AString::Cast(users.First());
		while (user) {
			if (((dir = GetRecordingsDir(*user)).Valid())        && (dir.Pos("{") < 0)) CreateDirectory(dir);
			if (((dir = GetRecordingsArchiveDir(*user)).Valid()) && (dir.Pos("{") < 0)) CreateDirectory(dir);

			user = user->Next();
		}
	}
}
示例#4
0
void MotionDetector::Configure()
{
    AString nstr = AString("%").Arg(index);

    log.printf("%s[%u]: Reading new settings...\n", ADateTime().DateFormat("%Y-%M-%D %h:%m:%s.%S").str(), index);

    stream.Close();
    stream.SetUsernameAndPassword(GetSetting("username", "admin"),
                                  GetSetting("password", "arsebark"));

    AString camera = GetSetting("camera", "");
    log.printf("%s[%u]: Connecting to %s...\n", ADateTime().DateFormat("%Y-%M-%D %h:%m:%s.%S").str(), index, camera.str());
    if (!stream.OpenHost(camera)) {
        log.printf("%s[%u]: Failed to connect to %s...\n", ADateTime().DateFormat("%Y-%M-%D %h:%m:%s.%S").str(), index, camera.str());
    }

    imagedir  = GetSetting("imagedir", "/media/cctv");
    imagefmt  = GetSetting("filename", "%Y-%M-%D/%h/Image-{camera}-%Y-%M-%D-%h-%m-%s-%S");
    detimgdir = GetSetting("detimagedir");
    detimgfmt = GetSetting("detfilename", "%Y-%M-%D/%h/detection/Image-{camera}-%Y-%M-%D-%h-%m-%s-%S");
    detcmd    = GetSetting("detcommand", "");
    nodetcmd  = GetSetting("nodetcommand", "");
    coeff  	  = (double)GetSetting("coeff", "1.0e-3");
    avgfactor = (double)GetSetting("avgfactor", "1.0");
    sdfactor  = (double)GetSetting("sdfactor", "2.0");
    redscale  = (double)GetSetting("rscale", "1.0");
    grnscale  = (double)GetSetting("gscale", "1.0");
    bluscale  = (double)GetSetting("bscale", "1.0");
    threshold = (double)GetSetting("threshold", "3000.0");
    verbose   = (uint_t)GetSetting("verbose", "0");

    matmul 	  = 1.f;
    matwid 	  = mathgt = 0;

    AString _matrix = GetSetting("matrix", "");
    if (_matrix.Valid()) {
        uint_t row, nrows = _matrix.CountLines(";");
        uint_t col, ncols = 1;
        int    p;

        if ((p = _matrix.Pos("*")) >= 0) {
            AString mul = _matrix.Mid(p + 1);

            _matrix = _matrix.Left(p);

            if ((p = mul.Pos("/")) >= 0) {
                matmul = (float)mul.Left(p) / (float)mul.Mid(p + 1);
            }
            else matmul = (float)mul;
        }
        else if ((p = _matrix.Pos("/")) >= 0) {
            AString mul = _matrix.Mid(p + 1);

            _matrix = _matrix.Left(p);

            matmul = 1.f / (float)mul;
        }

        for (row = 0; row < nrows; row++) {
            uint_t n = _matrix.Line(row, ";").CountLines(",");
            ncols = MAX(ncols, n);
        }

        nrows |= 1;
        ncols |= 1;

        matrix.resize(nrows * ncols);
        for (row = 0; row < nrows; row++) {
            AString line = _matrix.Line(row,";");

            for (col = 0; col < ncols; col++) matrix[col + row * ncols] = (float)line.Line(col, ",");
        }

        matwid = ncols;
        mathgt = nrows;

#if 0
        printf("Matrix is %u x %u:\n", matwid, mathgt);
        for (row = 0; row < nrows; row++) {
            for (col = 0; col < ncols; col++) printf("%8.3f", matrix[col + row * ncols]);
            printf("\n");
        }
        printf("Multiplier %0.6f\n", matmul);
#endif
    }
    else matrix.resize(0);
}
示例#5
0
bool DecodeXML(AStructuredNode& root, const AString& str)
{
	AStructuredNode *pNode = &root;
	AKeyValuePair   *pAttr;
	ADataList       stack;
	uint_t p1 = 0, p2;
	
	while (IsXMLWhiteSpace(str[p1])) p1++;
	while (!HasQuit() && pNode && (str[p1] == '<')) {
		bool popnode = false;

		p1++;
		if (str[p1] == '/') {
			p1++;
			if ((pNode != &root) && ((p2 = FindXMLMarker(str, p1)) > p1)) {
				uint_t p3 = p1;
				
				if (IsSymbolStart(str[p1])) p1++;
				while (IsXMLNameChar(str[p1])) p1++;

				AString name = str.Mid(p3, p1 - p3);
				if (name == pNode->Key) {
					if (debug_decode) debug("Closing node '%s'\n", pNode->Key.str());
					popnode = true;
					p1 = p2 + 1;
				}
				else {
					debug("Unknown close object '%s' at %u\n", name.str(), p1);
					break;
				}
			}
			else {
				debug("Unknown close marker at %u\n", p1);
				break;
			}
		}
		else if (str.Mid(p1, 3) == "!--") {
			if ((p2 = str.Pos("-->", p1 + 3)) > p1) p1 = p2 + 2;
			else {
				debug("Unterminated comment marker at %u\n", p1);
				break;
			}
		}
		else if ((p2 = FindXMLMarker(str, p1)) > p1) {
			if (pNode) stack.Push((void *)pNode);
			
			if ((pNode = new AStructuredNode) != NULL) {
				uint_t p3 = p2;
				bool   complete = ((str[p3 - 1] == '/') || ((str[p1] == '?') && (str[p3 - 1] == '?')));
				
				if (complete) p3--;

				complete |= (str[p1] == '!');

				if ((str[p1] == '?') || (str[p1] == '!')) pNode->SetType(str[p1++]);
				
				while (IsXMLWhiteSpace(str[p1])) p1++;

				uint_t p4 = p1;
				if (IsSymbolStart(str[p1])) p1++;
				while (IsXMLNameChar(str[p1])) p1++;

				pNode->Key = str.Mid(p4, p1 - p4).DeHTMLify();
				if (debug_decode) debug("Created new node '%s' (%s)\n", pNode->Key.str(), complete ? "complete" : "open");

				while (IsXMLWhiteSpace(str[p1])) p1++;

				while (p1 < p3) {
					p4 = p1;
					if (IsSymbolStart(str[p1])) p1++;
					while (IsXMLNameChar(str[p1])) p1++;
					uint_t p5 = p1;
					
					while (IsXMLWhiteSpace(str[p1])) p1++;
					if (str[p1] == '=') p1++;
					while (IsXMLWhiteSpace(str[p1])) p1++;

					int quote = 0;
					if (IsQuoteChar(str[p1])) quote = str[p1++];

					uint_t p6 = p1;
					while (str[p1] && ((quote && (str[p1] != quote)) ||
									   (!quote && !IsXMLWhiteSpace(str[p1])))) p1++;
					uint_t p7 = p1;

					if (quote && (str[p1] == quote)) p1++;
					while (IsXMLWhiteSpace(str[p1])) p1++;

					if ((p5 > p4) && ((pAttr = new AKeyValuePair) != NULL)) {
						pAttr->Key   = str.Mid(p4, p5 - p4).DeHTMLify();
						pAttr->Value = str.Mid(p6, p7 - p6).DeHTMLify();
						pNode->AddAttribute(pAttr);
						if (debug_decode) debug("Added attribute '%s'='%s' to '%s'\n", pAttr->Key.str(), pAttr->Value.str(), pNode->Key.str());
					}
					else break;
				}
				
				AStructuredNode *pParent = (AStructuredNode *)stack.Last();
				if (pParent) pParent->AddChild(pNode);

				p2++;
				while (IsXMLWhiteSpace(str[p2])) p2++;

				p3 = p1 = p2;
				while (str[p2] && (str[p2] != '<')) {
					p2++;
					if (!IsXMLWhiteSpace(str[p2 - 1])) p3 = p2;
				}
				if (p3 > p1) {
					pNode->Value = str.Mid(p1, p3 - p1).DeHTMLify();
					if (debug_decode) debug("Set value of '%s' to '%s'\n", pNode->Key.str(), pNode->Value.str());
				}
				p1 = p2;

				popnode = complete;
			}
		}

		if (popnode) {
			if (stack.Count()) {
				pNode = (AStructuredNode *)stack.EndPop();
				if (debug_decode) debug("Back to node '%s'\n", pNode->Key.str());
			}
			else {
				debug("Stack empty at %u\n", p1);
				break;
			}
		}
		
		while (IsXMLWhiteSpace(str[p1])) p1++;
	}

	if (stack.Count()) debug("Unterminated XML entries at %u\n", p1);
	if (!pNode)		   debug("Extra XML termination at %u\n", p1);
	
	return (!str[p1] && (pNode == &root));
}