Skip to content
This repository was archived by the owner on Mar 15, 2021. It is now read-only.

Commit

Permalink
add init resolution with Obs function
Browse files Browse the repository at this point in the history
  • Loading branch information
CatxFish committed Jul 23, 2017
1 parent 1c12049 commit 5541865
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 15 deletions.
28 changes: 21 additions & 7 deletions src/queue/share_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,31 @@ bool share_queue_init_index(share_queue* q)
return true;
}

bool shared_queue_get_video_format(share_queue* q,int* format ,int* width,
bool shared_queue_get_video_format(int* format ,int* width,
int* height, int64_t* avgtime)
{
if (!q || !q->header)
bool success =true;
HANDLE hwnd;
queue_header* header;

hwnd = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, MAPPING_NAMEV);
if (hwnd)
header = (queue_header*)MapViewOfFile(hwnd, FILE_MAP_ALL_ACCESS, 0, 0, 0);
else
return false;

*format = q->header->format;
*width = q->header->frame_width;
*height = q->header->frame_height;
*avgtime = (q->header->frame_time)/100;
return true;
if (header){
*format = header->format;
*width = header->frame_width;
*height = header->frame_height;
*avgtime = (header->frame_time) / 100;
UnmapViewOfFile(header);
}
else
success = false;

CloseHandle(hwnd);
return success;
}

bool shared_queue_get_video(share_queue* q, uint8_t** data,
Expand Down
2 changes: 1 addition & 1 deletion src/queue/share_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void shared_queue_close(share_queue* q);
bool shared_queue_check(int mode);
bool shared_queue_set_delay(share_queue* q, int delay_video_frame);
bool share_queue_init_index(share_queue* q);
bool shared_queue_get_video_format(share_queue* q, int* format, int* width,
bool shared_queue_get_video_format(int* format, int* width,
int* height, int64_t* avgtime);
bool shared_queue_get_video(share_queue* q, uint8_t** dst_ptr,
uint32_t*linesize, uint64_t* timestamp);
Expand Down
43 changes: 36 additions & 7 deletions src/virtual-source/virtual-cam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ HRESULT CVCam::NonDelegatingQueryInterface(REFIID riid, void **ppv)
CVCamStream::CVCamStream(HRESULT *phr, CVCam *pParent, LPCWSTR pPinName) :
CSourceStream(NAME("Video"), phr, pParent, pPinName), parent(pParent)
{
use_obs_format_init = CheckObsSetting();
GetMediaType(0,&m_mt);
prev_end_ts = 0;
}
Expand All @@ -40,13 +41,28 @@ CVCamStream::~CVCamStream()
{
}

bool CVCamStream::CheckObsSetting()
{
bool get= shared_queue_get_video_format(&obs_format, &obs_width,
&obs_height, &obs_time_perframe);

if (obs_width < 320 || obs_height < 240)
return false;
else if (obs_time_perframe < 166666 || obs_time_perframe>1000000)
return false;

if (obs_height % 2 != 0)
obs_height += 1;

return get;
}

HRESULT CVCamStream::ChangeMediaType(int nMediatype)
{
GetMediaType(0,&m_mt);
return S_OK;
}


void CVCamStream::SetConvertContext(int width, int height, AVPixelFormat fotmat)
{
VIDEOINFOHEADER *pvi = (VIDEOINFOHEADER *)(m_mt.Format());
Expand Down Expand Up @@ -83,7 +99,7 @@ HRESULT CVCamStream::FillBuffer(IMediaSample *pms)

if (!queue.hwnd){
if (shared_queue_open(&queue, ModeVideo)){
shared_queue_get_video_format(&queue, &format, &frame_width,
shared_queue_get_video_format(&format, &frame_width,
&frame_height, &time_perframe);
SetConvertContext(frame_width, frame_height, (AVPixelFormat)format);
}
Expand Down Expand Up @@ -152,7 +168,10 @@ HRESULT CVCamStream::SetMediaType(const CMediaType *pmt)

HRESULT CVCamStream::GetMediaType(int iPosition,CMediaType *pmt)
{
if (iPosition < 0 || iPosition>4)
if (!use_obs_format_init)
iPosition += 1;

if (iPosition < 0 || iPosition>5)
return E_INVALIDARG;

DECLARE_PTR(VIDEOINFOHEADER, pvi,
Expand All @@ -161,24 +180,32 @@ HRESULT CVCamStream::GetMediaType(int iPosition,CMediaType *pmt)

switch (iPosition){
case 0:
pvi->bmiHeader.biWidth = obs_width;
pvi->bmiHeader.biHeight = obs_height;
pvi->AvgTimePerFrame = obs_time_perframe;
break;
case 1:
pvi->bmiHeader.biWidth = 1920;
pvi->bmiHeader.biHeight = 1080;
pvi->AvgTimePerFrame = 333333;
break;
case 1:
case 2:
pvi->bmiHeader.biWidth = 1280;
pvi->bmiHeader.biHeight = 720;
pvi->AvgTimePerFrame = 333333;
break;
case 2:
case 3:
pvi->bmiHeader.biWidth = 960;
pvi->bmiHeader.biHeight = 540;
pvi->AvgTimePerFrame = 333333;
break;
case 3:
case 4:
pvi->bmiHeader.biWidth = 640;
pvi->bmiHeader.biHeight = 360;
pvi->AvgTimePerFrame = 333333;
break;
}

pvi->AvgTimePerFrame = 333333;
pvi->bmiHeader.biCompression = MAKEFOURCC('Y', 'U', 'Y', '2');;
pvi->bmiHeader.biBitCount = 16;
pvi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
Expand Down Expand Up @@ -235,6 +262,8 @@ bool CVCamStream::ValidateResolution(long width,long height)
return true;
else if (width * 3 == height * 4)
return true;
else if (use_obs_format_init && width == obs_width && height == obs_height)
return true;
else
return false;
}
Expand Down
7 changes: 7 additions & 0 deletions src/virtual-source/virtual-cam.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class CVCamStream : public CSourceStream, public IAMStreamConfig,public IKsPrope
HRESULT OnThreadCreate(void);
HRESULT OnThreadDestroy(void);
HRESULT ChangeMediaType(int nMediatype);
bool CheckObsSetting();
bool ValidateResolution(long width, long height);
void SetConvertContext(int width, int height, AVPixelFormat fotmat);

Expand All @@ -99,4 +100,10 @@ class CVCamStream : public CSourceStream, public IAMStreamConfig,public IKsPrope
int frame_height = 0;
int64_t time_perframe = 0;
struct SwsContext *convert_ctx = nullptr;

bool use_obs_format_init = false;
int obs_format = 0;
int obs_width = 1920;
int obs_height = 1080;
int64_t obs_time_perframe = 333333;
};

0 comments on commit 5541865

Please sign in to comment.