1
mirror of https://git.videolan.org/git/ffmpeg.git synced 2024-09-05 07:48:07 +02:00
Commit Graph

46 Commits

Author SHA1 Message Date
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
Jai Luthra
bc0ed17602 mlpenc: improve lpc filtering
* fix a possible memory leak (apply_filter returned before freeing)
* use apply_filters in process_major_frame
* revert back to checking bounds with 24 bitdepth, as huff offset takes
care of it

Signed-off-by: Jai Luthra <me@jailuthra.in>
2020-02-04 11:19:12 +01:00
Jai Luthra
ddeb58d58c mlpenc: prevent negative lsb_bits lshift
Fixes Coverity CID 1396239.

Signed-off-by: Jai Luthra <me@jailuthra.in>
2020-02-04 11:19:12 +01:00
Jai Luthra
990990ed5d mlpenc: fix huff offset calculation
huff offset wasn't always within the bounds before, which lead to
corrupt encoding that didn't always trigger lossless check failures

Signed-off-by: Jai Luthra <me@jailuthra.in>
2020-02-04 11:19:12 +01:00
Jai Luthra
c1c3916cec mlpenc: fix lossless check error in number_sbits
we need two bits instead of one bit to represent -1 in bitstream

Signed-off-by: Jai Luthra <me@jailuthra.in>
2020-02-04 11:19:12 +01:00
Jun Zhao
64e610b5f4 lavc/mlpenc: remove the redundant condition check
remove the redundant condition check for 'frame'

Signed-off-by: Jun Zhao <barryjzhao@tencent.com>
2019-05-12 14:18:08 +08:00
Jai Luthra
15b86f480a mlpenc: Working MLP/TrueHD encoder
* Multichannel support for TrueHD is experimental

    There should be downmix substreams present for 2+ channel bitstreams,
    but ffmpeg decoder doesn't need it. Will add support for this soon.

* There might be lossless check failures on LFE channels

* 32-bit sample support has been removed for now, will add it later

    While testing, some samples gave lossless check failures when enforcing
    s32. Probably this will also get solved with the LFE issues.

Signed-off-by: Jai Luthra <me@jailuthra.in>
2016-09-17 13:23:56 +01:00