mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
avcodec/wavpack: Use RefStruct API for DSD context
It avoids allocations and the corresponding error checks. It also avoids indirections and casts. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
parent
e1ba00ac8f
commit
05f557b259
@ -28,6 +28,7 @@
|
|||||||
#include "bytestream.h"
|
#include "bytestream.h"
|
||||||
#include "codec_internal.h"
|
#include "codec_internal.h"
|
||||||
#include "get_bits.h"
|
#include "get_bits.h"
|
||||||
|
#include "refstruct.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "threadframe.h"
|
#include "threadframe.h"
|
||||||
#include "unary.h"
|
#include "unary.h"
|
||||||
@ -110,8 +111,7 @@ typedef struct WavpackContext {
|
|||||||
ThreadFrame curr_frame, prev_frame;
|
ThreadFrame curr_frame, prev_frame;
|
||||||
Modulation modulation;
|
Modulation modulation;
|
||||||
|
|
||||||
AVBufferRef *dsd_ref;
|
DSDContext *dsdctx; ///< RefStruct reference
|
||||||
DSDContext *dsdctx;
|
|
||||||
int dsd_channels;
|
int dsd_channels;
|
||||||
} WavpackContext;
|
} WavpackContext;
|
||||||
|
|
||||||
@ -990,9 +990,8 @@ static int wv_dsd_reset(WavpackContext *s, int channels)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
s->dsdctx = NULL;
|
|
||||||
s->dsd_channels = 0;
|
s->dsd_channels = 0;
|
||||||
av_buffer_unref(&s->dsd_ref);
|
ff_refstruct_unref(&s->dsdctx);
|
||||||
|
|
||||||
if (!channels)
|
if (!channels)
|
||||||
return 0;
|
return 0;
|
||||||
@ -1000,10 +999,9 @@ static int wv_dsd_reset(WavpackContext *s, int channels)
|
|||||||
if (channels > INT_MAX / sizeof(*s->dsdctx))
|
if (channels > INT_MAX / sizeof(*s->dsdctx))
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
|
|
||||||
s->dsd_ref = av_buffer_allocz(channels * sizeof(*s->dsdctx));
|
s->dsdctx = ff_refstruct_allocz(channels * sizeof(*s->dsdctx));
|
||||||
if (!s->dsd_ref)
|
if (!s->dsdctx)
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
s->dsdctx = (DSDContext*)s->dsd_ref->data;
|
|
||||||
s->dsd_channels = channels;
|
s->dsd_channels = channels;
|
||||||
|
|
||||||
for (i = 0; i < channels; i++)
|
for (i = 0; i < channels; i++)
|
||||||
@ -1028,15 +1026,8 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
fdst->dsdctx = NULL;
|
ff_refstruct_replace(&fdst->dsdctx, fsrc->dsdctx);
|
||||||
fdst->dsd_channels = 0;
|
|
||||||
ret = av_buffer_replace(&fdst->dsd_ref, fsrc->dsd_ref);
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
if (fsrc->dsd_ref) {
|
|
||||||
fdst->dsdctx = (DSDContext*)fdst->dsd_ref->data;
|
|
||||||
fdst->dsd_channels = fsrc->dsd_channels;
|
fdst->dsd_channels = fsrc->dsd_channels;
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1076,7 +1067,7 @@ static av_cold int wavpack_decode_end(AVCodecContext *avctx)
|
|||||||
ff_thread_release_ext_buffer(avctx, &s->prev_frame);
|
ff_thread_release_ext_buffer(avctx, &s->prev_frame);
|
||||||
av_frame_free(&s->prev_frame.f);
|
av_frame_free(&s->prev_frame.f);
|
||||||
|
|
||||||
av_buffer_unref(&s->dsd_ref);
|
ff_refstruct_unref(&s->dsdctx);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user