Also allocate them jointly (thereby reducing the number of base
arrays considerably) and already set them on all slice contexts;
don't rely on ff_update_duplicate_context().
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
dct_error_sum and me.map are allocated per slice-context
and therefore their allocation has not been moved to
mpegvideoenc.c in 0154fb43e3.
This commit changes this by allocating them jointly and
moving said allocations to mpegvideo_enc.c like the other
encoder-only buffers.
The buffers are suitably aligned to ensure that no false
sharing occurs.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Several fields are not used by any generic code and can therefore
be moved to more specialized contexts.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Switch to using the length+symbol table combination that is
also used by the decoder and remove MVTable as well as
the old tables altogether.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Up until now, the decoder uses VLCs to determine whether
this is an escape element or an index in two separate tables
giving the x and y components of the motion vector.
Given that both these components fit into an int16_t and therefore
into a VLCElem's symbol one can simply use a symbol table
to avoid the latter lookups.
This necessitated to combine the two tables for x and y components.
While just at it, also switch to ff_vlc_init_tables_from_lengths().
This will allow to get rid of the code tables (about 4KiB) once
the encoder has been ported, too.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
It is a pointer to const to allow the slice threads to inspect
values without modifying them; also make it a simple cast
for codecs that don't support slice threading.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
It gets rid of a switch (with accompanying CONFIG_*_ENCODER checks);
for MJPEG, it even lets one perform the check for whether one is
really encoding or only recording the macroblock once during init.
Furthermore, the switch actually contained lots of dead code --
it is compiled three times (for different pixel formats: 420, 422, 444),
yet most encoders only support 420. The approach used here automatically
fixes this.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Will avoid forward declarations later.
While just at it, forward ff_mpv_encode_init() errors.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
The header is always written by the main thread, so it is
not surprising that header_bits can be moved to MPVMainEncContext
as well.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
avpriv_slicethread_free() is one of our functions that takes
a pointer to a pointer and resets the pointer when done.
It is legal for such functions to be passed a pointer to a NULL
pointer, yet passing a NULL pointer would be insane and should
not be tolerated.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This is no longer necessary given that the MPEG-1 encoder
now adapts the size of the last slice to ensure that
no slice header has an invalid slice_start_code.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
The valid values for slice_start_code are 0x1..0xAF, which implies
that one can't start a slice with row nb > 174 (zero-based).
This problem can be encountered with files of sufficient height
(more than 2800 pixels) either by using the slice option or by
imposing an RTP payload limit.
Fix this by making the last slice start on the maximum allowed
slice row if necessary and divide the first 174 rows to the remaining
slices. This will impede parallelism both in the decoder and encoder,
but that is unavoidable.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Everything except setting the dc_scale_tables can be done
before calling ff_mpv_encode_init(); setting the dc_scale_tables
unfortunately still has to be performed via a (now inlined)
callback performed by ff_mpv_encode_init() as it relies
on intra_dc_precision having been sanitized.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This is in preparation for merging ff_mpeg1_encode_init()
into the MPEG-1/2 encoder's init function.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Reuse the already computed value of macroblocks; use an array
instead of a switch, evaluate 64 * sizeof(MJpegHuffmanCode)
at compile-time.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Right now, ff_mpv_encode_init() is set as FFCodec.init and
calls ff_speedhq_encode_init(). The opposite is more natural,
avoids a non-static function and allows to reuse e.g.
slice_context_count instead of duplicating the logic from
ff_mpv_common_init().
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Namely use avctx directly instead of s->avctx. While just at it,
also move the switch to the other checks involving avctx.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Right now, ff_mpv_encode_init() is set as FFCodec.init and
calls ff_speedhq_encode_init(). The opposite is more natural
and avoids a non-static function.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Only the H.263-based decoders as well as the encoders need it;
so move it to ff_h263_decode_init() as well as ff_mpv_encode_init().
Also for the latter make it only set these tables if none are
already set.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Right now, ff_mpv_encode_init() is set as FFCodec.init and
calls ff_h261_encode_init(). The opposite is more natural
and avoids a non-static function.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Also move b_frame_strategy and b_sensitivity and brd_scale;
they are all only used by an encoder's main thread when
b_frame_strategy == 2.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This is in preparation for moving all the elements from
MpegEncContext that are only used by the main encoder thread
to MPVMainEncContext.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>