diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-03-03 12:54:07 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-03-03 12:54:07 +0000 |
| commit | 1629bd7df2150156109afbc7a16677cb29e82adf (patch) | |
| tree | f8d42b82976bf999eafd1abd499027a5ea5be02e /src/lib | |
| parent | cc3900735839ff4b0da0c046b5c606c440ba917a (diff) | |
| parent | f0738a22fc7555c306d49bcd1c356ce210e2c0e2 (diff) | |
Merge master.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/cross.cc | 17 | ||||
| -rw-r--r-- | src/lib/cross.h | 27 | ||||
| -rw-r--r-- | src/lib/encoder.cc | 2 | ||||
| -rw-r--r-- | src/lib/encoder.h | 2 | ||||
| -rw-r--r-- | src/lib/film.cc | 8 | ||||
| -rw-r--r-- | src/lib/sndfile_content.cc | 2 | ||||
| -rw-r--r-- | src/lib/util.cc | 10 | ||||
| -rw-r--r-- | src/lib/util.h | 1 |
8 files changed, 61 insertions, 8 deletions
diff --git a/src/lib/cross.cc b/src/lib/cross.cc index 9f7a76124..786f4b997 100644 --- a/src/lib/cross.cc +++ b/src/lib/cross.cc @@ -34,6 +34,7 @@ #ifdef DCPOMATIC_OSX #include <sys/sysctl.h> #include <mach-o/dyld.h> +#include <IOKit/pwr_mgt/IOPMLib.h> #endif #ifdef DCPOMATIC_POSIX #include <sys/types.h> @@ -300,9 +301,23 @@ dcpomatic_fseek (FILE* stream, int64_t offset, int whence) } void -kick () +Waker::nudge () { #ifdef DCPOMATIC_WINDOWS SetThreadExecutionState (ES_CONTINUOUS); #endif } + +Waker::Waker () +{ +#ifdef DCPOMATIC_OSX + IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, CFSTR ("Encoding DCP"), &_assertion_id); +#endif +} + +Waker::~Waker () +{ +#ifdef DCPOMATIC_OSX + IOPMAssertionRelease (_assertion_id); +#endif +} diff --git a/src/lib/cross.h b/src/lib/cross.h index 822b36631..1c7754503 100644 --- a/src/lib/cross.h +++ b/src/lib/cross.h @@ -17,7 +17,13 @@ */ +#ifndef DCPOMATIC_CROSS_H +#define DCPOMATIC_CROSS_H + #include <boost/filesystem.hpp> +#ifdef DCPOMATIC_OSX +#include <IOKit/pwr_mgt/IOPMLib.h> +#endif #ifdef DCPOMATIC_WINDOWS #define WEXITSTATUS(w) (w) @@ -35,4 +41,23 @@ extern boost::filesystem::path app_contents (); #endif extern FILE * fopen_boost (boost::filesystem::path, std::string); extern int dcpomatic_fseek (FILE *, int64_t, int); -void kick (); + +/** A class which tries to keep the computer awake on various operating systems. + * Create a Waker to prevent sleep, and call ::nudge every so often (every minute or so). + * Destroy the Waker to allow sleep again. + */ +class Waker +{ +public: + Waker (); + ~Waker (); + + void nudge (); + +private: +#ifdef DCPOMATIC_OSX + IOPMAssertionID _assertion_id; +#endif +}; + +#endif diff --git a/src/lib/encoder.cc b/src/lib/encoder.cc index f1c3e7e61..7863859de 100644 --- a/src/lib/encoder.cc +++ b/src/lib/encoder.cc @@ -180,7 +180,7 @@ Encoder::frame_done () void Encoder::process_video (shared_ptr<PlayerImage> image, Eyes eyes, ColourConversion conversion, bool same) { - kick (); + _waker.nudge (); boost::mutex::scoped_lock lock (_mutex); diff --git a/src/lib/encoder.h b/src/lib/encoder.h index 079174f89..e0ee2d414 100644 --- a/src/lib/encoder.h +++ b/src/lib/encoder.h @@ -37,6 +37,7 @@ extern "C" { } #include "util.h" #include "config.h" +#include "cross.h" class Image; class AudioBuffers; @@ -113,6 +114,7 @@ private: boost::condition _condition; boost::shared_ptr<Writer> _writer; + Waker _waker; }; #endif diff --git a/src/lib/film.cc b/src/lib/film.cc index e463a0e35..4b3f6a8dd 100644 --- a/src/lib/film.cc +++ b/src/lib/film.cc @@ -906,25 +906,25 @@ Film::playlist_changed () AudioFrame Film::time_to_audio_frames (DCPTime t) const { - return t * audio_frame_rate () / TIME_HZ; + return divide_with_round (t * audio_frame_rate (), TIME_HZ); } VideoFrame Film::time_to_video_frames (DCPTime t) const { - return t * video_frame_rate () / TIME_HZ; + return divide_with_round (t * video_frame_rate (), TIME_HZ); } DCPTime Film::audio_frames_to_time (AudioFrame f) const { - return f * TIME_HZ / audio_frame_rate (); + return divide_with_round (f * TIME_HZ, audio_frame_rate ()); } DCPTime Film::video_frames_to_time (VideoFrame f) const { - return f * TIME_HZ / video_frame_rate (); + return divide_with_round (f * TIME_HZ, video_frame_rate ()); } AudioFrame diff --git a/src/lib/sndfile_content.cc b/src/lib/sndfile_content.cc index d3acc7d2e..844f3dd47 100644 --- a/src/lib/sndfile_content.cc +++ b/src/lib/sndfile_content.cc @@ -147,7 +147,7 @@ SndfileContent::full_length () const shared_ptr<const Film> film = _film.lock (); assert (film); - AudioFrame const len = audio_length() * output_audio_frame_rate() / content_audio_frame_rate (); + AudioFrame const len = divide_with_round (audio_length() * output_audio_frame_rate(), content_audio_frame_rate ()); /* XXX: this depends on whether, alongside this audio, we are running video slower or faster than it should be. The calculation above works out the output audio frames assuming that we are just diff --git a/src/lib/util.cc b/src/lib/util.cc index 725039a7e..7089ef2a5 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -1026,3 +1026,13 @@ entities_to_text (string e) boost::algorithm::replace_all (e, "%2F", "/"); return e; } + +int64_t +divide_with_round (int64_t a, int64_t b) +{ + if (a % b >= (b / 2)) { + return (a + b - 1) / b; + } else { + return a / b; + } +} diff --git a/src/lib/util.h b/src/lib/util.h index f625b8572..13bf0f42d 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -130,6 +130,7 @@ extern std::string get_required_string (std::multimap<std::string, std::string> extern int get_optional_int (std::multimap<std::string, std::string> const & kv, std::string k); extern std::string get_optional_string (std::multimap<std::string, std::string> const & kv, std::string k); extern void* wrapped_av_malloc (size_t); +extern int64_t divide_with_round (int64_t a, int64_t b); /** @class Socket * @brief A class to wrap a boost::asio::ip::tcp::socket with some things |
