Rename TYPE_DEBUG_PLAYER to TYPE_DEBUG_VIDEO_VIEW.
[dcpomatic.git] / src / lib / util.h
1 /*
2     Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 /** @file src/util.h
22  *  @brief Some utility functions and classes.
23  */
24
25 #ifndef DCPOMATIC_UTIL_H
26 #define DCPOMATIC_UTIL_H
27
28 #include "types.h"
29 #include "dcpomatic_time.h"
30 #include "audio_mapping.h"
31 #include <dcp/util.h>
32 #include <dcp/subtitle_image.h>
33 #include <boost/shared_ptr.hpp>
34 #include <boost/optional.hpp>
35 #include <boost/filesystem.hpp>
36 #include <boost/date_time/gregorian/gregorian.hpp>
37 #include <string>
38 #include <map>
39 #include <vector>
40
41 #undef check
42
43 namespace dcp {
44         class PictureAsset;
45         class SoundAsset;
46 }
47
48 #ifndef M_PI
49 #define M_PI (3.14159265358979323846)
50 #endif
51
52 /** The maximum number of audio channels that we can have in a DCP */
53 #define MAX_DCP_AUDIO_CHANNELS 16
54 /** Message broadcast to find possible encoding servers */
55 #define DCPOMATIC_HELLO "I mean really, Ray, it's used."
56 /** Number of films to keep in history */
57 #define HISTORY_SIZE 10
58 #define REPORT_PROBLEM _("Please report this problem by using Help -> Report a problem or via email to carl@dcpomatic.com")
59 #define TEXT_FONT_ID "font"
60 /** Largest KDM size (in bytes) that will be accepted */
61 #define MAX_KDM_SIZE (256 * 1024)
62 /** Number of lines that closed caption viewers will display */
63 #define CLOSED_CAPTION_LINES 3
64 /** Maximum line length of closed caption viewers */
65 #define CLOSED_CAPTION_LENGTH 30
66 /* We are mis-using genre here, as only some metadata tags are written/read.
67    I tried the use_metadata_tags option but it didn't seem to make any difference.
68 */
69 #define SWAROOP_ID_TAG "genre"
70
71 extern std::string program_name;
72 extern bool is_batch_converter;
73
74 struct AVSubtitle;
75 class AudioBuffers;
76 class TextDecoder;
77
78 extern std::string seconds_to_hms (int);
79 extern std::string time_to_hmsf (dcpomatic::DCPTime time, Frame rate);
80 extern std::string seconds_to_approximate_hms (int);
81 extern double seconds (struct timeval);
82 extern void dcpomatic_setup ();
83 extern void dcpomatic_setup_path_encoding ();
84 extern void dcpomatic_setup_gettext_i18n (std::string);
85 extern std::string digest_head_tail (std::vector<boost::filesystem::path>, boost::uintmax_t size);
86 extern void ensure_ui_thread ();
87 extern std::string audio_channel_name (int);
88 extern std::string short_audio_channel_name (int);
89 extern bool valid_image_file (boost::filesystem::path);
90 extern bool valid_sound_file (boost::filesystem::path);
91 extern bool valid_j2k_file (boost::filesystem::path);
92 #ifdef DCPOMATIC_WINDOWS
93 extern boost::filesystem::path mo_path ();
94 #endif
95 extern std::string tidy_for_filename (std::string);
96 extern dcp::Size fit_ratio_within (float ratio, dcp::Size);
97 extern int stride_round_up (int, int const *, int);
98 extern void* wrapped_av_malloc (size_t);
99 extern void set_backtrace_file (boost::filesystem::path);
100 extern std::map<std::string, std::string> split_get_request (std::string url);
101 extern std::string video_asset_filename (boost::shared_ptr<dcp::PictureAsset> asset, int reel_index, int reel_count, boost::optional<std::string> content_summary);
102 extern std::string audio_asset_filename (boost::shared_ptr<dcp::SoundAsset> asset, int reel_index, int reel_count, boost::optional<std::string> content_summary);
103 extern float relaxed_string_to_float (std::string);
104 extern std::string careful_string_filter (std::string);
105 extern std::pair<int, int> audio_channel_types (std::list<int> mapped, int channels);
106 extern boost::shared_ptr<AudioBuffers> remap (boost::shared_ptr<const AudioBuffers> input, int output_channels, AudioMapping map);
107 extern Eyes increment_eyes (Eyes e);
108 extern void checked_fread (void* ptr, size_t size, FILE* stream, boost::filesystem::path path);
109 extern void checked_fwrite (void const * ptr, size_t size, FILE* stream, boost::filesystem::path path);
110 extern size_t utf8_strlen (std::string s);
111 extern std::string day_of_week_to_string (boost::gregorian::greg_weekday d);
112 extern void emit_subtitle_image (dcpomatic::ContentTimePeriod period, dcp::SubtitleImage sub, dcp::Size size, boost::shared_ptr<TextDecoder> decoder);
113 extern bool show_jobs_on_console (bool progress);
114 extern void copy_in_bits (boost::filesystem::path from, boost::filesystem::path to, boost::function<void (float)>);
115 #ifdef DCPOMATIC_VARIANT_SWAROOP
116 extern boost::shared_ptr<dcp::CertificateChain> read_swaroop_chain (boost::filesystem::path path);
117 extern void write_swaroop_chain (boost::shared_ptr<const dcp::CertificateChain> chain, boost::filesystem::path output);
118 #endif
119 extern dcp::Size scale_for_display (dcp::Size s, dcp::Size display_container, dcp::Size film_container);
120
121 template <class T>
122 std::list<T>
123 vector_to_list (std::vector<T> v)
124 {
125         std::list<T> l;
126         BOOST_FOREACH (T& i, v) {
127                 l.push_back (i);
128         }
129         return l;
130 }
131
132 template <class T>
133 std::vector<T>
134 list_to_vector (std::list<T> v)
135 {
136         std::vector<T> l;
137         BOOST_FOREACH (T& i, v) {
138                 l.push_back (i);
139         }
140         return l;
141 }
142
143 extern double db_to_linear (double db);
144 extern double linear_to_db (double linear);
145
146 #endif