13
0

Fix chunker to handle end of input properly

git-svn-id: svn://localhost/ardour2/branches/3.0@13370 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Sakari Bergen 2012-10-30 20:15:11 +00:00
parent a2de07a48f
commit b5c5fc7a08
2 changed files with 36 additions and 4 deletions

View File

@ -49,14 +49,15 @@ class Chunker
framecnt_t const frames_to_copy = chunk_size - position;
TypeUtils<T>::copy (&context.data()[input_position], &buffer[position], frames_to_copy);
// Output whole buffer
ProcessContext<T> c_out (context, buffer, chunk_size);
ListedSource<T>::output (c_out);
// Update counters
position = 0;
input_position += frames_to_copy;
frames_left -= frames_to_copy;
// Output whole buffer
ProcessContext<T> c_out (context, buffer, chunk_size);
if (frames_left) { c_out.remove_flag(ProcessContext<T>::EndOfInput); }
ListedSource<T>::output (c_out);
}
if (frames_left) {

View File

@ -14,6 +14,7 @@ class ChunkerTest : public CppUnit::TestFixture
CPPUNIT_TEST (testSynchronousProcess);
CPPUNIT_TEST (testAsynchronousProcess);
CPPUNIT_TEST (testChoppingProcess);
CPPUNIT_TEST (testEndOfInputFlagHandling);
CPPUNIT_TEST_SUITE_END ();
public:
@ -136,6 +137,36 @@ class ChunkerTest : public CppUnit::TestFixture
CPPUNIT_ASSERT (TestUtils::array_equals (random_data, &sink->get_array()[ 3 * frames / 2], frames / 2));
}
void testEndOfInputFlagHandling()
{
boost::shared_ptr<ProcessContextGrabber<float> > grabber(new ProcessContextGrabber<float>());
assert (frames % 2 == 0);
chunker.reset (new Chunker<float>(frames));
chunker->add_output (grabber);
ProcessContext<float> const half_context (random_data, frames / 2, 1);
ProcessContext<float> const context (random_data, frames, 1);
context.set_flag(ProcessContext<>::EndOfInput);
// Process 0.5 then 1.0
chunker->process (half_context);
chunker->process (context);
// Should output two contexts
CPPUNIT_ASSERT_EQUAL((int)grabber->contexts.size(), 2);
ProcessContextGrabber<float>::ContextList::iterator it = grabber->contexts.begin();
// first 1.0 not end of input
CPPUNIT_ASSERT_EQUAL(it->frames(), frames);
CPPUNIT_ASSERT(!it->has_flag(ProcessContext<>::EndOfInput));
// Then 0.5 with end of input
++it;
CPPUNIT_ASSERT_EQUAL(it->frames(), frames / 2);
CPPUNIT_ASSERT(it->has_flag(ProcessContext<>::EndOfInput));
}
private:
boost::shared_ptr<Chunker<float> > chunker;
boost::shared_ptr<VectorSink<float> > sink;