Merge master and multifarious hackery.
[dcpomatic.git] / src / lib / filter_graph.cc
index b0427a23d0566166921fd6e95eceb5b86c879505..4564033d5379dd5d6770addfdac826cff447237f 100644 (file)
@@ -33,7 +33,6 @@ extern "C" {
 #include "filter.h"
 #include "exceptions.h"
 #include "image.h"
-#include "film.h"
 #include "ffmpeg_decoder.h"
 
 #include "i18n.h"
@@ -42,15 +41,15 @@ using std::stringstream;
 using std::string;
 using std::list;
 using boost::shared_ptr;
+using boost::weak_ptr;
 using libdcp::Size;
 
-/** Construct a FFmpegFilterGraph for the settings in a film.
- *  @param film Film.
- *  @param decoder Decoder that we are using.
+/** Construct a FilterGraph for the settings in a piece of content.
+ *  @param content Content.
  *  @param s Size of the images to process.
  *  @param p Pixel format of the images to process.
  */
-FFmpegFilterGraph::FFmpegFilterGraph (shared_ptr<Film> film, FFmpegDecoder* decoder, libdcp::Size s, AVPixelFormat p)
+FilterGraph::FilterGraph (shared_ptr<const FFmpegContent> content, libdcp::Size s, AVPixelFormat p)
        : _buffer_src_context (0)
        , _buffer_sink_context (0)
        , _size (s)
@@ -58,12 +57,16 @@ FFmpegFilterGraph::FFmpegFilterGraph (shared_ptr<Film> film, FFmpegDecoder* deco
 {
        _frame = av_frame_alloc ();
        
-       string filters = Filter::ffmpeg_strings (film->filters()).first;
+       string filters = Filter::ffmpeg_strings (content->filters()).first;
        if (!filters.empty ()) {
-               filters += N_(",");
+               filters += ",";
        }
 
-       filters += crop_string (Position (film->crop().left, film->crop().top), film->cropped_size (decoder->native_size()));
+       Crop crop = content->crop ();
+       libdcp::Size cropped_size = _size;
+       cropped_size.width -= crop.left + crop.right;
+       cropped_size.height -= crop.top + crop.bottom;
+       filters += crop_string (Position (crop.left, crop.top), cropped_size);
 
        AVFilterGraph* graph = avfilter_graph_alloc();
        if (graph == 0) {
@@ -83,8 +86,8 @@ FFmpegFilterGraph::FFmpegFilterGraph (shared_ptr<Film> film, FFmpegDecoder* deco
        stringstream a;
        a << "video_size=" << _size.width << "x" << _size.height << ":"
          << "pix_fmt=" << _pixel_format << ":"
-         << "time_base=" << decoder->time_base_numerator() << "/" << decoder->time_base_denominator() << ":"
-         << "pixel_aspect=" << decoder->sample_aspect_ratio_numerator() << "/" << decoder->sample_aspect_ratio_denominator();
+         << "time_base=0/1:"
+         << "pixel_aspect=0/1";
 
        int r;
 
@@ -127,7 +130,7 @@ FFmpegFilterGraph::FFmpegFilterGraph (shared_ptr<Film> film, FFmpegDecoder* deco
        /* XXX: leaking `inputs' / `outputs' ? */
 }
 
-FFmpegFilterGraph::~FFmpegFilterGraph ()
+FilterGraph::~FilterGraph ()
 {
        av_frame_free (&_frame);
 }
@@ -136,7 +139,7 @@ FFmpegFilterGraph::~FFmpegFilterGraph ()
  *  set of Images.  Caller handles memory management of the input frame.
  */
 list<shared_ptr<Image> >
-FFmpegFilterGraph::process (AVFrame* frame)
+FilterGraph::process (AVFrame* frame)
 {
        list<shared_ptr<Image> > images;
 
@@ -160,25 +163,7 @@ FFmpegFilterGraph::process (AVFrame* frame)
  *  @return true if this chain can process images with `s' and `p', otherwise false.
  */
 bool
-FFmpegFilterGraph::can_process (libdcp::Size s, AVPixelFormat p) const
+FilterGraph::can_process (libdcp::Size s, AVPixelFormat p) const
 {
        return (_size == s && _pixel_format == p);
 }
-
-list<shared_ptr<Image> >
-EmptyFilterGraph::process (AVFrame* frame)
-{
-       list<shared_ptr<Image> > im;
-       im.push_back (shared_ptr<Image> (new SimpleImage (frame)));
-       return im;
-}
-
-shared_ptr<FilterGraph>
-filter_graph_factory (shared_ptr<Film> film, FFmpegDecoder* decoder, libdcp::Size size, AVPixelFormat pixel_format)
-{
-       if (film->filters().empty() && film->crop() == Crop()) {
-               return shared_ptr<FilterGraph> (new EmptyFilterGraph);
-       }
-
-       return shared_ptr<FilterGraph> (new FFmpegFilterGraph (film, decoder, size, pixel_format));
-}