summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-05-03 22:27:05 +0200
committerCarl Hetherington <cth@carlh.net>2021-05-07 09:29:59 +0200
commitc99c72164a6b598f13b4af5ec08f42205565cb34 (patch)
treed9d9487baa42da22c32bf96670fc58bf983c6e8a /src/lib
parentb8774cafefc3d7f00636b28bc3bcebd1fe60bdb9 (diff)
Add collect() for Player.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/player.cc64
-rw-r--r--src/lib/player.h3
2 files changed, 67 insertions, 0 deletions
diff --git a/src/lib/player.cc b/src/lib/player.cc
index f14f4d067..564adf5ce 100644
--- a/src/lib/player.cc
+++ b/src/lib/player.cc
@@ -94,6 +94,10 @@ int const PlayerProperty::DCP_DECODE_REDUCTION = 704;
int const PlayerProperty::PLAYBACK_LENGTH = 705;
+/** About 0.01dB */
+#define AUDIO_GAIN_EPSILON 0.001
+
+
Player::Player (shared_ptr<const Film> film)
: _film (film)
, _suspended (0)
@@ -155,6 +159,66 @@ have_audio (shared_ptr<const Content> content)
}
+vector<vector<shared_ptr<Content>>>
+collect (shared_ptr<const Film> film, ContentList content)
+{
+ vector<shared_ptr<Content>> ungrouped;
+ vector<vector<shared_ptr<Content>>> grouped;
+
+ auto same_settings = [](shared_ptr<const Film> film, shared_ptr<const AudioContent> a, shared_ptr<const AudioContent> b) {
+
+ auto a_streams = a->streams();
+ auto b_streams = b->streams();
+
+ if (a_streams.size() != b_streams.size()) {
+ return false;
+ }
+
+ for (size_t i = 0; i < a_streams.size(); ++i) {
+ auto a_stream = a_streams[i];
+ auto b_stream = b_streams[i];
+ if (
+ !a_stream->mapping().equals(b_stream->mapping(), AUDIO_GAIN_EPSILON) ||
+ a_stream->frame_rate() != b_stream->frame_rate() ||
+ a_stream->channels() != b_stream->channels()) {
+ return false;
+ }
+ }
+
+ return (
+ fabs(a->gain() - b->gain()) < AUDIO_GAIN_EPSILON &&
+ a->delay() == b->delay() &&
+ a->language() == b->language() &&
+ a->resampled_frame_rate(film) == b->resampled_frame_rate(film) &&
+ a->channel_names() == b->channel_names()
+ );
+ };
+
+ for (auto i: content) {
+ if (i->video || !i->audio || !i->text.empty()) {
+ ungrouped.push_back (i);
+ } else {
+ bool done = false;
+ for (auto& g: grouped) {
+ if (same_settings(film, g.front()->audio, i->audio) && i->position() == g.back()->end(film)) {
+ g.push_back (i);
+ done = true;
+ }
+ }
+ if (!done) {
+ grouped.push_back ({i});
+ }
+ }
+ }
+
+ for (auto i: ungrouped) {
+ grouped.push_back({i});
+ }
+
+ return grouped;
+}
+
+
void
Player::setup_pieces_unlocked ()
{
diff --git a/src/lib/player.h b/src/lib/player.h
index faebeb6db..797fac72f 100644
--- a/src/lib/player.h
+++ b/src/lib/player.h
@@ -217,4 +217,7 @@ private:
boost::signals2::scoped_connection _playlist_content_change_connection;
};
+
+std::vector<std::vector<std::shared_ptr<Content>>> collect (std::shared_ptr<const Film> film, ContentList content);
+
#endif