Commit graph

37 commits

Author SHA1 Message Date
Ram Mohan M
31fc8edb9c libavcenc: Correct Lagrange parameter for I, P & B slices
The Lambda tables for intra and inter(P) slices are slightly
modified. Lambda tables for B slices is completely replaced
wih new set.

This change is done in accordance with JVT-O079.doc
2023-10-01 01:37:17 +05:30
Ram Mohan M
50fd862b8d libavcenc: Remove duplicate code and improve readability
This commit does not introduce any new functionality w.r.t previous
commit. But it fixes few things. They are listed below:
1. Guard Bands in header files are fixed
2. Header files contains function definition comments. These are same
as in source file. Maintaining same comment at two locations is
unnecessary. These are removed.
3. Improved consistency and code indentation
4. Removed comments that dont align with implementation
5. Grouped headers of a workspace together
2023-10-01 01:37:17 +05:30
Ram Mohan M
f0b559e4dc libavcenc: forward current frame intra cost to rc accurately 2023-10-01 01:37:17 +05:30
Ram Mohan
c68f552fce libavcenc: signal header bits consumed count accurately to rc 2023-10-01 01:37:17 +05:30
Hamsalekha S
a24d3cf61f libavcenc: Fixed bug in the case of IDR frame being skipped.
When IDR frame is skipped due to VBV constraints, the frame
number should not be reset. Since it was reset earlier, it
was leading to bistream being not decodable in such a case.
Restore frame_num during idr skip.
2023-09-28 07:24:09 -07:00
Ram Mohan M
3fcf959359 libavcenc: relocate the update post enc routines
During bitstream overflow errors, it is possible that update post
enc gets skipped as last row might never have to be entropy coded
as we have already consumed the buffer. This can be fatal for
encoding further frames. Move this update to a location where it
is guaranteed to be updated

Bug: oss-fuzz-62378
Test: ./avc_enc_fuzzer

Change-Id: I279deb1f30c15c057c0b6e909834313a1df4fdac
2023-09-27 13:57:19 -07:00
Ram Mohan
30858f49ad libavcenc: do not reset status before all threads are made aware
At the end of encoding of a frame, the entropy thread communicates
the encoded bit stream size to rc module for update. After this
update, if rc decides to skip the frame due to vbv overflow, the
bitstream context is reset and frame is marked for skip.

Due to an oversight, if entropy encoding sees an error, then this
update is happening at the end of each row. Now rc has decided to
skip the frame and the context is reset. As the bitstream context is
reset, other threads are unaware of this problem and continue encoding.

This is causing issues.

Restrict the rc update to the thread that entropy code the last row.

Bug: oss-fuzz:59543
Bug: 285891354
Test: avc_enc_fuzzer

Change-Id: If45a5f34abb59ece812733af8f54f72ae5474d03
2023-09-13 20:38:10 -07:00
Aayush Soni
bbf593f216 libavcenc: fix null buffer dereferencing
During encoding, if encoder encounters an error, the library returns the
same. If the application ignores it and feeds further input, library
while processing the new input is facing a null dereference.

1. Added a error check in encode API call before processing input
2. Made entropy bitstream buffer overflow errors non-fatal.

Bug: 187499509
Test: POC in bug descriptions
      atest VtsHalMediaC2V1_0TargetVideoEncTest
      atest -c CtsMediaV2TestCases:CodecEncoderTest
2023-06-01 22:39:26 -07:00
Suyog Pawar
1806721a4d avcenc: Fix out of bound read in initialize process context
Using incorrect stride during copy from source buffer to intermediate buffer. This is corrected

Bug: 242379731
Bug: 242386193
Test: avcenc -c enc.cfg

Change-Id: I307525906ee6f6df5d8e114ebbafa40d6442662d
(cherry picked from commit 0a87a34fccffe15c2cc80670cf1058e7a3313c6a)
Merged-In: I307525906ee6f6df5d8e114ebbafa40d6442662d
2023-03-17 10:22:38 -07:00
Mallikarjun Kamble
8e41a50de4 libavc: Added support for SII SEI message
- Add SII flag and SII parameters for the encoder and decoder.
- Encoder: Added support for SII SEI
- Decoder: Added support for SII SEI parsing and exporting
2023-02-14 22:00:13 -08:00
Manisha Jajoo
e559967790 Encoder: add support for PSNR export
This CL adds support to report PSNR between incoming and resulting
encoded frames. Eventually be reported upstream as part of a feedback
mechanism.

Test: avcenc -c enc.cfg
Bug: b/235899898

Change-Id: Id520913ca5964965b5a86bc520240ccd1b28176c
2022-08-17 17:22:00 +00:00
Neelkamal Semwal
646a58ccf1 encoder: Use intermediate buffer for accessing last MB row
few SIMD modules read few more bytes from the input buffer
at the end of frame. To avoid OOB read, intermediate buffer
is used while processing last MB row.

Bug: 180505809

Test: poc in bug
Test: atest CtsMediaTestCases:VideoEncoderTest
Test: atest CtsMediaV2TestCases:CodecEncoderTest
Test: atest VtsHalMediaC2V1_0TargetVideoEncTest

Change-Id: I11ca65937c7dfaf623f3535c02158ceec0dcc6ee
2021-05-01 08:42:32 -07:00
Neelkamal Semwal
3de25bf0bb avcenc: Add bitstream overflow check during emulation prevention
Bug: 176533109

Test: poc in the bug description

Change-Id: Ia83383f9b65cbde8d7a50a1af8a054936daa4d78
(cherry picked from commit b59de5a25f)
2021-03-19 21:04:30 +00:00
Automerger Merge Worker
93a6f1db82 Merge "encoder: Return gracefully from entropy encoding errors" am: 94f5d3f0f7 am: 7be9fe31f8 am: 0b545cc625
Change-Id: Ia99a4e1a024310153d372cca66fa97aeb1e5b2bd
2020-01-22 20:37:55 +00:00
Chamarthi Kishore
4bc3e63c30 encoder: Return gracefully from entropy encoding errors
Recent error propagation change in encoder introduced a DoS when
output buffer is not large enough to hold the frame encoded.
This commit fixes the DoS seen.

Test: avcenc -c enc.cfg, avcdec -c dec.cfg
Test: revert fix for b/144928581 to reduce the output buffer size
Test: atest android.media.cts.VideoEncoderTest#testGoogH264FlexMaxMax
Test: atest android.media.cts.VideoEncoderTest#testGoogH264Flex1080p

Bug:145019703

Change-Id: I3b3408153a2cb8541a87547d51dd8bde25a33d6c
2019-12-03 15:30:38 +05:30
Chamarthi Kishore
68dce05ea6 Merge changes I015ebe03,Idc0b0db5 am: 00fa4b6490 am: 7684b467b4
am: d49fffd5f4

Change-Id: I0da6b5b695adb949b28ca9d29f806cd11625d2eb
2019-10-31 19:11:43 -07:00
Chamarthi Kishore
95a2113e4b libavc: Handling of Error propagation
This commit has changes to Error return propagation to
the caller functions.

Test: avcenc -c enc.cfg, avcdec -c dec.cfg
Bug: 142545567

Change-Id: I015ebe03e753a0edc1bf8bfc167180ead63193e1
2019-10-24 17:54:31 +05:30
Chamarthi Kishore
ad2eaf8c7d libavc: Add MDCV, CLL, CCV and AVE SEI messages
This commit add support for encoding and decoding of MDCV, CLL, CCV and
AVE SEI messages

Test: avcenc -c enc.cfg, avcdec -c dec.cfg
Bug: 141931623

Change-Id: Idc0b0db5291482ae2bc19cdff65669c32374b02a
2019-10-24 17:20:00 +05:30
Ram Mohan
5df8183189 libavcenc: Correct placement of sync synchronize
In entropy thread, after a call to __sync_synchronize(), store buffer is
receiving new entries. This is causing entropy threads to go out of sync,
resulting in erroneous bitstreams. The following change corrects this.

Bug: 130554568
Test: run cts -m CtsVideoTestCases -t
      android.video.cts.VideoEncoderDecoderTest#testAvcGoog0Qual0720x480
      --skip-preconditions

Change-Id: I81a2343f0f80c1e899e60e92fb48bbd3da006eab
2019-08-07 13:11:57 -07:00
Ram Mohan
82fb2d30cd avcenc: Allow intra mode evaluation during fast skip
For static content, skip and intra modes often compete with each other
neck and neck during mode evaluation. Upon fast skip detection, instead of
skipping all further mode analysis, disable motion search and allow intra
analysis.

This change applies to all presets except FASTEST.

Average bdrate improves by 1%.

Test: Tested on clips of different resolutions.

Change-Id: Ia0aabca5c1dcad03359bebaf071b7be27898e735
2017-12-04 11:55:54 +05:30
Ray Essick
fef5e9e203 Merge "Encoder: Defined structures for accessing MB header data"
am: 8aa140b8a5

Change-Id: Ib3e9cad8eb8ddbd5c941ff4d4c96a12e0f309831
2016-11-29 14:33:27 +00:00
Harish Mahendrakar
c7d9c91417 Encoder: Defined structures for accessing MB header data
Instead of using hard coded address offsets,
defined structures to access MB Header for each MB type
This improves readability of the code

Also helps in maintaining required alignment for MV
MV elements need to be aligned to 2 byte boundary
Unaligned accesses result in undefined behavior

Bug: 33073518
Test: Tested with -fsanitize=alignment enabled on avcenc
Change-Id: I51c009b7deded76315a4bf2880444d21ae7d517f
2016-11-24 12:25:49 +05:30
Doney Alex
983e1aecd4 Encoder: Added support for configuring VUI parameters.
Bug: 27442922

Change-Id: I781195e78c480e7449f49467abb1df71902e568d
2016-07-12 14:41:59 -07:00
Doney Alex
6581cbf841 DO NOT MERGE Encoder: Fixed adaptive intra refresh.
Earlier if an MB was coded as intra in the previous frame,
corresponding MB in the current frame will not be coded as intra
even though it was supposed to be intra according to adaptive intra refresh.
Now the MB will honour adaptive intra refresh irrespective of its type
in previous frame.

Change-Id: Icc84ddf962dad6f7d1f4d11e9cb2a37bcda567b8
2016-03-12 00:11:40 +00:00
Doney Alex
4f067b6d46 Encoder: Fixed adaptive intra refresh.
Earlier if an MB was coded as intra in the previous frame,
corresponding MB in the current frame will not be coded as intra
even though it was supposed to be intra according to adaptive intra refresh.
Now the MB will honour adaptive intra refresh irrespective of its type
in previous frame.

Change-Id: Icc84ddf962dad6f7d1f4d11e9cb2a37bcda567b8
2016-02-24 19:30:29 +05:30
Hamsalekha S
4202606c70 Encoder added support for VUI params
SPS will now include vui params
Removed a trailing space in ih264e_api.c

Change-Id: I67a57741689206e571e9a83f7e3360149f87e06a
2015-08-04 11:27:29 +05:30
Harinarayanan K K
8588303afa Added code to handle cases with qp less than 10
When qp goes less than 10, all I16x16 mode evaluations
are disabled and I4x4 evaluations are enabled irrespective
of preset. This will ensure that the residual will not
exceed the supported range of entropy

Minimum Qp cannot be set less than 4 now. When QP goes lesser,
the residual may exceed the supported range even with I4x4 enabled.

Change-Id: I25b404fcd9c9e9dbdd77679280968635ee047eb3
2015-06-24 21:04:58 +00:00
Harinarayanan K K
6cb6772805 Reduced memory requirements.
Buffer allocation is based on minimum level required for the
input resolution rather than the input max level.

Number of maximum context sets can be set to 1 to reduce
memory usage.

Added a macro ENC_MIN_PU_SIZE for minimum size of
inter prediction unit supported by encoder.

Changed the maximum constraint on number of MBs for NMB
processing to width in Mbs.

Change-Id: I5a9255e93935d90c13262681aafc772aedf8ae81
2015-06-24 21:04:04 +00:00
Martin Storsjo
f768297941 Always copy data to a local buffer if padding is needed
If horizontal padding is needed, copy the data to avoid having to try
to write into the input buffer.

If vertical padding is needed, we could get away with only copying
the last MB row (as previously was done), but then one extra row of
pixels are needed for intra pred. Thus always copy all of the picture,
for simplicity, if padding is needed.

Change-Id: I6b456a12956120d64e7c6b86d7b571e159f4566b
2015-06-24 20:54:23 +00:00
Martin Storsjo
90a3904fd3 Set the luma/chroma strides depending on source buffer
If the data is read directly from the input buffer, set the stride
values to those of the input buffer. If the data is copied, set the
stride to the value of the local buffer instead.

This fixes handling of cases where the input buffer stride is
(significantly) larger than the maxwidth of the video.

This also effectively makes the parameter
ive_ctl_set_dimensions_ip_t.u4_strd useless - nothing needs to
know the stride until you actually encode a frame, and at that point,
we can either use the stride of the input buffer, or of the local
pu1_y_csc_buf_base where the copied content is stored.

Change-Id: Icde400b4a0867d25855e621e143454e608748aa3
2015-06-24 20:50:12 +00:00
Martin Storsjo
53c6878c15 Use a separate field for the chroma stride
When both luma and chroma are copied to the local buffer (either
due to yuv format conversion, or due to padding), they have got
the same stride, but if chroma is copied while luma is used directly
from the input buffer, they might have different strides.

Therefore add a separate field for chroma stride.

This commit only adds the field, while it still has got the same
value as before.

Change-Id: I0dce97ad4d91cd1d9aba4b4472c6a0de45a314bc
2015-06-24 20:49:50 +00:00
Harinarayanan K K
134291ea0b Added support for Main Profile toolsets in encoder.
Added support for CABAC entropy coding.
Added support for B slices.
Fixed an issue in rate control constant QP mode.

Change-Id: Ib759d35e8e943f941aa9b8bbff0362d92c619994
2015-06-24 20:36:11 +00:00
Harish Mahendrakar
5cdb888fea Fixed an overread in YUV420 Semi-planar input usecase
Handled non-multiple of 16 dimensions for 420 semiplanar input
Modified test code to remove alignment of width and height

Change-Id: I83ff8165364a863d577fcac81e711b07eec9c004
2015-06-11 10:52:36 +05:30
Martin Storsjo
1bc6742182 Only initialize u4_deblk_prev_row if it will be used
This avoids reads out of bounds when encoding videos with a height
of one single macroblock.

Change-Id: Iec982cebb0995c8ecf160751eaa72df38604e8b0
2015-05-25 20:31:02 +03:00
Lajos Molnar
cd9e51fc2b fix file permissions
Change-Id: Ia4f99d5b963acd8d8a1afc2fbdf06b122d898f63
2015-05-05 17:34:51 +00:00
Harish Mahendrakar
c72323e723 Fixed few issues seen in CTS tests
Added support for encoding non-multiple of 16 dimensions
Added support for encoding dimensions smaller than 64x64
Aligned coeff data to 4 byte boundary

Change-Id: I111093950f94698296d8499a2845cfe2db6c557b
2015-04-28 19:17:04 +05:30
Hamsalekha S
8d3d303c79 Initial version
Change-Id: I7efe9a589cd24edf86e8d086b40c27cbbf8b4017
2015-04-02 15:59:02 +05:30