+ if (cache) {
+ cout << "cache hit.\n";
+ _format_context = cache->format_context;
+ } else {
+ cout << "cache miss.\n";
+ /* XXX: avio_buffer and the AVIOContext are never freed */
+ uint8_t* avio_buffer = static_cast<uint8_t*> (wrapped_av_malloc(_avio_buffer_size));
+ _format_context = avformat_alloc_context ();
+ _format_context->pb = avio_alloc_context (avio_buffer, _avio_buffer_size, 0, this, avio_read_wrapper, 0, avio_seek_wrapper);
+
+ AVDictionary* options = 0;
+ /* These durations are in microseconds, and represent how far into the content file
+ we will look for streams.
+ */
+ av_dict_set (&options, "analyzeduration", raw_convert<string>(5 * 60 * 1000000).c_str(), 0);
+ av_dict_set (&options, "probesize", raw_convert<string>(5 * 60 * 1000000).c_str(), 0);
+#ifdef DCPOMATIC_VARIANT_SWAROOP
+ if (_ffmpeg_content->kdm()) {
+ DecryptedECinemaKDM kdm (_ffmpeg_content->kdm().get(), Config::instance()->decryption_chain()->key().get());
+ av_dict_set (&options, "decryption_key", kdm.key().hex().c_str(), 0);
+ }
+#endif
+
+ int e = avformat_open_input (&_format_context, 0, 0, &options);
+ if (e < 0) {
+ throw OpenFileError (_ffmpeg_content->path(0), e, true);
+ }
+
+ if (avformat_find_stream_info (_format_context, 0) < 0) {
+ throw DecodeError (_("could not find stream information"));
+ }