summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-05-04 23:20:02 +0200
committerCarl Hetherington <cth@carlh.net>2021-05-07 09:29:59 +0200
commitd6fa7c8f5c89f195490a2c3bb91ca486179c3eef (patch)
tree45f8deb1213d7b3c08ccf225d962661f071c55d1
parenta1b841185f3d03813db95dc75827d563f23d9dff (diff)
Refer to Piece audio streams by index instead of pointer.
-rw-r--r--src/lib/piece.cc92
-rw-r--r--src/lib/piece.h18
-rw-r--r--src/lib/piece_audio.h10
-rw-r--r--src/lib/player.cc4
4 files changed, 68 insertions, 56 deletions
diff --git a/src/lib/piece.cc b/src/lib/piece.cc
index b1b4decba..7590698ab 100644
--- a/src/lib/piece.cc
+++ b/src/lib/piece.cc
@@ -56,9 +56,8 @@ Piece::Piece (weak_ptr<const Film> film, shared_ptr<Content> content, shared_ptr
, _fast (fast)
{
if (_content->audio) {
- for (auto j: _content->audio->streams()) {
- _stream_last_push_end[j] = _content->position();
- _positions[j] = 0;
+ for (auto const& i: content->audio->streams()) {
+ _audio_streams.push_back(Stream(_content->position(), i->mapping()));
}
}
@@ -92,32 +91,34 @@ Piece::video (shared_ptr<const ImageProxy> image, Frame frame, Eyes eyes, Part p
void
-Piece::audio (AudioStreamPtr stream, shared_ptr<const AudioBuffers> audio, Frame frame)
+Piece::audio (AudioStreamPtr stream_ptr, shared_ptr<const AudioBuffers> audio, Frame frame)
{
auto film = _film.lock ();
DCPOMATIC_ASSERT (film);
+ auto content_streams = _content->audio->streams();
+ auto content_stream_iter = std::find(content_streams.begin(), content_streams.end(), stream_ptr);
+ DCPOMATIC_ASSERT (content_stream_iter != content_streams.end());
+ int index = std::distance(content_streams.begin(), content_stream_iter);
+ DCPOMATIC_ASSERT (index >= 0 && index < static_cast<int>(_audio_streams.size()));
+ auto& stream = _audio_streams[index];
+
int const resampled_rate = _content->audio->resampled_frame_rate(film);
- shared_ptr<Resampler> resampler;
- auto i = _resamplers.find(stream);
- if (i != _resamplers.end()) {
- resampler = i->second;
- } else {
- if (stream->frame_rate() != resampled_rate) {
- LOG_GENERAL (
- "Creating new resampler from %1 to %2 with %3 channels",
- stream->frame_rate(),
- resampled_rate,
- stream->channels()
- );
-
- resampler = make_shared<Resampler>(stream->frame_rate(), resampled_rate, stream->channels());
- if (_fast) {
- resampler->set_fast ();
- }
- _resamplers[stream] = resampler;
+ auto resampler = stream.resampler;
+ if (!resampler && stream_ptr->frame_rate() != resampled_rate) {
+ LOG_GENERAL (
+ "Creating new resampler from %1 to %2 with %3 channels",
+ stream_ptr->frame_rate(),
+ resampled_rate,
+ stream_ptr->channels()
+ );
+
+ resampler = make_shared<Resampler>(stream_ptr->frame_rate(), resampled_rate, stream_ptr->channels());
+ if (_fast) {
+ resampler->set_fast ();
}
+ stream.resampler = resampler;
}
if (resampler) {
@@ -128,13 +129,13 @@ Piece::audio (AudioStreamPtr stream, shared_ptr<const AudioBuffers> audio, Frame
audio = ro;
}
- if (_positions[stream] == 0) {
- _positions[stream] = frame;
+ if (stream.position == 0) {
+ stream.position = frame;
}
- auto const pos = _positions[stream];
- Audio (PieceAudio(stream, audio, pos, resampled_audio_to_dcp(pos)));
- _positions[stream] += audio->frames();
+ auto const pos = stream.position;
+ Audio (PieceAudio(index, audio, pos, resampled_audio_to_dcp(pos), stream_ptr->mapping()));
+ stream.position += audio->frames();
}
@@ -169,21 +170,21 @@ Piece::atmos (shared_ptr<const dcp::AtmosFrame> data, Frame frame, AtmosMetadata
void
Piece::update_pull_to (DCPTime& pull_to) const
{
- if (done()) {
+ if (done() || _audio_streams.empty()) {
return;
}
- for (auto const& i: _stream_last_push_end) {
- pull_to = std::min(pull_to, i.second);
+ for (auto const& i: _audio_streams) {
+ pull_to = std::min(pull_to, i.last_push_end);
}
}
void
-Piece::set_last_push_end (AudioStreamPtr stream, DCPTime end)
+Piece::set_last_push_end (int stream, DCPTime end)
{
- DCPOMATIC_ASSERT (_stream_last_push_end.find(stream) != _stream_last_push_end.end());
- _stream_last_push_end[stream] = end;
+ DCPOMATIC_ASSERT (stream >= 0 && stream < static_cast<int>(_audio_streams.size()));
+ _audio_streams[stream].last_push_end = end;
}
@@ -341,13 +342,12 @@ Piece::reference_dcp_audio () const
void
Piece::seek (DCPTime time, bool accurate)
{
- for (auto i: _resamplers) {
- i.second->flush ();
- i.second->reset ();
- }
-
- for (auto& i: _positions) {
- i.second = 0;
+ for (auto& i: _audio_streams) {
+ if (i.resampler) {
+ i.resampler->flush ();
+ i.resampler->reset ();
+ }
+ i.position = 0;
}
if (time < position()) {
@@ -407,13 +407,15 @@ Piece::period () const
void
Piece::flush ()
{
- for (auto const& i: _resamplers) {
- auto ro = i.second->flush ();
+ int index = 0;
+ for (auto& i: _audio_streams) {
+ auto ro = i.resampler->flush ();
if (ro->frames() > 0) {
- auto const frame = _positions[i.first];
- Audio (PieceAudio(i.first, ro, frame, resampled_audio_to_dcp(frame)));
- _positions[i.first] += ro->frames();
+ auto const frame = i.position;
+ Audio (PieceAudio(index, ro, frame, resampled_audio_to_dcp(frame), i.mapping));
+ i.position += ro->frames();
}
+ ++index;
}
}
diff --git a/src/lib/piece.h b/src/lib/piece.h
index 1d50cb204..7abacbef7 100644
--- a/src/lib/piece.h
+++ b/src/lib/piece.h
@@ -51,7 +51,7 @@ public:
Piece (std::weak_ptr<const Film> film, std::shared_ptr<Content> content, std::shared_ptr<Decoder> decoder, FrameRateChange frc, bool fast);
void update_pull_to (dcpomatic::DCPTime& pull_to) const;
- void set_last_push_end (AudioStreamPtr stream, dcpomatic::DCPTime last_push_end);
+ void set_last_push_end (int stream, dcpomatic::DCPTime last_push_end);
boost::optional<dcpomatic::DCPTime> content_time_to_dcp (std::shared_ptr<const Content> content, dcpomatic::ContentTime t) const;
@@ -118,11 +118,21 @@ private:
FrameRateChange _frc;
bool _fast = false;
boost::optional<dcpomatic::DCPTimePeriod> _ignore_video;
- std::map<AudioStreamPtr, dcpomatic::DCPTime> _stream_last_push_end;
- std::map<AudioStreamPtr, std::shared_ptr<Resampler>> _resamplers;
- std::map<AudioStreamPtr, Frame> _positions;
+ struct Stream
+ {
+ Stream (dcpomatic::DCPTime lpe, AudioMapping m)
+ : last_push_end(lpe)
+ , mapping(m)
+ {}
+ dcpomatic::DCPTime last_push_end;
+ std::shared_ptr<Resampler> resampler;
+ Frame position = 0;
+ AudioMapping mapping;
+ };
+
+ std::vector<Stream> _audio_streams;
};
diff --git a/src/lib/piece_audio.h b/src/lib/piece_audio.h
index 876591c5b..e29cafd03 100644
--- a/src/lib/piece_audio.h
+++ b/src/lib/piece_audio.h
@@ -29,12 +29,10 @@
#include "audio_buffers.h"
+#include "audio_mapping.h"
#include "types.h"
-class AudioStream;
-
-
/** @class PieceAudio
* @brief A block of audio from a Piece, with a timestamp as a frame within that piece.
*/
@@ -45,17 +43,19 @@ public:
: audio (new AudioBuffers(0, 0))
{}
- PieceAudio (std::shared_ptr<AudioStream> s, std::shared_ptr<const AudioBuffers> a, Frame f, dcpomatic::DCPTime t)
+ PieceAudio (int s, std::shared_ptr<const AudioBuffers> a, Frame f, dcpomatic::DCPTime t, AudioMapping m)
: stream (s)
, audio (a)
, frame (f)
, time (t)
+ , mapping (m)
{}
- std::shared_ptr<AudioStream> stream;
+ int stream; ///< index of stream within the Piece
std::shared_ptr<const AudioBuffers> audio;
Frame frame = 0;
dcpomatic::DCPTime time;
+ AudioMapping mapping;
};
diff --git a/src/lib/player.cc b/src/lib/player.cc
index 7a4a9c2c7..2fa6805ba 100644
--- a/src/lib/player.cc
+++ b/src/lib/player.cc
@@ -947,12 +947,12 @@ Player::audio (weak_ptr<Piece> wp, PieceAudio audio)
/* Remap */
- audio.audio = remap (audio.audio, _film->audio_channels(), audio.stream->mapping());
+ audio.audio = remap (audio.audio, _film->audio_channels(), audio.mapping);
/* Process */
if (_audio_processor) {
- audio.audio = _audio_processor->run (audio.audio, _film->audio_channels ());
+ audio.audio = _audio_processor->run (audio.audio, _film->audio_channels());
}
/* Push */