Commit graph

2233 commits

Author SHA1 Message Date
Miika Metsoila e8e0e7596a Add a step-cutoff parameter for motion estimation search 2017-12-22 14:04:25 +02:00
Miika Metsoila 4e13608b01 Merge branch 'diamond_search' 2017-12-18 14:11:53 +02:00
Miika Metsoila 2cde0d1a18 Document diamond search option 2017-12-12 14:45:01 +02:00
Miika Metsoila b923b63b42 Add diamond search 2017-12-12 14:40:14 +02:00
Ari Lemmetti 14892fda00 Replace simple coefficient cost estimation with CABAC. Substantial improvement.
Approximation proved to be too inaccurate while not giving actually that much speedup.
2017-12-10 01:23:48 +02:00
Miika Metsoila ea79069dc8 Fix a type warning in encmain.c 2017-12-08 16:22:40 +02:00
Miika Metsoila 6aa4cd7528 Fix type warnings 2017-12-08 16:16:36 +02:00
Miika Metsoila b3486b5114 Fix gcc/clang warnings and errors in cfg.c 2017-12-08 16:09:00 +02:00
Miika Metsoila bac07457ea Merge branch 'hevc_level' 2017-12-08 15:57:38 +02:00
Miika Metsoila c67a24e6ec Update readme and --help text 2017-12-07 12:32:46 +02:00
Ari Lemmetti 713e694d82 Define HAVE_STRUCT_TIMESPEC on Visual Studio 2015 and later
Fixes redefinition of timespec that Pthreads-Win32 does even if it has been already defined.
2017-12-05 18:26:12 +02:00
Miika Metsoila f64d42169f Improve bitrate checking to accommodate non-integer and less than 1 framerates 2017-12-01 17:20:12 +02:00
Miika Metsoila 57cf92d35f Implement level's bitrate limit checking during encoding 2017-11-28 16:19:44 +02:00
Miika Metsoila 021fb27787 Add high-tier flag 2017-11-20 16:05:28 +02:00
Miika Metsoila d249059d61 Minor refactoring of level checking 2017-11-20 13:25:26 +02:00
Arttu Ylä-Outinen cf85d52b9d Kvazaar version 1.2.0 2017-11-17 15:23:33 +02:00
Miika Metsoila 4c1512e8c5 Add a check for maximum picture width and height for the given level 2017-11-15 16:39:59 +02:00
Arttu Ylä-Outinen 4cb054295a Fix linkers
Overrides the linkers used for kvazaar, libkvazaar.la and kvazaar_tests.
When crypto++ is enabled, the C++ linker is used and when it is
disabled, the C linker is used.

This removes the need to explicitly specify -lstdc++ in configure when
crypto++ is used and fixes the build with crypto++ when libstd++ is not
installed.
2017-11-13 15:09:38 +02:00
Miika Metsoila f9a4aba867 Update documentation, fix input fps default value, remove 0 as default level 2017-11-09 16:53:31 +02:00
Miika Metsoila ebba0a4f01 Test if input conforms to it's level's limits (excluding bitrate) 2017-11-08 16:15:41 +02:00
Miika Metsoila fb4d0c3cf2 Move level argument parsing to the correct place and give it initial values 2017-11-03 15:47:35 +02:00
Miika Metsoila 61a31054e1 Add level command-line parameter 2017-11-03 13:04:05 +02:00
Arttu Ylä-Outinen 9974380cdd Fix bipred and temporal MVP
- Fixes two errors in calculating the POC for the reference frame for
  temporal candidate MV scaling.
- Fixes using the MV for the wrong direction when the temporal MV
  predictor block uses bi-prediction.

Fixes #160.
2017-10-25 12:26:41 +03:00
Arttu Ylä-Outinen 841597e123 Fix picture and slice types
Changes handling of intra pictures for --gop=8 so that every picture
with POC divisible by the intra period is intra. The first picture is
IDR and the rest of the intra pictures are CRA. POC is not reset at CRA
pictures. The leading pictures that follow the CRA picture are changed
to RASL so they are allowed to refer to pictures before the CRA picture.

Changes inter slice types to P when the L1 reference list is empty and
to B otherwise.

In all-intra, all pictures are now IDR pictures with POC zero.
2017-10-20 13:35:26 +03:00
Jaakko Laitinen 957b6850c3 Change ref list printout to match hm decoded printout 2017-09-25 13:48:56 +03:00
Arttu Ylä-Outinen 20aea8df63 Fix POCs when using --gop=8
When using --gop=8 with an intra period greater than one, a single POC
would be skipped before every intra frame. This commit fixes the problem
by turning the intra frames into BLA frames with leading pictures when
using --gop=8.
2017-09-19 09:31:58 +03:00
Miika Metsoila 6e00f63469 Remove unused variables from search_pu_inter_ref function 2017-09-18 15:36:37 +03:00
Miika Metsoila 7b0101ce3d Merge branch 'reflist_changes'
# Conflicts:
#	src/encoderstate.c
#	src/search_inter.c
2017-09-18 14:59:37 +03:00
Miika Metsoila 769b17768d Change max function to MAX macro for clang/gcc compatibility.
Remove couple of unnecessary comments
2017-09-15 14:21:51 +03:00
Miika Metsoila 5f7c5443a3 Remove inter.poc 2017-09-12 14:23:19 +03:00
Miika Metsoila 6bd78a3da7 Reverse L0 list sort direction 2017-09-12 14:23:18 +03:00
Miika Metsoila 83dc7e7f50 Made L0 to sort and fixed mv_ref_coded in search_pu_inter 2017-09-12 14:23:18 +03:00
Timothe FRIGNAC d3362a238e changed strtod to strtol 2017-08-31 15:14:31 +02:00
Timothe FRIGNAC 3a1ab54ff0 Fixed memory leaks 2017-08-31 11:51:41 +02:00
Timothe FRIGNAC 466297fd77 Fixed build error 2017-08-29 17:01:18 +02:00
Timothe FRIGNAC 2e130912cb Add --key opt 2017-08-28 17:15:13 +02:00
Miika Metsoila a5f4cf09b5 Switched from storing POCs in inter.poc to state->frame->refLXs array 2017-08-21 16:34:57 +03:00
Arttu Ylä-Outinen 409d2114f0 Fix motion vector constraints
Fixes integer motion vectors being constrained more than what was
necessary when using --mv-constraint or --wpp.
2017-08-11 14:41:36 +03:00
Arttu Ylä-Outinen 7144a00beb Rewrite thread queue
Changes thread queue so that only the jobs that are ready to run are
stored in the queue. Other jobs are kept track of by pointers in the
reverse dependency lists of other jobs. When a job is ready to run it is
appended to the queue. The job queue is stored as a linked list.

The definitions of threadqueue_queue_t and threadqueue_job_t are moved
to the .c file, turning them into opaque structs.

Makes thread queue code simpler. Fixes some TSan errors.
2017-08-11 14:18:12 +03:00
Arttu Ylä-Outinen bc47fe94af Drop thread queue debug code 2017-08-11 14:18:12 +03:00
Eemeli Kallio e5cbc7a205 --sao now enables full sao 2017-08-11 13:26:55 +03:00
Eemeli Kallio 4c3453d26f Fixed issue with no-sao argument 2017-08-11 13:12:22 +03:00
Eemeli Kallio 8674c0f5ee Added paremeter for band and edge sao. 2017-08-11 11:57:09 +03:00
Eemeli Kallio d9b93ea368 Added possibility to skip edge or band sao. 2017-08-11 11:51:49 +03:00
Arttu Ylä-Outinen 4b73bdd9aa Skip checked motion vectors in early termination
Changes the second iteration of early termination to skip the motion
vectors that were already checked in the first iteration.
2017-08-09 14:29:09 +03:00
Arttu Ylä-Outinen 606d441362 Skip computing MV cost twice in hexagon search
Changes the first step of hexagon search to skip the zero offset since
the cost of the motion vector has already been computed.
2017-08-09 14:29:09 +03:00
Arttu Ylä-Outinen fa4648061d Add mv, cost and bitcost to inter_search_info_t 2017-08-09 14:29:08 +03:00
Arttu Ylä-Outinen 328f051d7f Put inter search parameters in a single struct
Adds struct inter_search_info_t for holding the parameters that are used
by most function related to inter search. Passing the parameters in
a single struct greatly reduces the number of parameters for many
functions.
2017-08-09 14:27:53 +03:00
Miika Metsoila 0dd069f8af Fixed using wrong POC in add_temporal_candidate 2017-08-09 13:50:21 +03:00
Miika Metsoila 25e0a954c7 Fixed 2 bugs causing incorrect video output 2017-08-09 13:50:21 +03:00
Arttu Ylä-Outinen 24ecddd2a5 Fix wrong strides in SAO reconstruction
Functions kvz_sao_reconstruct and encoder_sao_reconstruct used
frame->width as the stride instead of frame->rec->stride when accessing
frame->rec->data. This caused errors when using tiles and SAO.
2017-08-01 15:40:49 +03:00
Arttu Ylä-Outinen f0bf959d17 Fix alignment errors in 32-bit build with MSVC
Changes the work_tree parameter in search.c functions from an array to
a pointer. Fixes "formal parameter with requested alignment of 8 won't
be aligned" errors.
2017-07-28 09:27:02 +03:00
Arttu Ylä-Outinen 9694bd2fae Fix build on 32-bit systems
Function coeff_abs_sum_avx2 that was added in e950c9b was outside the
AVX2 #if directive.
2017-07-28 09:19:29 +03:00
Arttu Ylä-Outinen ecb0275cdd Store CU arrays as pointers to the main array
Changes field state->tile->frame->cu_array->data to point to the CU
array in the main encoder state. Removes the need to copy the CU array
to the main CU array after search.
2017-07-28 08:36:45 +03:00
Arttu Ylä-Outinen e950c9b101 Add AVX2 implementation for coefficient sum 2017-07-28 07:39:36 +03:00
Arttu Ylä-Outinen d50ae6990c Add sum of absolute coefficients to strategies 2017-07-28 07:39:15 +03:00
Arttu Ylä-Outinen 59faca0646 Skip CABAC coefficient cost for --rd=0 2017-07-28 07:33:03 +03:00
Arttu Ylä-Outinen 19e051ea40 Reduce intra threshold
Reduces intra threshold for --rd=0 from 20 to 8. Threshold of 20
increased BD-Rate too much.
2017-07-25 13:26:38 +03:00
Arttu Ylä-Outinen e9cf15465e Fix inter cost in bipred
The cost of coding MV ref indices and MV direction was added to bitcost
but not inter cost. Fixed by adding the extra bits to inter as well.
2017-07-24 15:24:04 +03:00
Arttu Ylä-Outinen edbe00763e Drop extra parameter in kvz_image_calc_sad
Drops the parameter max_lcu_below which was always set to -1.
2017-07-24 15:21:19 +03:00
Arttu Ylä-Outinen ffac29061f Fix extrapolated inter SATD 2017-07-24 15:11:05 +03:00
Arttu Ylä-Outinen 631ef53d2a Fix inter cost calculations
Inter costs are computed using SAD except when fractional motion
estimation or bi-prediction is enabled. This commit changes
search_pu_inter_ref to recalculate the cost with SATD. Fixes inter/intra
cost comparisons since intra costs are always SATD costs.
2017-07-24 15:11:05 +03:00
Arttu Ylä-Outinen 6ce2fb1238 Add pixel offsets to encoder_state_config_tile_t
Adds fields offset_x and offset_y to encoder_state_config_tile_t.
2017-07-24 15:11:05 +03:00
Arttu Ylä-Outinen 2380ba0d41 Reduce copying in kvz_get_coeff_cost
Changes function kvz_get_coeff_cost to only copy the CABAC contexts and
not the whole encoder state.

Other threads could be simultaneously using the other parts of the
encoder state. Only copying the CABAC fixes a TSan data race warning.
2017-07-24 12:38:41 +03:00
Arttu Ylä-Outinen 24b462f801 Align coefficients to 8 bytes
Adds alignment attribute to lcu_coeff_t. The coefficients are sometimes
handled as 64-bit integers containing four coefficients so the arrays
should be aligned to 8 bytes.

Fixes a UBSan error about misaligned reads.
2017-07-24 12:37:37 +03:00
Arttu Ylä-Outinen 5ddb43c6fe Fix undefined left shifts in rdo
Replaces left shifts by multiplications when the operand may be
a negative value. Left shift of a negative value is undefined behavior.
2017-07-24 12:35:10 +03:00
Arttu Ylä-Outinen d1e64ad62b Fix undefined left shifts
Replaces left shifts by multiplications when the operand may be
a negative value. Left shift of a negative value is undefined behavior.
2017-07-20 11:15:30 +03:00
Arttu Ylä-Outinen 07b5fb9caf Fix out-of-bounds read in encoderstate
When calling encoder_state_encode_leaf with POC 0, index -1 of the GOP
array would be accessed. Fixed by skipping the code for I-frames.
2017-07-20 11:15:30 +03:00
Arttu Ylä-Outinen 8c4a3473a8 Change --owf=auto and --threads=auto selection
Changes OWF selection so that it is chosen based on the maximum number
of parallel CTUs. Number of threads is limited to prevent overhead from
extra threads.
2017-07-20 09:42:28 +03:00
Arttu Ylä-Outinen 4fc9b743c1 Drop an unnecessary pthread_cond_broadcast
Drop pthread_cond_broadcast on threadqueue->cond in function
kvz_threadqueue_waitfor. The broadcast caused threads to be woken up
more often than necessary.
2017-07-19 11:09:30 +03:00
Arttu Ylä-Outinen 14003c6a30 Disable printing PSNR with --no-psnr 2017-07-19 10:38:37 +03:00
Arttu Ylä-Outinen e90bde5c62 Clarify PSNR output
Adds letters Y, U and V to the PSNR output to make it clearer that the
printed values are the luma and chroma PSNR.
2017-07-19 10:33:43 +03:00
Arttu Ylä-Outinen fdb3480b54 Enable strategies for SAO reconstruction
Re-enables strategies for SAO reconstruction. They were disabled in
commit ec9ff42.
2017-07-11 10:35:18 +03:00
Arttu Ylä-Outinen 333dba3884 Add static to SAO strategies 2017-07-11 10:02:01 +03:00
Miika Metsoila e8cc2d8f6a Small fixes 2017-07-07 13:58:19 +03:00
Arttu Ylä-Outinen 67a60a35e3 Fix invalid calls to normalize_lcu_weights
Changes encoder_state_init_new_frame to only call normalize_lcu_weights
when the weights have been written to the array and rate control is
enabled. When rate control is disabled, the weights are not used.
2017-07-07 11:05:31 +03:00
Arttu Ylä-Outinen 563bc26e71 Fix out-of-bounds read in AVX2 SAO
AVX2 version of SAO loaded offsets with a 256 bit read even though there
are only five 32 bit integers.
2017-07-06 13:04:52 +03:00
Arttu Ylä-Outinen 0850b17f96 Drop get_wpp_limit in search_inter
WPP limit for motion vectors is now computed inside fracmv_within_tile.
2017-07-05 13:22:53 +03:00
Arttu Ylä-Outinen 2a85f0f5a4 Move hard-coded MV limits to encoder_control_t
Adds field max_inter_ref_lcu to encoder_control_t. It is used to set up
inter-LCU dependencies in encoder_state_encode_leaf and restrict motion
vectors in fracmv_within_tile.
2017-07-05 13:22:53 +03:00
Arttu Ylä-Outinen bb5354f7e2 Relax inter-CTU dependencies when SAO is off
When using WPP and OWF, the first CTU of a row depends on the last CTU
of the row below in the reference frame. This is necessary when SAO is
enabled since we currently do SAO for a whole CTU row at a time. When
SAO is disabled, however, it is unnecessary to wait for the whole row.

Changes CTUs to depend only on the CTU below in the reference frame
instead of the whole row when WPP and OWF are enabled and SAO disabled.
Gives a significant speedup when running on a machine with many CPU
cores.
2017-07-05 13:21:06 +03:00
Arttu Ylä-Outinen 1efa2708b2 Do SAO reconstruction for a single CTU at a time
Moves SAO reconstruction into encoder_state_worker_encode_lcu instead of
doing it in a separate step for the whole CTU row. Reconstruction of the
rightmost 10 pixels and bottommost 10 pixels of a CTU is delayed until
the neighboring CTU has been deblocked.

Doing SAO for the whole CTU row at a time caused unnecessary inter-CTU
dependencies when using WPP and OWF. The first CTU of a row would need
to wait until SAO was done for the row below in the previous frame.
Moving SAO reconstruction to immediately after deblocking each CTU fixes
this problem.
2017-07-04 15:14:31 +03:00
Arttu Ylä-Outinen ec9ff42077 Rewrite SAO recon to handle arbitrary sized blocks
Adds width and height parameters to function kvz_sao_reconstruct and
changes it to take coordinates in units of pixels. This will be useful
for doing SAO for areas smaller than a whole CTU.
2017-06-30 16:09:18 +03:00
Miika Metsoila dcd7acf4fd Fixed crash and incorrect info output 2017-06-27 16:05:15 +03:00
Miika Metsoila f8b6234fdb Changes to refence lists to behave more like L0/L1 lists from the specification 2017-06-27 16:05:15 +03:00
Arttu Ylä-Outinen 2c66e0bbd2 Fix warnings about invalid reads in AVX2 ipol
AVX2 filter functions read pixels in chunks of 8 or 16 bytes. At the end
of the block, the read goes out of the bounds of the pixels array. The
extra pixels do not affect the result.

Fixes valgrind complaining about the invalid reads by allocating 5 extra
pixels in kvz_get_extended_block_avx2
2017-06-22 09:37:55 +03:00
Arttu Ylä-Outinen 4d20e156db Fix handling intra period not multiple of GOP length
With low delay GOP structure, it is possible to use an intra period that
is not a multiple of the GOP structure length. Commit 00c9f52 changed
encoder_state_init_new_frame to reset POC on intra frames. GOP offset,
however, was not reset, resulting in invalid POCs and references for the
following frames.

This commit changes function kvz_encoder_feed_frame so that GOP offset
is correctly reset on intra frames.
2017-06-22 09:29:00 +03:00
Arttu Ylä-Outinen 00c9f52bd4 Fix setting picture type when using GOP
Changes encoder_state_init_new_frame to set intra frame pictype to
KVZ_NAL_IDR_W_RADL even when using GOP.
2017-06-21 13:21:47 +03:00
Arttu Ylä-Outinen f54a25f112 Fix crash when immediately closing encoder
When closing the encoder, the pictures stored in the input frame buffer
are freed by repeatedly calling kvz_encoder_feed_frame. If the encoder
was closed immediately after opening it, kvz_encoder_feed_frame would be
called with an unprepared encoder state. This would trigger an assert.

Fixed by changing kvz_encoder_feed_frame so that it does not require the
encoder state to be prepared.
2017-06-15 11:57:46 +03:00
Arttu Ylä-Outinen b74e0458fd Set inter transform depth to zero
Sets max_transform_hierarchy_depth_inter to 0 in SPS. This saves some
bits because split_transform_flag does not need to be coded for inter
blocks.

When SMP and AMP blocks are enabled the depth is set to 1 instead.
Otherwise inter split flag would default to 1 for SMP and AMP blocks,
resulting in an unnecessary transform split.
2017-06-08 10:08:20 +03:00
Arttu Ylä-Outinen 8dd01ba5a9 Refactor helper functions in search
Combines functions lcu_set_intra_mode and lcu_set_inter_pu to a single
function. Removes some duplicated code.
2017-06-06 10:32:09 +03:00
Arttu Ylä-Outinen 1bbecf7584 Refactor work tree copy functions
Extracts common code shared by work_tree_copy_up and work_tree_copy_down
to a separate function.
2017-06-06 10:32:00 +03:00
Arttu Ylä-Outinen 2b169d5d63 Fix crash in kvazaar_close
Changes kvazaar_close to stop all threads before freeing encoder states.
Fixes a crash when the encoder is closed before all pictures have been
encoded.
2017-06-02 10:05:33 +03:00
Arttu Ylä-Outinen eb9a05b7ef Fix memory leak
Changes kvazaar_close to free the remaining pictures in the the input
frame buffer. Fixes a memory leak when the encoder is closed while there
are pictures left in the buffer.
2017-06-01 15:39:35 +03:00
Arttu Ylä-Outinen 8b2483ca1c Combine intra reconstruction functions
Replaces function kvz_intra_recon_lcu_luma and
kvz_intra_recon_lcu_chroma in intra.c with function kvz_intra_recon_cu.
The new function can handle reconstruction for both luma and chroma.
Removes some duplicated code.
2017-05-24 12:07:31 +03:00
Arttu Ylä-Outinen e67fdb853d Move intra leaf TB recon to a separate function
Moves code for intra leaf transform block reconstruction from functions
kvz_intra_recon_lcu_luma and kvz_intra_recon_lcu_chroma to a new
function intra_recon_tb_leaf. Removes some duplicated code.
2017-05-24 12:07:31 +03:00
Arttu Ylä-Outinen 13d2fdbd21 Drop unused kvz_videoframe_get_cu functions 2017-05-24 11:15:31 +03:00
Arttu Ylä-Outinen f5eef7f33c Use luma pixel coordinates in encode_coding_tree
Changes functions encode_intra_coding_unit and encode_coding_tree to
take coordinate arguments in units of luma pixels instead of 8 px
blocks. This should make the code easier to understand.
2017-05-24 11:15:31 +03:00
Arttu Ylä-Outinen 525a5180ff Combine intra CU encoding functions
Merges functions encode_intra_coding_unit and
encode_intra_coding_unit_encry. Removes a lot of duplicated code.
2017-05-24 11:12:40 +03:00
Arttu Ylä-Outinen 610c91b0c5 Use luma pixel coordinates in TU coding functions
Changes functions encode_transform_unit and encode_transform_coeff to
take coordinate arguments in units of luma pixels instead of 4 px
blocks. This should make the code easier to understand.
2017-05-23 15:36:16 +03:00
Arttu Ylä-Outinen 2e8838de6e Fix crash when crypto compiled in but disabled
When kvazaar was built with crypto++ but running without using
encryption features, kvazaar attempted to delete an uninitialized crypto
handle. Fixed by setting the handle to NULL in kvz_encoder_state_init.
2017-05-23 14:01:48 +03:00