Merge.
[dcpomatic.git] / src / lib / filter_graph.cc
index 1418384b85672235aa17cf6291d81ed588b08bdf..b0991a2da9d53f2e7ac45a17da509d5db4975a40 100644 (file)
 
 */
 
+/** @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>
@@ -28,45 +34,40 @@ 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, libdcp::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 ();
-       
        AVFilterGraph* graph = avfilter_graph_alloc();
        if (graph == 0) {
                throw DecodeError ("Could not create filter graph.");
@@ -133,8 +134,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;
        
@@ -195,8 +199,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
+FilterGraph::can_process (libdcp::Size s, AVPixelFormat p) const
 {
        return (_size == s && _pixel_format == p);
 }