Commit graph

3889 commits

Author SHA1 Message Date
Harish Mahendrakar
f9f0475b63 Revert "libavcenc: Correct default values in ih264e_defs.h"
This reverts commit 7f0c8a545b.

Reason: This changes behavior w.r.t. frame rates in terms of units.
2023-10-04 23:38:08 +05:30
Ram Mohan
072e69978a avcenc: clean up sample application
This commit does not introduce any new functionality. This is a
cosmetic change. It removes redundant comments, unused variables,
indents to a common guideline.
2023-10-03 14:24:25 -07:00
Ram Mohan M
7f0c8a545b libavcenc: Correct default values in ih264e_defs.h
I and IDR interval default values do not comply with requirements
of the codec. This is fixed. Also corrected few other default values.
2023-10-03 14:24:25 -07:00
Ram Mohan M
0c9dc5e7b2 libavcenc: use signed var for integer operations 2023-10-03 14:17:51 -07:00
Ram Mohan M
e4574d306f libavcenc: increment picture count only on valid inputs
If the encoder receives inputs that are empty or frames
that have to be skipped due to frame rate pull down,
do not increment picture count.

Bug: oss-fuzz-62827
Test: ./avc-enc-fuzzer
2023-10-03 14:17:51 -07:00
Ashwin Natesan
56a598ca6f svcenc: Fixes for incorrect handling of entropy coding errors
There were cases where errors in a process thread
executing the last MB row would result in the entropy
job list without a terminnating entry, which would
result in a call to ih264_list_dequeue blocking infinitely.
The enum 'ISVCE_ENTROPY_THREAD_STATES_T' is now used to
monitor the eecution state of the entropy thread and handle
the situation described appropriately.

Bug = ossfuzz:62786
Test: svc_enc_fuzzer
2023-10-02 07:09:21 -07:00
Ram Mohan M
2e128ba913 libavcenc: Modified conversion tables between Qstep & QP
avc-qp(QP) scale is logarithmic and Qstep scale is linear.
The translation between log to linear is carried during
rate control modelling.

Look up tables for these translations are modified as per
the literature
2023-10-01 01:37:17 +05:30
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
2074f2bfaf avcenc: Modify vui time scale based on target frame rate 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
Ram Mohan
7429c17294 libavcenc: reset mb qp delta ctxt during cabac encoding
When mb qp delta is not signalled due to cbp being zero,
mb qp delta ctxt is not being reset. This is causing bitstream
decode problems when mb qp is enabled
2023-09-29 01:34:57 +05:30
Ram Mohan
d9ef5790ef libavcenc: fix computations that are resulting in overflow
Intermediate precision for few computations are exceeding int max.
This is addressed
2023-09-29 01:34:57 +05:30
Ram Mohan
fef966515c avcenc: Fix Crash for 422 ILE inputs
The input buffers allocated for 422 formats is less by a chroma
plane. This causing memory over writes and results in crash while
freeing
2023-09-28 07:24:09 -07:00
Ram Mohan
f1f3a33bc4 libavcenc: fix the order of arguments passed to get_min_level 2023-09-28 07:24:09 -07:00
Ram Mohan
eb20999248 libavcenc: Cleanup air Mode and refresh period config options
Allow any refresh period if air mode is selected as none
2023-09-28 07:24:09 -07:00
Hamsalekha S
78dddbc900 libavcenc: Added more validity checks for IDR_interval and I_interval
When the i frame interval is larger than idr frame interval, bitrate
deviations are seen in bitstream.

Forced idr_interval to be a multiple of I frame interval.
2023-09-28 07:24:09 -07:00
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
Harish Mahendrakar
4ea89ecf7b Encoder test updates
- Rename AvcEncoderTest as AvcEncTest
- Enable AvcEncTest in cmake builds
- Rename AvcEncoderTestEnvironment.h as TestArgs.h

Change-Id: Iceba9c33e060bcb1138f03833da67c0ff6e84b2b
2023-09-28 10:22:54 +05:30
Aayush Soni
9cb4ae646c MediaTesting: Add AVC Encoder Test
Bug: 189191435

Test: atest AvcEncoderTest -- --enable-module-dynamic-download=true

Change-Id: I000c8076a219db1bfab9683cf8385a5084f9bccc
2023-09-28 10:22:54 +05:30
Harish Mahendrakar
47dfd4ca64 Rename test as examples
Also rename test/decoder as test/avcdec and test/encoder as test/avcenc

Change-Id: Ia21513d91206d806a2aa2177012765c54287bc77
2023-09-28 10:22:54 +05:30
Ram Mohan M
7c59eeb920 libavcenc: model CBR-NLDRC as CBR mode with out frame drops
In frame drop mode, the stream generated is non-compliant.
For now disable frame drop mode.

Bug: oss-fuzz-61202
Bug: oss-fuzz-59598
Test: ./avc_enc_fuzzer

Change-Id: Ifed950082ae2c6e70d6a7da4547b6ffeb44cf759
2023-09-27 13:57:19 -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
2ff6f15376 libavcenc: return partially encoded buffer for application
As bitstream overflow errors are not marked as fatal errors and
these recons are being used for reference, its best to return
the partial encoded buffers for application

Change-Id: I30a8e9907cf42d3bc883ee78b28cbae723bad7ac
2023-09-27 13:57:19 -07:00
Ram Mohan
29f519228a libavcenc: update bitstream context state only in successful writes
During entropy error, even though the bitstream buffer is not written
with additional bytes, the bitstream context state is getting updated.
As the number of bits left in current word is updated, the get_num_bits
used for computing header and texture bits can become negative causing
overflow errors

Change-Id: I2f990071a9935b2ee328dbd3915dfbefccbab4c5
2023-09-27 13:57:19 -07:00
srujan vandrangi
f27694faed decoder: join threads in flush mode
Test: avcdec
2023-09-25 08:47:41 -07:00
Ram Mohan M
bbcac434f2 libavc: tidy up android bp - 2
sort listings in alphabetical order

Test: Build
2023-09-20 06:19:47 -07:00
Ram Mohan
240680473f libavc: tidy up android bp
sort listings in alphabetical order

Test: Build
2023-09-20 14:38:12 +05:30
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
Harish Mahendrakar
a75597f240 OWNERS: Include avic_OWNERS
Bug: 295554840
Test: Treehugger

Change-Id: I52eab6f208bb4e88f8ee5e9a94fb0592f187a011
2023-08-11 15:54:38 -07:00
wujianxing1
283f9fcecb Correct comment spelling error.
Change-Id: Idd5e2c12da2b23f598c301bf6fb6a963c4420ae2
Signed-off-by: wujianxing1 <wujianxing1@xiaomi.corp-partner.google.com>
2023-08-11 15:54:38 -07:00
Harish Mahendrakar
9030e26c46 ossfuzz.sh: enable null sanitizer 2023-08-01 23:02:16 -07:00
Srujan Vandrangi
40a2df3244 decoder: limit number of calls to decode header
Test: avc_dec_fuzzer
2023-07-31 11:41:35 -07:00
Srujan Vandrangi
2e8e8e7d13 decoder: add "summary" before codec exit with error message
Test: avcdec

Change-Id: Ifee9140f0042f77304a1a662127bc049237987e5
2023-07-31 10:32:26 -07:00
Srujan Vandrangi
07452e198b decoder: set keep_threads_active to 1 in the testbench and fuzzer
Bug: 289097296
Test: Build
2023-07-29 16:38:34 -07:00
Ashwin Natesan
468e048959 mvcdec: Fixes for OOB accesses of refPicList
[x] For certain sequences of modification_of_pic_nums_idc,
    OOB accessses of the aps_mod_dpb buffer within mvc_dpb_manager_t
    struct could occur. This case has been now detected
    and handled.
[x] Removed unused variables in 'imvcd_slice_functions.c'.

Test: mvc_dec_fuzzer
2023-07-26 07:34:30 -07:00
Ashwin Natesan
c759935aad svcenc: Handling frames with few MB's in In-frame RC
A 'consumption ratio' is computed fr every MB when
in-frame RC is enabled. This computation can result in
divide-by-zeros in certain circumstances. Such cases
are now appropriately handled.

Bug: ossFuzz:60828
Test: svc_enc_fuzzer
2023-07-25 08:06:32 -07:00
Srujan Vandrangi
5b04d419d2 decoder: join threads in reset()
Test: Build
2023-07-24 09:37:28 -07:00
Srujan Vandrangi
72e8241a64 decoder: replace KEEP_THREADS_ACTIVE macro with avc decoder struct variable
Bug: 289097296
Test: Build
2023-07-22 09:51:37 -07:00
Srujan Vandrangi
6685e380b5 decoder: handle error returned by ih264d_decode_gaps_in_frame_num
Bug: oss-fuzz:55598, oss-fuzz:57605, oss-fuzz:55641
Test: avc_dec_fuzzer
2023-06-21 06:51:49 -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
Mallikarjun Kamble
84f955dd77 svcdec: Fix for out of range reference index during base mode flag
Bug: 58278
Test: svc_dec_fuzzer
2023-04-27 07:47:13 -07:00
Ashwin Natesan
f8ae418b38 mvcdec: Bitstream buf allocation accounts for FGC SEI
The worst case FGC SEI payload size in cojunction with the worst
case sizes of other NALU's can be significantly larger than the
default bitstream buffer size of 256000. It is now set to the sum
of 256000 and MAX_FGC_SEI_SIZE.

Bug: ossFuzz:58190
Test: mvc_dec_fuzzer
2023-04-20 15:35:41 -07:00
Srujan Vandrangi
7acfe28555 encoder: Add checks for ME search algorithm
Bug: oss-fuzz:57331
Test: avc_enc_fuzzer
2023-04-04 22:33:36 -07:00
Harish Mahendrakar
ba34616a11 encoder: Initialize s_inp_buf and s_out_buf to zero in ih264e_encode
In some cases, s_inp_buf and s_out_buf on stack in ih264e_encode()
can be accessed unininitialized. This is fixed by initializing these
two structures.

Bug: oss-fuzz:57333
Bug: 274906999
Test: avc_enc_fuzzer
2023-04-04 21:48:18 +05:30
Harish Mahendrakar
9783b509ac ossfuzz.sh: Enable mvc_dec_fuzzer 2023-03-23 13:23:10 -07:00
Mallikarjun Kamble
5a7d4325be svcdec: Fix for out of bound index in ii_pred
Bug: 274306469
Test: svc_dec_fuzzer
2023-03-23 12:10:07 -07:00
Harish Mahendrakar
33312473dc ossfuzz.sh: Enable avc_enc_fuzzer 2023-03-21 17:43:13 -07:00
Harish Mahendrakar
ad23214a83 ossfuzz: opt out of null and shift sanitizers 2023-03-21 12:01:30 -07:00