run-time video dump option

WIVRN_DUMP_VIDEO=/path/to/file will dump the raw video stream in
/path/to/file-{idx}.{codec} where idx is the stream index (one stream
per encoder) and codec is h264 or h265.
This commit is contained in:
Patrick Nicolas
2024-02-12 21:12:02 +01:00
parent 998cb917ef
commit 72e8a5d84d
2 changed files with 23 additions and 11 deletions
+20 -11
View File
@@ -21,7 +21,6 @@
#include "driver/wivrn_session.h" #include "driver/wivrn_session.h"
#include "video_encoder.h" #include "video_encoder.h"
#include "util/u_logging.h"
#include <string> #include <string>
@@ -69,13 +68,25 @@ std::unique_ptr<VideoEncoder> VideoEncoder::Create(
res = std::make_unique<VideoEncoderVA>(vk, settings, fps); res = std::make_unique<VideoEncoderVA>(vk, settings, fps);
} }
#endif #endif
if (res) if (not res)
throw std::runtime_error("Failed to create encoder " + settings.encoder_name);
res->stream_idx = stream_idx;
auto wivrn_dump_video= std::getenv("WIVRN_DUMP_VIDEO");
if (wivrn_dump_video)
{ {
res->stream_idx = stream_idx; std::string file(wivrn_dump_video);
} file += "-" + std::to_string(stream_idx);
else switch (settings.codec)
{ {
U_LOG_E("No video encoder %s", settings.encoder_name.c_str()); case h264:
file += ".h264";
break;
case h265:
file += ".h265";
break;
}
res->video_dump.open(file);
} }
return res; return res;
} }
@@ -109,10 +120,8 @@ void VideoEncoder::Encode(wivrn_session & cnx,
void VideoEncoder::SendData(std::span<uint8_t> data, bool end_of_frame) void VideoEncoder::SendData(std::span<uint8_t> data, bool end_of_frame)
{ {
std::lock_guard lock(mutex); std::lock_guard lock(mutex);
#if 0 if (video_dump)
std::ofstream debug("/tmp/video_dump-" + std::to_string(stream_idx), std::ios::app); video_dump.write((char*)data.data(), data.size());
debug.write((char*)data.data(), data.size());
#endif
if (shard.shard_idx == 0) if (shard.shard_idx == 0)
cnx->dump_time("send_begin", shard.frame_idx, os_monotonic_get_ns(), stream_idx); cnx->dump_time("send_begin", shard.frame_idx, os_monotonic_get_ns(), stream_idx);
+3
View File
@@ -23,6 +23,7 @@
#include "vk/vk_helpers.h" #include "vk/vk_helpers.h"
#include <atomic> #include <atomic>
#include <chrono> #include <chrono>
#include <fstream>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
@@ -55,6 +56,8 @@ private:
std::atomic_bool sync_needed = true; std::atomic_bool sync_needed = true;
std::ofstream video_dump;
public: public:
static std::unique_ptr<VideoEncoder> Create(vk_bundle * vk, static std::unique_ptr<VideoEncoder> Create(vk_bundle * vk,
vk_cmd_pool & pool, vk_cmd_pool & pool,