Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2016-10-26 14:59:15 +0300
committerAnton Khirnov <anton@khirnov.net>2016-12-14 11:06:44 +0300
commit061a0c14bb5767bca72e3a7227ca400de439ba09 (patch)
tree7b123da4ad30c37c9a954dc274c6208ea5311c83 /libavcodec/utils.c
parent549d0bdca53af7a6e0c612ab4b03baecf3a5878f (diff)
decode: restructure the core decoding code
Currently, the new decoding API is pretty much just a wrapper around the old deprecated one. This is problematic, since it interferes with making full use of the flexibility added by the new API. The old API should also be removed at some future point. Reorganize the code so that the new send_packet/receive_frame functions call the actual decoding directly and change the old deprecated avcodec_decode_* functions into wrappers around the new API. The new internal API for decoders is now changing as well. Before this commit, it mirrors the public API, so the decoders need to implement send_packet() and receive_frame() callbacks. This turns out to require awkward constructs in both the decoders and the generic code. After this commit, the decoders only implement the receive_frame() callback and call a new internal function, ff_decode_get_packet() to obtain input data, in the same manner to how the bitstream filters now work. avcodec will now always make a reference to the input packet, which means that non-refcounted input packets will be copied. Keeping the previous behaviour, where this copy could sometimes be avoided, would make the code significantly more complex and fragile for only dubious gains, since packets are typically small and everyone who cares about performance should use refcounted packets anyway.
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r--libavcodec/utils.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index b569b48f7a..8a422d7669 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -100,7 +100,7 @@ int av_codec_is_encoder(const AVCodec *codec)
int av_codec_is_decoder(const AVCodec *codec)
{
- return codec && (codec->decode || codec->send_packet);
+ return codec && (codec->decode || codec->receive_frame);
}
av_cold void avcodec_register(AVCodec *codec)
@@ -421,6 +421,12 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
goto free_and_end;
}
+ avctx->internal->compat_decode_frame = av_frame_alloc();
+ if (!avctx->internal->compat_decode_frame) {
+ ret = AVERROR(ENOMEM);
+ goto free_and_end;
+ }
+
avctx->internal->buffer_frame = av_frame_alloc();
if (!avctx->internal->buffer_frame) {
ret = AVERROR(ENOMEM);
@@ -433,6 +439,12 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
goto free_and_end;
}
+ avctx->internal->ds.in_pkt = av_packet_alloc();
+ if (!avctx->internal->ds.in_pkt) {
+ ret = AVERROR(ENOMEM);
+ goto free_and_end;
+ }
+
avctx->internal->last_pkt_props = av_packet_alloc();
if (!avctx->internal->last_pkt_props) {
ret = AVERROR(ENOMEM);
@@ -717,9 +729,13 @@ FF_ENABLE_DEPRECATION_WARNINGS
av_freep(&avctx->priv_data);
if (avctx->internal) {
av_frame_free(&avctx->internal->to_free);
+ av_frame_free(&avctx->internal->compat_decode_frame);
av_frame_free(&avctx->internal->buffer_frame);
av_packet_free(&avctx->internal->buffer_pkt);
av_packet_free(&avctx->internal->last_pkt_props);
+
+ av_packet_free(&avctx->internal->ds.in_pkt);
+
av_freep(&avctx->internal->pool);
}
av_freep(&avctx->internal);
@@ -758,9 +774,13 @@ av_cold int avcodec_close(AVCodecContext *avctx)
if (avctx->codec && avctx->codec->close)
avctx->codec->close(avctx);
av_frame_free(&avctx->internal->to_free);
+ av_frame_free(&avctx->internal->compat_decode_frame);
av_frame_free(&avctx->internal->buffer_frame);
av_packet_free(&avctx->internal->buffer_pkt);
av_packet_free(&avctx->internal->last_pkt_props);
+
+ av_packet_free(&avctx->internal->ds.in_pkt);
+
for (i = 0; i < FF_ARRAY_ELEMS(pool->pools); i++)
av_buffer_pool_uninit(&pool->pools[i]);
av_freep(&avctx->internal->pool);