Exemple #1
0
void CheckExistanceOfDirectoriesAndFiles(void)
{
	if(!DirectoryExists(getMediaDirectory()))
	{
		LogWarn(VB_SETTING, "FPP directory does not exist, creating it.\n");

		if ( mkdir(getMediaDirectory(), 0777) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create media directory.\n");
			exit(EXIT_FAILURE);
		}
	}
	if(!DirectoryExists(getMusicDirectory()))
	{
		LogWarn(VB_SETTING, "Music directory does not exist, creating it.\n");

		if ( mkdir(getMusicDirectory(), 0777) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create music directory.\n");
			exit(EXIT_FAILURE);
		}
	}
	if(!DirectoryExists(getSequenceDirectory()))
	{
		LogWarn(VB_SETTING, "Sequence directory does not exist, creating it.\n");

		if ( mkdir(getSequenceDirectory(), 0777) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create sequence directory.\n");
			exit(EXIT_FAILURE);
		}
	}
	if(!DirectoryExists(getEventDirectory()))
	{
		LogWarn(VB_SETTING, "Event directory does not exist, creating it.\n");

		if ( mkdir(getEventDirectory(), 0777) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create event directory.\n");
			exit(EXIT_FAILURE);
		}
	}
	if(!DirectoryExists(getVideoDirectory()))
	{
		LogWarn(VB_SETTING, "Video directory does not exist, creating it.\n");

		if ( mkdir(getVideoDirectory(), 0777) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create video directory.\n");
			exit(EXIT_FAILURE);
		}
	}
	if(!DirectoryExists(getEffectDirectory()))
	{
		LogWarn(VB_SETTING, "Effect directory does not exist, creating it.\n");

		if ( mkdir(getEffectDirectory(), 0777) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create effect directory.\n");
			exit(EXIT_FAILURE);
		}
	}
	if(!DirectoryExists(getScriptDirectory()))
	{
		LogWarn(VB_SETTING, "Script directory does not exist, creating it.\n");

		if ( mkdir(getScriptDirectory(), 0777) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create script directory.\n");
			exit(EXIT_FAILURE);
		}
	}
	if(!DirectoryExists(getPlaylistDirectory()))
	{
		LogWarn(VB_SETTING, "Playlist directory does not exist, creating it.\n");

		if ( mkdir(getPlaylistDirectory(), 0777) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create playlist directory.\n");
			exit(EXIT_FAILURE);
		}
	}

	if(!FileExists(getUniverseFile()))
	{
		LogWarn(VB_SETTING, "Universe file does not exist, creating it.\n");

		char *cmd, *file = getUniverseFile();
		cmd = (char *)malloc(strlen(file)+7);
		snprintf(cmd, strlen(file)+7, "touch %s", file);
		if ( system(cmd) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create universe file.\n");
			exit(EXIT_FAILURE);
		}
		free(cmd);
	}

	if(!FileExists(getScheduleFile()))
	{
		LogWarn(VB_SETTING, "Schedule file does not exist, creating it.\n");

		char *cmd, *file = getScheduleFile();
		cmd = (char *)malloc(strlen(file)+7);
		snprintf(cmd, strlen(file)+7, "touch %s", file);
		if ( system(cmd) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create schedule file.\n");
			exit(EXIT_FAILURE);
		}
		free(cmd);
	}
	if(!FileExists(getBytesFile()))
	{
		LogWarn(VB_SETTING, "Bytes file does not exist, creating it.\n");

		char *cmd, *file = getBytesFile();
		cmd = (char *)malloc(strlen(file)+7);
		snprintf(cmd, strlen(file)+7, "touch %s", file);
		if ( system(cmd) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create bytes file.\n");
			exit(EXIT_FAILURE);
		}
		free(cmd);
	}

	if(!FileExists(getSettingsFile()))
	{
		LogWarn(VB_SETTING, "Settings file does not exist, creating it.\n");

		char *cmd, *file = getSettingsFile();
		cmd = (char *)malloc(strlen(file)+7);
		snprintf(cmd, strlen(file)+7, "touch %s", file);
		if ( system(cmd) != 0 )
		{
			LogErr(VB_SETTING, "Error: Unable to create settings file.\n");
			exit(EXIT_FAILURE);
		}
		free(cmd);
	}
  


  
}
Exemple #2
0
int ogg123Output::Start(void)
{
	std::string fullAudioPath;

	LogDebug(VB_MEDIAOUT, "ogg123Output::Start(%s)\n", m_mediaFilename.c_str());

	bzero(m_mediaOutputStatus, sizeof(MediaOutputStatus));

	fullAudioPath = getMusicDirectory();
	fullAudioPath += "/";
	fullAudioPath += m_mediaFilename;

	if (!FileExists(fullAudioPath.c_str()))
	{
		LogErr(VB_MEDIAOUT, "%s does not exist!\n", fullAudioPath.c_str());
		return 0;
	}

	std::string oggPlayer(getSetting("oggPlayer"));
	if (!oggPlayer.length())
	{
		oggPlayer = OGG123_BINARY;
	}
	else if (!FileExists(oggPlayer.c_str()))
	{
		LogDebug(VB_MEDIAOUT, "Configured oggPlayer %s does not exist, "
			"falling back to %s\n", oggPlayer.c_str(), OGG123_BINARY);
		oggPlayer = OGG123_BINARY;
	}

	LogDebug(VB_MEDIAOUT, "Spawning %s for OGG playback\n", oggPlayer.c_str());

	// Create Pipes to/from ogg123
	pipe(m_childPipe);

	pid_t ogg123Pid = fork();
	if (ogg123Pid == 0)			// ogg123 process
	{
		//ogg123 uses stderr for output
	    dup2(m_childPipe[MEDIAOUTPUTPIPE_WRITE], STDERR_FILENO);
		close(m_childPipe[MEDIAOUTPUTPIPE_WRITE]);
		m_childPipe[MEDIAOUTPUTPIPE_WRITE] = 0;

		execl(oggPlayer.c_str(), oggPlayer.c_str(), fullAudioPath.c_str(), NULL);
	    exit(EXIT_FAILURE);
	}
	else							// Parent process
	{
		m_childPID = ogg123Pid;

		// Close write side of pipe from ogg
		close(m_childPipe[MEDIAOUTPUTPIPE_WRITE]);
		m_childPipe[MEDIAOUTPUTPIPE_WRITE] = 0;
	}

	LogDebug(VB_MEDIAOUT, "%s PID: %d\n", oggPlayer.c_str(), m_childPID);

	// Clear active file descriptor sets
	FD_ZERO (&m_activeFDSet);
	// Set description for reading from ogg
	FD_SET (m_childPipe[MEDIAOUTPUTPIPE_READ], &m_activeFDSet);

	m_mediaOutputStatus->status = MEDIAOUTPUTSTATUS_PLAYING;

	return 1;
}