Merge writer-thread with original which was time-cleanup.
[dcpomatic.git] / src / lib / filter_graph.cc
index 7d627b1b0b82d9687df9a6d6f85217bbe5d49b32..86864a762295c93c4d22085570d45feb5b7f6640 100644 (file)
@@ -1,6 +1,31 @@
+/*
+    Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+/** @file src/lib/filter_graph.cc
+ *  @brief A graph of FFmpeg filters.
+ */
+
 extern "C" {
 #include <libavfilter/avfiltergraph.h>
+#ifdef HAVE_BUFFERSRC_H        
 #include <libavfilter/buffersrc.h>
+#endif 
 #if (LIBAVFILTER_VERSION_MAJOR == 2 && LIBAVFILTER_VERSION_MINOR >= 53 && LIBAVFILTER_VERSION_MINOR <= 77) || LIBAVFILTER_VERSION_MAJOR == 3
 #include <libavfilter/avcodec.h>
 #include <libavfilter/buffersink.h>
@@ -9,42 +34,39 @@ extern "C" {
 #endif
 #include <libavformat/avio.h>
 }
-#include "film.h"
 #include "decoder.h"
 #include "filter_graph.h"
 #include "ffmpeg_compatibility.h"
 #include "filter.h"
 #include "exceptions.h"
 #include "image.h"
+#include "film.h"
+#include "ffmpeg_decoder.h"
 
 using std::stringstream;
 using std::string;
 using std::list;
 using boost::shared_ptr;
-
-FilterGraph::FilterGraph (shared_ptr<Film> film, Decoder* decoder, bool crop, Size s, AVPixelFormat p)
+using libdcp::Size;
+
+/** Construct a FilterGraph for the settings in a film.
+ *  @param film Film.
+ *  @param decoder Decoder that we are using.
+ *  @param s Size of the images to process.
+ *  @param p Pixel format of the images to process.
+ */
+FilterGraph::FilterGraph (shared_ptr<Film> film, FFmpegDecoder* decoder, Size s, AVPixelFormat p)
        : _buffer_src_context (0)
        , _buffer_sink_context (0)
        , _size (s)
        , _pixel_format (p)
 {
-       stringstream fs;
-       Size size_after_crop;
-       
-       if (crop) {
-               size_after_crop = film->cropped_size (decoder->native_size ());
-               fs << crop_string (Position (film->crop().left, film->crop().top), size_after_crop);
-       } else {
-               size_after_crop = decoder->native_size ();
-               fs << crop_string (Position (0, 0), size_after_crop);
-       }
-
        string filters = Filter::ffmpeg_strings (film->filters()).first;
        if (!filters.empty ()) {
                filters += ",";
        }
 
-       filters += fs.str ();
+       filters += crop_string (Position (film->crop().left, film->crop().top), film->cropped_size (decoder->native_size()));
 
        avfilter_register_all ();
        
@@ -114,8 +136,11 @@ FilterGraph::FilterGraph (shared_ptr<Film> film, Decoder* decoder, bool crop, Si
        /* XXX: leaking `inputs' / `outputs' ? */
 }
 
+/** Take an AVFrame and process it using our configured filters, returning a
+ *  set of Images.
+ */
 list<shared_ptr<Image> >
-FilterGraph::process (AVFrame* frame)
+FilterGraph::process (AVFrame const * frame)
 {
        list<shared_ptr<Image> > images;
        
@@ -176,9 +201,12 @@ FilterGraph::process (AVFrame* frame)
        return images;
 }
 
+/** @param s Image size.
+ *  @param p Pixel format.
+ *  @return true if this chain can process images with `s' and `p', otherwise false.
+ */
 bool
 FilterGraph::can_process (Size s, AVPixelFormat p) const
 {
        return (_size == s && _pixel_format == p);
 }
-