X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=kaeru.cpp;h=b3a9bb3e43f92e09501198cd54c190d3a5579538;hb=refs%2Fheads%2Fmjpeg;hp=011818d35832741321e4ce2b0970fa712a0e62af;hpb=8d846a0cf80b24e9189389b1d0e126a0a717c86d;p=nageru diff --git a/kaeru.cpp b/kaeru.cpp index 011818d..b3a9bb3 100644 --- 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 create_mux(HTTPD *httpd, AVOutputFormat *oformat, X264Encoder *x264_encoder, AudioEncoder *audio_encoder) { AVFormatContext *avctx = avformat_alloc_context(); @@ -129,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) @@ -172,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;