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

Commit

Permalink
fix time issues on virtual-source
Browse files Browse the repository at this point in the history
  • Loading branch information
CatxFish committed Sep 25, 2019
1 parent 8110f6d commit e20e234
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
15 changes: 8 additions & 7 deletions src/virtual-source/virtual-audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,27 @@ HRESULT CVAudioStream::FillBuffer(IMediaSample *pms)

hr = pms->GetPointer((BYTE**)&dst);

current_time = get_current_time();

if (prev_end_ts <= 0)
prev_end_ts = current_time;
if (system_start_time <= 0)
system_start_time = get_current_time();
else
current_time = get_current_time() - system_start_time;

if (!queue.hwnd)
shared_queue_open(&queue, ModeAudio);

if (sync_timeout <= 0) {
SetTimeout();
}
else if (prev_end_ts >current_time) {
sleepto(prev_end_ts);
}
else if (current_time - prev_end_ts > sync_timeout) {
if (queue.header)
share_queue_init_index(&queue);
else
prev_end_ts = current_time;
}

sleepto(prev_end_ts);

while (queue.header && !get_sample){

if (get_times > 20 || queue.header->state != OutputReady)
Expand All @@ -127,7 +128,6 @@ HRESULT CVAudioStream::FillBuffer(IMediaSample *pms)
}
}


if (get_sample && !obs_start_ts){
obs_start_ts = timestamp;
dshow_start_ts = prev_end_ts;
Expand Down Expand Up @@ -253,6 +253,7 @@ HRESULT CVAudioStream::OnThreadCreate()
obs_start_ts = 0;
dshow_start_ts = 0;
prev_end_ts = 0;
system_start_time = 0;
return NOERROR;
}

Expand Down
1 change: 1 addition & 0 deletions src/virtual-source/virtual-audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class CVAudioStream : public CSourceStream, public IAMStreamConfig,
uint64_t obs_start_ts = 0;
uint64_t dshow_start_ts = 0;
uint64_t sync_timeout = 0;
uint64_t system_start_time = 0;
REFERENCE_TIME prev_end_ts = 0;
ALLOCATOR_PROPERTIES alloc_prop;

Expand Down
14 changes: 9 additions & 5 deletions src/virtual-source/virtual-cam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,11 @@ HRESULT CVCamStream::FillBuffer(IMediaSample *pms)

hr = pms->GetPointer((BYTE**)&dst);

current_time = get_current_time();

if (prev_end_ts <= 0)
prev_end_ts = current_time;
if (system_start_time <= 0)
system_start_time = get_current_time();
else
current_time = get_current_time() - system_start_time;


if (!queue.hwnd) {
if (shared_queue_open(&queue, queue_mode)) {
Expand All @@ -167,6 +168,9 @@ HRESULT CVCamStream::FillBuffer(IMediaSample *pms)
if (sync_timeout <= 0) {
SetTimeout();
}
else if (prev_end_ts >current_time) {
sleepto(prev_end_ts);
}
else if (current_time - prev_end_ts > sync_timeout) {
if(queue.header)
share_queue_init_index(&queue);
Expand Down Expand Up @@ -198,7 +202,6 @@ HRESULT CVCamStream::FillBuffer(IMediaSample *pms)
duration = time_perframe;
} else {
int size = pms->GetActualDataLength();
sleepto(prev_end_ts);
memset(dst, 127, size);
start_time = prev_end_ts;
duration = ((VIDEOINFOHEADER*)m_mt.pbFormat)->AvgTimePerFrame;
Expand Down Expand Up @@ -349,6 +352,7 @@ HRESULT CVCamStream::OnThreadCreate()
prev_end_ts = 0;
obs_start_ts = 0;
dshow_start_ts = 0;
system_start_time = 0;
return NOERROR;
}

Expand Down
1 change: 1 addition & 0 deletions src/virtual-source/virtual-cam.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class CVCamStream : public CSourceStream, public IAMStreamConfig, public IKsProp
uint64_t obs_start_ts = 0;
uint64_t dshow_start_ts = 0;
uint64_t time_perframe = 0;
uint64_t system_start_time = 0;
uint64_t sync_timeout = 0;
REFERENCE_TIME prev_end_ts = 0;

Expand Down

0 comments on commit e20e234

Please sign in to comment.