]> git.sesse.net Git - bmusb/commitdiff
Add timestamps on each received frame.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 10 Dec 2016 11:10:04 +0000 (12:10 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 10 Dec 2016 11:10:04 +0000 (12:10 +0100)
Note that this breaks the ABI.

Makefile
bmusb.cpp
bmusb/bmusb.h
fake_capture.cpp

index ee0ba10393e089591c598e1b2385da8abed25e61..e1c33ecd0e87fb438f688a7755e0acb72fcfbc6f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -7,8 +7,8 @@ INSTALL := install
 PREFIX := /usr/local
 LIB := libbmusb.a
 SODEV := libbmusb.so
-SONAME := libbmusb.so.1
-SOLIB := libbmusb.so.1.0.0
+SONAME := libbmusb.so.2
+SOLIB := libbmusb.so.2.0.0
 
 all: $(LIB) $(SOLIB) main
 
index 2900709fd296339777263ea4dbbf7908a0836a99..9decbc9664d5c6931e94e4bd32a486ccdd0b941d 100644 (file)
--- a/bmusb.cpp
+++ b/bmusb.cpp
@@ -25,6 +25,7 @@
 
 #include <algorithm>
 #include <atomic>
+#include <chrono>
 #include <condition_variable>
 #include <cstddef>
 #include <cstdint>
@@ -37,6 +38,7 @@
 #include <thread>
 
 using namespace std;
+using namespace std::chrono;
 using namespace std::placeholders;
 
 #define USB_VENDOR_BLACKMAGIC 0x1edb
@@ -362,6 +364,8 @@ void BMUSBCapture::start_new_frame(const uint8_t *start)
        uint16_t timecode = (start[1] << 8) | start[0];
 
        if (current_video_frame.len > 0) {
+               current_video_frame.received_timestamp = steady_clock::now();
+
                // If format is 0x0800 (no signal), add a fake (empty) audio
                // frame to get it out of the queue.
                // TODO: Figure out if there are other formats that come with
@@ -405,6 +409,7 @@ void BMUSBCapture::start_new_audio_block(const uint8_t *start)
        uint16_t format = (start[3] << 8) | start[2];
        uint16_t timecode = (start[1] << 8) | start[0];
        if (current_audio_frame.len > 0) {
+               current_audio_frame.received_timestamp = steady_clock::now();
                //dump_audio_block();
                queue_frame(format, timecode, current_audio_frame, &pending_audio_frames);
        }
index f4af6aa14b2a1399168d3f75673b1d2215846770..6aabd51fcc39f68c1b0780e24d5451319083b317 100644 (file)
@@ -4,6 +4,7 @@
 #include <libusb.h>
 #include <stdint.h>
 #include <atomic>
+#include <chrono>
 #include <condition_variable>
 #include <deque>
 #include <functional>
@@ -39,6 +40,14 @@ class FrameAllocator {
                // If so, <len> and <size> are still about the number of total bytes
                // so if size == 1024, there's 512 bytes in data and 512 in data2.
                bool interleaved = false;
+
+               // At what point this frame was received. Note that this marks the
+               // _end_ of the frame being received, not the beginning.
+               // Thus, if you want to measure latency, you'll also need to include
+               // the time the frame actually took to transfer (usually 1/fps,
+               // ie., the frames are typically transferred in real time).
+               std::chrono::steady_clock::time_point received_timestamp =
+                       std::chrono::steady_clock::time_point::min();
        };
 
        virtual ~FrameAllocator();
index 5f53e95079db2553f39d6472afaf59c3e81980b0..fbcfeddbf14bffc9b020a41772db44eb0e629561 100644 (file)
@@ -13,6 +13,7 @@
 #if __SSE2__
 #include <immintrin.h>
 #endif
+#include <chrono>
 #include <cstddef>
 
 #include "bmusb/bmusb.h"
@@ -26,6 +27,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 {
@@ -255,6 +257,7 @@ void FakeCapture::producer_thread_func()
                                memset4(video_frame.data, ycbcr, width * height / 2);
                        }
                        video_frame.len = width * height * 2;
+                       video_frame.received_timestamp = steady_clock::now();
                }
 
                AudioFormat audio_format;
@@ -266,6 +269,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 = steady_clock::now();
 
                        if (audio_sin == 0.0f) {
                                // Silence.