X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;ds=sidebyside;f=nageru%2Fkaeru.cpp;h=7a058e47e5e0d4c1733953acf077d9d37c485186;hb=cc295d633756a6e43a36fc3b0b8f38021b4bfe49;hp=390e3cc5f7754c092baa32131a79f595943b00d1;hpb=eeda8995329601f9f4e35047358400833eeae68e;p=nageru diff --git a/nageru/kaeru.cpp b/nageru/kaeru.cpp index 390e3cc..7a058e4 100644 --- a/nageru/kaeru.cpp +++ b/nageru/kaeru.cpp @@ -73,7 +73,7 @@ unique_ptr create_mux(HTTPD *httpd, AVOutputFormat *oformat, X264Encoder *x unique_ptr mux; mux.reset(new Mux(avctx, global_flags.width, global_flags.height, Mux::CODEC_H264, video_extradata, audio_encoder->get_codec_parameters().get(), - get_color_space(global_flags.ycbcr_rec709_coefficients), Mux::WITH_AUDIO, COARSE_TIMEBASE, + get_color_space(global_flags.ycbcr_rec709_coefficients), COARSE_TIMEBASE, /*write_callback=*/nullptr, Mux::WRITE_FOREGROUND, { &stream_mux_metrics })); stream_mux_metrics.init({{ "destination", "http" }}); return mux; @@ -91,7 +91,7 @@ void video_frame_callback(FFmpegCapture *video, X264Encoder *x264_encoder, Audio 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_den / video_format.frame_rate_nom; + int64_t frame_duration = int64_t(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); } @@ -104,17 +104,18 @@ void video_frame_callback(FFmpegCapture *video, X264Encoder *x264_encoder, Audio size_t num_samples = audio_frame.len / (audio_format.bits_per_sample / 8); vector float_samples; float_samples.resize(num_samples); + if (audio_format.bits_per_sample == 16) { const int16_t *src = (const int16_t *)audio_frame.data; float *dst = &float_samples[0]; for (size_t i = 0; i < num_samples; ++i) { - *dst++ = le16toh(*src++) * (1.0f / 32768.0f); + *dst++ = int16_t(le16toh(*src++)) * (1.0f / 32768.0f); } } else if (audio_format.bits_per_sample == 32) { const int32_t *src = (const int32_t *)audio_frame.data; float *dst = &float_samples[0]; for (size_t i = 0; i < num_samples; ++i) { - *dst++ = le32toh(*src++) * (1.0f / 2147483648.0f); + *dst++ = int32_t(le32toh(*src++)) * (1.0f / 2147483648.0f); } } else { assert(false); @@ -209,7 +210,7 @@ int main(int argc, char *argv[]) } video.configure_card(); 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. + video.change_rate(10.0); // Play as fast as possible. BasicStats basic_stats(/*verbose=*/false, /*use_opengl=*/false); global_basic_stats = &basic_stats; @@ -225,6 +226,7 @@ int main(int argc, char *argv[]) video.stop_dequeue_thread(); // Stop the x264 encoder before killing the mux it's writing to. + global_x264_encoder = nullptr; x264_encoder.reset(); return 0; }