]> git.sesse.net Git - casparcg/blobdiff - modules/ffmpeg/producer/util/util.cpp
[ffmpeg] Copied flush logic when seeking from 2.0, as well as current frame in clip...
[casparcg] / modules / ffmpeg / producer / util / util.cpp
index e848c56eeec3fe2a5ffd73e965022fa06f8dc053..eb773c6c115f5818572bdee16ddd1072e409a4ba 100644 (file)
@@ -205,8 +205,7 @@ core::mutable_frame make_frame(const void* tag, const spl::shared_ptr<AVFrame>&
                                                                        boost::errinfo_api_function("sws_getContext"));
                }       
                
-               spl::shared_ptr<AVFrame> av_frame(avcodec_alloc_frame(), av_free);      
-               avcodec_get_frame_defaults(av_frame.get());                     
+               auto av_frame = create_frame();
                if(target_pix_fmt == PIX_FMT_BGRA)
                {
                        auto size = avpicture_fill(reinterpret_cast<AVPicture*>(av_frame.get()), write.image_data(0).begin(), PIX_FMT_BGRA, width, height);
@@ -273,8 +272,7 @@ spl::shared_ptr<AVFrame> make_av_frame(core::mutable_frame& frame)
 
 spl::shared_ptr<AVFrame> make_av_frame(std::array<uint8_t*, 4> data, const core::pixel_format_desc& pix_desc)
 {
-       spl::shared_ptr<AVFrame> av_frame(avcodec_alloc_frame(), av_free);      
-       avcodec_get_frame_defaults(av_frame.get());
+       auto av_frame = create_frame();
        
        auto planes              = pix_desc.planes;
        auto format              = pix_desc.format;
@@ -485,15 +483,28 @@ spl::shared_ptr<AVPacket> create_packet()
 
 spl::shared_ptr<AVFrame> create_frame()
 {      
-       spl::shared_ptr<AVFrame> frame(avcodec_alloc_frame(), av_free);
+       spl::shared_ptr<AVFrame> frame(av_frame_alloc(), [](AVFrame* p)
+       {
+               av_frame_free(&p);
+       });
        avcodec_get_frame_defaults(frame.get());
        return frame;
 }
 
+std::shared_ptr<AVFrame> flush()
+{
+       static std::shared_ptr<AVFrame> dummy(av_frame_alloc(), [](AVFrame* p)
+       {
+               av_frame_free(&p);
+       });
+
+       return dummy;
+}
+
 spl::shared_ptr<AVCodecContext> open_codec(AVFormatContext& context, enum AVMediaType type, int& index, bool single_threaded)
 {      
        AVCodec* decoder;
-       index = THROW_ON_ERROR2(av_find_best_stream(&context, type, -1, -1, &decoder, 0), "");
+       index = THROW_ON_ERROR2(av_find_best_stream(&context, type, index, -1, &decoder, 0), "");
        //if(strcmp(decoder->name, "prores") == 0 && decoder->next && strcmp(decoder->next->name, "prores_lgpl") == 0)
        //      decoder = decoder->next;
 
@@ -587,7 +598,7 @@ bool is_valid_file(const std::wstring& filename, bool only_video)
                buf.push_back(*file_it);
 
        if(buf.empty())
-               return nullptr;
+               return false;
 
        pb.buf          = buf.data();
        pb.buf_size = static_cast<int>(buf.size());