win-dshow: Put device id mangling in separate file

This is going to be used for other code as well, so may as well put it
in its own file.
This commit is contained in:
jp9000
2014-12-18 15:33:35 -08:00
parent 1884fea349
commit 77f0f6802a
3 changed files with 79 additions and 56 deletions

View File

@@ -4,6 +4,7 @@ find_package(FFMpeg REQUIRED COMPONENTS avcodec avutil)
include_directories(${FFMPEG_INCLUDE_DIRS})
set(win-dshow_HEADERS
encode-dstr.hpp
ffmpeg-decode.h)
set(win-dshow_SOURCES

View File

@@ -0,0 +1,76 @@
#pragma once
#include <util/util.hpp>
static inline void encode_dstr(struct dstr *str)
{
dstr_replace(str, "#", "#22");
dstr_replace(str, ":", "#3A");
}
static inline void decode_dstr(struct dstr *str)
{
dstr_replace(str, "#3A", ":");
dstr_replace(str, "#22", "#");
}
static inline void EncodeDeviceId(struct dstr *encodedStr,
const wchar_t *name_str, const wchar_t *path_str)
{
DStr name;
DStr path;
dstr_from_wcs(name, name_str);
dstr_from_wcs(path, path_str);
encode_dstr(name);
encode_dstr(path);
dstr_copy_dstr(encodedStr, name);
dstr_cat(encodedStr, ":");
dstr_cat_dstr(encodedStr, path);
}
static inline bool DecodeDeviceDStr(DStr &name, DStr &path,
const char *device_id)
{
const char *path_str;
if (!device_id || !*device_id)
return false;
path_str = strchr(device_id, ':');
if (!path_str)
return false;
dstr_copy(path, path_str+1);
dstr_copy(name, device_id);
size_t len = path_str - device_id;
name->array[len] = 0;
name->len = len;
decode_dstr(name);
decode_dstr(path);
return true;
}
static inline bool DecodeDeviceId(DShow::DeviceId &out, const char *device_id)
{
DStr name, path;
if (!DecodeDeviceDStr(name, path, device_id))
return false;
BPtr<wchar_t> wname = dstr_to_wcs(name);
out.name = wname;
if (!dstr_is_empty(path)) {
BPtr<wchar_t> wpath = dstr_to_wcs(path);
out.path = wpath;
}
return true;
}

View File

@@ -3,11 +3,11 @@
#include <obs-module.h>
#include <obs.hpp>
#include <util/dstr.hpp>
#include <util/util.hpp>
#include <util/platform.h>
#include <util/windows/WinHandle.hpp>
#include "libdshowcapture/dshowcapture.hpp"
#include "ffmpeg-decode.h"
#include "encode-dstr.hpp"
#include <algorithm>
#include <limits>
@@ -317,18 +317,6 @@ static long long FrameRateInterval(const VideoInfo &cap,
min(desired_interval, cap.maxInterval);
}
static inline void encode_dstr(struct dstr *str)
{
dstr_replace(str, "#", "#22");
dstr_replace(str, ":", "#3A");
}
static inline void decode_dstr(struct dstr *str)
{
dstr_replace(str, "#3A", ":");
dstr_replace(str, "#22", "#");
}
static inline video_format ConvertVideoFormat(VideoFormat format)
{
switch (format) {
@@ -496,48 +484,6 @@ void DShowInput::OnAudioData(const AudioConfig &config,
UNUSED_PARAMETER(endTime);
}
static bool DecodeDeviceId(DStr &name, DStr &path, const char *device_id)
{
const char *path_str;
if (!device_id || !*device_id)
return false;
path_str = strchr(device_id, ':');
if (!path_str)
return false;
dstr_copy(path, path_str+1);
dstr_copy(name, device_id);
size_t len = path_str - device_id;
name->array[len] = 0;
name->len = len;
decode_dstr(name);
decode_dstr(path);
return true;
}
static bool DecodeDeviceId(DeviceId &out, const char *device_id)
{
DStr name, path;
if (!DecodeDeviceId(name, path, device_id))
return false;
BPtr<wchar_t> wname = dstr_to_wcs(name);
out.name = wname;
if (!dstr_is_empty(path)) {
BPtr<wchar_t> wpath = dstr_to_wcs(path);
out.path = wpath;
}
return true;
}
struct PropertiesData {
vector<VideoDevice> devices;
vector<AudioDevice> audioDevices;
@@ -1032,7 +978,7 @@ static bool ResTypeChanged(obs_properties_t *props, obs_property_t *p,
static size_t AddDevice(obs_property_t *device_list, const string &id)
{
DStr name, path;
if (!DecodeDeviceId(name, path, id.c_str()))
if (!DecodeDeviceDStr(name, path, id.c_str()))
return numeric_limits<size_t>::max();
return obs_property_list_add_string(device_list, name, id.c_str());