summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-07-01 16:05:28 +0100
committerCarl Hetherington <cth@carlh.net>2014-07-01 16:05:28 +0100
commite777b4336af5eb8c83fdd5dfe56116b10f973ad3 (patch)
treeecc174901194c3b31763b2663ffbc789af5f6955 /src
parent362bc777b951bdbd7e9231c4dfe5cbd183aaa64a (diff)
Optimise filter graphs with no filters.
Diffstat (limited to 'src')
-rw-r--r--src/lib/filter_graph.cc43
-rw-r--r--src/lib/filter_graph.h2
2 files changed, 28 insertions, 17 deletions
diff --git a/src/lib/filter_graph.cc b/src/lib/filter_graph.cc
index 8b259a12d..f6a6c4529 100644
--- a/src/lib/filter_graph.cc
+++ b/src/lib/filter_graph.cc
@@ -53,18 +53,21 @@ using dcp::Size;
* @param p Pixel format of the images to process.
*/
FilterGraph::FilterGraph (shared_ptr<const FFmpegContent> content, dcp::Size s, AVPixelFormat p)
- : _buffer_src_context (0)
+ : _copy (false)
+ , _buffer_src_context (0)
, _buffer_sink_context (0)
, _size (s)
, _pixel_format (p)
+ , _frame (0)
{
- _frame = av_frame_alloc ();
-
- string filters = Filter::ffmpeg_string (content->filters());
+ string const filters = Filter::ffmpeg_string (content->filters());
if (filters.empty ()) {
- filters = "copy";
+ _copy = true;
+ return;
}
+ _frame = av_frame_alloc ();
+
AVFilterGraph* graph = avfilter_graph_alloc();
if (graph == 0) {
throw DecodeError (N_("could not create filter graph."));
@@ -128,7 +131,9 @@ FilterGraph::FilterGraph (shared_ptr<const FFmpegContent> content, dcp::Size s,
FilterGraph::~FilterGraph ()
{
- av_frame_free (&_frame);
+ if (_frame) {
+ av_frame_free (&_frame);
+ }
}
/** Take an AVFrame and process it using our configured filters, returning a
@@ -139,19 +144,23 @@ FilterGraph::process (AVFrame* frame)
{
list<pair<shared_ptr<Image>, int64_t> > images;
- if (av_buffersrc_write_frame (_buffer_src_context, frame) < 0) {
- throw DecodeError (N_("could not push buffer into filter chain."));
- }
-
- while (true) {
- if (av_buffersink_get_frame (_buffer_sink_context, _frame) < 0) {
- break;
+ if (_copy) {
+ images.push_back (make_pair (shared_ptr<Image> (new Image (frame)), av_frame_get_best_effort_timestamp (frame)));
+ } else {
+ if (av_buffersrc_write_frame (_buffer_src_context, frame) < 0) {
+ throw DecodeError (N_("could not push buffer into filter chain."));
+ }
+
+ while (true) {
+ if (av_buffersink_get_frame (_buffer_sink_context, _frame) < 0) {
+ break;
+ }
+
+ images.push_back (make_pair (shared_ptr<Image> (new Image (_frame)), av_frame_get_best_effort_timestamp (_frame)));
+ av_frame_unref (_frame);
}
-
- images.push_back (make_pair (shared_ptr<Image> (new Image (_frame)), av_frame_get_best_effort_timestamp (_frame)));
- av_frame_unref (_frame);
}
-
+
return images;
}
diff --git a/src/lib/filter_graph.h b/src/lib/filter_graph.h
index 45ad5d998..5b43c5512 100644
--- a/src/lib/filter_graph.h
+++ b/src/lib/filter_graph.h
@@ -43,6 +43,8 @@ public:
std::list<std::pair<boost::shared_ptr<Image>, int64_t> > process (AVFrame * frame);
private:
+ /** true if this graph has no filters in, so it just copies stuff straight through */
+ bool _copy;
AVFilterContext* _buffer_src_context;
AVFilterContext* _buffer_sink_context;
dcp::Size _size; ///< size of the images that this chain can process