2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file src/encoder.h
21 * @brief Parent class for classes which can encode video and audio frames.
27 using namespace boost;
29 int const Encoder::_history_size = 25;
31 /** @param s FilmState of the film that we are encoding.
35 Encoder::Encoder (shared_ptr<const FilmState> s, shared_ptr<const Options> o, Log* l)
39 , _just_skipped (false)
46 /** @return an estimate of the current number of frames we are encoding per second,
50 Encoder::current_frames_per_second () const
52 boost::mutex::scoped_lock lock (_history_mutex);
53 if (int (_time_history.size()) < _history_size) {
58 gettimeofday (&now, 0);
60 return _history_size / (seconds (now) - seconds (_time_history.back ()));
64 Encoder::skipping () const
66 boost::mutex::scoped_lock (_history_mutex);
71 Encoder::last_frame () const
73 boost::mutex::scoped_lock (_history_mutex);
78 Encoder::frame_done (int n)
80 boost::mutex::scoped_lock lock (_history_mutex);
81 _just_skipped = false;
85 gettimeofday (&tv, 0);
86 _time_history.push_front (tv);
87 if (int (_time_history.size()) > _history_size) {
88 _time_history.pop_back ();
92 /** Called by a subclass when it has just skipped the processing
93 of a frame because it has already been done.
96 Encoder::frame_skipped ()
98 boost::mutex::scoped_lock lock (_history_mutex);