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 "video_encoder.h"
#include "util/u_logging.h"
#include <string>
@@ -69,13 +68,25 @@ std::unique_ptr<VideoEncoder> VideoEncoder::Create(
res = std::make_unique<VideoEncoderVA>(vk, settings, fps);
}
#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;
}
else
{
U_LOG_E("No video encoder %s", settings.encoder_name.c_str());
std::string file(wivrn_dump_video);
file += "-" + std::to_string(stream_idx);
switch (settings.codec)
{
case h264:
file += ".h264";
break;
case h265:
file += ".h265";
break;
}
res->video_dump.open(file);
}
return res;
}
@@ -109,10 +120,8 @@ void VideoEncoder::Encode(wivrn_session & cnx,
void VideoEncoder::SendData(std::span<uint8_t> data, bool end_of_frame)
{
std::lock_guard lock(mutex);
#if 0
std::ofstream debug("/tmp/video_dump-" + std::to_string(stream_idx), std::ios::app);
debug.write((char*)data.data(), data.size());
#endif
if (video_dump)
video_dump.write((char*)data.data(), data.size());
if (shard.shard_idx == 0)
cnx->dump_time("send_begin", shard.frame_idx, os_monotonic_get_ns(), stream_idx);