Exemplo n.º 1
0
	bool ConfigManager::loadConfig( const ConstString & _fileGroup, const ConstString & _applicationPath )
	{
		InputStreamInterfacePtr applicationInputStream = 
			FILE_SERVICE(m_serviceProvider)->openInputFile( _fileGroup, _applicationPath, false );

		if( applicationInputStream == nullptr )
		{
			LOGGER_ERROR(m_serviceProvider)("ConfigManager::loadConfig Invalid open application settings %s"
				, _applicationPath.c_str()
				);

			return false;
		}

		if( IniUtil::loadIni( m_ini, applicationInputStream, m_serviceProvider ) == false )
		{
			LOGGER_ERROR(m_serviceProvider)("ConfigManager::loadConfig Invalid load application settings %s"
				, _applicationPath.c_str()
				);

			return false;
		}

		return true;
	}
Exemplo n.º 2
0
static void
write_out_stream (const char *filename, char *data) {
    vmbuf_reset(&write_buffer);
    vmbuf_sprintf(&write_buffer, "{ \"message\": \"%s|%s|", hostname, filename);
    json_escape_str_vmb(&write_buffer, data);
    vmbuf_strcpy(&write_buffer, "\" }");
    vmbuf_chrcpy(&write_buffer, '\0');

    if (write_to_file) {
        if (0 > file_writer_write(&fw, vmbuf_data(&write_buffer), vmbuf_wlocpos(&write_buffer))) {
            LOGGER_ERROR("%s", "failed write attempt on outfile| aborting to diagnose!");
            abort();
        }
        return;
    }

    int threshold = INTERFACE_ONERROR_RETRY_THRESHOLD;
    while (0 > post_to_interface(vmbuf_data(&write_buffer), vmbuf_wlocpos(&write_buffer)) && (0 < threshold--)) {
        if (0 == post_to_interface(vmbuf_data(&write_buffer), vmbuf_wlocpos(&write_buffer))) {
            LOGGER_ERROR("post failed to %s, issuing reattempt#%d", eserv.hostname, threshold);
            --failure;
            break;
        }
    }
}
Exemplo n.º 3
0
	const RenderMaterialStage * RenderMaterialManager::createRenderStageGroup( const ConstString & _name, const RenderMaterialStage & _stage )
    {
		TMapRenderStage::const_iterator it_found = m_materialStageIndexer.find( _name );

		if( it_found != m_materialStageIndexer.end() )
        {
            LOGGER_ERROR(m_serviceProvider)("RenderMaterialManager::createRenderStageGroup '%s' is already created"
                , _name.c_str()
                );

            return nullptr;
        }

		const RenderMaterialStage * cache_stage = this->cacheStage( _stage );

		if( cache_stage == nullptr )
		{
			LOGGER_ERROR( m_serviceProvider )("RenderMaterialManager::createRenderStageGroup '%s' invalid cache"
				, _name.c_str()
				);

			return nullptr;
		}
		
		return cache_stage;
    }
Exemplo n.º 4
0
int http_server_init(struct http_server *server) {
    /*
     * one time global initializers
     */
    if (0 > mime_types_init())
        return LOGGER_ERROR("failed to initialize mime types"), -1;
    if (0 > http_headers_init())
        return LOGGER_ERROR("failed to initialize http headers"), -1;
    /*
     * idle connection handler
     */
    server->idle_ctx = ribs_context_create(SMALL_STACK_SIZE, http_server_idle_handler);
    server->idle_ctx->data.ptr = server;
    /*
     * context pool
     */
    if (0 == server->stack_size || 0 == server->num_stacks) {
        struct rlimit rlim;
        if (0 > getrlimit(RLIMIT_STACK, &rlim))
            return LOGGER_PERROR("getrlimit(RLIMIT_STACK)"), -1;

        long total_mem = sysconf(_SC_PHYS_PAGES);
        if (total_mem < 0)
            return LOGGER_PERROR("sysconf"), -1;
        total_mem *= getpagesize();
        size_t num_ctx_in_one_map = total_mem / rlim.rlim_cur;
        /* half of total mem to start with so we don't need to enable overcommit */
        num_ctx_in_one_map >>= 1;
        LOGGER_INFO("http server pool: initial=%zu, grow=%zu", num_ctx_in_one_map, num_ctx_in_one_map);
        ctx_pool_init(&server->ctx_pool, num_ctx_in_one_map, num_ctx_in_one_map, rlim.rlim_cur, sizeof(struct http_server_context) + server->context_size);
    } else {
Exemplo n.º 5
0
int msi_kill(MSISession *session, Logger *log)
{
    if (session == NULL) {
        LOGGER_ERROR(log, "Tried to terminate non-existing session");
        return -1;
    }

    m_callback_msi_packet((struct Messenger *) session->messenger, NULL, NULL);

    if (pthread_mutex_trylock(session->mutex) != 0) {
        LOGGER_ERROR(session->messenger->log, "Failed to aquire lock on msi mutex");
        return -1;
    }

    if (session->calls) {
        MSIMessage msg;
        msg_init(&msg, requ_pop);

        MSICall *it = get_call(session, session->calls_head);

        while (it) {
            send_message(session->messenger, it->friend_number, &msg);
            MSICall *temp_it = it;
            it = it->next;
            kill_call(temp_it); /* This will eventually free session->calls */
        }
    }

    pthread_mutex_unlock(session->mutex);
    pthread_mutex_destroy(session->mutex);

    LOGGER_DEBUG(session->messenger->log, "Terminated session: %p", session);
    free(session);
    return 0;
}
Exemplo n.º 6
0
	RenderMaterialInterfacePtr RenderMaterialManager::getMaterial( const ConstString & _materialName
		, EPrimitiveType _primitiveType
		, uint32_t _textureCount
		, const RenderTextureInterfacePtr * _textures )
	{
		TMapRenderStage::const_iterator it_found = m_materialStageIndexer.find( _materialName );

		if( it_found == m_materialStageIndexer.end() )
		{
			LOGGER_ERROR( m_serviceProvider )("RenderMaterialManager::getMaterial stage %s not found"
				, _materialName.c_str()
				);

			return nullptr;
		}

		const RenderMaterialStage * stage = it_found->second;

		for( uint32_t i = 0; i != _textureCount; ++i )
		{
			if( _textures[i] == nullptr )
			{
				LOGGER_ERROR( m_serviceProvider )("RenderMaterialManager::getMaterial stage %s invalid setup texture %d"
					, _materialName.c_str()
					, i
					);

				return nullptr;
			}
		}

		RenderMaterialInterfacePtr material = this->getMaterial2( _materialName, stage, _primitiveType, _textureCount, _textures );

		return material;
	}
Exemplo n.º 7
0
int msi_hangup(MSICall *call)
{
    if (!call || !call->session) {
        return -1;
    }

    MSISession *session = call->session;

    LOGGER_DEBUG(session->messenger->log, "Session: %p Hanging up call with friend: %u", call->session,
                 call->friend_number);

    if (pthread_mutex_trylock(session->mutex) != 0) {
        LOGGER_ERROR(session->messenger->log, "Failed to aquire lock on msi mutex");
        return -1;
    }

    if (call->state == msi_CallInactive) {
        LOGGER_ERROR(session->messenger->log, "Call is in invalid state!");
        pthread_mutex_unlock(session->mutex);
        return -1;
    }

    MSIMessage msg;
    msg_init(&msg, requ_pop);

    send_message(session->messenger, call->friend_number, &msg);

    kill_call(call);
    pthread_mutex_unlock(session->mutex);
    return 0;
}
Exemplo n.º 8
0
/**
 * @brief Call this at the end of the transmission.
 *
 * @param av Handler.
 * @return int
 * @retval 0 Success.
 * @retval ToxAvError On error.
 */
int toxav_kill_transmission ( ToxAv *av, int32_t call_index )
{
    if (cii(call_index, av->msi_session)) return ErrorNoCall;

    CallSpecific *call = &av->calls[call_index];

    if ( call->crtps[audio_index] && -1 == rtp_terminate_session(call->crtps[audio_index], av->messenger) ) {
        LOGGER_ERROR("Error while terminating audio RTP session!\n");
        return ErrorTerminatingAudioRtp;
    }

    if ( call->crtps[video_index] && -1 == rtp_terminate_session(call->crtps[video_index], av->messenger) ) {
        LOGGER_ERROR("Error while terminating video RTP session!\n");
        return ErrorTerminatingVideoRtp;
    }

    call->crtps[audio_index] = NULL;
    call->crtps[video_index] = NULL;

    if ( call->j_buf ) {
        terminate_queue(call->j_buf);
        call->j_buf = NULL;
        LOGGER_DEBUG("Terminated j queue");
    } else LOGGER_DEBUG("No j queue");

    if ( call->cs ) {
        codec_terminate_session(call->cs);
        call->cs = NULL;
        LOGGER_DEBUG("Terminated codec session");
    } else LOGGER_DEBUG("No codec session");

    return ErrorNone;
}
Exemplo n.º 9
0
static int init_audio_encoder(CSSession *cs)
{
    int rc = OPUS_OK;
    cs->audio_encoder = opus_encoder_create(cs->audio_encoder_sample_rate,
                                            cs->audio_encoder_channels, OPUS_APPLICATION_AUDIO, &rc);

    if ( rc != OPUS_OK ) {
        LOGGER_ERROR("Error while starting audio encoder: %s", opus_strerror(rc));
        return -1;
    }

    rc = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_BITRATE(cs->audio_encoder_bitrate));

    if ( rc != OPUS_OK ) {
        LOGGER_ERROR("Error while setting encoder ctl: %s", opus_strerror(rc));
        return -1;
    }

    rc = opus_encoder_ctl(cs->audio_encoder, OPUS_SET_COMPLEXITY(10));

    if ( rc != OPUS_OK ) {
        LOGGER_ERROR("Error while setting encoder ctl: %s", opus_strerror(rc));
        return -1;
    }

    return 0;
}
Exemplo n.º 10
0
	ParticleEmitterContainerInterface2Ptr ParticleEngine2::createEmitterContainerFromFile( const ConstString& _fileGroupName, const FilePath & _fileName )
	{
		if( m_available == false )
		{
			return nullptr;
		}
		
		InputStreamInterfacePtr stream = FILE_SERVICE(m_serviceProvider)
			->openInputFile( _fileGroupName, _fileName, false );
		
		if( stream == nullptr )
		{
			LOGGER_ERROR(m_serviceProvider)("ParticleEngine2::createEmitterContainerFromFile can't open file %s:%s"
				, _fileGroupName.c_str()
				, _fileName.c_str() 
				);

			return nullptr;
		}

		ParticleEmitterContainerInterface2Ptr container = PARTICLE_SYSTEM2(m_serviceProvider)
            ->createEmitterContainerFromMemory( stream, m_archivator );

		if( container == nullptr )
		{
			LOGGER_ERROR(m_serviceProvider)("ParticleEngine2::createEmitterContainerFromFile can't create emitter container '%s'"
				, _fileName.c_str() 
				);

			return nullptr;
		}

		return container;
	}
Exemplo n.º 11
0
	AccountInterfacePtr AccountManager::loadAccount_( const WString& _accountID )
	{
		AccountInterfacePtr account = this->newAccount_( _accountID );

        if( account == nullptr )
        {
            LOGGER_ERROR(m_serviceProvider)("AccountManager::loadAccount_ invalid create account %ls"
                , _accountID.c_str()
                );

            return nullptr;
        }
        
        if( m_accountProvider != nullptr )
        {
            m_currentAccount = account;
            m_accountProvider->onCreateAccount( _accountID );
            m_currentAccount = nullptr;
        }

        if( account->load() == false )
        {
            LOGGER_ERROR(m_serviceProvider)("AccountManager::loadAccount_ invalid load account %ls"
                , _accountID.c_str()
                );

            return nullptr;
        }       
        
		return account;
	}
Exemplo n.º 12
0
    bool SDLFileInputStream::openFile_( const FilePath & _folder, const FilePath & _fileName, Char * _filePath )
    {
        if( SDLLAYER_SERVICE(m_serviceProvider)
            ->concatenateFilePath( _folder, _fileName, _filePath, MENGINE_MAX_PATH ) == false )
        {
            LOGGER_ERROR(m_serviceProvider)("SDLFileInputStream::open invlalid concatenate filePath '%s':'%s'"
                , _folder.c_str()
                , _fileName.c_str()
                );

            return false;
        }

        m_rwops = SDL_RWFromFile(_filePath, "rb");

        if ( m_rwops == nullptr )
        {
            LOGGER_ERROR(m_serviceProvider)("SDLFileInputStream::open %s invalid open"
                , _filePath
                );

            return false;
        }

#	ifdef _DEBUG
        if( SERVICE_EXIST( m_serviceProvider, NotificationServiceInterface ) == true )
        {
            NOTIFICATION_SERVICE( m_serviceProvider )
                ->notify( NOTIFICATOR_DEBUG_OPEN_FILE, _folder.c_str(), _fileName.c_str() );
        }
#	endif

        return true;
    }
Exemplo n.º 13
0
int ribs_ssl_set_options(SSL_CTX *ssl_ctx, char *cipher_list) {
    /* bugs */
    SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL); /* almost all bugs */
    SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_SSLv2); /* disable SSLv2 per RFC 6176 */
    SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_SSLv3); /* disable SSLv3. goodbye IE6 */
    SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_COMPRESSION);
    SSL_CTX_set_options(ssl_ctx, SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION);

    /* ciphers */
    if (!cipher_list)
        cipher_list = _HTTP_SERVER_SSL_CIPHERS;
    SSL_CTX_set_options(ssl_ctx, SSL_OP_CIPHER_SERVER_PREFERENCE);
    if (0 == SSL_CTX_set_cipher_list(ssl_ctx, cipher_list))
        return LOGGER_ERROR("failed to initialize SSL:cipher_list"), -1;

    /* DH 2048 bits */
    SSL_CTX_set_options(ssl_ctx, SSL_OP_SINGLE_DH_USE);
    DH *dh = DH_new();
    dh->p = get_rfc3526_prime_2048(NULL);
    BN_dec2bn(&dh->g, "2");
    if (0 == SSL_CTX_set_tmp_dh(ssl_ctx, dh))
        return LOGGER_ERROR("failed to initialize SSL:dh"), -1;
    DH_free(dh);

    /* Ecliptic Curve DH */
    SSL_CTX_set_options(ssl_ctx, SSL_OP_SINGLE_ECDH_USE);
    EC_KEY *ecdh = EC_KEY_new_by_curve_name(OBJ_sn2nid("prime256v1"));
    if (ecdh == NULL)
        return LOGGER_ERROR("failed to initialize SSL:edch"), -1;
    SSL_CTX_set_tmp_ecdh(ssl_ctx, ecdh);
    EC_KEY_free(ecdh);

    return 0;
}
Exemplo n.º 14
0
MSISession *msi_new(Messenger *m)
{
    if (m == NULL) {
        return NULL;
    }

    MSISession *retu = (MSISession *)calloc(sizeof(MSISession), 1);

    if (retu == NULL) {
        LOGGER_ERROR(m->log, "Allocation failed! Program might misbehave!");
        return NULL;
    }

    if (create_recursive_mutex(retu->mutex) != 0) {
        LOGGER_ERROR(m->log, "Failed to init mutex! Program might misbehave");
        free(retu);
        return NULL;
    }

    retu->messenger = m;

    m_callback_msi_packet(m, handle_msi_packet, retu);

    /* This is called when remote terminates session */
    m_callback_connectionstatus_internal_av(m, on_peer_status, retu);

    LOGGER_DEBUG(m->log, "New msi session: %p ", retu);
    return retu;
}
Exemplo n.º 15
0
int msi_change_capabilities(MSICall *call, uint8_t capabilities)
{
    if (!call || !call->session) {
        return -1;
    }

    MSISession *session = call->session;

    LOGGER_DEBUG(session->messenger->log, "Session: %p Trying to change capabilities to friend %u", call->session,
                 call->friend_number);

    if (pthread_mutex_trylock(session->mutex) != 0) {
        LOGGER_ERROR(session->messenger->log, "Failed to aquire lock on msi mutex");
        return -1;
    }

    if (call->state != msi_CallActive) {
        LOGGER_ERROR(session->messenger->log, "Call is in invalid state!");
        pthread_mutex_unlock(session->mutex);
        return -1;
    }

    call->self_capabilities = capabilities;

    MSIMessage msg;
    msg_init(&msg, requ_push);

    msg.capabilities.exists = true;
    msg.capabilities.value = capabilities;

    send_message(call->session->messenger, call->friend_number, &msg);

    pthread_mutex_unlock(session->mutex);
    return 0;
}
Exemplo n.º 16
0
bool CSocker::createSocket(SOCKET sock)
{
	if( m_socket != INVALID_SOCKET )
	{
		LOGGER_ERROR("create socket failed: socket not invalid %d", m_socket);
		return false;
	}

	m_socket = sock != INVALID_SOCKET ? sock : SocketOps::CreateTCPFileDescriptor();
	if( m_socket == INVALID_SOCKET )
	{
		LOGGER_ERROR("create socket failed:%d", SocketOps::GetLastError());
		return false;
	}

	if( !SocketOps::SetGracefulClose(m_socket) )
	{
		LOGGER_ERROR("SocketOps::SetGracefulClose error:%d, socket=%d", SocketOps::GetLastError(), m_socket);
		return false;
	}

	m_status = Key_Work;

	return true;
}
Exemplo n.º 17
0
	bool Win32FileGroupDirectory::openInputFile( const FilePath & _fileName, const InputStreamInterfacePtr & _stream, size_t _offset, size_t _size, bool _streaming )
	{
		(void)_streaming;

        if( _stream == nullptr )
        {
            LOGGER_ERROR(m_serviceProvider)("Win32FileGroupDirectory::openInputFile failed _stream == NULL"
                );

            return false;
        }

        FileInputStreamInterface * file = stdex::intrusive_get<FileInputStreamInterface *>(_stream);

		if( file->open( m_path, _fileName, _offset, _size ) == false )
        {
            LOGGER_ERROR(m_serviceProvider)("Win32FileGroupDirectory::openInputFile failed open file '%s':'%s'"
                , m_path.c_str()
                , _fileName.c_str()
                );

            return false;
        }

		return true;
	}
Exemplo n.º 18
0
	bool ParticleConverterPTCToPTZ::convert()
	{
        FileGroupInterfacePtr fileGroup;
        if( FILE_SERVICE(m_serviceProvider)->hasFileGroup( m_options.pakName, &fileGroup ) == false )
        {
            LOGGER_ERROR(m_serviceProvider)("ParticleConverterPTCToPTZ::convert_: not found file group '%s'"
                , m_options.pakName.c_str()
                );

            return false;
        }

        const ConstString & pakPath = fileGroup->getPath();            

        ConstString full_input = Helper::concatenationFilePath( m_serviceProvider, pakPath, m_options.inputFileName );
        ConstString full_output = Helper::concatenationFilePath( m_serviceProvider, pakPath, m_options.outputFileName );
		        
		MemoryCacheBufferInterfacePtr data_cache = Helper::createMemoryCacheFile( m_serviceProvider, STRINGIZE_STRING_LOCAL( m_serviceProvider, "dev" ), full_input, false, "ParticleConverterPTCToPTZ_data" );

		if( data_cache == nullptr )
		{
			return false;
		}
			
		const Blobject::value_type * data_memory = data_cache->getMemory();
		size_t data_size = data_cache->getSize();

		if( data_memory == nullptr )
		{
			LOGGER_ERROR(m_serviceProvider)("ParticleConverterPTCToPTZ::convert_: invalid cache memory '%s'"
				, full_input.c_str()
				);

			return false;
		}

        OutputStreamInterfacePtr output = FILE_SERVICE(m_serviceProvider)
            ->openOutputFile( STRINGIZE_STRING_LOCAL( m_serviceProvider, "dev" ), full_output );

		if( output == nullptr )
		{
			LOGGER_ERROR(m_serviceProvider)("ParticleConverterPTCToPTZ::convert_: invalid open '%s'"
				, full_output.c_str()
				);

			return false;
		}

		if( Helper::writeStreamArchiveData( m_serviceProvider, output, m_archivator, GET_MAGIC_NUMBER(MAGIC_PTZ), GET_MAGIC_VERSION(MAGIC_PTZ), false, data_memory, data_size ) == false )
		{
			LOGGER_ERROR(m_serviceProvider)("ParticleConverterPTCToPTZ::convert_: invalid write '%s'"
				, full_output.c_str()
				);

			return false;
		}

		return true;
	}
Exemplo n.º 19
0
int vc_reconfigure_encoder(VCSession *vc, uint32_t bit_rate, uint16_t width, uint16_t height, int16_t kf_max_dist)
{
    if (!vc) {
        return -1;
    }

    vpx_codec_enc_cfg_t cfg2 = *vc->encoder->config.enc;
    vpx_codec_err_t rc;

    if (cfg2.rc_target_bitrate == bit_rate && cfg2.g_w == width && cfg2.g_h == height && kf_max_dist == -1) {
        return 0; /* Nothing changed */
    }

    if (cfg2.g_w == width && cfg2.g_h == height && kf_max_dist == -1) {
        /* Only bit rate changed */
        LOGGER_INFO(vc->log, "bitrate change from: %u to: %u", (uint32_t)cfg2.rc_target_bitrate, (uint32_t)bit_rate);
        cfg2.rc_target_bitrate = bit_rate;
        rc = vpx_codec_enc_config_set(vc->encoder, &cfg2);

        if (rc != VPX_CODEC_OK) {
            LOGGER_ERROR(vc->log, "Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc));
            return -1;
        }
    } else {
        /* Resolution is changed, must reinitialize encoder since libvpx v1.4 doesn't support
         * reconfiguring encoder to use resolutions greater than initially set.
         */
        LOGGER_DEBUG(vc->log, "Have to reinitialize vpx encoder on session %p", (void *)vc);
        vpx_codec_ctx_t new_c;
        vpx_codec_enc_cfg_t  cfg;
        vc_init_encoder_cfg(vc->log, &cfg, kf_max_dist);
        cfg.rc_target_bitrate = bit_rate;
        cfg.g_w = width;
        cfg.g_h = height;

        LOGGER_DEBUG(vc->log, "Using VP8 codec for encoder");
        rc = vpx_codec_enc_init(&new_c, video_codec_encoder_interface(), &cfg, VPX_CODEC_USE_FRAME_THREADING);

        if (rc != VPX_CODEC_OK) {
            LOGGER_ERROR(vc->log, "Failed to initialize encoder: %s", vpx_codec_err_to_string(rc));
            return -1;
        }

        int cpu_used_value = VP8E_SET_CPUUSED_VALUE;

        rc = vpx_codec_control(&new_c, VP8E_SET_CPUUSED, cpu_used_value);

        if (rc != VPX_CODEC_OK) {
            LOGGER_ERROR(vc->log, "Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc));
            vpx_codec_destroy(&new_c);
            return -1;
        }

        vpx_codec_destroy(vc->encoder);
        memcpy(vc->encoder, &new_c, sizeof(new_c));
    }

    return 0;
}
Exemplo n.º 20
0
	bool SoundConverterFFMPEGToOGG::convert()
	{
        FileGroupInterfacePtr fileGroup;
        if( FILE_SERVICE(m_serviceProvider)->hasFileGroup( m_options.pakName, &fileGroup ) == false )
        {
            LOGGER_ERROR(m_serviceProvider)("SoundConverterFFMPEGToOGG::convert_: not found file group '%s'"
                , m_options.pakName.c_str()
                );

            return false;
        }

        const ConstString & pakPath = fileGroup->getPath();            

        String full_input = pakPath.c_str();
        full_input += m_options.inputFileName.c_str();

        String full_output = pakPath.c_str();
        full_output += m_options.outputFileName.c_str();

        WString unicode_input;
        if( Helper::utf8ToUnicode( m_serviceProvider, full_input, unicode_input ) == false )
        {
            LOGGER_ERROR(m_serviceProvider)("SoundConverterFFMPEGToOGG::convert_: invalid convert input utf8 to unicode %s"
                , full_input.c_str()
                );

            return false;
        }
                
        WString unicode_output;
        if( Helper::utf8ToUnicode( m_serviceProvider, full_output, unicode_output ) == false )
        {
            LOGGER_ERROR(m_serviceProvider)("SoundConverterFFMPEGToOGG::convert_: invalid convert output utf8 to unicode %s"
                , full_output.c_str()
                );
            
            return false;
        }

        WString buffer = L"ffmpeg.exe -loglevel error -y -threads 4 -i \""  + unicode_input + L"\" -map_metadata -1 -ac 2 -ar 44100 -acodec libvorbis -aq 100 \"" + unicode_output + L"\"";
		
		LOGGER_WARNING(m_serviceProvider)( "SoundDecoderConverterFFMPEGToOGG:: converting file '%ls' to '%ls'"
			, unicode_input.c_str()
			, unicode_output.c_str()
			);

        if( WINDOWSLAYER_SERVICE(m_serviceProvider)
            ->cmd( buffer ) == false )
        {
			LOGGER_ERROR(m_serviceProvider)("SoundConverterFFMPEGToOGG::convert_: invalid convert:"
				);

			return false;
		}

        return true;
	}
Exemplo n.º 21
0
	static bool s_writeAek( const WString & _protocolPath, const WString & _xmlPath, const WString & _aekPath )
	{
		String utf8_protocolPath;
		Helper::unicodeToUtf8( serviceProvider, _protocolPath, utf8_protocolPath );

		String utf8_xmlPath;
		Helper::unicodeToUtf8( serviceProvider, _xmlPath, utf8_xmlPath );

		String utf8_aekPath;
		Helper::unicodeToUtf8( serviceProvider, _aekPath, utf8_aekPath );
		
		LOADER_SERVICE( serviceProvider )
			->setProtocolPath( Helper::stringizeString( serviceProvider, utf8_protocolPath ) );
	
		String framePackPath( utf8_xmlPath.c_str(), utf8_xmlPath.size() );

		String::size_type size = framePackPath.size();
		framePackPath[size-3] = L'x';
		framePackPath[size-2] = L'm';
		framePackPath[size-1] = L'l';

		FilePath path_xml = Helper::stringizeString( serviceProvider, framePackPath );

		ConverterOptions options;
		   
		options.pakName = ConstString::none();
		options.inputFileName = path_xml;
		options.outputFileName = Helper::stringizeString(serviceProvider, utf8_aekPath);
		
		ConverterInterfacePtr converter = CONVERTER_SERVICE(serviceProvider)
			->createConverter( Helper::stringizeString(serviceProvider, "xmlToAekMovie") );

		if( converter == nullptr )
		{
			LOGGER_ERROR(serviceProvider)( "writeAek can't create convert '%s'\nfrom: %s\nto: %s\n"
				, "xmlToAekMovie"
				, options.inputFileName.c_str()
				, options.outputFileName.c_str()
				);

			return false;
		}
 
		converter->setOptions( &options );
		
		if( converter->convert() == false )
		{
			LOGGER_ERROR(serviceProvider)( "ConverterEngine::convert can't convert '%s'\nfrom: %s\nto: %s\n"
				, Helper::stringizeString(serviceProvider, "xmlToAekMovie").c_str()
				, options.inputFileName.c_str()
				, options.outputFileName.c_str()
				);
			
			return false;
		}
		
		return true;
	}
Exemplo n.º 22
0
	bool PosixFileInputStream::open( const FilePath & _folder, const FilePath & _fileName, size_t _offset, size_t _size )
	{
		m_folder = _folder;
		m_filename = _fileName;

		Char filePath[MENGINE_MAX_PATH];
		if( this->concatenateFilePath( _folder, _fileName, filePath, MENGINE_MAX_PATH ) == false )
		{
			LOGGER_ERROR(m_serviceProvider)("PosixFileGroupDirectory::open invalid concatenate '%s':'%s'"
				, m_folder.c_str()
				, m_filename.c_str()
				);

			return false;
		}

        m_hFile = fopen( filePath, "rb" );

        if( m_hFile == nullptr )
        {
            LOGGER_ERROR(m_serviceProvider)("PosixFileGroupDirectory::open s3eFileOpen %s:%s get error"
                , m_folder.c_str()
                , m_filename.c_str()
                );

            return false;
        }

		fseek( m_hFile, 0, SEEK_END );
		long size = (size_t)ftell( m_hFile );
		rewind( m_hFile );

		if( _offset + _size > (size_t)size )
		{
			LOGGER_ERROR(m_serviceProvider)("PosixFileGroupDirectory::open %ls invalid file range %d:%d size %d"
				, filePath
				, _offset
				, _size
				, size
				);

			return false;
		}

		m_size = _size == 0 ? (size_t)size : _size;
		m_offset = _offset;
		
		m_carriage = 0;
		m_capacity = 0;
		m_reading = 0;

		if( m_offset != 0 )
		{
			this->seek( 0 );
		}	

		return true;
	}
Exemplo n.º 23
0
static void
trigger_writer (
    const char *filename,
    struct logz_file_def *filedef) {

    vmbuf_reset(&write_buffer);
    ssize_t res;
    char *fn = basename(ribs_strdup(filename));
    while(1) {
        vmbuf_reset(&write_buffer);
        res = read(filedef->fd, vmbuf_wloc(&write_buffer), (BUFSIZ + 1024) &~ 1024);

        filedef->size += res;
        lseek (filedef->fd, filedef->size, SEEK_SET);

        if (0 > vmbuf_wseek(&write_buffer, res)) {
            LOGGER_ERROR("%s", "wseek error");
            break;
        } else if (0 > res) {
            LOGGER_ERROR("%s", "read error"); // EAGAIN is handled by poller
            break;
        } else if (0 < res) {
            // initial sanitizer
            vmbuf_chrcpy(&write_buffer, '\0'); // kill garbage
            char *data = ribs_strdup(vmbuf_data(&write_buffer));
            //data = strchr(data, '\n') + 1; // skip broken data from initial buffer start. we read from where the file was first observed
            ssize_t write_depth = res = strlen(data);
            // line doesn't end here
            if (data[res - 1] != '\n') {
                char *datafringe = ribs_strdup((char *)memrchr(data, '\n', res));
                if (SSTRISEMPTY(datafringe))
                    break;
                write_depth = strlen(data) - strlen(datafringe);
                *(data + write_depth) = 0;

                if (filedef->size != 0) {
                    char *rebalanced_data = write_file_fringe(fn, data, filedef->fd);
                    if (NULL != rebalanced_data) {
                        data = rebalanced_data;
                        write_depth = strlen(data);
                    }
                }

                thashtable_rec_t *rec = thashtable_lookup(delta_push, &filedef->fd, sizeof(filedef->fd));
                struct vmbuf kdelta = *(struct vmbuf *)thashtable_get_val(rec);
                vmbuf_strcpy(&kdelta, datafringe);
                vmbuf_chrcpy(&kdelta, '\0');
            }

            vmbuf_reset(&write_buffer);
            vmbuf_memcpy(&write_buffer, data, write_depth);
            vmbuf_chrcpy(&write_buffer, '\0');
            write_out_stream(fn, ribs_strdup(vmbuf_data(&write_buffer)));
        } else if (0 == res) {
            break;
        }
    }
}
Exemplo n.º 24
0
    static bool s_writeBin( const WString & _protocolPath, const WString & _xmlPath, const WString & _binPath )
    {
        String utf8_protocolPath;
        Helper::unicodeToUtf8( serviceProvider, _protocolPath, utf8_protocolPath );

        String utf8_xmlPath;
        Helper::unicodeToUtf8( serviceProvider, _xmlPath, utf8_xmlPath );

        String utf8_binPath;
        Helper::unicodeToUtf8( serviceProvider, _binPath, utf8_binPath );

        XmlDecoderInterfacePtr decoder = CODEC_SERVICE(serviceProvider)
            ->createDecoderT<XmlDecoderInterfacePtr>( Helper::stringizeString(serviceProvider, "xml2bin") );

        if( decoder == nullptr )
        {
            LOGGER_ERROR(serviceProvider)("writeBin invalid create decoder xml2bin for %s"
                , utf8_xmlPath.c_str()
                );

            return false;
        }

		if( decoder->prepareData( nullptr ) == false )
		{
			LOGGER_ERROR(serviceProvider)("writeBin invalid initialize decoder xml2bin for %s"
				, utf8_xmlPath.c_str()
				);

			return false;
		}

        XmlCodecOptions options;
        options.pathProtocol = Helper::stringizeString( serviceProvider, utf8_protocolPath );
        options.pathXml = Helper::stringizeString( serviceProvider, utf8_xmlPath );
        options.pathBin = Helper::stringizeString( serviceProvider, utf8_binPath );

        if( decoder->setOptions( &options ) == false )
        {
            LOGGER_ERROR(serviceProvider)("writeBin invalid setup decoder xml2bin for %s"
                , utf8_xmlPath.c_str()
                );

            return false;
        }

        if( decoder->decode( 0, 0 ) == 0 )
        {
            LOGGER_ERROR(serviceProvider)("writeBin invalid decode %s"
                , utf8_xmlPath.c_str()
                );

            return false;
        }

        return true;
    }
Exemplo n.º 25
0
/**
 * @brief Must be call before any RTP transmission occurs.
 *
 * @param av Handler.
 * @return int
 * @retval 0 Success.
 * @retval ToxAvError On error.
 */
int toxav_prepare_transmission ( ToxAv *av, int32_t call_index, ToxAvCodecSettings *codec_settings, int support_video )
{
    if ( !av->msi_session || cii(call_index, av->msi_session) || !av->msi_session->calls[call_index] ) {
        LOGGER_ERROR("Error while starting audio RTP session: invalid call!\n");
        return ErrorInternal;
    }

    CallSpecific *call = &av->calls[call_index];

    call->crtps[audio_index] =
        rtp_init_session(
            type_audio,
            av->messenger,
            av->msi_session->calls[call_index]->peers[0],
            av->msi_session->calls[call_index]->key_peer,
            av->msi_session->calls[call_index]->key_local,
            av->msi_session->calls[call_index]->nonce_peer,
            av->msi_session->calls[call_index]->nonce_local);


    if ( !call->crtps[audio_index] ) {
        LOGGER_ERROR("Error while starting audio RTP session!\n");
        return ErrorStartingAudioRtp;
    }


    if ( support_video ) {
        call->crtps[video_index] =
            rtp_init_session (
                type_video,
                av->messenger,
                av->msi_session->calls[call_index]->peers[0],
                av->msi_session->calls[call_index]->key_peer,
                av->msi_session->calls[call_index]->key_local,
                av->msi_session->calls[call_index]->nonce_peer,
                av->msi_session->calls[call_index]->nonce_local);


        if ( !call->crtps[video_index] ) {
            LOGGER_ERROR("Error while starting video RTP session!\n");
            return ErrorStartingVideoRtp;
        }
    }

    if ( !(call->j_buf = create_queue(codec_settings->jbuf_capacity)) ) return ErrorInternal;

    call->cs = codec_init_session(codec_settings->audio_bitrate,
                                  codec_settings->audio_frame_duration,
                                  codec_settings->audio_sample_rate,
                                  codec_settings->audio_channels,
                                  codec_settings->video_width,
                                  codec_settings->video_height,
                                  codec_settings->video_bitrate);

    return call->cs ? ErrorNone : ErrorInternal;
}
Exemplo n.º 26
0
	bool ThreadTaskPrefetchDataflow::_onRun()
	{
		m_group = FILE_SERVICE( m_serviceProvider )
			->getFileGroup( m_pakName );

		if( m_group == nullptr )
		{
			LOGGER_ERROR(m_serviceProvider)("ThreadTaskPrefetchDataflow::_onRun can't get group '%s'"
				, m_pakName.c_str()
				);

			return false;
		}

		m_stream = m_group->createInputFile( m_filePath, false );

		if( m_stream == nullptr )
		{
			LOGGER_ERROR(m_serviceProvider)("ThreadTaskPrefetchDataflow::_onRun can't create input file '%s'"
				, m_pakName.c_str()
				);

			return nullptr;
		}
	
		m_dataflow = DATA_SERVICE(m_serviceProvider)
			->getDataflow( m_dataflowType );
			
		if( m_dataflow == nullptr )
		{
			LOGGER_ERROR(m_serviceProvider)("ThreadTaskPrefetchDataflow::_onRun: '%s':'%s' invalide get dataflow '%s'"
				, m_pakName.c_str()
				, m_filePath.c_str()
				, m_dataflowType.c_str()
				);

			return false;
		}

		m_data = m_dataflow->create();

		if( m_data == nullptr )
		{
			LOGGER_ERROR(m_serviceProvider)("ThreadTaskPrefetchDataflow::_onRun: '%s':'%s' dataflow invalid create data '%s'"
				, m_pakName.c_str()
				, m_filePath.c_str()
				, m_dataflowType.c_str()
				);

			return false;
		}
		
		return true;
	}
Exemplo n.º 27
0
    bool MovieInternalObject::_compile()
    {
		if( m_movie == nullptr )
		{
			LOGGER_ERROR(m_serviceProvider)("MovieInternalObject::_compile '%s' movie not setup"
				, m_name.c_str()
				);

			return false;
		}

        if( m_resourceInternalObject == nullptr )
        {
            LOGGER_ERROR(m_serviceProvider)("MovieInternalObject::_compile '%s' resource not setup"
                , m_name.c_str()
                );
            
            return false;
        }

        if( m_resourceInternalObject.compile() == false )
        {
            LOGGER_ERROR(m_serviceProvider)("MovieInternalObject::_compile '%s' resource '%s' not compile"
                , m_name.c_str()
                , m_resourceInternalObject->getName().c_str()
                );

            return false;
        }

        const ConstString & internalGroup = m_resourceInternalObject->getInternalGroup();
        const ConstString & internalName = m_resourceInternalObject->getInternalName();

        pybind::object py_object = EVENTABLE_METHODR( m_movie, EVENT_MOVIE_GET_INTERNAL, pybind::object() )
            ->onMovieGetInternal( internalGroup, internalName );
		//pybind::object py_object;
		//EVENTABLE_ASK( m_serviceProvider, m_movie, EVENT_MOVIE_GET_INTERNAL, py_object )(internalGroup, internalName);

		if( py_object.is_invalid() == true )
        {
            LOGGER_ERROR(m_serviceProvider)("MovieInternalObject::_compile '%s' resource '%s' can't find internal object '%s:%s'"
                , m_name.c_str()
                , m_resourceInternalObject->getName().c_str()
                , internalGroup.c_str()
                , internalName.c_str()				
                );

            return false;
        }

        m_internalObject = py_object;        

        return true;
    }
Exemplo n.º 28
0
	ScriptModuleInterfacePtr ScriptEngine::importModule( const ConstString & _name )
	{
		PyObject * py_module = nullptr;
		bool exist = false;

		try
		{
			py_module = pybind::module_import( _name.c_str(), exist );
		}
		catch( ... )
		{
			ScriptEngine::handleException();

			LOGGER_ERROR(m_serviceProvider)( "ScriptEngine: invalid import module '%s'(c-exception)"
				, _name.c_str()
				);

			return nullptr;
		}

		if( exist == false )
		{
			LOGGER_WARNING(m_serviceProvider)( "ScriptEngine: invalid import module '%s'(not exist)"
				, _name.c_str()
				);

			return nullptr;
		}

		if( py_module == nullptr )
		{			
			LOGGER_ERROR(m_serviceProvider)( "ScriptEngine: invalid import module '%s'(script)"
				, _name.c_str()
				);

			return nullptr;
		}

		ScriptModulePtr module = m_factoryScriptModule.createObject();

		if( module->initialize( pybind::object(py_module) ) == false )
		{
			LOGGER_ERROR( m_serviceProvider )("ScriptEngine: invalid import initialize '%s'(script)"
				, _name.c_str()
				);

			return nullptr;
		}

		return module;
	}
Exemplo n.º 29
0
bool MarmaladeAmplifier::_initialize()
{
    LOGGER_INFO(m_serviceProvider)( "Starting Marmalade Amplifier..." );

    int32 available = s3eAudioGetInt( S3E_AUDIO_AVAILABLE );

    if( available == 0 )
    {
        LOGGER_ERROR(m_serviceProvider)("Unavailable..."
                                       );

        return false;
    }

    s3eResult result = s3eAudioRegister( S3E_AUDIO_STOP, (s3eCallback)&s_Amplifier_AudioCallback_Stop, this );

    if( result != S3E_RESULT_SUCCESS )
    {
        s3eAudioError s3eAudio_error = s3eAudioGetError();
        const char * s3eAudio_string = s3eAudioGetErrorString();

        LOGGER_ERROR(m_serviceProvider)("Amplifier::initialize: invalid register callback %d [%s]"
                                        , s3eAudio_error
                                        , s3eAudio_string
                                       );

        return false;
    }

    SOUND_SERVICE(m_serviceProvider)
    ->addSoundVolumeProvider( this );

#	define MARMALADE_AMPLIFIER_SUPPORT_CODEC( Codec )\
	LOGGER_WARNING(m_serviceProvider)("Amplifier::initialize: " #Codec " %s"\
		, s3eAudioIsCodecSupported( Codec ) ? "support" : "unsupport!" )

    MARMALADE_AMPLIFIER_SUPPORT_CODEC( S3E_AUDIO_CODEC_MIDI );
    MARMALADE_AMPLIFIER_SUPPORT_CODEC( S3E_AUDIO_CODEC_MP3 );
    MARMALADE_AMPLIFIER_SUPPORT_CODEC( S3E_AUDIO_CODEC_AAC );
    MARMALADE_AMPLIFIER_SUPPORT_CODEC( S3E_AUDIO_CODEC_AACPLUS );
    MARMALADE_AMPLIFIER_SUPPORT_CODEC( S3E_AUDIO_CODEC_QCP );
    MARMALADE_AMPLIFIER_SUPPORT_CODEC( S3E_AUDIO_CODEC_PCM );
    MARMALADE_AMPLIFIER_SUPPORT_CODEC( S3E_AUDIO_CODEC_SPF );
    MARMALADE_AMPLIFIER_SUPPORT_CODEC( S3E_AUDIO_CODEC_AMR );
    MARMALADE_AMPLIFIER_SUPPORT_CODEC( S3E_AUDIO_CODEC_MP4 );

#	undef AMPLIFIER_SUPPORT_CODEC

    return true;
}
Exemplo n.º 30
0
OpusEncoder *create_audio_encoder(Logger *log, int32_t bit_rate, int32_t sampling_rate, int32_t channel_count)
{
    int status = OPUS_OK;
    OpusEncoder *rc = opus_encoder_create(sampling_rate, channel_count, OPUS_APPLICATION_VOIP, &status);

    if (status != OPUS_OK) {
        LOGGER_ERROR(log, "Error while starting audio encoder: %s", opus_strerror(status));
        return NULL;
    }

    status = opus_encoder_ctl(rc, OPUS_SET_BITRATE(bit_rate));

    if (status != OPUS_OK) {
        LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status));
        goto FAILURE;
    }

    /* Enable in-band forward error correction in codec */
    status = opus_encoder_ctl(rc, OPUS_SET_INBAND_FEC(1));

    if (status != OPUS_OK) {
        LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status));
        goto FAILURE;
    }

    /* Make codec resistant to up to 10% packet loss
     * NOTE This could also be adjusted on the fly, rather than hard-coded,
     *      with feedback from the receiving client.
     */
    status = opus_encoder_ctl(rc, OPUS_SET_PACKET_LOSS_PERC(10));

    if (status != OPUS_OK) {
        LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status));
        goto FAILURE;
    }

    /* Set algorithm to the highest complexity, maximizing compression */
    status = opus_encoder_ctl(rc, OPUS_SET_COMPLEXITY(10));

    if (status != OPUS_OK) {
        LOGGER_ERROR(log, "Error while setting encoder ctl: %s", opus_strerror(status));
        goto FAILURE;
    }

    return rc;

FAILURE:
    opus_encoder_destroy(rc);
    return NULL;
}