]> git.sesse.net Git - nageru/blobdiff - shared/ffmpeg_raii.cpp
Support SRT inputs.
[nageru] / shared / ffmpeg_raii.cpp
index 746e03d19122da0cd11ad70735670b9b9d318af5..a1028f844b9cbe3dc8299a7fdbc3d518590d6309 100644 (file)
@@ -37,6 +37,23 @@ AVFormatContextWithCloser avformat_open_input_unique(
        return AVFormatContextWithCloser(format_ctx);
 }
 
+AVFormatContextWithCloser avformat_open_input_unique(
+       int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
+       void *opaque, AVInputFormat *fmt, AVDictionary **options,
+       const AVIOInterruptCB &interrupt_cb)
+{
+       AVFormatContext *format_ctx = avformat_alloc_context();
+       format_ctx->interrupt_callback = interrupt_cb;
+       constexpr size_t buf_size = 4096;
+       unsigned char *buf = (unsigned char *)av_malloc(buf_size);
+       format_ctx->pb = avio_alloc_context(buf, buf_size, /*write_flag=*/false, opaque,
+               read_packet, /*write_packet=*/nullptr, /*seek=*/nullptr);
+       if (avformat_open_input(&format_ctx, "", fmt, options) != 0) {
+               format_ctx = nullptr;
+       }
+       return AVFormatContextWithCloser(format_ctx);
+}
+
 // AVCodecContext
 
 void avcodec_free_context_unique::operator() (AVCodecContext *codec_ctx) const