summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libs/audiographer/audiographer/general/chunker.h9
-rw-r--r--libs/audiographer/tests/general/chunker_test.cc31
2 files changed, 36 insertions, 4 deletions
diff --git a/libs/audiographer/audiographer/general/chunker.h b/libs/audiographer/audiographer/general/chunker.h
index 397d67ffc5..cc46aa4575 100644
--- a/libs/audiographer/audiographer/general/chunker.h
+++ b/libs/audiographer/audiographer/general/chunker.h
@@ -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) {
diff --git a/libs/audiographer/tests/general/chunker_test.cc b/libs/audiographer/tests/general/chunker_test.cc
index ea5c29a410..d3adab3691 100644
--- a/libs/audiographer/tests/general/chunker_test.cc
+++ b/libs/audiographer/tests/general/chunker_test.cc
@@ -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;