Commit graph

45 commits

Author SHA1 Message Date
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 2991962033 Add reference counting to threadequeue_job_t
Both the thread queue and the encoder states hold pointers to the thread
queue jobs. It is possible that a job is removed from the thread queue
and freed while the encoder state is still using it. This commit adds
reference counting to threadqueue_job_t in order to fix the problem.

Fixes #161.
2017-04-12 16:13:52 +03:00
Arttu Ylä-Outinen 51786eda67 Drop redundant fields in encoder_control_t
Some of the fields in encoder_control_t were simply copies of the
corresponding fields in kvz_config. This commit drops the copied fields
in favor of using the fields in encoder_control_t.cfg directly.
2017-02-09 14:05:28 +09:00
Arttu Ylä-Outinen e78a8dfcf5 Copy the kvz_config passed to encoder_open
The kvz_config struct is created by the user but kvazaar keeps a pointer
to it. It is easy to break things by modifying the configuration outside
kvazaar. In addition, kvazaar modifies the struct even though it is has
a const modifier.

This commit changes the field cfg in encoder_control_t to be a copy of
the kvz_config struct instead of a pointer, removing modifications to
the const struct and allowing users to do whatever they want with it
after opening the encoder.
2017-02-09 13:23:54 +09:00
Ari Koivula ed3bd898fd Remove Exp-Golomb lookup table
This table takes 256kB and isn't used very much. Au revoir!
2017-01-31 18:31:05 +02:00
Arttu Ylä-Outinen 6c4f2d196a Move fields from encoder_state_t to frame
Moves fields prepared and frame_done from encoder_state_t to
encoder_state_config_frame_t.
2017-01-09 01:24:23 +09:00
Ari Koivula 16790c9f15 Remove number of references from --gop=lp syntax
The number of references should be part of the presets, so gop should
be defined separately.
2016-09-29 00:03:19 +03:00
Ari Koivula 032ed30ff4 Add chroma format support to kvz_picture
Add picture_alloc_csp to libkvz api to allocated pictures with chroma
format different from 420.
2016-08-24 19:20:53 +03:00
Arttu Ylä-Outinen 2a946bd88e Rename encoder_state_t.global to frame
"Frame" is more accurate than "global" since when OWF is used, encoder
states for each frame have their own struct.
2016-08-10 13:22:36 +09:00
Arttu Ylä-Outinen aaec473a19 Refactor encoder state initialization.
- Moves allocation of the reconstructed picture after the source picture
  is set.
- Extracts main state initialization to a separate function from
  encoder_state_new_frame.
- Changes kvz_encoder_feed_frame to return the frame.
- Renames some functions to better match their purpose.
2016-08-03 14:25:08 +09:00
Arttu Ylä-Outinen 22cc97ffb1 Fix missing field initializers. 2016-08-03 14:25:08 +09:00
Ari Koivula 61fc3e87ba Run include-what-you-use fix_includes.py fix_includes.py
The includes should make more sense now and not just happen to compile
due to headers included from other headers.

Used a modified version of IWYU. Modifications were to attribute int8_t
and so on to stdint.h instead of sys/types.h and immintrin.h instead of
more specific headers.

include-what-you-use 0.7 (git:b70df35)
based on clang version 3.9.0 (trunk 264728)
2016-04-01 17:46:55 +03:00
Ari Koivula 8ad7d2a714 Move interlacing stuff to libkvazaaar API
This moves the interlacing from CLI code to api->encoder_encode, in
order to make it possible to use field coding through the lib API.

The field order is now determined per frame, as FFmpeg gives it per
frame and it's signaled per frame.

As a side effect, the CLI also now prints info from frames instead of
fields. While we might want to extend the API in the future to allow
printing of more detailed information about fields, for now it's
more important that the CLI uses the real lib API.

PSNR calculation for interlaced frames disabled until we have a way to
avoid deinterlacing the frame when it's not necessary.
2016-01-27 15:29:45 +02:00
Arttu Ylä-Outinen 49677810b5 Rename config module to cfg.
Prevents a conflict with config.h and src/config.h so that the config.h
generated by configure is included in global.h. Fixes problems with
large input files on 32-bit systems.
2016-01-25 12:26:46 +02:00
Arttu Ylä-Outinen 1cf55f066f Fix memory leak in encoder_headers.
The header data was not freed when data_out was NULL.
2015-10-23 09:55:08 +03:00
Arttu Ylä-Outinen d5f3778f72 Add function encoder_headers to API.
This provides means for obtaining the VPS, SPS and PPS separately from
the rest of the bitstream.
2015-10-16 11:47:27 +03:00
Arttu Ylä-Outinen 8f404a3b6f Add NAL unit type to frame_info. 2015-09-28 10:30:59 +03:00
Arttu Ylä-Outinen efd361ee8e Return the original picture from encoder_encode. 2015-09-28 10:30:58 +03:00
Arttu Ylä-Outinen 7edc1b0b1c Add reference picture lists to kvz_frame_info. 2015-09-28 10:30:57 +03:00
Arttu Ylä-Outinen c856a6b598 Output frame info from encoder_encode.
Adds a new output parameter info_out to encoder_encode. It returns
a struct containing information about the encoded frame, including POC,
QP and slice type.
2015-09-28 10:30:57 +03:00
Arttu Ylä-Outinen 25c23aa298 Remove static variables from kvz_encoder_feed_frame.
Adds struct input_frame_buffer_t for storing the input buffer state.
2015-09-14 14:12:19 +03:00
Arttu Ylä-Outinen 1d2a398197 Move function kvz_encoder_feed_frame to a separate module.
Adds module input_frame_buffer.
2015-09-14 14:12:18 +03:00
Arttu Ylä-Outinen 70b3e10e27 Fix a crash with owf=4, gop=8, frames=10.
A call to kvz_threadqueue_waitfor caused the tqj_bitstream_written field
of the previous encoder state to become a dangling pointer, subsequently
causing an assertion to fail. This would only occur when the encoder
state used for a new frame was not the last finished one.

Fixed by setting tqj_bitstream_written to NULL after the job is done and
removing unnecessary calls to kvz_threadqueue_waitfor.
2015-09-07 15:37:04 +03:00
Arttu Ylä-Outinen 3a10e9e3e0 Prefix all non-static symbols with "kvz_". 2015-08-26 13:02:28 +03:00
Ari Lemmetti 5d96dbc6c0 Make strategy selection use bit depth given via parameter instead of excluding registration with defines 2015-08-12 13:33:38 +03:00
Arttu Ylä-Outinen a4ec92081a Make symbols hidden by default.
Adds "-fvisibility=hidden" to CFLAGS and LDFLAGS. Defines macro
KVZ_PUBLIC for marking symbols that should be visible.
2015-07-13 14:20:21 +03:00
Arttu Ylä-Outinen 907451590e Fix encoding when both GOP and OWF are enabled.
Changes kvazaar_encode to not increase cur_state_num unless a frame is
started.
2015-07-07 10:05:42 +03:00
Arttu Ylä-Outinen 4ab9aa3e2f Move kvz_encoder definition to kvazaar_internal.h. 2015-07-02 16:58:30 +03:00
Arttu Ylä-Outinen b715ae9767 Return length of the data from encoder_encode.
Adds parameter len_out returning the length of the encoded data in bytes
to function encoder_encode.
2015-07-02 16:58:29 +03:00
Arttu Ylä-Outinen 538deaa9d6 Add functions picture_{alloc,free} to kvazaar API. 2015-07-02 16:58:29 +03:00
Arttu Ylä-Outinen 6451df9a4f Move bitstream chunk definition to kvazaar.h.
- Renames struct bitstream_chunk_t to kvz_data_chunk.
- Renames macro BITSTREAM_MEMORY_CHUNK_SIZE to KVZ_DATA_CHUNK_SIZE.
- Removes kvz_payload typedef.
- Adds function chunk_free(kvz_data_chunk *chunk) to kvazaar API.
2015-07-02 16:58:28 +03:00
Arttu Ylä-Outinen cecea44d37 Rename config_t to kvz_config. 2015-07-02 16:58:28 +03:00
Arttu Ylä-Outinen cecdf4f34e Move config validation to encoder_control_init.
Ensures that config is valid even when not initialized by config_read.
2015-07-02 16:47:28 +03:00
Arttu Ylä-Outinen 398f0c823b Replace memory bitstreams with linked lists.
- Removes all bitstream types.
- Changes encoder_encode to return the encoded data as list of chunks.
- Moves writing of the encoded data to the main function.
2015-07-02 16:35:46 +03:00
Arttu Ylä-Outinen 7e20e62cc7 Make kvazaar_encode consume one frame on each call.
- Replaces read_one_frame by encoder_feed_frame.
- Adds field "prepared" to encoderstate_t to indicate that
  encoder_next_frame has been called.
- Input frames are read in the main function and passed to
  encoder_encode.
2015-07-02 16:28:40 +03:00
Arttu Ylä-Outinen 1f41717351 Rename stats_done to frame_done in encoderstate.
The new field frame_done is set to zero when starting to encode a new
frame and reset to one when the encoded data has been written.
2015-07-02 16:24:26 +03:00
Arttu Ylä-Outinen 50a5d5faa5 Let subimages have multiple references.
Adds function image_copy_ref to image module for getting a new reference
to an image. It can be used instead of image_make_subimage when the
sizes of the original and the subimage are same.
2015-07-02 16:24:26 +03:00
Arttu Ylä-Outinen f41ce04488 Refactor main function.
- Make sure that everything which is allocated gets deallocated.
- Move finalization of encoder states to kvazaar.c.
- Remove empty strategyselector_free function.
- Remove unused variable curpos.
- Fix includes.
2015-07-02 16:24:24 +03:00
Arttu Ylä-Outinen 4a7b86a43b Make g_exp_table statically allocated.
Removes the need to free the table.
2015-07-02 16:14:52 +03:00
Arttu Ylä-Outinen b130ecc9bb Fix "reference not found" when GOP is enabled.
The encoder state must be cleared by calling encoder_next_frame before
calling read_one_frame.
2015-07-02 16:14:51 +03:00
Ari Koivula 7e98a483d7 Use the API for checking whether the encoding is finished. 2015-07-02 16:14:51 +03:00
Ari Koivula fc58748ae8 Output bitstream through API.
- Use the existing bitstream_t type to give access to the bitstream.
  We can extend it later to make it a linked list like I was planning
  to do with the payload type.
- The main encoder now also stores the bitstream in memory.
2015-07-02 16:10:51 +03:00
Ari Koivula df50a0dae6 Move config_parse into api. 2015-07-02 15:52:24 +03:00
Ari Koivula 4e5326d3d5 Move encoding to API.
- Api->encoder_encode can now be called repeatedly to start encoder
  jobs and to retrieve the results.

Conflicts:
	src/encmain.c
2015-07-02 15:52:23 +03:00
Ari Koivula ad11d1bca5 Add kvazaar.h to hold high-level encoder API.
- Move encoder initialization from main to kvazaar.c.
- Have main use the API for initialization.

Conflicts:
	src/encmain.c
2015-07-02 15:52:23 +03:00