]> git.sesse.net Git - nageru/blobdiff - kaeru.cpp
Add an option to control the mapping of streams to export to MJPEG (or turn it off...
[nageru] / kaeru.cpp
index e763c3429383064c529d8d1e45c5f8450b75ec51..b3a9bb3e43f92e09501198cd54c190d3a5579538 100644 (file)
--- a/kaeru.cpp
+++ b/kaeru.cpp
@@ -1,5 +1,4 @@
 // Kaeru (換える), a simple transcoder intended for use with Nageru.
-// This is experimental code, not yet supported.
 
 #include "audio_encoder.h"
 #include "basic_stats.h"
@@ -32,6 +31,8 @@ BasicStats *global_basic_stats = nullptr;
 QuittableSleeper should_quit;
 MuxMetrics stream_mux_metrics;
 
+namespace {
+
 int write_packet(void *opaque, uint8_t *buf, int buf_size, AVIODataMarkerType type, int64_t time)
 {
        static bool seen_sync_markers = false;
@@ -48,13 +49,15 @@ int write_packet(void *opaque, uint8_t *buf, int buf_size, AVIODataMarkerType ty
 
        if (type == AVIO_DATA_MARKER_HEADER) {
                stream_mux_header.append((char *)buf, buf_size);
-               httpd->set_header(stream_mux_header);
+               httpd->set_header(HTTPD::MAIN_STREAM, stream_mux_header);
        } else {
-               httpd->add_data((char *)buf, buf_size, type == AVIO_DATA_MARKER_SYNC_POINT, time, AVRational{ AV_TIME_BASE, 1 });
+               httpd->add_data(HTTPD::MAIN_STREAM, (char *)buf, buf_size, type == AVIO_DATA_MARKER_SYNC_POINT, time, AVRational{ AV_TIME_BASE, 1 });
        }
        return buf_size;
 }
 
+}  // namespace
+
 unique_ptr<Mux> create_mux(HTTPD *httpd, AVOutputFormat *oformat, X264Encoder *x264_encoder, AudioEncoder *audio_encoder)
 {
        AVFormatContext *avctx = avformat_alloc_context();
@@ -69,8 +72,7 @@ unique_ptr<Mux> create_mux(HTTPD *httpd, AVOutputFormat *oformat, X264Encoder *x
        string video_extradata = x264_encoder->get_global_headers();
 
        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,
+       mux.reset(new Mux(avctx, global_flags.width, global_flags.height, Mux::CODEC_H264, video_extradata, audio_encoder->get_codec_parameters().get(), COARSE_TIMEBASE,
                /*write_callback=*/nullptr, Mux::WRITE_FOREGROUND, { &stream_mux_metrics }));
        stream_mux_metrics.init({{ "destination", "http" }});
        return mux;
@@ -130,7 +132,7 @@ void video_frame_callback(FFmpegCapture *video, X264Encoder *x264_encoder, Audio
 
 void audio_frame_callback(Mux *mux, const AVPacket *pkt, AVRational timebase)
 {
-       mux->add_packet(*pkt, pkt->pts, pkt->dts == AV_NOPTS_VALUE ? pkt->pts : pkt->dts, timebase);
+       mux->add_packet(*pkt, pkt->pts, pkt->dts == AV_NOPTS_VALUE ? pkt->pts : pkt->dts, timebase, /*stream_index=*/1);
 }
 
 void adjust_bitrate(int signal)
@@ -173,7 +175,9 @@ int main(int argc, char *argv[])
        }
        global_flags.num_cards = 1;  // For latency metrics.
 
+#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(58, 9, 100)
        av_register_all();
+#endif
        avformat_network_init();
 
        HTTPD httpd;
@@ -206,7 +210,7 @@ int main(int argc, char *argv[])
        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);
+       BasicStats basic_stats(/*verbose=*/false, /*use_opengl=*/false);
        global_basic_stats = &basic_stats;
        httpd.start(global_flags.http_port);