X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=fake_capture.cpp;h=2ef1d7d68dc58b71a2c2cd93a76efd0f5473d536;hb=aac15101d9cc85681eee3e02c960d57e32414db6;hp=5f53e95079db2553f39d6472afaf59c3e81980b0;hpb=a765e066b74ac52ff0abf239d430d6f8d83f792e;p=bmusb diff --git a/fake_capture.cpp b/fake_capture.cpp index 5f53e95..2ef1d7d 100644 --- a/fake_capture.cpp +++ b/fake_capture.cpp @@ -4,6 +4,7 @@ #include "bmusb/fake_capture.h" #include +#include #include #include #include @@ -13,6 +14,7 @@ #if __SSE2__ #include #endif +#include #include #include "bmusb/bmusb.h" @@ -26,6 +28,7 @@ constexpr uint8_t cbs[NUM_COLORS] = { 90, 54, 240, 128 }; constexpr uint8_t crs[NUM_COLORS] = { 240, 34, 110, 128 }; using namespace std; +using namespace std::chrono; namespace bmusb { namespace { @@ -87,7 +90,7 @@ void memset4(uint8_t *s, const uint8_t c[4], size_t n) } // namespace FakeCapture::FakeCapture(unsigned width, unsigned height, unsigned fps, unsigned audio_sample_frequency, int card_index, bool has_audio) - : width(width), height(height), fps(fps), audio_sample_frequency(audio_sample_frequency) + : width(width), height(height), fps(fps), audio_sample_frequency(audio_sample_frequency), card_index(card_index) { char buf[256]; snprintf(buf, sizeof(buf), "Fake card %d", card_index + 1); @@ -199,6 +202,10 @@ bool timespec_less_than(const timespec &a, const timespec &b) void FakeCapture::producer_thread_func() { + char thread_name[16]; + snprintf(thread_name, sizeof(thread_name), "FakeCapture_%d", card_index); + pthread_setname_np(pthread_self(), thread_name); + uint16_t timecode = 0; if (has_dequeue_callbacks) { @@ -231,6 +238,7 @@ void FakeCapture::producer_thread_func() next_frame = now; } } + steady_clock::time_point timestamp = steady_clock::now(); // Figure out when the next frame is to be, then compute the current one. add_time(1.0 / fps, &next_frame); @@ -255,6 +263,7 @@ void FakeCapture::producer_thread_func() memset4(video_frame.data, ycbcr, width * height / 2); } video_frame.len = width * height * 2; + video_frame.received_timestamp = timestamp; } AudioFormat audio_format; @@ -266,6 +275,7 @@ void FakeCapture::producer_thread_func() const unsigned num_stereo_samples = audio_sample_frequency / fps; assert(audio_frame.size >= audio_format.num_channels * sizeof(int32_t) * num_stereo_samples); audio_frame.len = audio_format.num_channels * sizeof(int32_t) * num_stereo_samples; + audio_frame.received_timestamp = timestamp; if (audio_sin == 0.0f) { // Silence.