Add support for delay in FFmpegSourceAudioProvider as FFMS2 only handles it automatically in the avisynth plugin

Originally committed to SVN as r4828.
This commit is contained in:
Thomas Goyne 2010-11-04 04:58:27 +00:00
parent a73091ef5c
commit 50f8389615
2 changed files with 23 additions and 7 deletions

View File

@ -184,8 +184,9 @@ void FFmpegSourceAudioProvider::LoadAudio(wxString filename) {
channels = AudioInfo.Channels; channels = AudioInfo.Channels;
sample_rate = AudioInfo.SampleRate; sample_rate = AudioInfo.SampleRate;
num_samples = AudioInfo.NumSamples; delay = AudioInfo.FirstTime * sample_rate;
if (channels <= 0 || sample_rate <= 0 || num_samples <= 0) num_samples = AudioInfo.NumSamples + delay;
if (channels <= 0 || sample_rate <= 0 || num_samples <= 0 || delay < 0)
throw AudioOpenError("sanity check failed, consult your local psychiatrist"); throw AudioOpenError("sanity check failed, consult your local psychiatrist");
// FIXME: use the actual sample format too? // FIXME: use the actual sample format too?
@ -222,7 +223,19 @@ void FFmpegSourceAudioProvider::Close() {
/// @param Count /// @param Count
/// ///
void FFmpegSourceAudioProvider::GetAudio(void *Buf, int64_t Start, int64_t Count) { void FFmpegSourceAudioProvider::GetAudio(void *Buf, int64_t Start, int64_t Count) {
if (FFMS_GetAudio(AudioSource, Buf, Start, Count, &ErrInfo)) { uint8_t *Buf2 = static_cast<uint8_t*>(Buf);
Start -= delay;
if (Start < 0) {
size_t Bytes = std::min(-Start, Count) * bytes_per_sample * channels;
memset(Buf2, 0, Bytes);
Count += Start;
if (Count <= 0) return;
Start = 0;
Buf2 += Bytes;
}
if (FFMS_GetAudio(AudioSource, Buf2, Start, Count, &ErrInfo)) {
throw AudioDecodeError(std::string("Failed to get audio samples: ") + ErrInfo.Buffer); throw AudioDecodeError(std::string("Failed to get audio samples: ") + ErrInfo.Buffer);
} }
} }

View File

@ -43,15 +43,18 @@
/// @brief Implements audio loading with the FFMS library. /// @brief Implements audio loading with the FFMS library.
class FFmpegSourceAudioProvider : public AudioProvider, FFmpegSourceProvider { class FFmpegSourceAudioProvider : public AudioProvider, FFmpegSourceProvider {
private: private:
FFMS_AudioSource *AudioSource; /// audio source object FFMS_AudioSource *AudioSource; ///< audio source object
bool COMInited; /// COM initialization state bool COMInited; ///< COM initialization state
char FFMSErrMsg[1024]; /// FFMS error message char FFMSErrMsg[1024]; ///< FFMS error message
FFMS_ErrorInfo ErrInfo; /// FFMS error codes/messages FFMS_ErrorInfo ErrInfo; ///< FFMS error codes/messages
void Close(); void Close();
void LoadAudio(wxString filename); void LoadAudio(wxString filename);
/// Audio delay in samples
int64_t delay;
public: public:
FFmpegSourceAudioProvider(wxString filename); FFmpegSourceAudioProvider(wxString filename);
virtual ~FFmpegSourceAudioProvider(); virtual ~FFmpegSourceAudioProvider();