Skip to content

Preprocess video packets only once right before processing them - #1553

Open
ulmus-scott wants to merge 7 commits into
MythTV:masterfrom
ulmus-scott:preprocess
Open

ulmus-scott wants to merge 7 commits into
MythTV:masterfrom
ulmus-scott:preprocess

Conversation

@ulmus-scott

Copy link
Copy Markdown
Contributor

This is preliminary work for extracting A/53 embedded captions from the video frames.

Instead of preprocessing a video packet multiple times until all frames are received from the decoder, preprocess each packet exactly once and modify GetFrame() to preprocess the packet immediately before sending it to the decoder.

Checklist

…Packet

While av_packet_move_ref() does not guarantee the AVPacket is reference counted,
all of the AVPackets added to m_storedPackets are already reference counted, so
Pkt is still always reference counted.

This avoids potential unnecessary memory allocations and atomic increments and
decrements.

Use av_packet_free() to ensure the AVPacket is always freed properly, instead of
duplicating the code.
Since 8e34e6e in 2018, ProcessVideoPacket()
will not call avcodec_send_packet() until avcodec_receive_frame() (called via
MythCodecContext::FilteredReceiveFrame()) does not return an AVFrame.

However, this means that the same AVPacket will be pre-processesed repeatedly
until all frames are recieved from the decoder.  For software decoding, this
means that after the first AVPacket is pre-processed and sent, every AVPacket
will be processed twice since it will be pre-processed, the previous frame
received, pre-processed again, and then sent to the decoder.  If a decoder
returns multiple frames at a time, one packet will be pre-processed the number
of returned frames plus one times.

Note that the AVPacket is still pre-processed before the previous frame is
returned.
This helps reasoning about what the function does.

Also improve documentation.  I'm not really satisfied with the
return documentation, but it is only used by MythCommFlagPlayer
and MythCCExtractorPlayer to seemingly see if a frame was output.
This simplifies some of the branching logic.

gotpicture was always 0 for the log messages, so it has been removed from them.

That sentPacket is only true when avcodec_send_packet() returns 0 doesn't change
the behavior since the function will return early on errors.
This should help enable preprocessing video packets immediately before they are
sent to the decoder, instead of preprocessing them before the previous frame is
received.

Note: MythDVDDecoder::ProcessVideoPacket() is now called once per packet instead
of twice, but I don't anticipate this being an issue.
copying the preceeding code into the if statement.

No functional change since it breaks early.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant