23#include <opendht/utils.h>
34#warning Debug utilities included in build
36using Clock = std::chrono::steady_clock;
37using namespace std::literals;
57 template<
class Period = std::ratio<1>>
60 auto diff = std::chrono::duration_cast<Period>(Clock::now() - start_);
65 JAMI_LOG(
"{}: {} after {}", name_,
action, dht::print_duration(Clock::now() - start_));
69 std::string_view name_;
70 std::chrono::time_point<Clock> start_;
82 using time_point = std::chrono::time_point<Clock>;
83 using duration = Clock::duration;
88 auto duration = Clock::now() - start_;
89 auto [
avg, count] = inc(duration);
90 JAMI_LOG(
"{}: end after {}", Tag::name(), dht::print_duration(duration));
92 JAMI_LOG(
"{}: Average duration: {} ({})", Tag::name(), dht::print_duration(
avg), count);
97 static inline std::mutex mutex_;
98 static inline duration total_duration_ {};
99 static inline duration::rep count_ {0};
101 std::pair<duration, duration::rep> inc(duration
dt) {
102 std::lock_guard lock(mutex_);
103 total_duration_ +=
dt;
105 return {total_duration_ / count_, count_};
109#define STATS_TIMER(tag) \
110 struct StatsTimerTag_##tag { \
111 static constexpr std::string_view name() { return #tag; } \
113 jami::debug::StatsTimer<StatsTimerTag_##tag> stats_timer_##tag
125 throw std::runtime_error(
"Failed to allocate output format context");
128 switch (
frame->format) {
152 throw std::runtime_error(
"Unsupported audio format");
157 throw std::runtime_error(
"Failed to find audio codec");
161 throw std::runtime_error(
"Failed to allocate audio codec context");
164 codec_ctx_->ch_layout =
frame->ch_layout;
165 codec_ctx_->sample_rate =
frame->sample_rate;
170 throw std::runtime_error(
"Failed to open audio codec");
174 throw std::runtime_error(
"Failed to create audio stream");
177 throw std::runtime_error(
"Failed to copy codec parameters to stream");
181 throw std::runtime_error(
"Failed to open output file for writing");
185 throw std::runtime_error(
"Failed to write header to output file");
191 JAMI_ERROR(
"Error sending a frame to the encoder");
201 pkt->stream_index = stream_->index;
204 lastPts +=
frame->nb_samples * (
int64_t)stream_->time_base.den / (stream_->time_base.num * (
int64_t)
frame->sample_rate);
207 JAMI_ERROR(
"Error while writing output packet");
240 : filename_(filename)
245 f_ =
fopen(filename.c_str(),
"wb");
249 VideoWriter(
const std::string& filename,
int format,
int width,
int height)
256 JAMI_DBG(
"Play video file with: ffplay -f rawvideo -pixel_format %s -video_size %dx%d %s",
269 if (format_ !=
f->format || width_ !=
f->width || height_ !=
f->height)
280 reinterpret_cast<const int*
>(
f->linesize),
296 std::string filename_;
Ex: Timer t; std::this_thread::sleep_for(std::chrono::milliseconds(10)); JAMI_DBG() << "Task took " <...
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)
void av_packet_free(AVPacket **frame)