Commit graph

218 commits

Author SHA1 Message Date
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
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
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
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
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
Ashwin Natesan
5beaa86db4 svcenc: nullSan errors in ILPMv fixed
The ILP MV struct pointer will be set to NULL for I slices and
for spatial layer ID 0. A NULL check ought to be used in all places
that access this pointer. This was missing in 2 places and has been
added.

Test: svc_enc_fuzzer
2023-03-21 10:17:44 -07:00
Ashwin Natesan
c5f3b0c976 svcenc: RC bitrate overflows prevented
RC uses int32_t for storing multiple quantities related to
bits in a given period.
'isvce_svc_frame_params_validate' has been added, which queries
RC API for the relevant quantities and returns with and error
if computations involving those quantities exceed INT32_MAX.

Bug: 274221347
Bug: 274265498
Test: svc_enc_fuzzer
2023-03-19 23:02:06 -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
Ashwin Natesan
ab835f3240 svcenc: fixed incorrect EPB checks
If 'u4_strm_buf_offset < 4' when 'isvce_cabac_flush' is called,
then EPB could not have been inserted into the stream buffer.

BUG = ossfuzz:56816
Test: svc_enc_fuzzer
2023-03-09 06:51:21 -08:00
Harish Mahendrakar
7164209291 Updates to Android.bp and some formatting fixes
- Only libavcdec is marked as available to apex modules instead
  of marking all decoder libraries to be available to apex modules.
- some formatting changes for consistency with neighboring lines.

Test: Builds
2023-03-08 20:27:18 -08:00
Ashwin Natesan
ed00dfc325 svcenc: fixed a bug in low bitrate encodes
Certain ILP buffers are reset when encoded bitrate exceeds
configured bitrate. The size used for one of them was incorrect.
2023-02-20 08:03:08 -08:00
Ashwin Natesan
c38af025ab svcenc: fixed incorrect streamBuf accesses
If 'u4_strm_buf_offset == 0' when 'isvce_cabac_flush' is called,
then 'carry' is implicitly 0.

'u4_strm_buf_offset == 0' implies stream buffer is empty.

Invocation of 'isvce_cabac_flush' implies all MB's in a slice
have been encoded.

BUG = ossfuzz:56137
Test: svc_enc_fuzzer
2023-02-20 08:02:26 -08:00
Mallikarjun Kamble
7f19ac2206 Remove printf's from sei
These printf's were inserted for debugging
2023-02-14 22:00:13 -08: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
Ashwin Natesan
47125f49a4 svcenc: increased minimum outbuf size
For certain configurations of the fuzzer input, the minimum
output buffer size is insufficient.
The minimum value has been doubled in this commit.

BUG=oss-fuzz:55797
Test: svc_enc_fuzzer
2023-02-13 10:06:08 -08:00
Ashwin Natesan
43629a63d8 svcenc: fixed riscv4 soong build errors
riscv4 soong builds were failing due to incorrect usage of
'ARM' macro. This was fixed.
2023-02-07 07:09:18 -08:00
Ashwin Natesan
d6441bc469 Fixed OOB access of residue buf attributes in some cases
Fixed incorrect access of residue buf attributes when
'isvce_rc_post_enc' returns 'u1_is_post_enc_skip=1'.
Also, fixed incorrect memory initialisations for bitstream_t.

BUG=oss-fuzz:55640
Test: svc_enc_fuzzer
2023-02-05 08:57:41 -08:00
Ashwin Natesan
f89d401064 Fixed incorrect outbuf size assignment in 'isvce_get_buf_info'
BUG=oss-fuzz:55639
BUG=oss-fuzz:55643
Test: svc_enc_fuzzer
2023-02-05 08:52:38 -08:00
Ashwin Natesan
bb0f31cb6b Encoder: SVC encoding support added
Added support for encoding 'Scalable Baseline' profile, corresponding to
profile_idc of 83 in 'Rec. ITU-T H.264 (11/2007)'.

Bug: 248891908
Test: svcenc -c enc.cfg
Change-Id: Ib12ca4c4a8c0e674738ae2af01558a08cefe0929
2023-01-30 11:07:10 -08:00
Harish Mahendrakar
6334fd9a1c Remove mips specific files
Test: Builds
Bug: 261484694

Change-Id: Ied9694ee9f7245e2db37ff42b7fb98cb58397af9
2022-12-06 02:52:33 +05:30
Mao Han
e8b0093646 Add riscv64 support
Use generic function pointers on riscv.

Test: built for aosp_riscv64
Signed-off-by: Mao Han <han_mao@linux.alibaba.com>
Change-Id: I424d15396d7e9711d23a6118f92aee0fc7924c28
2022-12-01 22:27:12 +00:00
Ray Essick
a0660f6242 Merge "avcenc: Fix recon dump for last frame" 2022-08-24 16:04:57 +00:00
Harish Mahendrakar
ba6f646849 avcenc: Fix recon dump for last frame
Last recon frame wasn't being saved in some cases, it is now fixed.

Bug: 242104774
Test: avcenc -c enc.cfg

Change-Id: I50fcd6709988b7126a36cc88d8abdb75e871a37a
2022-08-17 22:41:33 +00: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
Harish Mahendrakar
afd2eeb402 encoder: Update dimension check for semi-planar input
For YUV 420 semi-planar input, second plane's width was
wrongly being checked to be equal to half of first plane's width.
Corrected this condition now to check that both these widths are
same.

Bug: 242103647
Test: avcenc -c enc.cfg

Change-Id: I3c06f6e40823ddbf00df0435bfbd1cd314c982e3
2022-08-10 22:47:10 +00:00
Ray Essick
c4f2671a16 Merge "Set correct defaults for video signal flags in VUI" 2022-07-28 22:05:03 +00:00
Ray Essick
0948bc7fe3 Merge "Fix setting IVE_CMD_CTL_SET_VUI_PARAMS with IVE_ENC_MODE_HEADER mode" 2022-07-28 21:12:06 +00:00
Martin Storsjo
8362f0939b Set correct defaults for video signal flags in VUI
When u1_video_signal_type_present_flag and
u1_colour_description_present_flag were set, we did write all
fields relating to video signal and color description into
the VUI, even if all those fields were uninitialized (left
at the default cleared zero, which for most fields are
invalid/reserved value zero).

Instead have these flags default to zero, making it clear
that the VUI doesn't (yet) contain correctly set values
for those fields.

Bug: 240470605
Change-Id: I86628cff190c8a40e9c6fd12d3fc8e06419ece7c
2022-07-28 00:31:09 +03:00
Martin Storsjo
a3eaf9ccfc Fix setting IVE_CMD_CTL_SET_VUI_PARAMS with IVE_ENC_MODE_HEADER mode
The ih264e_vui_ip_t struct doesn't contain any input timestamps,
and the IVE_CMD_CTL_SET_VUI_PARAMS command didn't set these fields
at all (leaving them at their default initialized state 0,0).

At the start of ih264e_encode, pending configurations are
applied if their timestamp matches the timestamp of the frame
to be encoded, or applied unconditionally if the timestamps are
equal to -1.

Thus, the parameters set with IVE_CMD_CTL_SET_VUI_PARAMS
previously only got applied if encoding a frame with the specific
timestamp 0, but now they get applied unconditionally on the
next encoded frame.

Bug: 240466320
Change-Id: I12c50251d8485e3f171ac5c87132ddfbc80377d6
2022-07-27 23:57:57 +03:00
Rakesh Kumar
672f2bfab3 Encoder: Rename INSERT_EPB
INSERT_EPB doesn't insert emulation prevention byte and instead
is used to check if an emulation prevention byte is to be inserted.
Renaming INSERT_EPB to SHOULD_INSERT_EPB.

Bug: 180962392
Test: build library

Change-Id: I9ac8d8ca6b2d29d5bccab68404f02883acf5d361
2022-02-28 04:57:49 +00:00
Ashwin Natesan
ca68f61641 Builds: Modular cmake scripts added
Cmake scripts are now modular. Separate scripts now handle
build specifications for each target and dependency.

Toolchain files have been added for armv7, armv8 builds.

Bug: 213579857
Test: Builds using cmake
Test: Builds in OSS-fuzz

Change-Id: Iac62b443c0a0de09a2ce6553a660db2c3d5dc846
2022-02-02 11:14:55 +05:30
Manisha Jajoo
2f3d043b17 Encoder: Fix memory uninitialized issue in the encoder
Test: atest android.mediav2.cts.CodecEncoderTest
Test: atest VtsHalMediaC2V1_0TargetVideoEncTest
Bug: 193442575

Change-Id: I75475d3bb822fa0e0493ecc2d67c7da26a907d19
(cherry picked from commit c9d7c5cda4)
2021-09-20 18:45:52 +00:00
Ray Essick
e84ea05642 Merge "encoder: Use intermediate buffer for accessing last MB row" into sc-dev 2021-05-01 18:31:15 +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
954f023c74 encoder: fix invalid free of raw buffers
Return current input buffer as buffer to be freed in case
of errors that are seen before picking up the input buffer
to be from the input queue.
Once a buffer is picked up from the queue, that is returned
as the buffer to be freed.

There is no need to return a buffer from ps_proc context

Bug: 180643802

Test: poc in the bug description
Test: atest CtsMediaV2TestCases:CodecEncoderTest
Test: atest VtsHalMediaC2V1_0TargetVideoEncTest

Change-Id: I1671ca1e82f522004d1f070df89b256b856f75b8
2021-04-30 14:49:41 -07:00
Aayush Soni
29b671c12b encoder: fix null buffer dereferencing am: 3139d13ccd am: 3a4aac7376
Original change: 1663964

Change-Id: I61881dbaabbc24871883557486d0b8c1d8b3ce1a
2021-04-16 18:25:06 +00:00
Aayush Soni
3139d13ccd encoder: fix null buffer dereferencing
Do not set the picture type as NA for the last frame in encoding
order.

Bug: 180219345

Test: POC in bug descriptions
Test: atest CtsMediaV2TestCases:CodecEncoderTest
Test: atest VtsHalMediaC2V1_0TargetVideoEncTest

Change-Id: I57ee7db9e2e55fba2666a6aaa4002ef31276e4b9
2021-04-15 11:49:29 +05:30
Neelkamal Semwal
8bbc8ab63a avcenc: Add bitstream overflow check during emulation prevention am: 10910bf910 am: 51373e847b am: 08e74b410b am: 4e4dc6be01 am: 2c9758d16a am: 66997f22b0
Original change: 13932334

Change-Id: Ifa8df9d2a76df40d313d0d1e35b09cb55ffc1d17
2021-03-31 20:10:03 +00:00
Neelkamal Semwal
66997f22b0 avcenc: Add bitstream overflow check during emulation prevention am: 10910bf910 am: 51373e847b am: 08e74b410b am: 4e4dc6be01 am: 2c9758d16a
Original change: 13932334

Change-Id: Ib9e3a137286a16ebbcd5a38c3a38c0707ada405c
2021-03-31 19:29:59 +00:00
Neelkamal Semwal
2c9758d16a avcenc: Add bitstream overflow check during emulation prevention am: 10910bf910 am: 51373e847b am: 08e74b410b am: 4e4dc6be01
Original change: 13932334

Change-Id: I5c98ae2cae9b4e1d5577f961247ba1fc06f97b58
2021-03-31 19:08:46 +00:00
Neelkamal Semwal
08e74b410b avcenc: Add bitstream overflow check during emulation prevention am: 10910bf910 am: 51373e847b
Original change: 13932334

Change-Id: I5e70babd452137048665c8181eb7aaa59a9229e3
2021-03-31 17:59:49 +00:00
Harish Mahendrakar
1959bc1e12 Validate input dimensions in process() am: a073696092
Original change: 13991496

Change-Id: I4d391ec76874eb579a439376b1ae972fdb690ffc
2021-03-31 17:55:18 +00:00
Neelkamal Semwal
51373e847b avcenc: Add bitstream overflow check during emulation prevention am: 10910bf910
Original change: 13932334

Change-Id: I53fa66c08c448484d5c0b5457a6e6a726d453095
2021-03-31 17:08:38 +00:00
Harish Mahendrakar
a073696092 Validate input dimensions in process()
Input dimensions are checked for supported range in set_dimensions
control call. Encoder returns an error for unsupported values in
this control call. But if the caller ignores this error and proceeds
to call process(), encoder wasn't checking the dimensions again.

Unsupported dimensions are now checked in process() call as well.

Note: This is relanding previously reverted commit
06c30b33c4

Bug: 172908358
Test: Poc in bug
Test: atest android.mediav2.cts
Test: atest android.media.cts
Change-Id: Icf3f296ab24432c680427a82da3505491acca3bd
2021-03-25 03:04:25 +00:00
Neelkamal Semwal
10910bf910 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-20 15:36:08 +00:00
Harish Mahendrakar
cd1928dca1 Encoder: Fix in returning recon buffers with smaller IDR interval
For every IDR generated after the first one, one recon buffer was not
released from the buffer manager, when recon was enabled. This resulted
in encoder returning with an error after couple of IDRs when recon was
enabled.

This is fixed by calling recon buffer release based on pic_cnt instead
of frm_num. frm_num is reset to 0 for every IDR where as pic_cnt is not.

Bug: 173150684
Test: avcenc -i qcif.yuv -w 176 -h 144 -o out.h264 \
      --bframes 2 --idr_interval 4 --recon_enable 1 \
      --recon recon.yuv

Change-Id: I8b72e5aedc6a460292388e4e46f56c07486db4a6
2020-11-12 23:49:41 +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