AudioBuffers::accumulate_frames (AudioBuffers const * from, int read_offset, int write_offset, int frames)
{
assert (_channels == from->channels ());
+ assert (read_offset >= 0);
+ assert (write_offset >= 0);
for (int i = 0; i < _channels; ++i) {
for (int j = 0; j < frames; ++j) {
output_audio_frame_rate()
);
}
+
+void
+AudioContent::set_audio_mapping (AudioMapping)
+{
+ signal_changed (AudioContentProperty::AUDIO_MAPPING);
+}
virtual int content_audio_frame_rate () const = 0;
virtual int output_audio_frame_rate () const = 0;
virtual AudioMapping audio_mapping () const = 0;
- virtual void set_audio_mapping (AudioMapping) = 0;
+ virtual void set_audio_mapping (AudioMapping);
virtual boost::filesystem::path audio_analysis_path () const;
boost::signals2::connection analyse_audio (boost::function<void()>);
using std::pair;
using std::cout;
using std::min;
+using std::max;
using boost::optional;
using boost::shared_ptr;
seek (ContentTime::from_frames (frame, _audio_content->content_audio_frame_rate()), accurate);
}
+ /* Offset of the data that we want from the start of _decoded_audio.audio
+ (to be set up shortly)
+ */
AudioFrame decoded_offset = 0;
/* Now enough pass() calls will either:
* otherwise any frames will do.
*/
if (accurate) {
- while (!pass() && _decoded_audio.audio->frames() < length) {}
- /* Use decoded_offset of 0, as we don't really care what frames we return */
- } else {
+ /* Keep stuffing data into _decoded_audio until we have enough data, or the subclass does not want to give us any more */
while (!pass() && (_decoded_audio.frame > frame || (_decoded_audio.frame + _decoded_audio.audio->frames()) < end)) {}
decoded_offset = frame - _decoded_audio.frame;
+ } else {
+ while (!pass() && _decoded_audio.audio->frames() < length) {}
+ /* Use decoded_offset of 0, as we don't really care what frames we return */
}
+ /* The amount of data available in _decoded_audio.audio starting from `frame'. This could be -ve
+ if pass() returned true before we got enough data
+ */
AudioFrame const amount_left = _decoded_audio.audio->frames() - decoded_offset;
- AudioFrame const to_return = min (amount_left, length);
+ /* We will return either that, or the requested amount, whichever is smaller */
+ AudioFrame const to_return = max ((AudioFrame) 0, min (amount_left, length));
+
+ /* Copy our data to the output */
shared_ptr<AudioBuffers> out (new AudioBuffers (_decoded_audio.audio->channels(), to_return));
out->copy_from (_decoded_audio.audio.get(), to_return, decoded_offset, 0);
- /* Clean up decoded */
+ /* Clean up decoded; first, move the data after what we just returned to the start of the buffer */
_decoded_audio.audio->move (decoded_offset + to_return, 0, amount_left - to_return);
+ /* And set up the number of frames we have left */
_decoded_audio.audio->set_frames (amount_left - to_return);
+ /* Also bump where those frames are in terms of the content */
+ _decoded_audio.frame += decoded_offset + to_return;
return shared_ptr<ContentAudio> (new ContentAudio (out, frame));
}
/*
- Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
}
/** Create a default AudioMapping for a given channel count.
- * @param c Number of channels.
+ * @param channels Number of channels.
*/
-AudioMapping::AudioMapping (int c)
+AudioMapping::AudioMapping (int channels)
{
- setup (c);
+ setup (channels);
}
void
/*
- Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
{
public:
AudioMapping ();
- AudioMapping (int);
+ AudioMapping (int channels);
AudioMapping (boost::shared_ptr<const cxml::Node>, int);
/* Default copy constructor is fine */
return *this;
}
+ DCPTime operator- () const {
+ return DCPTime (-_t);
+ }
+
DCPTime operator- (DCPTime const & o) const {
return DCPTime (_t - o._t);
}
FFmpegContent::set_audio_mapping (AudioMapping m)
{
audio_stream()->mapping = m;
- signal_changed (AudioContentProperty::AUDIO_MAPPING);
+ AudioContent::set_audio_mapping (m);
}
string
setup_pieces ();
}
- list<shared_ptr<Piece> > ov = overlaps<VideoContent> (time);
+ list<shared_ptr<Piece> > ov = overlaps<VideoContent> (
+ time,
+ time + DCPTime::from_frames (1, _film->video_frame_rate ())
+ );
+
if (ov.empty ()) {
/* No video content at this time */
return black_dcp_video (time);
/* Add subtitles */
- ov = overlaps<SubtitleContent> (time);
+ ov = overlaps<SubtitleContent> (
+ time,
+ time + DCPTime::from_frames (1, _film->video_frame_rate ())
+ );
+
list<PositionImage> sub_images;
for (list<shared_ptr<Piece> >::const_iterator i = ov.begin(); i != ov.end(); ++i) {
shared_ptr<AudioBuffers> audio (new AudioBuffers (_film->audio_channels(), length_frames));
audio->make_silent ();
- list<shared_ptr<Piece> > ov = overlaps<AudioContent> (time);
+ list<shared_ptr<Piece> > ov = overlaps<AudioContent> (time, time + length);
if (ov.empty ()) {
return audio;
}
continue;
}
- AudioFrame const content_time = dcp_to_content_audio (*i, time);
+ /* The time that we should request from the content */
+ DCPTime request = time - DCPTime::from_seconds (content->audio_delay() / 1000.0);
+ DCPTime offset;
+ if (request < DCPTime ()) {
+ /* We went off the start of the content, so we will need to offset
+ the stuff we get back.
+ */
+ offset = -request;
+ request = DCPTime ();
+ }
+
+ AudioFrame const content_frame = dcp_to_content_audio (*i, request);
- /* Audio from this piece's decoder (which might be more than what we asked for) */
- shared_ptr<ContentAudio> all = decoder->get_audio (content_time, length_frames, accurate);
+ /* Audio from this piece's decoder (which might be more or less than what we asked for) */
+ shared_ptr<ContentAudio> all = decoder->get_audio (content_frame, length_frames, accurate);
/* Gain */
if (content->audio_gain() != 0) {
}
all->audio = dcp_mapped;
-
- /* Delay */
- /* XXX
- audio->dcp_time += content->audio_delay() * TIME_HZ / 1000;
- if (audio->dcp_time < 0) {
- int const frames = - audio->dcp_time * _film->audio_frame_rate() / TIME_HZ;
- if (frames >= audio->audio->frames ()) {
- return;
- }
-
- shared_ptr<AudioBuffers> trimmed (new AudioBuffers (audio->audio->channels(), audio->audio->frames() - frames));
- trimmed->copy_from (audio->audio.get(), audio->audio->frames() - frames, frames, 0);
-
- audio->audio = trimmed;
- audio->dcp_time = 0;
- }
- */
- audio->accumulate_frames (all->audio.get(), all->frame - content_time, 0, min (AudioFrame (all->audio->frames()), length_frames));
+ audio->accumulate_frames (
+ all->audio.get(),
+ content_frame - all->frame,
+ offset.frames (_film->audio_frame_rate()),
+ min (AudioFrame (all->audio->frames()), length_frames) - offset.frames (_film->audio_frame_rate ())
+ );
}
return audio;
private:
friend class PlayerWrapper;
friend class Piece;
+ friend class player_overlaps_test;
void setup_pieces ();
void playlist_changed ();
ContentTime dcp_to_content_subtitle (boost::shared_ptr<const Piece> piece, DCPTime t) const;
boost::shared_ptr<DCPVideo> black_dcp_video (DCPTime) const;
+ /** @return Pieces of content type C that overlap a specified time range in the DCP */
template<class C>
std::list<boost::shared_ptr<Piece> >
- overlaps (DCPTime t)
+ overlaps (DCPTime from, DCPTime to)
{
+ if (!_have_valid_pieces) {
+ setup_pieces ();
+ }
+
std::list<boost::shared_ptr<Piece> > overlaps;
for (typename std::list<boost::shared_ptr<Piece> >::const_iterator i = _pieces.begin(); i != _pieces.end(); ++i) {
- if (boost::dynamic_pointer_cast<C> ((*i)->content) && (*i)->content->position() <= t && t < (*i)->content->end()) {
+ if (!boost::dynamic_pointer_cast<C> ((*i)->content)) {
+ continue;
+ }
+
+ if ((*i)->content->position() <= to && (*i)->content->end() >= from) {
overlaps.push_back (*i);
}
}
_audio_mapping = m;
}
- signal_changed (AudioContentProperty::AUDIO_MAPPING);
+ AudioContent::set_audio_mapping (m);
}
AudioAnalysis: audio_analysis_test
AudioBuffers: audio_buffers_test
+AudioDecoder: audio_decoder_test
AudioMapping: audio_mapping_test
ColourConversion: colour_conversion_test
FileGroup: file_group_test
Image: image_test, pixel_formats_test, make_black_test
+Player: player_test
Job/JobManager: job_test
SubRip: subrip_test
Ratio: ratio_test
client_server_test
film_metadata_test
frame_rate_test
-player_silence_padding_test
recover_test
repeat_frame_test
scaling_test
--- /dev/null
+/*
+ Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+
+ This program 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.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+/** @file test/audio_decoder_test.cc
+ * @brief Tests of the AudioDecoder class.
+ */
+
+#include <cassert>
+#include <boost/test/unit_test.hpp>
+#include "test.h"
+#include "lib/audio_decoder.h"
+#include "lib/audio_content.h"
+
+using std::string;
+using std::cout;
+using std::min;
+using boost::shared_ptr;
+
+class TestAudioDecoder : public AudioDecoder
+{
+public:
+ TestAudioDecoder (shared_ptr<AudioContent> content)
+ : AudioDecoder (content)
+ , _position (0)
+ {}
+
+ bool pass ()
+ {
+ AudioFrame const N = min (
+ AudioFrame (2000),
+ _audio_content->audio_length().frames (_audio_content->output_audio_frame_rate ()) - _position
+ );
+
+ shared_ptr<AudioBuffers> buffers (new AudioBuffers (_audio_content->audio_channels(), N));
+ for (int i = 0; i < _audio_content->audio_channels(); ++i) {
+ for (int j = 0; j < N; ++j) {
+ buffers->data(i)[j] = j + _position;
+ }
+ }
+
+ audio (buffers, ContentTime::from_frames (_position, _audio_content->output_audio_frame_rate ()));
+ _position += N;
+
+ return N < 2000;
+ }
+
+ void seek (ContentTime t, bool accurate)
+ {
+ AudioDecoder::seek (t, accurate);
+ _position = t.frames (_audio_content->output_audio_frame_rate ());
+ }
+
+private:
+ AudioFrame _position;
+};
+
+class TestAudioContent : public AudioContent
+{
+public:
+ TestAudioContent (shared_ptr<Film> film)
+ : Content (film)
+ , AudioContent (film, DCPTime ())
+ {}
+
+ string summary () const {
+ return "";
+ }
+
+ string information () const {
+ return "";
+ }
+
+ DCPTime full_length () const {
+ return DCPTime (audio_length().get ());
+ }
+
+ int audio_channels () const {
+ return 2;
+ }
+
+ ContentTime audio_length () const {
+ return ContentTime::from_seconds (61.2942);
+ }
+
+ int content_audio_frame_rate () const {
+ return 48000;
+ }
+
+ int output_audio_frame_rate () const {
+ return 48000;
+ }
+
+ AudioMapping audio_mapping () const {
+ return AudioMapping (audio_channels ());
+ }
+
+ void set_audio_mapping (AudioMapping) {}
+};
+
+shared_ptr<TestAudioContent> content;
+shared_ptr<TestAudioDecoder> decoder;
+
+static shared_ptr<ContentAudio>
+get (AudioFrame from, AudioFrame length)
+{
+ decoder->seek (ContentTime::from_frames (from, content->output_audio_frame_rate ()), true);
+ shared_ptr<ContentAudio> ca = decoder->get_audio (from, length, true);
+ BOOST_CHECK_EQUAL (ca->frame, from);
+ return ca;
+}
+
+static void
+check (AudioFrame from, AudioFrame length)
+{
+ shared_ptr<ContentAudio> ca = get (from, length);
+ for (int i = 0; i < content->audio_channels(); ++i) {
+ for (int j = 0; j < length; ++j) {
+ BOOST_CHECK_EQUAL (ca->audio->data(i)[j], j + from);
+ assert (ca->audio->data(i)[j] == j + from);
+ }
+ }
+}
+
+/** Check the logic in AudioDecoder::get_audio */
+BOOST_AUTO_TEST_CASE (audio_decoder_get_audio_test)
+{
+ shared_ptr<Film> film = new_test_film ("audio_decoder_test");
+
+ content.reset (new TestAudioContent (film));
+ decoder.reset (new TestAudioDecoder (content));
+
+ /* Simple reads */
+ check (0, 48000);
+ check (44, 9123);
+ check (9991, 22);
+
+ /* Read off the end */
+
+ AudioFrame const from = content->output_audio_frame_rate() * 61;
+ AudioFrame const length = content->output_audio_frame_rate() * 4;
+ shared_ptr<ContentAudio> ca = get (from, length);
+
+ for (int i = 0; i < content->audio_channels(); ++i) {
+ for (int j = 0; j < ca->audio->frames(); ++j) {
+ BOOST_CHECK_EQUAL (ca->audio->data(i)[j], j + from);
+ assert (ca->audio->data(i)[j] == j + from);
+ }
+ }
+}
+++ /dev/null
-/*
- Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
-
- This program 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.
-
- This program 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 this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-*/
-
-/* @file test/player_silence_padding_test.cc
- * @brief Check that the Player correctly generates silence when used with a silent FFmpegContent.
- */
-
-#include <iostream>
-#include <boost/test/unit_test.hpp>
-#include "lib/film.h"
-#include "lib/ffmpeg_content.h"
-#include "lib/dcp_content_type.h"
-#include "lib/ratio.h"
-#include "lib/audio_buffers.h"
-#include "lib/player.h"
-#include "test.h"
-
-using std::cout;
-using boost::shared_ptr;
-
-BOOST_AUTO_TEST_CASE (player_silence_padding_test)
-{
- shared_ptr<Film> film = new_test_film ("player_silence_padding_test");
- film->set_name ("player_silence_padding_test");
- shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/test.mp4"));
- film->set_container (Ratio::from_id ("185"));
- film->set_audio_channels (6);
-
- film->examine_and_add_content (c);
- wait_for_jobs ();
-
- shared_ptr<Player> player = film->make_player ();
- shared_ptr<AudioBuffers> test = player->get_audio (DCPTime (0), DCPTime::from_seconds (1), true);
- BOOST_CHECK_EQUAL (test->frames(), 48000);
- BOOST_CHECK_EQUAL (test->channels(), film->audio_channels ());
-
- for (int i = 0; i < test->frames(); ++i) {
- for (int c = 0; c < test->channels(); ++c) {
- BOOST_CHECK_EQUAL (test->data()[c][i], 0);
- }
- }
-}
-
--- /dev/null
+/*
+ Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
+
+ This program 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.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+/** @file test/player_test.cc
+ * @brief Various tests of Player.
+ */
+
+#include <iostream>
+#include <boost/test/unit_test.hpp>
+#include "lib/film.h"
+#include "lib/ffmpeg_content.h"
+#include "lib/dcp_content_type.h"
+#include "lib/ratio.h"
+#include "lib/audio_buffers.h"
+#include "lib/player.h"
+#include "test.h"
+
+using std::cout;
+using std::list;
+using boost::shared_ptr;
+
+/** Player::overlaps */
+BOOST_AUTO_TEST_CASE (player_overlaps_test)
+{
+ shared_ptr<Film> film = new_test_film ("player_overlaps_test");
+ film->set_container (Ratio::from_id ("185"));
+ shared_ptr<FFmpegContent> A (new FFmpegContent (film, "test/data/test.mp4"));
+ shared_ptr<FFmpegContent> B (new FFmpegContent (film, "test/data/test.mp4"));
+ shared_ptr<FFmpegContent> C (new FFmpegContent (film, "test/data/test.mp4"));
+
+ film->examine_and_add_content (A);
+ film->examine_and_add_content (B);
+ film->examine_and_add_content (C);
+ wait_for_jobs ();
+
+ BOOST_CHECK_EQUAL (A->full_length(), DCPTime::from_seconds (3));
+
+ A->set_position (DCPTime::from_seconds (0));
+ B->set_position (DCPTime::from_seconds (10));
+ C->set_position (DCPTime::from_seconds (20));
+
+ shared_ptr<Player> player = film->make_player ();
+
+ list<shared_ptr<Piece> > o = player->overlaps<FFmpegContent> (DCPTime::from_seconds (0), DCPTime::from_seconds (5));
+ BOOST_CHECK_EQUAL (o.size(), 1);
+ BOOST_CHECK_EQUAL (o.front()->content, A);
+
+ o = player->overlaps<FFmpegContent> (DCPTime::from_seconds (5), DCPTime::from_seconds (8));
+ BOOST_CHECK_EQUAL (o.size(), 0);
+
+ o = player->overlaps<FFmpegContent> (DCPTime::from_seconds (8), DCPTime::from_seconds (12));
+ BOOST_CHECK_EQUAL (o.size(), 1);
+ BOOST_CHECK_EQUAL (o.front()->content, B);
+
+ o = player->overlaps<FFmpegContent> (DCPTime::from_seconds (2), DCPTime::from_seconds (12));
+ BOOST_CHECK_EQUAL (o.size(), 2);
+ BOOST_CHECK_EQUAL (o.front()->content, A);
+ BOOST_CHECK_EQUAL (o.back()->content, B);
+
+ o = player->overlaps<FFmpegContent> (DCPTime::from_seconds (8), DCPTime::from_seconds (11));
+ BOOST_CHECK_EQUAL (o.size(), 1);
+ BOOST_CHECK_EQUAL (o.front()->content, B);
+}
+
+/** Check that the Player correctly generates silence when used with a silent FFmpegContent */
+BOOST_AUTO_TEST_CASE (player_silence_padding_test)
+{
+ shared_ptr<Film> film = new_test_film ("player_silence_padding_test");
+ film->set_name ("player_silence_padding_test");
+ shared_ptr<FFmpegContent> c (new FFmpegContent (film, "test/data/test.mp4"));
+ film->set_container (Ratio::from_id ("185"));
+ film->set_audio_channels (6);
+
+ film->examine_and_add_content (c);
+ wait_for_jobs ();
+
+ shared_ptr<Player> player = film->make_player ();
+ shared_ptr<AudioBuffers> test = player->get_audio (DCPTime (0), DCPTime::from_seconds (1), true);
+ BOOST_CHECK_EQUAL (test->frames(), 48000);
+ BOOST_CHECK_EQUAL (test->channels(), film->audio_channels ());
+
+ for (int i = 0; i < test->frames(); ++i) {
+ for (int c = 0; c < test->channels(); ++c) {
+ BOOST_CHECK_EQUAL (test->data()[c][i], 0);
+ }
+ }
+}
+
audio_analysis_test.cc
audio_buffers_test.cc
audio_delay_test.cc
+ audio_decoder_test.cc
audio_mapping_test.cc
black_fill_test.cc
client_server_test.cc
image_test.cc
job_test.cc
make_black_test.cc
- player_silence_padding_test.cc
+ player_test.cc
pixel_formats_test.cc
ratio_test.cc
repeat_frame_test.cc