]> git.sesse.net Git - nageru/blobdiff - httpd.cpp
Fix yet another memory leak in the serving part.
[nageru] / httpd.cpp
index 6a92699936c45ef3a0c324064512af69abd2d2b8..401509d265f5404a63119691e345d35f7f954d86 100644 (file)
--- a/httpd.cpp
+++ b/httpd.cpp
@@ -162,6 +162,9 @@ HTTPD::Mux::Mux(AVFormatContext *avctx, int width, int height)
        avstream_video->codec->color_range = AVCOL_RANGE_MPEG;  // Full vs. limited range (output_ycbcr_format.full_range).
        avstream_video->codec->chroma_sample_location = AVCHROMA_LOC_LEFT;  // Chroma sample location. See chroma_offset_0[] in Mixer::subsample_chroma().
        avstream_video->codec->field_order = AV_FIELD_PROGRESSIVE;
+       if (avctx->oformat->flags & AVFMT_GLOBALHEADER) {
+               avstream_video->codec->flags = AV_CODEC_FLAG_GLOBAL_HEADER;
+       }
 
        AVCodec *codec_audio = avcodec_find_encoder(AUDIO_OUTPUT_CODEC);
        avstream_audio = avformat_new_stream(avctx, codec_audio);
@@ -176,6 +179,9 @@ HTTPD::Mux::Mux(AVFormatContext *avctx, int width, int height)
        avstream_audio->codec->channels = 2;
        avstream_audio->codec->channel_layout = AV_CH_LAYOUT_STEREO;
        avstream_audio->codec->time_base = AVRational{1, TIMEBASE};
+       if (avctx->oformat->flags & AVFMT_GLOBALHEADER) {
+               avstream_audio->codec->flags = AV_CODEC_FLAG_GLOBAL_HEADER;
+       }
 
        AVDictionary *options = NULL;
        vector<pair<string, string>> opts = MUX_OPTS;
@@ -191,6 +197,8 @@ HTTPD::Mux::Mux(AVFormatContext *avctx, int width, int height)
 HTTPD::Mux::~Mux()
 {
        av_write_trailer(avctx);
+       av_free(avctx->pb->buffer);
+       av_free(avctx->pb);
        avformat_free_context(avctx);
 }
 
@@ -218,6 +226,8 @@ void HTTPD::Mux::add_packet(const AVPacket &pkt, int64_t pts, int64_t dts)
                fprintf(stderr, "av_interleaved_write_frame() failed\n");
                exit(1);
        }
+
+       av_packet_unref(&pkt_copy);
 }
 
 HTTPD::Stream::Stream(AVOutputFormat *oformat, int width, int height)