X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=nageru%2Fkaeru.cpp;h=2bdc6861f2dffa5a17a0d81922e38adcbaf0b95b;hb=HEAD;hp=ce58aef9473f3da33112ca5d72e5d8ca5da24ded;hpb=bdc9f1ea04141e71906d486f9d254c3346835e72;p=nageru diff --git a/nageru/kaeru.cpp b/nageru/kaeru.cpp index ce58aef..caa71c6 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 = oformat; + 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); } } @@ -244,7 +267,7 @@ int main(int argc, char *argv[]) } global_x264_encoder = x264_encoder.get(); - FFmpegCapture video(argv[optind], global_flags.width, global_flags.height); + FFmpegCapture video(argv[optind], global_flags.width, global_flags.height, /*surface=*/nullptr); video.set_pixel_format(FFmpegCapture::PixelFormat_NV12); if (global_flags.transcode_video) { video.set_frame_callback(bind(video_frame_callback, &video, x264_encoder.get(), audio_encoder.get(), _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11));