X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fkaeru.cpp;h=2bdc6861f2dffa5a17a0d81922e38adcbaf0b95b;hb=f1d22d113f924803ee0e0f33b81f0720f9378eae;hp=9ff672d0f16ab946f1b7e03dce85f068af67f01d;hpb=f0db8fcc58dd66a7dfd019f99add721d8161b75a;p=nageru diff --git a/nageru/kaeru.cpp b/nageru/kaeru.cpp index 9ff672d..2bdc686 100644 --- a/nageru/kaeru.cpp +++ b/nageru/kaeru.cpp @@ -6,20 +6,45 @@ #include "flags.h" #include "ffmpeg_capture.h" #include "mixer.h" +#include "print_latency.h" +#include "shared/ffmpeg_raii.h" +#include "shared/httpd.h" #include "shared/mux.h" #include "quittable_sleeper.h" +#include "shared/shared_defs.h" #include "shared/timebase.h" #include "x264_encoder.h" #include -#include -#include -#include +#include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include +#include extern "C" { #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include } using namespace bmusb; @@ -66,7 +91,7 @@ int write_packet(void *opaque, uint8_t *buf, int buf_size, AVIODataMarkerType ty unique_ptr create_mux(HTTPD *httpd, const AVOutputFormat *oformat, X264Encoder *x264_encoder, AudioEncoder *audio_encoder) { AVFormatContext *avctx = avformat_alloc_context(); - avctx->oformat = const_castoformat)>(oformat); // const_cast is a hack to work in FFmpeg both before and after 5.0. + avctx->oformat = oformat; // const_cast is a hack to work in FFmpeg both before and after 5.0. uint8_t *buf = (uint8_t *)av_malloc(MUX_BUFFER_SIZE); avctx->pb = avio_alloc_context(buf, MUX_BUFFER_SIZE, 1, httpd, nullptr, nullptr, nullptr); @@ -93,8 +118,8 @@ void video_frame_callback(FFmpegCapture *video, X264Encoder *x264_encoder, Audio int64_t video_pts, AVRational video_timebase, int64_t audio_pts, AVRational audio_timebase, uint16_t timecode, - FrameAllocator::Frame video_frame, size_t video_offset, VideoFormat video_format, - FrameAllocator::Frame audio_frame, size_t audio_offset, AudioFormat audio_format) + FrameAllocator::Frame video_frame, size_t video_offset, VideoFormat video_format, + FrameAllocator::Frame audio_frame, size_t audio_offset, AudioFormat audio_format) { if (video_pts >= 0 && video_frame.len > 0) { ReceivedTimestamps ts; @@ -132,7 +157,7 @@ void video_frame_callback(FFmpegCapture *video, X264Encoder *x264_encoder, Audio } audio_pts = av_rescale_q(audio_pts, audio_timebase, AVRational{ 1, TIMEBASE }); audio_encoder->encode_audio(float_samples, audio_pts); - } + } if (video_frame.owner) { video_frame.owner->release_frame(video_frame); @@ -162,10 +187,8 @@ void filter_packet_callback(Mux *mux, int stream_index, AVBSFContext *bsfctx, co fprintf(stderr, "av_bsf_send_packet() failed with %d, ignoring\n", err); } for ( ;; ) { - AVPacket out_pkt; - unique_ptr pkt_cleanup(&out_pkt, av_packet_unref); - av_init_packet(&out_pkt); - err = av_bsf_receive_packet(bsfctx, &out_pkt); + AVPacketWithDeleter out_pkt = av_packet_alloc_unique(); + err = av_bsf_receive_packet(bsfctx, out_pkt.get()); if (err == AVERROR(EAGAIN)) { break; } @@ -173,7 +196,7 @@ void filter_packet_callback(Mux *mux, int stream_index, AVBSFContext *bsfctx, co fprintf(stderr, "av_bsf_receive_packet() failed with %d, ignoring\n", err); return; } - mux->add_packet(out_pkt, out_pkt.pts, out_pkt.dts == AV_NOPTS_VALUE ? out_pkt.pts : out_pkt.dts, timebase, stream_index); + mux->add_packet(*out_pkt, out_pkt->pts, out_pkt->dts == AV_NOPTS_VALUE ? out_pkt->pts : out_pkt->dts, timebase, stream_index); } }