Add the needed support for internal buffering by audio codec
Some audio codecs may want to internally buffer to send the audio in larger blocks. Add method avi_audio_codec::flush() that signals to the codec that incomplete block should be flushed in preparation to close the AVI file (after calling that, audio packet queue is flushed).
This commit is contained in:
parent
043cac8894
commit
a0663b5450
2 changed files with 22 additions and 0 deletions
|
@ -174,6 +174,10 @@ struct avi_audio_codec
|
|||
* Parameter samples: Number of samples offered.
|
||||
*/
|
||||
virtual void samples(int16_t* data, size_t samples) = 0;
|
||||
/**
|
||||
* Flush the audio state. Default implementation does nothing.
|
||||
*/
|
||||
virtual void flush();
|
||||
/**
|
||||
* Is the codec ready to receive a new frame?
|
||||
*
|
||||
|
@ -237,6 +241,10 @@ struct avi_output_stream
|
|||
* Parameter samplecount: Count of samples.
|
||||
*/
|
||||
void samples(int16_t* samples, size_t samplecount);
|
||||
/**
|
||||
* Flush audio codec state in preparation to close the AVI.
|
||||
*/
|
||||
void flushaudio();
|
||||
/**
|
||||
* Get number of samples for the next frame.
|
||||
*
|
||||
|
|
|
@ -218,8 +218,18 @@ void avi_output_stream::samples(int16_t* samples, size_t samplecount)
|
|||
audio_timer.increment();
|
||||
}
|
||||
|
||||
void avi_output_stream::flushaudio()
|
||||
{
|
||||
if(!in_segment)
|
||||
throw std::runtime_error("Trying to write to non-open AVI");
|
||||
acodec->flush();
|
||||
while(!acodec->ready())
|
||||
write_pkt(avifile, acodec->getpacket(), 1);
|
||||
}
|
||||
|
||||
void avi_output_stream::end()
|
||||
{
|
||||
flushaudio(); //In case audio codec uses internal buffering...
|
||||
std::ostream& out = *avifile.outstream;
|
||||
avifile.finish_avi();
|
||||
in_segment = false;
|
||||
|
@ -261,6 +271,10 @@ bool avi_output_stream::readqueue(uint32_t* _frame, sample_queue& aqueue, bool f
|
|||
return true;
|
||||
}
|
||||
|
||||
void avi_audio_codec::flush()
|
||||
{
|
||||
//Do nothing.
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
avi_codec_type<T>::avi_codec_type(const char* _iname, const char* _hname, T* (*_instance)())
|
||||
|
|
Loading…
Add table
Reference in a new issue