Пример #1
0
bool AudioController::test(int fmt_in, int fmt_out) {
	return isSupported(fmt_in) && isSupported(fmt_out);
}
Пример #2
0
int AudioController::reinitialize(mp_audio *in) {
	if (!in)
		return AF_ERROR;
	auto makeFormat = [] (const mp_audio *audio) {
		AudioFormat format;
		format.m_samplerate = audio->rate/1000.0; // kHz
		format.m_bitrate = audio->rate*audio->nch*audio->bps*8;
		format.m_bits = audio->bps*8;
		format.m_channels = ChannelLayoutInfo::description(ChannelLayoutMap::toLayout(audio->channels));
		format.m_type = af_fmt_to_str(audio->format);
		return format;
	};
	d->input = makeFormat(in);
	auto out = d->af->data;
	out->rate = in->rate;
	bool ret = true;
	if (!isSupported(in->format)) {
		ret = false;
		mp_audio_set_format(in, af_fmt_is_planar(in->format) ? AF_FORMAT_FLOATP : AF_FORMAT_FLOAT);
	}
	if (d->fmt_conv) {
		mp_audio_set_format(out, d->fmt_conv);
		d->fmt_conv = AF_FORMAT_UNKNOWN;
	} else
		mp_audio_set_format(out, in->format);
	d->chmap = in->channels;
	if (!mp_chmap_from_str(&d->chmap, bstr0(ChannelLayoutInfo::data(d->layout).constData())))
		_Error("Cannot find matched channel layout for '%%'", ChannelLayoutInfo::description(d->layout));
	mp_audio_set_channels(out, &d->chmap);
	if (d->outrate != 0)
		out->rate = d->outrate;
	if (!ret)
		return false;
	d->af->mul = (double)out->channels.num/in->channels.num;
	if (d->tempoScalerActivated)
		d->af->mul /= d->scale;
	if ((d->resample = out->rate != in->rate)) {
		d->af->mul *= (double)out->rate/in->rate;
		const auto nch = in->channels.num;/*mp_chmap_to_lavc_unchecked(&in->channels);*/
		const auto fmt = af_to_avformat(in->format);
		if (!d->swr)
			d->swr = swr_alloc();
		av_opt_set_int(d->swr,  "in_channel_count", nch, 0);
		av_opt_set_int(d->swr, "out_channel_count", nch, 0);
		av_opt_set_int(d->swr,  "in_sample_rate", in->rate, 0);
		av_opt_set_int(d->swr, "out_sample_rate", out->rate, 0);
		av_opt_set_sample_fmt(d->swr,  "in_sample_fmt", fmt, 0);
		av_opt_set_sample_fmt(d->swr, "out_sample_fmt", fmt, 0);
		swr_init(d->swr);
		if (!d->resampled)
			d->resampled = talloc_zero(nullptr, mp_audio);
		*d->resampled = *in;
		d->resampled->rate = out->rate;
		in = d->resampled;
	}
	d->output = makeFormat(out);
	const AudioDataFormat fmt_in(*in), fmt_out(*out);
	check(d->mixer, d->clip, fmt_in, fmt_out);
	d->mixer->setOutput(out);
	d->mixer->setChannelLayoutMap(d->map);
	d->dirty = 0xffffffff;
	return true;
}
Пример #3
0
	void VulkanGpuProgram::initialize()
	{
		if (!isSupported())
		{
			mIsCompiled = false;
			mCompileMessages = "Specified program is not supported by the current render system.";

			GpuProgram::initialize();
			return;
		}

		if(!mBytecode || mBytecode->compilerId != VULKAN_COMPILER_ID || 
			mBytecode->compilerVersion != VULKAN_COMPILER_VERSION)
		{
			GPU_PROGRAM_DESC desc;
			desc.type = mType;
			desc.entryPoint = mEntryPoint;
			desc.language = "vksl";
			desc.source = mSource;

			mBytecode = compileBytecode(desc);
		}

		mCompileMessages = mBytecode->messages;
		mIsCompiled = mBytecode->instructions.data != nullptr;

		if(mIsCompiled)
		{
			VulkanRenderAPI& rapi = static_cast<VulkanRenderAPI&>(RenderAPI::instance());
			VulkanDevice* devices[BS_MAX_DEVICES];

			// Create Vulkan module
			VkShaderModuleCreateInfo moduleCI;
			moduleCI.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
			moduleCI.pNext = nullptr;
			moduleCI.flags = 0;
			moduleCI.codeSize = mBytecode->instructions.size;
			moduleCI.pCode = (uint32_t*)mBytecode->instructions.data;

			VulkanUtility::getDevices(rapi, mDeviceMask, devices);

			for (UINT32 i = 0; i < BS_MAX_DEVICES; i++)
			{
				if (devices[i] != nullptr)
				{
					VkDevice vkDevice = devices[i]->getLogical();
					VulkanResourceManager& rescManager = devices[i]->getResourceManager();

					VkShaderModule shaderModule;
					VkResult result = vkCreateShaderModule(vkDevice, &moduleCI, gVulkanAllocator, &shaderModule);
					assert(result == VK_SUCCESS);

					mModules[i] = rescManager.create<VulkanShaderModule>(shaderModule);
				}
			}

			mParametersDesc = mBytecode->paramDesc;

			if (mType == GPT_VERTEX_PROGRAM)
			{
				mInputDeclaration = HardwareBufferManager::instance().createVertexDeclaration(
					mBytecode->vertexInput, mDeviceMask);
			}
		}

		BS_INC_RENDER_STAT_CAT(ResCreated, RenderStatObject_GpuProgram);

		GpuProgram::initialize();
	}
Пример #4
0
	bool GLSLESProgram::compile(const bool checkErrors)
	{
		if (mCompiled == 1)
		{
			return true;
		}
		// Only create a shader object if glsl es is supported
		if (isSupported())
		{
            GL_CHECK_ERROR

			// Create shader object
			GLenum shaderType = 0x0000;
			if (mType == GPT_VERTEX_PROGRAM)
			{
				shaderType = GL_VERTEX_SHADER;
			}
            else if (mType == GPT_FRAGMENT_PROGRAM)
            {
				shaderType = GL_FRAGMENT_SHADER;
			}
			mGLShaderHandle = glCreateShader(shaderType);
            GL_CHECK_ERROR

#if GL_EXT_debug_label
            glLabelObjectEXT(GL_SHADER_OBJECT_EXT, mGLShaderHandle, 0, mName.c_str());
#endif

            if(Root::getSingleton().getRenderSystem()->getCapabilities()->hasCapability(RSC_SEPARATE_SHADER_OBJECTS))
            {
                mGLProgramHandle = glCreateProgram();
                GL_CHECK_ERROR
#if GL_EXT_debug_label
                glLabelObjectEXT(GL_PROGRAM_OBJECT_EXT, mGLProgramHandle, 0, mName.c_str());
#endif
            }
		}

		// Add preprocessor extras and main source
		if (!mSource.empty())
		{
			const char *source = mSource.c_str();
			glShaderSource(mGLShaderHandle, 1, &source, NULL);
			// Check for load errors
            GL_CHECK_ERROR
		}

        if (checkErrors)
            logObjectInfo("GLSL ES compiling: " + mName, mGLShaderHandle);

		glCompileShader(mGLShaderHandle);
        GL_CHECK_ERROR

		// Check for compile errors
		glGetShaderiv(mGLShaderHandle, GL_COMPILE_STATUS, &mCompiled);
        if(!mCompiled && checkErrors)
		{
            String message = logObjectInfo("GLSL ES compile log: " + mName, mGLShaderHandle);
			checkAndFixInvalidDefaultPrecisionError(message);
		}

		// Log a message that the shader compiled successfully.
        if (mCompiled && checkErrors)
            logObjectInfo("GLSL ES compiled: " + mName, mGLShaderHandle);

		return (mCompiled == 1);
	}
Пример #5
0
void ServicesDbReader::open(QString urlStr)
{
  if (!isSupported(urlStr))
  {
    throw HootException("An unsupported URL was passed in.");
  }
  initializePartial();

  QUrl url(urlStr);
  QString osmElemId = url.queryItemValue("osm-element-id");
  QString osmElemType = url.queryItemValue("osm-element-type");
  QStringList pList = url.path().split("/");
  LOG_DEBUG("url path = "+url.path());
  bool ok;
  bool ok2;
  QString mapName;
  _database.open(url);

  long requestedMapId = pList[pList.size() - 1].toLong(&ok);

  if(osmElemId.length() > 0 && osmElemType.length() > 0)
  {
    _osmElemId = osmElemId.toLong(&ok2);
    _osmElemType = ElementType::fromString(osmElemType);

  }

  if (!ok && _database.getDatabaseType() != ServicesDb::DBTYPE_OSMAPI)
  {
    if (_email == "")
    {
      throw HootException("If a map name is specified then the user email must also be specified "
                          "via: " + emailKey());
    }

    mapName = pList[pList.size() - 1];
    _database.setUserId(_database.getUserId(_email));
    set<long> mapIds = _database.selectMapIds(mapName);
    if (mapIds.size() != 1)
    {
      QString str = QString("Expected 1 map with the name '%1' but found %2 maps.").arg(mapName)
          .arg(mapIds.size());
      throw HootException(str);
    }
    requestedMapId = *mapIds.begin();
  }

  if( _database.getDatabaseType() != ServicesDb::DBTYPE_OSMAPI )
  {
    if (!_database.mapExists(requestedMapId))
    {
      _database.close();
      throw HootException("No map exists with ID: " + QString::number(requestedMapId));
    }
    _database.setMapId(requestedMapId);
  }

  //using a transaction seems to make sense here, b/c we don't want to read a map being modified
  //in the middle of its modification caused by a changeset upload, which could cause the map to
  //be invalid as a whole
  _database.transaction();
  _open = true;
}
Пример #6
0
void ServicesDbWriter::_openDb(QString& urlStr, bool deleteMapFlag)
{
    if (!isSupported(urlStr))
    {
        throw HootException("An unsupported URL was passed in.");
    }
    if (_userEmail.isEmpty())
    {
        throw HootException("Please set the user's email address via the '" + emailKey() + "' "
                            "configuration setting.");
    }

    QUrl url(urlStr);

    _sdb.open(url);
    _open = true;

    LOG_DEBUG("DB opened");

    // create the user before we have a transaction so we can make sure the user gets added.
    if (_createUserIfNotFound)
    {
        _sdb.setUserId(_sdb.getOrCreateUser(_userEmail, _userEmail));
    }
    else
    {
        _sdb.setUserId(_sdb.getUserId(_userEmail, true));
    }

    //LOG_DEBUG("DB user set");

    // start the transaction. We'll close it when finalizePartial is called.
    _sdb.transaction();

    if ( _sdb.getDatabaseType() == ServicesDb::DBTYPE_SERVICES)
    {   \
        QStringList pList = url.path().split("/");
        QString mapName = pList[2];
        set<long> mapIds = _sdb.selectMapIds(mapName);

        if (mapIds.size() > 0)
        {
            if (deleteMapFlag) // deleteMapFlag is either True or _overwriteMap
            {
                for (set<long>::const_iterator it = mapIds.begin(); it != mapIds.end(); ++it)
                {
                    LOG_INFO("Removing map with ID: " << *it);
                    _sdb.deleteMap(*it);
                    LOG_INFO("Finished removing map with ID: " << *it);
                }

                _sdb.setMapId(_sdb.insertMap(mapName, true));

            }
            else
            {
                LOG_INFO("There are one or more maps with this name. Consider using "
                         "'services.db.writer.overwrite.map'. Map IDs: " << mapIds);
            }
        }
        else if ( mapIds.size() == 0 )
        {
            LOG_DEBUG("Map " << mapName << " was not found, must insert");
            _sdb.setMapId(_sdb.insertMap(mapName, true));
        }
    }
}