Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

take into account the filter size when packetizing #123

Merged
merged 2 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/audioresampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ bool AudioResampler::pop(AudioSamples &dst, bool getall, OptionalErrorCode ec)
//clog << " delay [pop]: " << result << endl;

// Need more data
if (result < dst.samplesCount() && getall == false)
if (result < dst.samplesCount() + m_filterSize / 2 && getall == false)
{
return false;
}
Expand Down Expand Up @@ -209,7 +209,7 @@ AudioSamples AudioResampler::pop(size_t samplesCount, OptionalErrorCode ec)
auto delay = swr_get_delay(m_raw, m_dstRate);

// Need more data
if (size_t(delay) < samplesCount && samplesCount)
if (size_t(delay) < samplesCount + m_filterSize / 2 && samplesCount)
{
return AudioSamples(nullptr);
}
Expand Down Expand Up @@ -404,6 +404,10 @@ bool AudioResampler::init(uint64_t dstChannelsLayout, int dstRate, SampleFormat
if (sts < 0)
goto ffmpeg_internal_fails;

sts = av_opt_get_int(m_raw, "filter_size", 0, &m_filterSize);
if (sts < 0)
goto ffmpeg_internal_fails;

// Set optional options
if (dict)
{
Expand Down
2 changes: 2 additions & 0 deletions src/audioresampler.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class AudioResampler : public FFWrapperPtr<SwrContext>, public noncopyable
int m_streamIndex = -1;
Timestamp m_prevPts;
Timestamp m_nextPts;

int64_t m_filterSize;
};

} // namespace av
Expand Down