summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-10-03 02:02:12 +0200
committerCarl Hetherington <cth@carlh.net>2021-10-03 23:41:02 +0200
commitc2a17a87868eba87072fc369102b2b3cd8905e5a (patch)
tree0f5b5e425476efca9ad297c5e65845ae31531ba6 /src/lib
parentaee64f1b2c9252f8315eaead7d43e1ec58a39ee2 (diff)
Add PixelQuanta to VideoContent.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/dcp_examiner.h4
-rw-r--r--src/lib/ffmpeg_examiner.cc9
-rw-r--r--src/lib/ffmpeg_examiner.h2
-rw-r--r--src/lib/image_examiner.h4
-rw-r--r--src/lib/pixel_quanta.cc47
-rw-r--r--src/lib/pixel_quanta.h63
-rw-r--r--src/lib/video_content.cc9
-rw-r--r--src/lib/video_content.h2
-rw-r--r--src/lib/video_examiner.h7
-rw-r--r--src/lib/video_mxf_examiner.h3
-rw-r--r--src/lib/wscript1
11 files changed, 150 insertions, 1 deletions
diff --git a/src/lib/dcp_examiner.h b/src/lib/dcp_examiner.h
index 66f694f72..fd643a754 100644
--- a/src/lib/dcp_examiner.h
+++ b/src/lib/dcp_examiner.h
@@ -62,6 +62,10 @@ public:
return VideoRange::FULL;
}
+ PixelQuanta pixel_quanta () const {
+ return {};
+ }
+
std::string name () const {
return _name;
}
diff --git a/src/lib/ffmpeg_examiner.cc b/src/lib/ffmpeg_examiner.cc
index 853db90be..0a236d836 100644
--- a/src/lib/ffmpeg_examiner.cc
+++ b/src/lib/ffmpeg_examiner.cc
@@ -480,3 +480,12 @@ FFmpegExaminer::range () const
return VideoRange::FULL;
}
}
+
+
+PixelQuanta
+FFmpegExaminer::pixel_quanta () const
+{
+ auto const desc = av_pix_fmt_desc_get(video_codec_context()->pix_fmt);
+ return { 1 << desc->log2_chroma_w, 1 << desc->log2_chroma_h };
+}
+
diff --git a/src/lib/ffmpeg_examiner.h b/src/lib/ffmpeg_examiner.h
index 793460f9b..f978eb52b 100644
--- a/src/lib/ffmpeg_examiner.h
+++ b/src/lib/ffmpeg_examiner.h
@@ -57,6 +57,8 @@ public:
VideoRange range () const;
+ PixelQuanta pixel_quanta () const;
+
AVColorRange color_range () const {
return video_codec_context()->color_range;
}
diff --git a/src/lib/image_examiner.h b/src/lib/image_examiner.h
index cad8683a1..0dcdebad0 100644
--- a/src/lib/image_examiner.h
+++ b/src/lib/image_examiner.h
@@ -39,6 +39,10 @@ public:
VideoRange range () const {
return VideoRange::FULL;
}
+ PixelQuanta pixel_quanta () const {
+ /* See ::yuv - we're assuming the image is not YUV and so not subsampled */
+ return {};
+ }
private:
std::weak_ptr<const Film> _film;
diff --git a/src/lib/pixel_quanta.cc b/src/lib/pixel_quanta.cc
new file mode 100644
index 000000000..12eea5031
--- /dev/null
+++ b/src/lib/pixel_quanta.cc
@@ -0,0 +1,47 @@
+/*
+ Copyright (C) 2021 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#include "pixel_quanta.h"
+#include <dcp/raw_convert.h>
+
+
+PixelQuanta::PixelQuanta (cxml::ConstNodePtr node)
+ : x(node->number_child<int>("X"))
+ , y(node->number_child<int>("Y"))
+{
+
+}
+
+
+void
+PixelQuanta::as_xml (xmlpp::Element* node) const
+{
+ node->add_child("X")->add_child_text(dcp::raw_convert<std::string>(x));
+ node->add_child("Y")->add_child_text(dcp::raw_convert<std::string>(y));
+}
+
+
+PixelQuanta
+max (PixelQuanta const& a, PixelQuanta const& b)
+{
+ return { std::max(a.x, b.x), std::max(a.y, b.y) };
+}
+
diff --git a/src/lib/pixel_quanta.h b/src/lib/pixel_quanta.h
new file mode 100644
index 000000000..e4a03c9d2
--- /dev/null
+++ b/src/lib/pixel_quanta.h
@@ -0,0 +1,63 @@
+/*
+ Copyright (C) 2021 Carl Hetherington <cth@carlh.net>
+
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ DCP-o-matic is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+
+#ifndef DCPOMATIC_PIXEL_QUANTA_H
+#define DCPOMATIC_PIXEL_QUANTA_H
+
+
+#include "warnings.h"
+
+#include <libcxml/cxml.h>
+DCPOMATIC_DISABLE_WARNINGS
+#include <libxml++/libxml++.h>
+DCPOMATIC_ENABLE_WARNINGS
+
+
+class PixelQuanta
+{
+public:
+ PixelQuanta ()
+ : x(1)
+ , y(1)
+ {}
+
+ /** @param x number of pixels that must not be split in the x direction; e.g. if x=2 scale should
+ * only happen to multiples of 2 width, and x crop should only happen at multiples of 2 position.
+ * @param y similar value for y / height.
+ */
+ PixelQuanta (int x_, int y_)
+ : x(x_)
+ , y(y_)
+ {}
+
+ PixelQuanta (cxml::ConstNodePtr node);
+
+ void as_xml (xmlpp::Element* node) const;
+
+ int x;
+ int y;
+};
+
+
+PixelQuanta max (PixelQuanta const& a, PixelQuanta const& b);
+
+#endif
+
diff --git a/src/lib/video_content.cc b/src/lib/video_content.cc
index 655b8baf6..bffe2e322 100644
--- a/src/lib/video_content.cc
+++ b/src/lib/video_content.cc
@@ -184,6 +184,10 @@ VideoContent::VideoContent (Content* parent, cxml::ConstNodePtr node, int versio
_range = VideoRange::VIDEO;
}
+ if (auto pixel_quanta = node->optional_node_child("PixelQuanta")) {
+ _pixel_quanta = PixelQuanta(pixel_quanta);
+ }
+
auto burnt = node->optional_string_child("BurntSubtitleLanguage");
if (burnt) {
_burnt_subtitle_language = dcp::LanguageTag (*burnt);
@@ -243,6 +247,8 @@ VideoContent::VideoContent (Content* parent, vector<shared_ptr<Content> > c)
if (c[i]->video->yuv ()) {
_yuv = true;
}
+
+ _pixel_quanta = max(_pixel_quanta, c[i]->video->_pixel_quanta);
}
_use = ref->use ();
@@ -285,6 +291,7 @@ VideoContent::as_xml (xmlpp::Node* node) const
node->add_child("FadeIn")->add_child_text (raw_convert<string> (_fade_in));
node->add_child("FadeOut")->add_child_text (raw_convert<string> (_fade_out));
node->add_child("Range")->add_child_text(_range == VideoRange::FULL ? "full" : "video");
+ _pixel_quanta.as_xml(node->add_child("PixelQuanta"));
if (_burnt_subtitle_language) {
node->add_child("BurntSubtitleLanguage")->add_child_text(_burnt_subtitle_language->to_string());
}
@@ -299,6 +306,7 @@ VideoContent::take_from_examiner (shared_ptr<VideoExaminer> d)
auto const ar = d->sample_aspect_ratio ();
auto const yuv = d->yuv ();
auto const range = d->range ();
+ auto const pixel_quanta = d->pixel_quanta ();
ContentChangeSignaller cc1 (_parent, VideoContentProperty::SIZE);
ContentChangeSignaller cc2 (_parent, ContentProperty::LENGTH);
@@ -311,6 +319,7 @@ VideoContent::take_from_examiner (shared_ptr<VideoExaminer> d)
_sample_aspect_ratio = ar;
_yuv = yuv;
_range = range;
+ _pixel_quanta = pixel_quanta;
}
LOG_GENERAL ("Video length obtained from header as %1 frames", _length);
diff --git a/src/lib/video_content.h b/src/lib/video_content.h
index 0c4649954..de151e145 100644
--- a/src/lib/video_content.h
+++ b/src/lib/video_content.h
@@ -26,6 +26,7 @@
#include "colour_conversion.h"
#include "content_part.h"
#include "dcpomatic_time.h"
+#include "pixel_quanta.h"
#include "types.h"
#include "user_property.h"
#include <dcp/language_tag.h>
@@ -245,6 +246,7 @@ private:
/** fade out time in content frames */
Frame _fade_out;
VideoRange _range;
+ PixelQuanta _pixel_quanta;
boost::optional<dcp::LanguageTag> _burnt_subtitle_language;
};
diff --git a/src/lib/video_examiner.h b/src/lib/video_examiner.h
index 4e5c6dc0a..c56530448 100644
--- a/src/lib/video_examiner.h
+++ b/src/lib/video_examiner.h
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,14 +18,18 @@
*/
+
/** @file src/lib/video_examiner.h
* @brief VideoExaminer class.
*/
+
+#include "pixel_quanta.h"
#include "types.h"
#include "video_content.h"
#include <dcp/types.h>
+
/** @class VideoExaminer
* @brief Parent for classes which examine video sources and obtain information about them.
*/
@@ -49,4 +53,5 @@ public:
/** @return true if this video is in YUV; must not be called if has_video() == false */
virtual bool yuv () const = 0;
virtual VideoRange range () const = 0;
+ virtual PixelQuanta pixel_quanta () const = 0;
};
diff --git a/src/lib/video_mxf_examiner.h b/src/lib/video_mxf_examiner.h
index 37badafba..3719d3efc 100644
--- a/src/lib/video_mxf_examiner.h
+++ b/src/lib/video_mxf_examiner.h
@@ -42,6 +42,9 @@ public:
VideoRange range () const {
return VideoRange::FULL;
}
+ PixelQuanta pixel_quanta () const {
+ return {};
+ }
private:
std::shared_ptr<dcp::PictureAsset> _asset;
diff --git a/src/lib/wscript b/src/lib/wscript
index 06bb555b2..fd243db68 100644
--- a/src/lib/wscript
+++ b/src/lib/wscript
@@ -133,6 +133,7 @@ sources = """
log_entry.cc
mid_side_decoder.cc
overlaps.cc
+ pixel_quanta.cc
player.cc
player_text.cc
player_video.cc