Implement frame timestamps and use wpi::Now() for generation.

This commit is contained in:
Peter Johnson
2016-10-22 22:09:47 -07:00
parent aad1266a94
commit 1f6b386325
6 changed files with 23 additions and 7 deletions

View File

@@ -9,7 +9,6 @@
#define CAMERASERVER_FRAME_H_
#include <atomic>
#include <chrono>
#include <memory>
#include "llvm/StringRef.h"
@@ -24,7 +23,7 @@ class Frame {
friend class SourceImpl;
public:
typedef std::chrono::system_clock::time_point Time;
typedef uint64_t Time;
private:
struct Data {

View File

@@ -401,9 +401,7 @@ void MJPEGServerImpl::SendStream(wpi::raw_socket_ostream& os) {
// print the individual mimetype and the length
// sending the content-length fixes random stream disruption observed
// with firefox
double timestamp = std::chrono::duration_cast<std::chrono::seconds>(
frame.time().time_since_epoch())
.count();
double timestamp = frame.time() / 10000000.0;
header.clear();
oss << "Content-Type: image/jpeg\r\n"
<< "Content-Length: " << frame.size() << "\r\n"

View File

@@ -32,6 +32,16 @@ SourceImpl::~SourceImpl() {
// Everything else can clean up itself.
}
uint64_t SourceImpl::GetCurFrameTime() {
std::unique_lock<std::mutex> lock{m_frameMutex};
return m_frame.time();
}
Frame SourceImpl::GetCurFrame() {
std::unique_lock<std::mutex> lock{m_frameMutex};
return m_frame;
}
Frame SourceImpl::GetNextFrame() {
std::unique_lock<std::mutex> lock{m_frameMutex};
// TODO: handle spurious wakeup by comparing frame timestamps

View File

@@ -65,6 +65,9 @@ class SourceImpl {
NumSinksEnabledChanged();
}
// Gets the current frame time (without waiting for a new one).
uint64_t GetCurFrameTime();
// Gets the current frame (without waiting for a new one).
Frame GetCurFrame();

View File

@@ -31,6 +31,7 @@
#include "llvm/raw_ostream.h"
#include "llvm/SmallString.h"
#include "support/timestamp.h"
#include "cameraserver_cpp.h"
#include "c_util.h"
@@ -561,7 +562,7 @@ void USBCameraImpl::CameraThreadMain() {
llvm::StringRef(
static_cast<const char*>(m_buffers[buf.index].m_data),
static_cast<std::size_t>(buf.bytesused)),
Frame::Time{}); // TODO: time
wpi::Now()); // TODO: time
}
// Requeue buffer

View File

@@ -198,7 +198,12 @@ llvm::StringRef GetSourceDescription(CS_Source source,
}
uint64_t GetSourceLastFrameTime(CS_Source source, CS_Status* status) {
return 0; // TODO
auto data = Sources::GetInstance().Get(source);
if (!data) {
*status = CS_INVALID_HANDLE;
return 0;
}
return data->source->GetCurFrameTime();
}
bool IsSourceConnected(CS_Source source, CS_Status* status) {