#include "audio_decoder.h"
using std::string;
+using std::cout;
using boost::shared_ptr;
using boost::dynamic_pointer_cast;
assert (_encoder);
if (f->audio_stream()) {
- AudioStream st = f->audio_stream().get();
- _matcher.reset (new Matcher (f->log(), st.sample_rate(), f->frames_per_second()));
- _delay_line.reset (new DelayLine (f->log(), st.channels(), f->audio_delay() * st.sample_rate() / 1000));
+ shared_ptr<AudioStream> st = f->audio_stream();
+ _matcher.reset (new Matcher (f->log(), st->sample_rate(), f->frames_per_second()));
+ _delay_line.reset (new DelayLine (f->log(), st->channels(), f->audio_delay() * st->sample_rate() / 1000));
_gain.reset (new Gain (f->log(), f->audio_gain()));
}
{
_encoder->process_begin ();
try {
+ bool done[2] = { false, false };
+
while (1) {
- bool const v = _decoders.first->pass ();
+ if (!done[0]) {
+ done[0] = _decoders.first->pass ();
+ _decoders.first->set_progress ();
+ }
- bool a = true;
- if (dynamic_pointer_cast<Decoder> (_decoders.second) != dynamic_pointer_cast<Decoder> (_decoders.first)) {
- a = _decoders.second->pass ();
+ if (!done[1] && dynamic_pointer_cast<Decoder> (_decoders.second) != dynamic_pointer_cast<Decoder> (_decoders.first)) {
+ done[1] = _decoders.second->pass ();
+ } else {
+ done[1] = true;
}
- if (v && a) {
+ if (done[0] && done[1]) {
break;
}
}
} catch (...) {
- /* process_end() is important as the decoder may have worker
- threads that need to be cleaned up.
- */
_encoder->process_end ();
throw;
}
-
+
+ if (_delay_line) {
+ _delay_line->process_end ();
+ }
+ if (_matcher) {
+ _matcher->process_end ();
+ }
+ if (_gain) {
+ _gain->process_end ();
+ }
_encoder->process_end ();
}