X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=shared%2Fffmpeg_raii.cpp;h=a1028f844b9cbe3dc8299a7fdbc3d518590d6309;hb=4df45e479ddbc8e2247be8aab7f2bab5ddaa1b74;hp=746e03d19122da0cd11ad70735670b9b9d318af5;hpb=b563b8903fa84bb7fd62d7d0b84b70cb26843dbf;p=nageru diff --git a/shared/ffmpeg_raii.cpp b/shared/ffmpeg_raii.cpp index 746e03d..a1028f8 100644 --- a/shared/ffmpeg_raii.cpp +++ b/shared/ffmpeg_raii.cpp @@ -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