22#include <opendht/utils.h>
33#warning Debug utilities included in build
35using Clock = std::chrono::steady_clock;
36using namespace std::literals;
58 template<
class Period = std::ratio<1>>
61 auto diff = std::chrono::duration_cast<Period>(Clock::now() - start_);
67 JAMI_LOG(
"{}: {} after {}", name_,
action, dht::print_duration(Clock::now() - start_));
71 std::string_view name_;
72 std::chrono::time_point<Clock> start_;
88template<StringLiteral Tag>
91 using time_point = std::chrono::time_point<Clock>;
92 using duration = Clock::duration;
101 auto dt = Clock::now() - start_;
103 if (
stats.count > 1) {
104 JAMI_LOG(
"{}: end after {} - Average duration: {} ({}) Total: {} Min: {} Max: {}",
106 dht::print_duration(
dt),
107 fmt::styled(dht::print_duration(
stats.total_duration /
stats.count), fmt::emphasis::bold),
109 dht::print_duration(
stats.total_duration),
110 dht::print_duration(
stats.min_duration),
111 dht::print_duration(
stats.max_duration));
113 JAMI_LOG(
"{}: end after {}",
Tag.value, dht::print_duration(
dt));
120 duration total_duration {};
121 duration min_duration {duration::max()};
122 duration max_duration {duration::min()};
123 duration::rep count {0};
127 static inline std::mutex mutex_;
128 static inline Stats stats_;
130 Stats inc(duration
dt)
132 std::lock_guard lock(mutex_);
133 stats_.total_duration +=
dt;
135 if (
dt < stats_.min_duration)
136 stats_.min_duration =
dt;
137 if (
dt > stats_.max_duration)
138 stats_.max_duration =
dt;
157 throw std::runtime_error(
"Failed to allocate output format context");
160 switch (
frame->format) {
184 throw std::runtime_error(
"Unsupported audio format");
189 throw std::runtime_error(
"Failed to find audio codec");
193 throw std::runtime_error(
"Failed to allocate audio codec context");
196 codec_ctx_->ch_layout =
frame->ch_layout;
197 codec_ctx_->sample_rate =
frame->sample_rate;
202 throw std::runtime_error(
"Failed to open audio codec");
206 throw std::runtime_error(
"Failed to create audio stream");
209 throw std::runtime_error(
"Failed to copy codec parameters to stream");
213 throw std::runtime_error(
"Failed to open output file for writing");
217 throw std::runtime_error(
"Failed to write header to output file");
224 JAMI_ERROR(
"Error sending a frame to the encoder");
234 pkt->stream_index = stream_->index;
237 lastPts +=
frame->nb_samples * (
int64_t) stream_->time_base.den
238 / (stream_->time_base.num * (
int64_t)
frame->sample_rate);
241 JAMI_ERROR(
"Error while writing output packet");
292 JAMI_DBG(
"Play video file with: ffplay -f rawvideo -pixel_format %s -video_size %dx%d %s",
303 auto*
f =
frame.pointer();
305 if (format_ !=
f->format || width_ !=
f->width || height_ !=
f->height)
316 reinterpret_cast<const int*
>(
f->linesize),
332 std::string filename_;
Ex: Timer t; std::this_thread::sleep_for(std::chrono::milliseconds(10)); JAMI_LOG("Task took {} ns",...
Timer(std::string_view name)
void print(std::string_view action) const
uint64_t getDuration() const
Minimally invasive video writer.
void write(VideoFrame &frame)
VideoWriter(const std::string &filename, int format, int width, int height)
VideoWriter(const std::string &filename, AVPixelFormat format, int width, int height)
void write(AVFrame *frame)
WavWriter(const char *filename, AVFrame *frame)
std::chrono::steady_clock Clock
#define JAMI_ERROR(formatstr,...)
#define JAMI_WARNING(formatstr,...)
#define JAMI_LOG(formatstr,...)
void emitSignal(Args... args)
consteval StringLiteral(const char(&str)[N])
void av_packet_free(AVPacket **frame)