1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-02 03:06:28 +02:00
Commit Graph

55 Commits

Author SHA1 Message Date
Andreas Rheinhardt
b2421c4f26 avcodec/h264_parse: Move ff_h264_get_profile() to h264_ps.h
It is a more fitting place for it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-01-26 15:30:54 +01:00
sfan5
b32b32ba89 lavc/mediacodecdec: set codec profile and level from extradata for H264+HEVC
This value is later passed to MediaCodec and checked at decoder init.
Notably decoding of 10-bit streams before this commit would "work" without
returning errors but only return garbage output (on most Android devices).
2021-12-30 18:19:53 +02:00
Andreas Rheinhardt
a247ac640d avcodec: Constify AVCodecs
Given that the AVCodec.next pointer has now been removed, most of the
AVCodecs are not modified at all any more and can therefore be made
const (as this patch does); the only exceptions are the very few codecs
for external libraries that have a init_static_data callback.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:15 -03:00
sfan5
6f80953554 avcodec/mediacodecdec: do not abort when H264/HEVC extradata extraction fails
Although rare, extradata can be present but empty and extraction will fail.
However Android also supports passing codec-specific data inline and
will likely play such a stream anyway. So there's no reason to abort
initialization before we know for sure.
2021-02-14 13:38:46 +02:00
Mark Thompson
cd322794ee lavc: Mark hw_config pointer arrays as const
They are read-only just like the HWConfig structures they point to.
2020-11-08 18:54:42 +00:00
Mark Thompson
2594f6a362 lavc: Rename hwaccel.h to hwconfig.h
This already applied to decoders as well as hwaccels, and adding encoder
support was going to make the name even more inaccurate.
2020-04-26 18:38:25 +01:00
Aman Gupta
8a3623e2fb avcodec/mediacodecdec: warn when input buffers are not configured with proper size
In rare circumstances, if the codec is not configured with the
proper parameters the input buffers can be allocated with a size
that's too small to hold an individual packet. Since MediaCodec
expects exactly one incoming buffer with a given PTS, it is not
valid to split data for a given PTS across two input buffers.

See https://developer.android.com/reference/android/media/MediaCodec#data-processing:

  > Do not submit multiple input buffers with the same timestamp

Signed-off-by: Aman Gupta <aman@tmm1.net>
2019-09-10 13:51:05 -07:00
Matthieu Bouron
d83985ce11 avcodec/mediacodecdec: try to receive a frame after signaling EOF to the codec
Avoids returning EAGAIN after signaling EOF to the codec in
ff_mediacodec_dec_send() so we can try to receive a frame before
returning in mediacodec_receive_frame().

This helps avoiding an extra round-trip between avcodec_send_frame() and
avcodec_receive_frame() while draining the remaining frames.
2019-06-13 11:41:18 +02:00
Aman Gupta
9b563f6584 avcodec/mediacodecdec: add workaround for buggy amlogic mpeg2 decoder
I tested the previous mediacodec changes on seven different Android
TV devices, with both mpeg2 and h264 content. All except one worked
as expected. The exception was the MiBox3 running Android 6.0.1,
where playback would freeze on a frame every few seconds. I tested
two other AMLogic devices with newer Android versions that did not
show the same problem. H264 decoding on the MiBox3 was also not affected,
so this workaround applies only to OMX.amlogic.mpeg2.decoder.awesome
on Android API22.

There is a rumor that Xiaomi is planning to release Android Oreo for
the MiBox3, so I will revisit in a few months to confirm whether this
is specific to os/driver version or the chipset used in that device.

Signed-off-by: Aman Gupta <aman@tmm1.net>
Signed-off-by: Matthieu Bouron <matthieu.bouron@gmail.com>
2018-05-04 11:53:44 -07:00
Aman Gupta
f6681feda6 avcodec/mediacodecdec: restructure mediacodec_receive_frame
The new logic follows a recommendation by @rcombs to use
dequeueInputBuffer with a timeout of 0 as a way to detect
whether the codec wants more data. The dequeued buffer index is
kept in MediaCodecDecContext until it can be used next.

A similar technique is also used by the Google's official media
player Exoplayer: see MediaCodecRenderer.feedInputBuffer().

Signed-off-by: Aman Gupta <aman@tmm1.net>
Signed-off-by: Matthieu Bouron <matthieu.bouron@gmail.com>
2018-05-04 11:53:33 -07:00
Aman Gupta
6a7a84b2d1 avcodec/mediacodecdec: clarify delay_flush specific code
As of 2a0eb8685, ff_mediacodec_dec_is_flushing() only returns
true in delay_flush mode. Make this more obvious by adding
delay_flush to the if statement.

Signed-off-by: Matthieu Bouron <matthieu.bouron@gmail.com>
Signed-off-by: Aman Gupta <aman@tmm1.net>
2018-04-25 10:53:52 -07:00
Aman Gupta
3172b31223 avcodec/mediacodecdec: fix immediate EAGAIN with buffered packet
In cases where the mediacodec decoder consumed a partial packet,
receive_frame() would start returning EAGAIN if the rest of the
packet couldn't be flushed and no frames were immediately available.

This fixes receive_frame() to perform its normal blocking wait for
new frames before returning EAGAIN. Fixes an issue I could reproduce
fairly often on a FireOS 6 device, and reported to be happening
intermittently by two mpv users.

Signed-off-by: Aman Gupta <aman@tmm1.net>
Signed-off-by: Matthieu Bouron <matthieu.bouron@gmail.com>
2018-03-13 12:32:08 -07:00
Aman Gupta
2a0eb86857 avcodec/mediacodecdec: add delay_flush option
The default behavior of the mediacodec decoder before this commit
was to delay flushes until all pending hardware frames were
returned to the decoder. This was useful for certain types of
applications, but was unexpected behavior for others.

The new default behavior with this commit is now to execute
flushes immediately to invalidate all pending frames. The old
behavior can be enabled by setting delay_flush=1.

With the new behavior, video players implementing seek can simply
call flush on the decoder without having to worry about whether
they have one or more mediacodec frames still buffered in their
rendering pipeline. Previously, all these frames had to be
explictly freed (or rendered) before the seek/flush would execute.

The new behavior matches the behavior of all other lavc decoders,
reducing the amount of special casing required when using the
mediacodec decoder.

Signed-off-by: Aman Gupta <aman@tmm1.net>
Signed-off-by: Matthieu Bouron <matthieu.bouron@gmail.com>
2018-03-07 16:22:47 -08:00
Matthieu Bouron
2238e54ef0 avcodec/mediacodecdec: factorize codec declarations 2018-03-03 21:18:39 +01:00
Matthieu Bouron
af167d970b avcodec/mediacodecdec: factorize common extradata functions 2018-03-03 21:18:39 +01:00
Matthieu Bouron
535e020225 avcodec/mediacodecdec: add missing "libavutil/internal.h" include
libavutil/internal.h defines NULL_IF_CONFIG_SMALL.
2018-03-03 21:18:39 +01:00
Aman Gupta
f611fef37c avcodec/mediacodecdec: refactor to take advantage of new decoding api
This refactor splits up the main mediacodec decode loop into two
send/receive helpers, which are then used to rewrite the receive_frame
callback and take full advantage of the new decoding api. Since we
can now request packets on demand with ff_decode_get_packet(), the
fifo buffer is no longer necessary and has been removed.

This change was motivated by behavior observed on certain Android TV
devices, featuring hardware mpeg2/h264 decoders which also deinterlace
content (to produce multiple frames per field). Previously, this code
caused buffering issues because queueInputBuffer() was always invoked
before each dequeueOutputBuffer(), even though twice as many output
buffers were being generated.

With this patch, the decoder will always attempt to drain new frames
first before sending more data into the underlying codec.

Signed-off-by: Matthieu Bouron <matthieu.bouron@gmail.com>
2018-02-19 15:27:34 +01:00
James Almer
782e066e3e avcodec/mediacodecdec: use ff_hevc_ps_uninit()
Fixes memleaks.

Signed-off-by: James Almer <jamrial@gmail.com>
2018-01-30 13:15:44 -03:00
Matthieu Bouron
d19174c673 lavc/mediacodecdec: remove mediacodec_process_data() indirection 2018-01-06 22:12:51 +01:00
Aman Gupta
9d9835017f lavc/mediacodecdec: switch to new decoding API
Using the new API gives the decoder the ability to produce
N frames per input packet. This is particularly useful with
mpeg2 decoders on some android devices, which automatically
deinterlace video and produce one frame per field.

Signed-off-by: Aman Gupta <aman@tmm1.net>
Signed-off-by: Matthieu Bouron <matthieu.bouron@gmail.com>
2018-01-06 22:12:31 +01:00
Aman Gupta
8bf4e6d3ce lavc/mediacodec: use AVMediaCodecDeviceContext hw_device_ctx if set
Signed-off-by: Matthieu Bouron <matthieu.bouron@gmail.com>
2017-12-16 00:52:27 +01:00
wm4
b945fed629 avcodec: add metadata to identify wrappers and hardware decoders
Explicitly identify decoder/encoder wrappers with a common name. This
saves API users from guessing by the name suffix. For example, they
don't have to guess that "h264_qsv" is the h264 QSV implementation, and
instead they can just check the AVCodec .codec and .wrapper_name fields.

Explicitly mark AVCodec entries that are hardware decoders or most
likely hardware decoders with new AV_CODEC_CAPs. The purpose is allowing
API users listing hardware decoders in a more generic way. The proposed
AVCodecHWConfig does not provide this information fully, because it's
concerned with decoder configuration, not information about the fact
whether the hardware is used or not.

AV_CODEC_CAP_HYBRID exists specifically for QSV, which can have software
implementations in case the hardware is not capable.

Based on a patch by Philip Langdale <philipl@overt.org>.

Merges Libav commit 47687a2f8a.
2017-12-14 19:37:56 +01:00
Jan Ekström
6939b3cb9d mediacodecdec: fix build by including hwaccel.h
Enables the decoder to utilize the type AVCodecHWConfigInternal.
2017-12-01 22:51:53 +02:00
Mark Thompson
758fbc54fe lavc: Add hardware config metadata for decoders supporting hardware output
This includes a pointer to the associated hwaccel for decoders using
hwaccels - these will be used later to implement the hwaccel setup
without needing a global list.

Also added is a new file listing all hwaccels as external declarations -
this will be used later to generate the hwaccel list at configure time.
2017-11-26 21:35:53 +00:00
James Almer
bd8f1fa100 avcodec/hevc_sei: rename HEVCSEIContext to HEVCSEI
Cosmetic change skipped in 0b30cb8dae
by mistake.

Signed-off-by: James Almer <jamrial@gmail.com>
2017-10-31 12:27:57 -03:00
Matthieu Bouron
3839580b71 lavc/mediacodecdec: switch to the new generic filtering mechanism 2017-06-13 14:33:54 +02:00
Aman Gupta
a32a6b4201 lavc: add mpeg2 mediacodec decoder
Android TV and FireOS hardware supports mpeg2 hardware decoding via
MediaCodec.

Signed-off-by: Matthieu Bouron <matthieu.bouron@gmail.com>
2017-06-08 19:16:09 +02:00
James Almer
6a72578cc2 avcodec/hevc_parse: decode SEI message NALUs in extradata
They may be available in hvcc style extradata.

Based on a patch by Hendrik Leppkes.

Reviewed-by: Hendrik Leppkes <h.leppkes@gmail.com>
Reviewed-by: Aaron Levinson <alevinsn@aracnet.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2017-05-05 17:30:38 -03:00
James Almer
f1533979a2 avcodec/hevc_parse: allow setting apply_defdispwin when decoding SPS NAL units
Reviewed-by: nevcairiel
Signed-off-by: James Almer <jamrial@gmail.com>
2017-04-09 13:46:35 -03:00
Matthieu Bouron
3fce174d4f lavc/mediacodecdec: set AV_CODEC_CAP_AVOID_PROBING capability 2017-04-04 09:50:44 +02:00
Matthieu Bouron
6ffaf90b32 lavc/mediacodecdec: switch to AV_CODEC_CAP_DELAY 2017-04-04 09:50:44 +02:00
James Almer
6397815be0 Merge commit 'c359d624d3efc3fd1d83210d78c4152bd329b765'
* commit 'c359d624d3efc3fd1d83210d78c4152bd329b765':
  hevcdec: move decoder-independent declarations into a separate header

Merged-by: James Almer <jamrial@gmail.com>
2017-03-23 14:27:48 -03:00
James Almer
005da88c1e avcodec/mediacodec: convert to stdatomic
Reviewed-by: wm4 <nfxjfg@googlemail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2017-03-23 11:44:58 -03:00
Matthieu Bouron
d5082a2ce7 lavc/mediacodec: use more meaningful filenames
Adds the following changes:
  * mediacodecdec.{c,h} -> mediacodecdec_common.{c,h}
  * mediacodecdec_h2645.c -> mediacodecdec.c
2016-10-19 10:50:56 +02:00
Matthieu Bouron
f62c54456d lavc: add mpeg4 mediacodec decoder 2016-10-19 10:50:52 +02:00
Matthieu Bouron
0f7fce87ea lavc: add vp8/vp9 mediacodec decoders 2016-10-19 10:50:12 +02:00
Matthieu Bouron
cfa3c2655a lavc/mediacodecdec: rename dequeued_buffer_nb to output_buffer_count 2016-10-12 09:50:42 +02:00
Matthieu Bouron
a458ed65b5 lavc/mediacodecdec: remove first output buffer timing debug log 2016-10-12 09:50:42 +02:00
Hendrik Leppkes
3f9137c57d Merge commit '32c8359093d1ff4f45ed19518b449b3ac3769d27'
* commit '32c8359093d1ff4f45ed19518b449b3ac3769d27':
  lavc: export the timestamps when decoding in AVFrame.pts

Merged-by: Hendrik Leppkes <h.leppkes@gmail.com>
2016-10-07 13:03:36 +02:00
Matthieu Bouron
0919151651 lavc/mediacodecdec: fix size variable shadowing in ff_mediacodec_dec_decode
Fixes incompatible pointer type warning on 64-bit systems.
2016-10-06 16:49:28 +02:00
Matthieu Bouron
140da8e810 lavc: add hevc mediacodec decoder 2016-09-15 21:48:28 +02:00
Matthieu Bouron
0f2654c9a3 lavc: add mediacodec hwaccel support 2016-07-08 17:02:37 +02:00
Matthieu Bouron
55816c9269 lavc/mediacodec: increase buffer dequeue timeout when the codec needs to be drained
Increase buffer dequeue timeout when the codec needs to be drained as it
could happen that no input buffer is available when we receive a null
packet for the first time (meaning we are unable to signal end of stream
and mark the codec as draining).

Fixes potential loss of last frames after sending a null packet.
2016-06-23 14:14:15 +02:00
Matthieu Bouron
b316ebf46d lavc/mediacodec: rely on buffer flags to detect end of stream 2016-06-23 14:14:15 +02:00
Matthieu Bouron
30e3a27119 lavc/mediacodec: re-indent after previous commit 2016-06-23 14:14:15 +02:00
Matthieu Bouron
a71d518575 lavc/mediacodec: discard 0-sized buffers
Their only purpose is to carry the end of stream flag.
2016-06-23 14:14:15 +02:00
Matthieu Bouron
432891a96e lavc/mediacodecdec{,_h264}: set FF_CODEC_CAP_SETS_PKT_DTS capability
And sets frames pkt_dts to AV_NOPTS_VALUE as we do not want lavc/utils
to overwrite the field with incorrect values as the decoder is
asynchronous.
2016-06-20 10:07:41 +02:00
Matthieu Bouron
e452abc5c2 lavc/mediacodec: refactor ff_AMediaCodecList_getCodecByType
Allows to select a codec (encoder or decoder) only if it supports a
specific profile.

Adds ff_AMediaCodecProfile_getProfileFromAVCodecContext to convert an
AVCodecContext profile to a MediaCodec profile. It only supports H264
for now.

The codepath using MediaCodecList.findDecoderForFormat() (Android >= 5.0)
has been dropped as this method does not allow to select a decoder
compatible with a specific profile.
2016-06-15 16:36:13 +02:00
Matthieu Bouron
1729387c7a lavc/mediacodec: improve error messages 2016-06-07 10:22:27 +02:00
Matthieu Bouron
93f4d1646e lavc/mediacodec: bypass width/height restrictions when looking for a decoder
Codec width/height restrictions seem hardcoded at the OMX level and
seem arbitrary. Bypassing those restrictions allows a device to decode
streams at higher resolutions.

For example it allows a Nexus 5 to decode h264 streams with a resolution
higher than 1920x1080.
2016-06-07 10:22:20 +02:00