]> git.sesse.net Git - nageru/blobdiff - shared/ffmpeg_raii.cpp
zita-resampler was mentioned twice in the dependency list.
[nageru] / shared / ffmpeg_raii.cpp
index 746e03d19122da0cd11ad70735670b9b9d318af5..0e087c27b063a03ef80e909f22ec1d2c9516fbde 100644 (file)
@@ -18,20 +18,45 @@ void avformat_close_input_unique::operator() (AVFormatContext *format_ctx) const
 }
 
 AVFormatContextWithCloser avformat_open_input_unique(
-       const char *pathname, AVInputFormat *fmt,
+       const char *pathname, const AVInputFormat *fmt,
        AVDictionary **options)
 {
        return avformat_open_input_unique(pathname, fmt, options, AVIOInterruptCB{ nullptr, nullptr });
 }
 
 AVFormatContextWithCloser avformat_open_input_unique(
-       const char *pathname, AVInputFormat *fmt,
+       const char *pathname, const AVInputFormat *fmt,
        AVDictionary **options,
        const AVIOInterruptCB &interrupt_cb)
 {
        AVFormatContext *format_ctx = avformat_alloc_context();
        format_ctx->interrupt_callback = interrupt_cb;
+#ifdef ff_const59
+       if (avformat_open_input(&format_ctx, pathname, const_cast<ff_const59 AVInputFormat *>(fmt), options) != 0) {
+#else
        if (avformat_open_input(&format_ctx, pathname, fmt, options) != 0) {
+#endif
+               format_ctx = nullptr;
+       }
+       return AVFormatContextWithCloser(format_ctx);
+}
+
+AVFormatContextWithCloser avformat_open_input_unique(
+       int (*read_packet)(void *opaque, uint8_t *buf, int buf_size),
+       void *opaque, const 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);
+#ifdef ff_const59
+       if (avformat_open_input(&format_ctx, "", const_cast<ff_const59 AVInputFormat *>(fmt), options) != 0) {
+#else
+       if (avformat_open_input(&format_ctx, "", fmt, options) != 0) {
+#endif
                format_ctx = nullptr;
        }
        return AVFormatContextWithCloser(format_ctx);