Skip to content
Snippets Groups Projects
Commit e675beaa authored by Philippe Gorley's avatar Philippe Gorley Committed by Adrien Béraud
Browse files

recorder: flush properly

Adds flushing capability to filters.

Change-Id: I015d7931318deb5d099fcaac1356f5fc17b890d6
parent c455eceb
Branches
No related tags found
No related merge requests found
......@@ -161,6 +161,9 @@ MediaFilter::feedInput(AVFrame* frame, const std::string& inputName)
if (!initialized_)
return fail("Filter not initialized", -1);
if (!frame)
return 0;
for (size_t i = 0; i < inputs_.size(); ++i) {
auto& ms = inputParams_[i];
if (ms.name != inputName)
......@@ -210,6 +213,13 @@ MediaFilter::readOutput()
return nullptr;
}
void
MediaFilter::flush()
{
for (size_t i = 0; i < inputs_.size(); ++i)
av_buffersrc_add_frame_flags(inputs_[i], nullptr, 0);
}
int
MediaFilter::initOutputFilter(AVFilterInOut* out)
{
......
......@@ -99,6 +99,11 @@ class MediaFilter {
*/
AVFrame* readOutput();
/**
* Flush filter to indicate EOF.
*/
void flush();
private:
NON_COPYABLE(MediaFilter);
......
......@@ -156,9 +156,10 @@ MediaRecorder::onFrame(const std::string& name, const std::shared_ptr<MediaFrame
// copy frame to not mess with the original frame's pts (does not actually copy frame data)
MediaFrame clone;
const auto& ms = streams_[name]->info;
clone.copyFrom(*frame);
clone.pointer()->pts -= streams_[name]->info.firstTimestamp;
if (clone.pointer()->width > 0 && clone.pointer()->height > 0)
clone.pointer()->pts -= ms.firstTimestamp;
if (ms.isVideo)
videoFilter_->feedInput(clone.pointer(), name);
else
audioFilter_->feedInput(clone.pointer(), name);
......@@ -417,8 +418,12 @@ void
MediaRecorder::flush()
{
std::lock_guard<std::mutex> lk(mutex_);
if (videoFilter_)
videoFilter_->flush();
if (audioFilter_)
audioFilter_->flush();
filterAndEncode(videoFilter_.get(), videoIdx_);
filterAndEncode(audioFilter_.get(), videoIdx_);
filterAndEncode(audioFilter_.get(), audioIdx_);
encoder_->flush();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment