summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-04-09 00:03:35 +0200
committerCarl Hetherington <cth@carlh.net>2021-04-09 00:03:35 +0200
commit4e9a15d558ecca660eb74f54b693d1e4a3aa7381 (patch)
tree45dd4160839ca9b40b866b5908736b7b7448c690 /src/lib
parent37a6d1a768debea28c24174503d85903f7f90aa5 (diff)
Extract audio/subtitle language from imported DCPs.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/dcp_content.cc20
-rw-r--r--src/lib/dcp_examiner.cc16
-rw-r--r--src/lib/dcp_examiner.h10
3 files changed, 37 insertions, 9 deletions
diff --git a/src/lib/dcp_content.cc b/src/lib/dcp_content.cc
index 42c371ee5..0da42502f 100644
--- a/src/lib/dcp_content.cc
+++ b/src/lib/dcp_content.cc
@@ -242,6 +242,7 @@ DCPContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job)
boost::mutex::scoped_lock lm (_mutex);
audio = make_shared<AudioContent>(this);
}
+ audio->set_language (examiner->audio_language());
auto as = make_shared<AudioStream>(examiner->audio_frame_rate(), examiner->audio_length(), examiner->audio_channels());
audio->set_stream (as);
auto m = as->mapping ();
@@ -262,14 +263,17 @@ DCPContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job)
}
list<shared_ptr<TextContent>> new_text;
- for (int i = 0; i < static_cast<int>(TextType::COUNT); ++i) {
- for (int j = 0; j < examiner->text_count(static_cast<TextType>(i)); ++j) {
- auto c = make_shared<TextContent>(this, static_cast<TextType>(i), static_cast<TextType>(i));
- if (i == static_cast<int>(TextType::CLOSED_CAPTION)) {
- c->set_dcp_track (examiner->dcp_text_track(j));
- }
- new_text.push_back (c);
- }
+
+ for (int i = 0; i < examiner->text_count(TextType::OPEN_SUBTITLE); ++i) {
+ auto c = make_shared<TextContent>(this, TextType::OPEN_SUBTITLE, TextType::OPEN_SUBTITLE);
+ c->set_language (examiner->open_subtitle_language());
+ new_text.push_back (c);
+ }
+
+ for (int i = 0; i < examiner->text_count(TextType::CLOSED_CAPTION); ++i) {
+ auto c = make_shared<TextContent>(this, TextType::CLOSED_CAPTION, TextType::CLOSED_CAPTION);
+ c->set_dcp_track (examiner->dcp_text_track(i));
+ new_text.push_back (c);
}
{
diff --git a/src/lib/dcp_examiner.cc b/src/lib/dcp_examiner.cc
index ca851db2d..a0bc487d9 100644
--- a/src/lib/dcp_examiner.cc
+++ b/src/lib/dcp_examiner.cc
@@ -53,7 +53,10 @@ using std::cout;
using std::runtime_error;
using std::map;
using std::shared_ptr;
+using std::string;
using std::dynamic_pointer_cast;
+using boost::optional;
+
DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
: DCP (content, tolerant)
@@ -108,6 +111,15 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
_name = cpl->content_title_text ();
_content_kind = cpl->content_kind ();
+ auto try_to_parse_language = [](optional<string> lang) -> boost::optional<dcp::LanguageTag> {
+ try {
+ if (lang) {
+ return dcp::LanguageTag (*lang);
+ }
+ } catch (...) {}
+ return boost::none;
+ };
+
for (auto i: cpl->reels()) {
if (i->main_picture ()) {
@@ -159,6 +171,7 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
}
_audio_length += i->main_sound()->actual_duration();
+ _audio_language = try_to_parse_language (asset->language());
}
if (i->main_subtitle ()) {
@@ -169,6 +182,7 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
}
_text_count[static_cast<int>(TextType::OPEN_SUBTITLE)] = 1;
+ _open_subtitle_language = try_to_parse_language (i->main_subtitle()->language());
}
for (auto j: i->closed_captions()) {
@@ -183,7 +197,7 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
}
if (i->main_markers ()) {
- map<dcp::Marker, dcp::Time> rm = i->main_markers()->get();
+ auto rm = i->main_markers()->get();
_markers.insert (rm.begin(), rm.end());
}
diff --git a/src/lib/dcp_examiner.h b/src/lib/dcp_examiner.h
index 3fedaca06..66f694f72 100644
--- a/src/lib/dcp_examiner.h
+++ b/src/lib/dcp_examiner.h
@@ -90,6 +90,10 @@ public:
return _audio_frame_rate.get_value_or (48000);
}
+ boost::optional<dcp::LanguageTag> audio_language () const {
+ return _audio_language;
+ }
+
/** @param type TEXT_OPEN_SUBTITLE or TEXT_CLOSED_CAPTION.
* @return Number of assets of this type in this DCP.
*/
@@ -97,6 +101,10 @@ public:
return _text_count[static_cast<int>(type)];
}
+ boost::optional<dcp::LanguageTag> open_subtitle_language () const {
+ return _open_subtitle_language;
+ }
+
DCPTextTrack dcp_text_track (int i) const {
DCPOMATIC_ASSERT (i >= 0 && i < static_cast<int>(_dcp_text_tracks.size()));
return _dcp_text_tracks[i];
@@ -162,8 +170,10 @@ private:
bool _has_video = false;
/** true if this DCP has audio content (but false if it has unresolved references to audio content) */
bool _has_audio = false;
+ boost::optional<dcp::LanguageTag> _audio_language;
/** number of different assets of each type (OCAP/CCAP) */
int _text_count[static_cast<int>(TextType::COUNT)];
+ boost::optional<dcp::LanguageTag> _open_subtitle_language;
/** the DCPTextTracks for each of our CCAPs */
std::vector<DCPTextTrack> _dcp_text_tracks;
bool _encrypted = false;