]> git.sesse.net Git - casparcg/blobdiff - modules/ffmpeg/producer/ffmpeg_producer.cpp
2.0. ffmpeg_producer: Fixed integer overflow when looping.
[casparcg] / modules / ffmpeg / producer / ffmpeg_producer.cpp
index d6ec0d8994eeb82a6c2a708d1666a23a585b6cbc..839e35a1d02611da708a264500fb65994da7515c 100644 (file)
@@ -65,10 +65,9 @@ struct ffmpeg_producer : public core::frame_producer
        double                                                                                  fps_;\r
        frame_muxer                                                                             muxer_;\r
 \r
-       int                                                                                             late_frames_;\r
        const int                                                                               start_;\r
        const bool                                                                              loop_;\r
-       const int64_t                                                                   length_;\r
+       const size_t                                                                    length_;\r
 \r
        safe_ptr<core::basic_frame>                                             last_frame_;\r
 \r
@@ -77,7 +76,7 @@ struct ffmpeg_producer : public core::frame_producer
        bool                                                                                    is_progressive_;\r
        \r
 public:\r
-       explicit ffmpeg_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& filename, const std::wstring& filter, bool loop, int start, int length) \r
+       explicit ffmpeg_producer(const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& filename, const std::wstring& filter, bool loop, int start, size_t length) \r
                : filename_(filename)\r
                , graph_(diagnostics::create_graph([this]{return print();}))\r
                , frame_factory_(frame_factory)         \r
@@ -87,7 +86,6 @@ public:
                , audio_decoder_(input_.context(), frame_factory->get_video_format_desc())\r
                , fps_(video_decoder_.fps())\r
                , muxer_(fps_, frame_factory)\r
-               , late_frames_(0)\r
                , start_(start)\r
                , loop_(loop)\r
                , length_(length)\r
@@ -121,11 +119,8 @@ public:
                {\r
                        if(input_.eof())\r
                                return core::basic_frame::eof();\r
-                       else\r
-                       {\r
+                       else                    \r
                                graph_->add_tag("underflow");   \r
-                               ++late_frames_;         \r
-                       }\r
                }\r
                \r
                return frame;\r
@@ -177,7 +172,7 @@ public:
        virtual int64_t nb_frames() const \r
        {\r
                if(loop_)\r
-                       return std::numeric_limits<int64_t>::max();\r
+                       return std::numeric_limits<int>::max();\r
 \r
                // This function estimates nb_frames until input has read all packets for one loop, at which point the count should be accurate.\r
 \r
@@ -187,14 +182,14 @@ public:
                        int64_t video_nb_frames = video_decoder_.nb_frames();\r
                        int64_t audio_nb_frames = audio_decoder_.nb_frames();\r
 \r
-                       nb_frames = std::min(length_, std::max(nb_frames, std::max(video_nb_frames, audio_nb_frames)));\r
+                       nb_frames = std::min(static_cast<int64_t>(length_), std::max(nb_frames, std::max(video_nb_frames, audio_nb_frames)));\r
                }\r
 \r
                nb_frames = muxer_.calc_nb_frames(nb_frames);\r
 \r
                // TODO: Might need to scale nb_frames av frame_muxer transformations.\r
 \r
-               return nb_frames + late_frames_ - start_;\r
+               return nb_frames - start_;\r
        }\r
                                \r
        virtual std::wstring print() const\r