From 9900ce33c6026e9513d9a4f2a67e4366601c1292 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 29 Apr 2021 21:43:44 +0200 Subject: [PATCH] Rename ContentAudio -> PieceAudio and pass audio through Piece. --- src/lib/audio_decoder.cc | 6 ++-- src/lib/audio_decoder.h | 6 ++-- src/lib/piece.cc | 12 +++++++ src/lib/piece.h | 3 ++ src/lib/{content_audio.h => piece_audio.h} | 37 ++++++++++++++-------- src/lib/player.cc | 35 ++++++++++---------- src/lib/player.h | 4 +-- 7 files changed, 63 insertions(+), 40 deletions(-) rename src/lib/{content_audio.h => piece_audio.h} (59%) diff --git a/src/lib/audio_decoder.cc b/src/lib/audio_decoder.cc index 77c9b0695..9227cb962 100644 --- a/src/lib/audio_decoder.cc +++ b/src/lib/audio_decoder.cc @@ -128,7 +128,7 @@ AudioDecoder::emit (shared_ptr film, AudioStreamPtr stream, shared_p data = ro; } - Data(stream, ContentAudio (data, _positions[stream])); + Data(stream, data, _positions[stream]); _positions[stream] += data->frames(); } @@ -178,7 +178,7 @@ AudioDecoder::flush () for (auto const& i: _resamplers) { auto ro = i.second->flush (); if (ro->frames() > 0) { - Data (i.first, ContentAudio (ro, _positions[i.first])); + Data (i.first, ro, _positions[i.first]); _positions[i.first] += ro->frames(); } } @@ -197,6 +197,6 @@ AudioDecoder::silence (int milliseconds) int const samples = ContentTime::from_seconds(milliseconds / 1000.0).frames_round(i->frame_rate()); auto silence = make_shared(i->channels(), samples); silence->make_silent (); - Data (i, ContentAudio (silence, _positions[i])); + Data (i, silence, _positions[i]); } } diff --git a/src/lib/audio_decoder.h b/src/lib/audio_decoder.h index 754321880..ff0db6e8f 100644 --- a/src/lib/audio_decoder.h +++ b/src/lib/audio_decoder.h @@ -28,10 +28,10 @@ #define DCPOMATIC_AUDIO_DECODER_H -#include "decoder.h" -#include "content_audio.h" #include "audio_stream.h" +#include "decoder.h" #include "decoder_part.h" +#include "piece_audio.h" #include @@ -58,7 +58,7 @@ public: dcpomatic::ContentTime stream_position (std::shared_ptr film, AudioStreamPtr stream) const; - boost::signals2::signal Data; + boost::signals2::signal, Frame)> Data; private: void silence (int milliseconds); diff --git a/src/lib/piece.cc b/src/lib/piece.cc index 29f82f80c..521a5e56d 100644 --- a/src/lib/piece.cc +++ b/src/lib/piece.cc @@ -20,6 +20,7 @@ #include "audio_content.h" +#include "audio_decoder.h" #include "content.h" #include "dcp_content.h" #include "dcpomatic_log.h" @@ -56,6 +57,10 @@ Piece::Piece (weak_ptr film, shared_ptr c, shared_ptrvideo) { _decoder->video->Data.connect (boost::bind(&Piece::video, this, _1, _2, _3, _4)); } + + if (_decoder->audio) { + _decoder->audio->Data.connect (boost::bind(&Piece::audio, this, _1, _2, _3)); + } } @@ -66,6 +71,13 @@ Piece::video (shared_ptr image, Frame frame, Eyes eyes, Part p } +void +Piece::audio (AudioStreamPtr stream, shared_ptr audio, Frame frame) +{ + Audio (PieceAudio(stream, audio, frame)); +} + + void Piece::update_pull_to (DCPTime& pull_to) const { diff --git a/src/lib/piece.h b/src/lib/piece.h index 2d9272bd6..25d97a466 100644 --- a/src/lib/piece.h +++ b/src/lib/piece.h @@ -27,6 +27,7 @@ #include "dcpomatic_time.h" #include "font_data.h" #include "frame_rate_change.h" +#include "piece_audio.h" #include "piece_video.h" #include "types.h" #include @@ -85,12 +86,14 @@ public: bool ignore_video_at (dcpomatic::DCPTime time) const; boost::signals2::signal Video; + boost::signals2::signal Audio; private: friend struct overlap_video_test1; friend struct check_reuse_old_data_test; void video (std::shared_ptr image, Frame frame, Eyes eyes, Part part); + void audio (std::shared_ptr stream, std::shared_ptr audio, Frame frame); std::weak_ptr _film; std::shared_ptr _content; diff --git a/src/lib/content_audio.h b/src/lib/piece_audio.h similarity index 59% rename from src/lib/content_audio.h rename to src/lib/piece_audio.h index 0d16799d7..a6f345f3e 100644 --- a/src/lib/content_audio.h +++ b/src/lib/piece_audio.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2014 Carl Hetherington + Copyright (C) 2014-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,34 +18,43 @@ */ -#ifndef DCPOMATIC_CONTENT_AUDIO_H -#define DCPOMATIC_CONTENT_AUDIO_H -/** @file src/lib/content_audio.h - * @brief ContentAudio class. +#ifndef DCPOMATIC_PIECE_AUDIO_H +#define DCPOMATIC_PIECE_AUDIO_H + + +/** @file src/lib/piece_audio.h + * @brief PieceAudio class. */ + #include "audio_buffers.h" #include "types.h" -/** @class ContentAudio - * @brief A block of audio from a piece of content, with a timestamp as a frame within that content. + +class AudioStream; + + +/** @class PieceAudio + * @brief A block of audio from a Piece, with a timestamp as a frame within that piece. */ -class ContentAudio +class PieceAudio { public: - ContentAudio () - : audio (new AudioBuffers (0, 0)) - , frame (0) + PieceAudio () + : audio (new AudioBuffers(0, 0)) {} - ContentAudio (std::shared_ptr a, Frame f) - : audio (a) + PieceAudio (std::shared_ptr s, std::shared_ptr a, Frame f) + : stream (s) + , audio (a) , frame (f) {} + std::shared_ptr stream; std::shared_ptr audio; - Frame frame; + Frame frame = 0; }; + #endif diff --git a/src/lib/player.cc b/src/lib/player.cc index 2ddd99a29..94ccc48ad 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -26,7 +26,6 @@ #include "audio_processor.h" #include "compose.hpp" #include "config.h" -#include "content_audio.h" #include "dcp_content.h" #include "dcp_decoder.h" #include "dcpomatic_log.h" @@ -226,8 +225,8 @@ Player::setup_pieces_unlocked () } } - if (decoder->audio) { - decoder->audio->Data.connect (bind (&Player::audio, this, weak_ptr (piece), _1, _2)); + if (i->audio) { + piece->Audio.connect (bind(&Player::audio, this, weak_ptr(piece), _1)); } auto j = decoder->text.begin(); @@ -854,9 +853,9 @@ Player::video (weak_ptr wp, PieceVideo video) void -Player::audio (weak_ptr wp, AudioStreamPtr stream, ContentAudio content_audio) +Player::audio (weak_ptr wp, PieceAudio piece_audio) { - DCPOMATIC_ASSERT (content_audio.audio->frames() > 0); + DCPOMATIC_ASSERT (piece_audio.audio->frames() > 0); auto piece = wp.lock (); if (!piece) { @@ -866,20 +865,20 @@ Player::audio (weak_ptr wp, AudioStreamPtr stream, ContentAudio content_a int const rfr = piece->resampled_audio_frame_rate (); /* Compute time in the DCP */ - auto time = piece->resampled_audio_to_dcp (content_audio.frame); - LOG_DEBUG_PLAYER("Received audio frame %1 at %2", content_audio.frame, to_string(time)); + auto time = piece->resampled_audio_to_dcp (piece_audio.frame); + LOG_DEBUG_PLAYER("Received audio frame %1 at %2", piece_audio.frame, to_string(time)); /* And the end of this block in the DCP */ - auto end = time + DCPTime::from_frames(content_audio.audio->frames(), rfr); + auto end = time + DCPTime::from_frames(piece_audio.audio->frames(), rfr); /* Remove anything that comes before the start or after the end of the content */ if (time < piece->position()) { - auto cut = discard_audio (content_audio.audio, time, piece->position()); + auto cut = discard_audio (piece_audio.audio, time, piece->position()); if (!cut.first) { /* This audio is entirely discarded */ return; } - content_audio.audio = cut.first; + piece_audio.audio = cut.first; time = cut.second; } else if (time > piece->end()) { /* Discard it all */ @@ -889,33 +888,33 @@ Player::audio (weak_ptr wp, AudioStreamPtr stream, ContentAudio content_a if (remaining_frames == 0) { return; } - content_audio.audio = make_shared(content_audio.audio, remaining_frames, 0); + piece_audio.audio = make_shared(piece_audio.audio, remaining_frames, 0); } - DCPOMATIC_ASSERT (content_audio.audio->frames() > 0); + DCPOMATIC_ASSERT (piece_audio.audio->frames() > 0); /* Gain */ if (piece->audio_gain() != 0) { - auto gain = make_shared(content_audio.audio); + auto gain = make_shared(piece_audio.audio); gain->apply_gain (piece->audio_gain()); - content_audio.audio = gain; + piece_audio.audio = gain; } /* Remap */ - content_audio.audio = remap (content_audio.audio, _film->audio_channels(), stream->mapping()); + piece_audio.audio = remap (piece_audio.audio, _film->audio_channels(), piece_audio.stream->mapping()); /* Process */ if (_audio_processor) { - content_audio.audio = _audio_processor->run (content_audio.audio, _film->audio_channels ()); + piece_audio.audio = _audio_processor->run (piece_audio.audio, _film->audio_channels ()); } /* Push */ - _audio_merger.push (content_audio.audio, time); - piece->set_last_push_end (stream, time + DCPTime::from_frames(content_audio.audio->frames(), _film->audio_frame_rate())); + _audio_merger.push (piece_audio.audio, time); + piece->set_last_push_end (piece_audio.stream, time + DCPTime::from_frames(piece_audio.audio->frames(), _film->audio_frame_rate())); } diff --git a/src/lib/player.h b/src/lib/player.h index 2b7fcf343..faebeb6db 100644 --- a/src/lib/player.h +++ b/src/lib/player.h @@ -29,11 +29,11 @@ #include "audio_stream.h" #include "content.h" #include "content_atmos.h" -#include "content_audio.h" #include "content_text.h" #include "empty.h" #include "film.h" #include "piece.h" +#include "piece_audio.h" #include "piece_video.h" #include "player_text.h" #include "position_image.h" @@ -139,7 +139,7 @@ private: std::shared_ptr black_player_video_frame (Eyes eyes) const; void video (std::weak_ptr, PieceVideo); - void audio (std::weak_ptr, AudioStreamPtr, ContentAudio); + void audio (std::weak_ptr, PieceAudio); void bitmap_text_start (std::weak_ptr, std::weak_ptr, std::weak_ptr, ContentBitmapText); void plain_text_start (std::weak_ptr, std::weak_ptr, std::weak_ptr, ContentStringText); void subtitle_stop (std::weak_ptr, std::weak_ptr, std::weak_ptr, dcpomatic::ContentTime); -- 2.30.2