Commit Graph

56 Commits

Author SHA1 Message Date
Paul B Mahol
f67403edb3 avcodec/mlpenc: fix encoding after receiving last frame
This happened when major header needed to be written
after input EOF.
2022-04-13 14:22:39 +02:00
Paul B Mahol
c2351d5a53 avcodec/mlpenc: simplify calling function 2022-04-12 19:30:58 +02:00
Paul B Mahol
dc068a7265 avcodec/mlpenc: use FFMAX() 2022-04-12 19:30:58 +02:00
Paul B Mahol
cbad385f04 avcodec/mlpenc: improve handling of last samples 2022-04-12 19:30:58 +02:00
Andreas Rheinhardt
4243da4ff4 avcodec/codec_internal: Use union for FFCodec decode/encode callbacks
This is possible, because every given FFCodec has to implement
exactly one of these. Doing so decreases sizeof(FFCodec) and
therefore decreases the size of the binary.
Notice that in case of position-independent code the decrease
is in .data.rel.ro, so that this translates to decreased
memory consumption.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-04-05 20:02:37 +02:00
Andreas Rheinhardt
20f9727018 avcodec/codec_internal: Add FFCodec, hide internal part of AVCodec
Up until now, codec.h contains both public and private parts
of AVCodec. This exposes the internals of AVCodec to users
and leads them into the temptation of actually using them
and forces us to forward-declare structures and types that
users can't use at all.

This commit changes this by adding a new structure FFCodec to
codec_internal.h that extends AVCodec, i.e. contains the public
AVCodec as first member; the private fields of AVCodec are moved
to this structure, leaving codec.h clean.

Reviewed-by: Anton Khirnov <anton@khirnov.net>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-03-21 01:33:09 +01:00
Andreas Rheinhardt
a688f3c13c avcodec/internal: Move FF_CODEC_CAP_* to a new header codec_internal.h
Also move FF_CODEC_TAGS_END as well as struct AVCodecDefault.
This reduces the amount of files that have to include internal.h
(which comes with quite a lot of indirect inclusions), as e.g.
most encoders don't need it. It is furthemore in preparation
for moving the private part of AVCodec out of the public codec.h.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2022-03-21 01:33:09 +01:00
Martin Storsjö
a78f136f3f configure: Use a separate config_components.h header for $ALL_COMPONENTS
This avoids unnecessary rebuilds of most source files if only the
list of enabled components has changed, but not the other properties
of the build, set in config.h.

Signed-off-by: Martin Storsjö <martin@martin.st>
2022-03-16 14:12:49 +02:00
Anton Khirnov
d4b79b2e32 mlp: convert to new channel layout API
Signed-off-by: James Almer <jamrial@gmail.com>
2022-03-15 09:42:43 -03:00
Paul B Mahol
a8a7c5d502 avcodec/thd: fix special stereo support 2021-12-18 10:20:24 +01:00
Andreas Rheinhardt
db25180e9d avcodec/mlpenc: Set AV_PKT_FLAG_KEY manually
TrueHD/MLP is one of the audio formats with keyframes. Currently,
the generic encoding code just sets the keyframe flag for all
returned packets, yet this is wrong for these encoders and will
be changed in a future commit. So set the flag here for those
packets that ought to have it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-28 01:53:11 +02:00
Paul B Mahol
cd7e25b14a avcodec/mlpenc: fix encoding stereo single stream in TrueHD 2021-09-23 23:43:48 +02:00
Andreas Rheinhardt
bb9141cc13 avcodec/mlpenc: Fix mixed declarations and code warning
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-09 12:07:06 +02:00
Paul B Mahol
9e33572b3d avcodec/mlpenc: simplify some complicated expressions more 2021-09-07 18:16:13 +02:00
Paul B Mahol
1cbd4b00b1 avcodec/mlpenc: simplify strange pointer initializations 2021-09-07 18:16:13 +02:00
Paul B Mahol
b9426f371a avcodec/mlpenc: remove convoluted incomplete multiple substreams support code
It is very hard to follow data structures indirections in current code,
so just remove it for now.
2021-09-07 00:18:33 +02:00
Paul B Mahol
e811b0080e avcodec/mlpenc: use variables local to for loops 2021-09-07 00:18:33 +02:00
Paul B Mahol
0c87b43c6c avcodec/mlp: move sync defines to common header 2021-09-05 18:12:56 +02:00
Paul B Mahol
3ea0171ea3 avcodec/mlpenc: remove frame_size array from private context
It is supposed to be used with different bit depth and/or sample rates
per each substream, but such currently not implemented feature is not
important and current state causes problems when implementing variable
restart interval to fix decoding with sample rates not multiple of 40.
2021-09-05 16:08:19 +02:00
Paul B Mahol
5852bb6b4b avcodec/mlpenc: stop using hardcoded value 2021-09-05 15:02:39 +02:00
Paul B Mahol
ac29cec312 avcodec/mlpenc: use av_shrink_packet() 2021-09-05 14:09:50 +02:00
Paul B Mahol
cfc491bf44 avcodec/mlpenc: remove no more needed goto 2021-09-05 14:09:50 +02:00
Paul B Mahol
4ca9877b91 avcodec/mlpenc: fix removal of packet timestamp/size from queue 2021-09-05 12:15:34 +02:00
Paul B Mahol
d8863013a8 avcodec/mlpenc: remove not needed buf_size checks 2021-09-05 11:44:50 +02:00
Paul B Mahol
85b9b96957 avcodec/mlpenc: fix indentation 2021-09-05 11:44:50 +02:00
Paul B Mahol
036d94da43 avcodec/mlpenc: stop returning packets with no data 2021-09-05 11:44:50 +02:00
Paul B Mahol
589cd58c85 avcodec/mlpenc: simplify compare_best_offset() 2021-09-05 00:28:40 +02:00
Paul B Mahol
5b28a5db03 avcodec/mlpenc: use ff_ctz() 2021-09-05 00:11:40 +02:00
Paul B Mahol
d18b445689 avcodec/mlpenc: remove unused item 2021-09-05 00:09:55 +02:00
Paul B Mahol
19b52a7cc4 avcodec/mlpenc: remove log messages when allocation fails at init 2021-09-04 14:46:40 +02:00
Paul B Mahol
30c213fa6c avcodec/mlpenc: allocate filter buffers once at init 2021-09-04 14:46:40 +02:00
Paul B Mahol
57988fc496 avcodec/mlpenc: simplify allocations in mlp_encode_init() 2021-09-04 14:46:40 +02:00
Paul B Mahol
2bb9d2be5e avcodec/mlpenc: add support for 24bit encoding 2021-09-02 18:02:22 +02:00
Paul B Mahol
9f420163c6 avcodec/mlpenc: fix encoding last samples when not within full interval
Also implement shorten_by in bitstream.
2021-08-31 21:22:02 +02:00
Andreas Rheinhardt
1be3d8a0cb avcodec/avcodec: Stop including channel_layout.h in avcodec.h
Also include channel_layout.h directly wherever used.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-07-22 11:14:31 +02:00
Andreas Rheinhardt
56e9e0273a avcodec/encode: Always use intermediate buffer in ff_alloc_packet2()
Up until now, ff_alloc_packet2() has a min_size parameter:
It is supposed to be a lower bound on the final size of the packet
to allocate. If it is not too far from the upper bound (namely,
if it is at least half the upper bound), then ff_alloc_packet2()
already allocates the final, already refcounted packet; if it is
not, then the packet is not refcounted and its data only points to
a buffer owned by the AVCodecContext (in this case, the packet will
be made refcounted in encode_simple_internal() in libavcodec/encode.c).
The goal of this was to avoid data copies and intermediate buffers
if one has a precise lower bound.

Yet those encoders for which precise lower bounds exist have recently
been switched to ff_get_encode_buffer() (which automatically allocates
final buffers), leaving only two encoders to actually set the min_size
to something else than zero (namely aliaspixenc and hapenc). Both of
these encoders use a very low lower bound that is not helpful in any
nontrivial case.

This commit therefore removes the min_size parameter as well as the
codepath in ff_alloc_packet2() for the allocation of final buffers.
Furthermore, the function has been renamed to ff_alloc_packet() and
moved to encode.h alongside ff_get_encode_buffer().

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-06-08 12:52:50 +02:00
Andreas Rheinhardt
5541cffa17 avcodec/mlpenc: Make encoders init-threadsafe
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-05-02 05:14:42 +02:00
Andreas Rheinhardt
0166bb12e7 avcodec/mlpenc: Add const where appropriate
The MLP/TrueHD encoder uses pointers to non-const to access several
static objects that are only initialized at runtime and are therefore
not declared as const. This does not result in compiler warnings, but it
is fragile, as these objects are really not to be modified as they are
not owned by any encoder instance. Therefore this commit adds const to
the pointed to type of the pointers used to access them after their
initialization. One object has even been made const.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-05-02 05:14:42 +02:00
Andreas Rheinhardt
a247ac640d avcodec: Constify AVCodecs
Given that the AVCodec.next pointer has now been removed, most of the
AVCodecs are not modified at all any more and can therefore be made
const (as this patch does); the only exceptions are the very few codecs
for external libraries that have a init_static_data callback.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2021-04-27 10:43:15 -03:00
Andreas Rheinhardt
c81b8e04aa Avoid intermediate bitcount for number of bytes in PutBitContext
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-03-30 12:36:32 +02:00
Andreas Rheinhardt
3183eda0fa avcodec/mlpenc: Avoid redundant temporary PutBitContext
We are already word-aligned here, so one can just as well flush the main
PutBitContext.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2021-03-30 12:36:31 +02:00
Andreas Rheinhardt
15072d2753 avcodec/mlpenc: Simplify finding best codebook
Finding the best codebook involves comparing different paths, where each
path is a sequence of several decisions (namely which codebook to use).
Up until now, these sequence was encoded in a NUL-terminated string and
the actual decisions were encoded as ’\0'..'\3' (which encoded 0..3).
This commit modifies this to actually encode it via 0..3 by switching
away from a C-string to a simple array with an explicit length field.

Reviewed-by: Lynne <dev@lynne.ee>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-12-31 21:46:01 +01:00
Andreas Rheinhardt
b78031cf16 avcodec/mlpenc: Fix memleak upon init failure
If an error happens during init after an allocation has succeeded,
the already allocated data leaked up until now. Fix this by setting the
FF_CODEC_CAP_INIT_CLEANUP flag.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-09-15 19:25:26 +02:00
James Almer
52b9bd2c95 avcodec/mlpenc: free filter state buffers on allocation failure
Signed-off-by: James Almer <jamrial@gmail.com>
2020-07-01 00:24:25 -03:00
James Almer
4cdd2d6d4c avcodec/mlpenc: propagate proper error values
Signed-off-by: James Almer <jamrial@gmail.com>
2020-07-01 00:24:25 -03:00
James Almer
14f919515d avcodec/mlpenc: remove delay codec capability
The encoder has no delayed packets at the end of the encoding
process, so signaling this capability is unnecessary.

This also fixes an assertion failure introduced in 827d6fe73d, as
return values higher than 0 are not expected.

Signed-off-by: James Almer <jamrial@gmail.com>
2020-07-01 00:23:02 -03:00
Paul B Mahol
c35382aaf4 avcodec/mlpenc: fix small memory leak 2020-02-04 11:35:02 +01:00
Jai Luthra
49cfbedb9d mlp: check huff_lsbs only when codebook is used
When no codebook is used, huff_lsbs can be more than 24 and still decode to
original values once filters are applied.

Signed-off-by: Jai Luthra <me@jailuthra.in>
2020-02-04 11:19:12 +01:00
Jai Luthra
d6cef144e2 mlpenc: fix some -fsanitize=integer errors
Signed-off-by: Jai Luthra <me@jailuthra.in>
2020-02-04 11:19:12 +01:00
Jai Luthra
ad26384734 mlpenc: clean up
Signed-off-by: Jai Luthra <me@jailuthra.in>
2020-02-04 11:19:12 +01:00