X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Ffilter_graph.cc;h=86864a762295c93c4d22085570d45feb5b7f6640;hb=039ac5848730d154e0b3f3dd841a55e45ba922d8;hp=7d627b1b0b82d9687df9a6d6f85217bbe5d49b32;hpb=7ffd5bd9b4571c2db06a8c50419fe90b06ef1a07;p=dcpomatic.git diff --git a/src/lib/filter_graph.cc b/src/lib/filter_graph.cc index 7d627b1b0..86864a762 100644 --- a/src/lib/filter_graph.cc +++ b/src/lib/filter_graph.cc @@ -1,6 +1,31 @@ +/* + Copyright (C) 2012 Carl Hetherington + + 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 +#ifdef HAVE_BUFFERSRC_H #include +#endif #if (LIBAVFILTER_VERSION_MAJOR == 2 && LIBAVFILTER_VERSION_MINOR >= 53 && LIBAVFILTER_VERSION_MINOR <= 77) || LIBAVFILTER_VERSION_MAJOR == 3 #include #include @@ -9,42 +34,39 @@ extern "C" { #endif #include } -#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, 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, 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, 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 > -FilterGraph::process (AVFrame* frame) +FilterGraph::process (AVFrame const * frame) { list > 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); } -