da6f660a7f559ec0f61aa34cde3fb49627e6ed9e
[dcpomatic.git] / src / lib / util.h
1 /*
2     Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
3
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.
8
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.
13
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.
17
18 */
19
20 /** @file src/util.h
21  *  @brief Some utility functions and classes.
22  */
23
24 #ifndef DCPOMATIC_UTIL_H
25 #define DCPOMATIC_UTIL_H
26
27 #include "compose.hpp"
28 #include "types.h"
29 #include "exceptions.h"
30 #include "dcpomatic_time.h"
31 #include <dcp/util.h>
32 #include <dcp/picture_asset_writer.h>
33 extern "C" {
34 #include <libavcodec/avcodec.h>
35 #include <libavfilter/avfilter.h>
36 }
37 #include <boost/shared_ptr.hpp>
38 #include <boost/optional.hpp>
39 #include <boost/filesystem.hpp>
40 #include <string>
41 #include <vector>
42
43 #undef check
44
45 namespace dcp {
46         class PictureAsset;
47         class SoundAsset;
48         class SubtitleAsset;
49 }
50
51 /** The maximum number of audio channels that we can have in a DCP */
52 #define MAX_DCP_AUDIO_CHANNELS 12
53 /** Message broadcast to find possible encoding servers */
54 #define DCPOMATIC_HELLO "Boys, you gotta learn not to talk to nuns that way"
55 /** Number of films to keep in history */
56 #define HISTORY_SIZE 10
57 #define REPORT_PROBLEM _("Please report this problem by using Help -> Report a problem or via email to carl@dcpomatic.com")
58
59 extern std::string program_name;
60
61 class Job;
62 struct AVSubtitle;
63
64 extern std::string seconds_to_hms (int);
65 extern std::string seconds_to_approximate_hms (int);
66 extern double seconds (struct timeval);
67 extern void dcpomatic_setup ();
68 extern void dcpomatic_setup_gettext_i18n (std::string);
69 extern std::string md5_digest_head_tail (std::vector<boost::filesystem::path>, boost::uintmax_t size);
70 extern void ensure_ui_thread ();
71 extern std::string audio_channel_name (int);
72 extern bool valid_image_file (boost::filesystem::path);
73 extern bool valid_j2k_file (boost::filesystem::path);
74 #ifdef DCPOMATIC_WINDOWS
75 extern boost::filesystem::path mo_path ();
76 #endif
77 extern std::string tidy_for_filename (std::string);
78 extern dcp::Size fit_ratio_within (float ratio, dcp::Size);
79 extern int dcp_audio_frame_rate (int);
80 extern int stride_round_up (int, int const *, int);
81 extern int round_to (float n, int r);
82 extern void* wrapped_av_malloc (size_t);
83
84 class FFmpegSubtitlePeriod
85 {
86 public:
87         FFmpegSubtitlePeriod (ContentTime f)
88                 : from (f)
89         {}
90
91         FFmpegSubtitlePeriod (ContentTime f, ContentTime t)
92                 : from (f)
93                 , to (t)
94         {}
95
96         ContentTime from;
97         boost::optional<ContentTime> to;
98 };
99
100 extern FFmpegSubtitlePeriod subtitle_period (AVSubtitle const &);
101 extern void set_backtrace_file (boost::filesystem::path);
102 extern std::map<std::string, std::string> split_get_request (std::string url);
103 extern std::string video_asset_filename (boost::shared_ptr<dcp::PictureAsset> asset);
104 extern std::string audio_asset_filename (boost::shared_ptr<dcp::SoundAsset> asset);
105
106 #endif
107