Send vulkan video idr over tcp
This commit is contained in:
@@ -60,7 +60,7 @@ video_encoder::sender::sender() :
|
|||||||
}
|
}
|
||||||
if (d and not d->span.empty())
|
if (d and not d->span.empty())
|
||||||
{
|
{
|
||||||
d->encoder->SendData(d->span, true);
|
d->encoder->SendData(d->span, true, d->prefer_control);
|
||||||
std::unique_lock lock(mutex);
|
std::unique_lock lock(mutex);
|
||||||
pending.pop_front();
|
pending.pop_front();
|
||||||
cv.notify_all();
|
cv.notify_all();
|
||||||
@@ -314,7 +314,7 @@ void video_encoder::encode(wivrn_session & cnx,
|
|||||||
std::rethrow_exception(ex);
|
std::rethrow_exception(ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void video_encoder::SendData(std::span<uint8_t> data, bool end_of_frame)
|
void video_encoder::SendData(std::span<uint8_t> data, bool end_of_frame, bool control)
|
||||||
{
|
{
|
||||||
std::lock_guard lock(mutex);
|
std::lock_guard lock(mutex);
|
||||||
if (end_of_frame)
|
if (end_of_frame)
|
||||||
@@ -336,8 +336,7 @@ void video_encoder::SendData(std::span<uint8_t> data, bool end_of_frame)
|
|||||||
auto end = data.end();
|
auto end = data.end();
|
||||||
while (begin != end)
|
while (begin != end)
|
||||||
{
|
{
|
||||||
const size_t view_info_size = sizeof(to_headset::video_stream_data_shard::view_info_t);
|
const size_t max_payload_size = to_headset::video_stream_data_shard::max_payload_size - serialized_size(shard.view_info);
|
||||||
const size_t max_payload_size = to_headset::video_stream_data_shard::max_payload_size - (shard.view_info ? view_info_size : 0);
|
|
||||||
auto next = std::min(end, begin + max_payload_size);
|
auto next = std::min(end, begin + max_payload_size);
|
||||||
if (next == end)
|
if (next == end)
|
||||||
{
|
{
|
||||||
@@ -351,7 +350,10 @@ void video_encoder::SendData(std::span<uint8_t> data, bool end_of_frame)
|
|||||||
shard.payload = {begin, next};
|
shard.payload = {begin, next};
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cnx->send_stream(to_headset::video_stream_data_shard{shard});
|
if (control)
|
||||||
|
cnx->send_control(to_headset::video_stream_data_shard{shard});
|
||||||
|
else
|
||||||
|
cnx->send_stream(to_headset::video_stream_data_shard{shard});
|
||||||
}
|
}
|
||||||
catch (...)
|
catch (...)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ protected:
|
|||||||
video_encoder * encoder;
|
video_encoder * encoder;
|
||||||
std::span<uint8_t> span;
|
std::span<uint8_t> span;
|
||||||
std::shared_ptr<void> mem;
|
std::shared_ptr<void> mem;
|
||||||
|
// true if data should be sent over reliable (TCP) socket
|
||||||
|
bool prefer_control = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -140,7 +142,7 @@ public:
|
|||||||
// called when command buffer finished executing
|
// called when command buffer finished executing
|
||||||
virtual std::optional<data> encode(bool idr, std::chrono::steady_clock::time_point target_timestamp, uint8_t slot) = 0;
|
virtual std::optional<data> encode(bool idr, std::chrono::steady_clock::time_point target_timestamp, uint8_t slot) = 0;
|
||||||
|
|
||||||
void SendData(std::span<uint8_t> data, bool end_of_frame);
|
void SendData(std::span<uint8_t> data, bool end_of_frame, bool control = false);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace wivrn
|
} // namespace wivrn
|
||||||
|
|||||||
@@ -416,9 +416,11 @@ std::vector<uint8_t> wivrn::video_encoder_vulkan::get_encoded_parameters(void *
|
|||||||
|
|
||||||
std::optional<wivrn::video_encoder::data> wivrn::video_encoder_vulkan::encode(bool idr, std::chrono::steady_clock::time_point target_timestamp, uint8_t encode_slot)
|
std::optional<wivrn::video_encoder::data> wivrn::video_encoder_vulkan::encode(bool idr, std::chrono::steady_clock::time_point target_timestamp, uint8_t encode_slot)
|
||||||
{
|
{
|
||||||
if (idr)
|
// we manage idrs ourselves
|
||||||
send_idr_data();
|
(void)idr;
|
||||||
auto & slot_item = slot_data[encode_slot];
|
auto & slot_item = slot_data[encode_slot];
|
||||||
|
if (slot_item.idr)
|
||||||
|
send_idr_data();
|
||||||
|
|
||||||
if (auto res = vk.device.waitForFences(*slot_item.fence, true, 1'000'000'000);
|
if (auto res = vk.device.waitForFences(*slot_item.fence, true, 1'000'000'000);
|
||||||
res != vk::Result::eSuccess)
|
res != vk::Result::eSuccess)
|
||||||
@@ -438,6 +440,7 @@ std::optional<wivrn::video_encoder::data> wivrn::video_encoder_vulkan::encode(bo
|
|||||||
return data{
|
return data{
|
||||||
.encoder = this,
|
.encoder = this,
|
||||||
.span = std::span(((uint8_t *)mapped) + feedback[0], feedback[1]),
|
.span = std::span(((uint8_t *)mapped) + feedback[0], feedback[1]),
|
||||||
|
.prefer_control = slot_item.idr,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -611,31 +614,15 @@ std::pair<bool, vk::Semaphore> wivrn::video_encoder_vulkan::present_image(vk::Im
|
|||||||
|
|
||||||
auto last_ack = this->last_ack.load();
|
auto last_ack = this->last_ack.load();
|
||||||
dpb_item * ref_slot = nullptr;
|
dpb_item * ref_slot = nullptr;
|
||||||
for (size_t i = 0; i < dpb.size(); ++i)
|
for (auto & i: dpb)
|
||||||
{
|
{
|
||||||
if (dpb[i].frame_index == last_ack and dpb[i].info.slotIndex != -1)
|
if (i.frame_index == last_ack and i.info.slotIndex != -1)
|
||||||
{
|
{
|
||||||
ref_slot = &dpb[i];
|
ref_slot = &i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Avoid sending many IDR in a row
|
|
||||||
if (frame_num < 100 and not ref_slot)
|
|
||||||
{
|
|
||||||
for (size_t i = 0; i < dpb.size(); ++i)
|
|
||||||
{
|
|
||||||
if (dpb[i].info.slotIndex != -1)
|
|
||||||
{
|
|
||||||
if (not ref_slot or ref_slot->frame_index < dpb[i].frame_index)
|
|
||||||
{
|
|
||||||
ref_slot = &dpb[i];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (not ref_slot)
|
if (not ref_slot)
|
||||||
{
|
{
|
||||||
frame_num = 0;
|
frame_num = 0;
|
||||||
@@ -645,6 +632,12 @@ std::pair<bool, vk::Semaphore> wivrn::video_encoder_vulkan::present_image(vk::Im
|
|||||||
slot.info.pPictureResource = nullptr;
|
slot.info.pPictureResource = nullptr;
|
||||||
slot.frame_index = -1;
|
slot.frame_index = -1;
|
||||||
}
|
}
|
||||||
|
slot_item.idr = true;
|
||||||
|
last_ack = frame_index;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
slot_item.idr = false;
|
||||||
}
|
}
|
||||||
slot->frame_index = frame_index;
|
slot->frame_index = frame_index;
|
||||||
slot->info.pPictureResource = &slot->resource;
|
slot->info.pPictureResource = &slot->resource;
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ class video_encoder_vulkan : public video_encoder
|
|||||||
vk::raii::ImageView view = nullptr;
|
vk::raii::ImageView view = nullptr;
|
||||||
buffer_allocation output_buffer;
|
buffer_allocation output_buffer;
|
||||||
buffer_allocation host_buffer;
|
buffer_allocation host_buffer;
|
||||||
|
bool idr = false;
|
||||||
};
|
};
|
||||||
std::array<slot_item, num_slots> slot_data;
|
std::array<slot_item, num_slots> slot_data;
|
||||||
|
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ std::vector<uint8_t> wivrn::video_encoder_vulkan_h264::get_sps_pps()
|
|||||||
void wivrn::video_encoder_vulkan_h264::send_idr_data()
|
void wivrn::video_encoder_vulkan_h264::send_idr_data()
|
||||||
{
|
{
|
||||||
auto data = get_sps_pps();
|
auto data = get_sps_pps();
|
||||||
SendData(data, false);
|
SendData(data, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void * wivrn::video_encoder_vulkan_h264::encode_info_next(uint32_t frame_num, size_t slot, std::optional<int32_t> ref_slot)
|
void * wivrn::video_encoder_vulkan_h264::encode_info_next(uint32_t frame_num, size_t slot, std::optional<int32_t> ref_slot)
|
||||||
|
|||||||
Reference in New Issue
Block a user