]> git.sesse.net Git - casparcg/commitdiff
[ffmpeg_producer] Constrain SEEK values
authorDimitry Ishenko <dimitry.ishenko@gmail.com>
Wed, 2 Nov 2016 14:00:53 +0000 (10:00 -0400)
committerDimitry Ishenko <dimitry.ishenko@gmail.com>
Wed, 2 Nov 2016 14:32:18 +0000 (10:32 -0400)
modules/ffmpeg/producer/ffmpeg_producer.cpp

index 48facf644a8e2a22696a433830bfb33ab396b48d..fe0492adea5816d2c893b28f8df2d7e376057091 100644 (file)
@@ -441,19 +441,21 @@ public:
                }
                else if(boost::regex_match(param, what, seek_exp))
                {
-                       auto value = boost::lexical_cast<uint32_t>(what["VALUE"].str());
+                       auto value = boost::lexical_cast<int64_t>(what["VALUE"].str());
                        auto whence = what["WHENCE"].str();
+                       auto total = file_nb_frames();
 
                        if(boost::iequals(whence, L"REL"))
-                       {
                                value = file_frame_number() + value;
-                       }
                        else if(boost::iequals(whence, L"END"))
-                       {
-                               value = file_nb_frames() - value;
-                       }
+                               value = total - value;
+
+                       if(value < 0)
+                               value = 0;
+                       else if(value >= total)
+                               value = total - 1;
 
-                       input_.seek(value);
+                       input_.seek(static_cast<uint32_t>(value));
                }
                else if(boost::regex_match(param, what, length_exp))
                {