// This is experimental code, not yet supported.
#include "audio_encoder.h"
+#include "basic_stats.h"
#include "defs.h"
#include "flags.h"
#include "ffmpeg_capture.h"
#include <fcntl.h>
#include <signal.h>
#include <unistd.h>
+#include <chrono>
#include <string>
using namespace bmusb;
using namespace movit;
using namespace std;
+using namespace std::chrono;
using namespace std::placeholders;
Mixer *global_mixer = nullptr;
X264Encoder *global_x264_encoder = nullptr;
+int frame_num = 0;
+BasicStats *global_basic_stats = nullptr;
+MuxMetrics stream_mux_metrics;
int write_packet(void *opaque, uint8_t *buf, int buf_size, AVIODataMarkerType type, int64_t time)
{
unique_ptr<Mux> mux;
int time_base = global_flags.stream_coarse_timebase ? COARSE_TIMEBASE : TIMEBASE;
mux.reset(new Mux(avctx, global_flags.width, global_flags.height, Mux::CODEC_H264, video_extradata, audio_encoder->get_codec_parameters().get(), time_base,
- /*write_callback=*/nullptr, Mux::WRITE_FOREGROUND, {}));
+ /*write_callback=*/nullptr, Mux::WRITE_FOREGROUND, { &stream_mux_metrics }));
+ stream_mux_metrics.init({{ "destination", "http" }});
return mux;
}
FrameAllocator::Frame audio_frame, size_t audio_offset, AudioFormat audio_format)
{
if (video_pts >= 0 && video_frame.len > 0) {
+ ReceivedTimestamps ts;
+ ts.ts.push_back(steady_clock::now());
+
video_pts = av_rescale_q(video_pts, video_timebase, AVRational{ 1, TIMEBASE });
- int64_t frame_duration = TIMEBASE * video_format.frame_rate_nom / video_format.frame_rate_den;
- x264_encoder->add_frame(video_pts, frame_duration, video->get_current_frame_ycbcr_format().luma_coefficients, video_frame.data + video_offset, ReceivedTimestamps());
+ int64_t frame_duration = TIMEBASE * video_format.frame_rate_den / video_format.frame_rate_nom;
+ x264_encoder->add_frame(video_pts, frame_duration, video->get_current_frame_ycbcr_format().luma_coefficients, video_frame.data + video_offset, ts);
+ global_basic_stats->update(frame_num++, /*dropped_frames=*/0);
}
if (audio_frame.len > 0) {
// FFmpegCapture takes care of this for us.
usage(PROGRAM_KAERU);
exit(1);
}
+ global_flags.num_cards = 1; // For latency metrics.
av_register_all();
avformat_network_init();
video.start_bm_capture();
video.change_rate(2.0); // Be sure never to really fall behind, but also don't dump huge amounts of stuff onto x264.
+ BasicStats basic_stats(/*verbose=*/false);
+ global_basic_stats = &basic_stats;
httpd.start(9095);
signal(SIGUSR1, adjust_bitrate);