Example #1
0
void DShowInput::Update(obs_data_t settings)
{
	if (!device.ResetGraph())
		return;

	if (!UpdateVideoConfig(settings)) {
		blog(LOG_WARNING, "%s: Video configuration failed",
				obs_source_get_name(source));
		return;
	}

	if (!UpdateAudioConfig(settings))
		blog(LOG_WARNING, "%s: Audio configuration failed, ignoring "
		                  "audio", obs_source_get_name(source));

	if (!device.ConnectFilters())
		return;

	if (device.Start() != Result::Success)
		return;

	enum video_colorspace cs = (videoConfig.format == VideoFormat::HDYC) ?
		VIDEO_CS_709 : VIDEO_CS_601;

	if (!video_format_get_parameters(cs, VIDEO_RANGE_PARTIAL,
			frame.color_matrix,
			frame.color_range_min,
			frame.color_range_max)) {
		blog(LOG_ERROR, "Failed to get video format parameters for " \
		                "video format %u", cs);
	}
}
Example #2
0
inline bool DShowInput::Activate(obs_data_t *settings)
{
	if (!device.ResetGraph())
		return false;

	if (!UpdateVideoConfig(settings)) {
		blog(LOG_WARNING, "%s: Video configuration failed",
				obs_source_get_name(source));
		return false;
	}

	if (!UpdateAudioConfig(settings))
		blog(LOG_WARNING, "%s: Audio configuration failed, ignoring "
		                  "audio", obs_source_get_name(source));

	if (!device.ConnectFilters())
		return false;

	if (device.Start() != Result::Success)
		return false;

	enum video_colorspace cs = GetColorSpace(settings);

	bool success = video_format_get_parameters(
			cs, GetColorRange(settings),
			frame.color_matrix,
			frame.color_range_min,
			frame.color_range_max);
	if (!success) {
		blog(LOG_ERROR, "Failed to get video format parameters for " \
		                "video format %u", cs);
	}

	return true;
}
Example #3
0
void DShowInput::Update(obs_data_t settings)
{
	if (!comInitialized) {
		CoInitialize(nullptr);
		comInitialized = true;
	}

	if (!device.ResetGraph())
		return;

	if (!UpdateVideoConfig(settings)) {
		blog(LOG_WARNING, "%s: Video configuration failed",
				obs_source_get_name(source));
		return;
	}

	if (!UpdateAudioConfig(settings))
		blog(LOG_WARNING, "%s: Audio configuration failed, ignoring "
		                  "audio", obs_source_get_name(source));

	if (!device.ConnectFilters())
		return;

	if (device.Start() != Result::Success)
		return;

	frame.width      = videoConfig.cx;
	frame.height     = videoConfig.cy;
	frame.format     = ConvertVideoFormat(videoConfig.format);
	frame.full_range = false;
	frame.flip       = (videoConfig.format == VideoFormat::XRGB ||
	                    videoConfig.format == VideoFormat::ARGB);

	audio.speakers        = (enum speaker_layout)audioConfig.channels;
	audio.format          = ConvertAudioFormat(audioConfig.format);
	audio.samples_per_sec = (uint32_t)audioConfig.sampleRate;

	enum video_colorspace cs = (videoConfig.format == VideoFormat::HDYC) ?
		VIDEO_CS_709 : VIDEO_CS_601;

	if (!video_format_get_parameters(cs, VIDEO_RANGE_PARTIAL,
			frame.color_matrix,
			frame.color_range_min,
			frame.color_range_max)) {
		blog(LOG_ERROR, "Failed to get video format parameters for " \
		                "video format %u", VIDEO_CS_601);
	}
}
Example #4
0
void DShowInput::Update(obs_data_t settings)
{
	string video_device_id = obs_data_getstring(settings, VIDEO_DEVICE_ID);

	if (!comInitialized) {
		CoInitialize(nullptr);
		comInitialized = true;
	}

	if (!device.ResetGraph())
		return;

	DeviceId id;
	if (!DecodeDeviceId(id, video_device_id.c_str()))
		return;

	PropertiesData data;
	Device::EnumVideoDevices(data.devices);
	VideoDevice dev;
	if (!data.GetDevice(dev, video_device_id.c_str()))
		return;

	int resType = (int)obs_data_getint(settings, RES_TYPE);
	int cx = 0, cy = 0;
	long long interval = 0;
	VideoFormat format = VideoFormat::Any;

	if (resType == ResType_Custom) {
		string resolution = obs_data_getstring(settings, RESOLUTION);
		if (!ResolutionValid(resolution, cx, cy))
			return;

		interval = obs_data_has_autoselect(settings, FRAME_INTERVAL) ?
			obs_data_get_autoselect_int(settings, FRAME_INTERVAL) :
			obs_data_getint(settings, FRAME_INTERVAL);

		if (interval == FPS_MATCHING)
			interval = GetOBSFPS();

		format = (VideoFormat)obs_data_getint(settings, VIDEO_FORMAT);

		long long best_interval = numeric_limits<long long>::max();
		bool video_format_match = false;
		if (!CapsMatch(dev,
			ResolutionMatcher(cx, cy),
			VideoFormatMatcher(format, video_format_match),
			ClosestFrameRateSelector(interval, best_interval),
			FrameRateMatcher(interval)) && !video_format_match)
			return;

		interval = best_interval;
		blog(LOG_INFO, "%s: Using interval %lld",
				obs_source_getname(source), interval);
	}

	videoConfig.name             = id.name.c_str();
	videoConfig.path             = id.path.c_str();
	videoConfig.callback         = CaptureProc(DShowInput::OnVideoData);
	videoConfig.param            = this;
	videoConfig.useDefaultConfig = resType == ResType_Preferred;
	videoConfig.cx               = cx;
	videoConfig.cy               = cy;
	videoConfig.frameInterval    = interval;
	videoConfig.internalFormat   = format;

	if (videoConfig.internalFormat != VideoFormat::MJPEG)
		videoConfig.format = videoConfig.internalFormat;

	device.SetVideoConfig(&videoConfig);

	if (videoConfig.internalFormat == VideoFormat::MJPEG) {
		videoConfig.format   = VideoFormat::XRGB;
		device.SetVideoConfig(&videoConfig);
	}

	if (!device.ConnectFilters())
		return;

	if (device.Start() != Result::Success)
		return;

	frame.width      = videoConfig.cx;
	frame.height     = videoConfig.cy;
	frame.format     = ConvertVideoFormat(videoConfig.format);
	frame.full_range = false;
	frame.flip       = (videoConfig.format == VideoFormat::XRGB ||
	                    videoConfig.format == VideoFormat::ARGB);

	if (!video_format_get_parameters(VIDEO_CS_601, VIDEO_RANGE_PARTIAL,
			frame.color_matrix,
			frame.color_range_min,
			frame.color_range_max)) {
		blog(LOG_ERROR, "Failed to get video format parameters for " \
		                "video format %u", VIDEO_CS_601);
	}
}