Merge master.
[dcpomatic.git] / src / lib / filter_graph.cc
index 8ff5e75df3d3ee6f5575778147db7210e0350d77..472480de300dee5834555ddde7aba22f5fb369a2 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"
@@ -41,16 +40,17 @@ extern "C" {
 using std::stringstream;
 using std::string;
 using std::list;
+using std::cout;
 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 +58,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 +87,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=1/1:"
+         << "pixel_aspect=1/1";
 
        int r;
 
@@ -127,7 +131,7 @@ FFmpegFilterGraph::FFmpegFilterGraph (shared_ptr<Film> film, FFmpegDecoder* deco
        /* XXX: leaking `inputs' / `outputs' ? */
 }
 
-FFmpegFilterGraph::~FFmpegFilterGraph ()
+FilterGraph::~FilterGraph ()
 {
        av_frame_free (&_frame);
 }
@@ -136,7 +140,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;
 
@@ -161,25 +165,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));
-}