Skip to content

Commit

Permalink
deadlock fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Ren authored and Steven Lovegrove committed Jun 28, 2017
1 parent d876c9e commit 858a17f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/pangolin/log/packetstream_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class PANGOLIN_EXPORT PacketStreamWriter
PacketStreamSourceId AddSource(const PacketStreamSource& source);

void WriteSourcePacket(
PacketStreamSourceId src, const char* source,
PacketStreamSourceId src, const char* source,const int64_t receive_time_us,
size_t sourcelen, const picojson::value& meta = picojson::value()
);

Expand Down
7 changes: 3 additions & 4 deletions src/log/packetstream_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,17 @@ void PacketStreamWriter::WriteMeta(PacketStreamSourceId src, const picojson::val
data.serialize(std::ostream_iterator<char>(_stream), false);
}

void PacketStreamWriter::WriteSourcePacket(PacketStreamSourceId src, const char* source, size_t sourcelen, const picojson::value& meta)
void PacketStreamWriter::WriteSourcePacket(PacketStreamSourceId src, const char* source, const int64_t receive_time_us, size_t sourcelen, const picojson::value& meta)
{
const int64_t time_us = Time_us(TimeNow());

SCOPED_LOCK;
_sources[src].index.push_back({_stream.tellp(), time_us});
_sources[src].index.push_back({_stream.tellp(), receive_time_us});

if (!meta.is<picojson::null>())
WriteMeta(src, meta);

writeTag(_stream, TAG_SRC_PACKET);
writeTimestamp(_stream, time_us);
writeTimestamp(_stream, receive_time_us);
writeCompressedUnsignedInt(_stream, src);

if (_sources[src].data_size_bytes) {
Expand Down
16 changes: 14 additions & 2 deletions src/video/drivers/pango_video_output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <pangolin/utils/memstreambuf.h>
#include <pangolin/utils/picojson.h>
#include <pangolin/utils/sigstate.h>
#include <pangolin/utils/timer.h>
#include <pangolin/video/drivers/pango_video_output.h>
#include <pangolin/video/iostream_operators.h>
#include <set>
Expand Down Expand Up @@ -195,6 +196,17 @@ int PangoVideoOutput::WriteStreams(const unsigned char* data, const picojson::va
}
#endif

int64_t receive_time_us;

if (frame_properties.contains("timestamp_us"))
{
receive_time_us = frame_properties["timestamp_us"].get<int64_t>();
}
else
{
receive_time_us = Time_us(TimeNow());
}

if(!fixed_size) {
memstreambuf encoded(total_frame_size);
std::ostream encode_stream(&encoded);
Expand All @@ -217,9 +229,9 @@ int PangoVideoOutput::WriteStreams(const unsigned char* data, const picojson::va
}
}
encode_stream.flush();
packetstream.WriteSourcePacket(packetstreamsrcid, reinterpret_cast<const char*>(encoded.data()), encoded.size(), frame_properties);
packetstream.WriteSourcePacket(packetstreamsrcid, reinterpret_cast<const char*>(encoded.data()), receive_time_us, encoded.size(), frame_properties);
}else{
packetstream.WriteSourcePacket(packetstreamsrcid, reinterpret_cast<const char*>(data), total_frame_size, frame_properties);
packetstream.WriteSourcePacket(packetstreamsrcid, reinterpret_cast<const char*>(data), receive_time_us, total_frame_size, frame_properties);
}

return 0;
Expand Down

0 comments on commit 858a17f

Please sign in to comment.