1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

avcodec/cri,tdsc,tiff: Use ff_mjpeg_decoder directly

This is simpler than calling avcodec_find_decoder().
Notice that av_codec_init_static() has already been called
by the time we reach these decoders' init functions,
so it is not necessary to call avcodec_find_decoder()
for it (which doesn't do anything for the mjpeg decoder
anyway).

Reviewed-by: Kacper Michajlow <kasper93@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-04-21 18:48:10 +02:00
parent 25b0a8e295
commit 289cb3beff
3 changed files with 12 additions and 18 deletions

View File

@ -27,6 +27,7 @@
#define BITSTREAM_READER_LE
#include "libavutil/attributes_internal.h"
#include "libavutil/intfloat.h"
#include "libavutil/display.h"
#include "avcodec.h"
@ -51,7 +52,6 @@ typedef struct CRIContext {
static av_cold int cri_decode_init(AVCodecContext *avctx)
{
CRIContext *s = avctx->priv_data;
const AVCodec *codec;
int ret;
s->jpgframe = av_frame_alloc();
@ -62,16 +62,14 @@ static av_cold int cri_decode_init(AVCodecContext *avctx)
if (!s->jpkt)
return AVERROR(ENOMEM);
codec = avcodec_find_decoder(AV_CODEC_ID_MJPEG);
if (!codec)
return AVERROR_BUG;
s->jpeg_avctx = avcodec_alloc_context3(codec);
EXTERN const FFCodec ff_mjpeg_decoder;
s->jpeg_avctx = avcodec_alloc_context3(&ff_mjpeg_decoder.p);
if (!s->jpeg_avctx)
return AVERROR(ENOMEM);
s->jpeg_avctx->flags = avctx->flags;
s->jpeg_avctx->flags2 = avctx->flags2;
s->jpeg_avctx->idct_algo = avctx->idct_algo;
ret = avcodec_open2(s->jpeg_avctx, codec, NULL);
ret = avcodec_open2(s->jpeg_avctx, NULL, NULL);
if (ret < 0)
return ret;

View File

@ -36,6 +36,7 @@
#include <stdint.h>
#include <zlib.h>
#include "libavutil/attributes_internal.h"
#include "libavutil/imgutils.h"
#include "libavutil/mem.h"
@ -95,7 +96,6 @@ static av_cold int tdsc_close(AVCodecContext *avctx)
static av_cold int tdsc_init(AVCodecContext *avctx)
{
TDSCContext *ctx = avctx->priv_data;
const AVCodec *codec;
int ret;
avctx->pix_fmt = AV_PIX_FMT_BGR24;
@ -120,16 +120,14 @@ static av_cold int tdsc_init(AVCodecContext *avctx)
return AVERROR(ENOMEM);
/* Prepare everything needed for JPEG decoding */
codec = avcodec_find_decoder(AV_CODEC_ID_MJPEG);
if (!codec)
return AVERROR_BUG;
ctx->jpeg_avctx = avcodec_alloc_context3(codec);
EXTERN const FFCodec ff_mjpeg_decoder;
ctx->jpeg_avctx = avcodec_alloc_context3(&ff_mjpeg_decoder.p);
if (!ctx->jpeg_avctx)
return AVERROR(ENOMEM);
ctx->jpeg_avctx->flags = avctx->flags;
ctx->jpeg_avctx->flags2 = avctx->flags2;
ctx->jpeg_avctx->idct_algo = avctx->idct_algo;
ret = avcodec_open2(ctx->jpeg_avctx, codec, NULL);
ret = avcodec_open2(ctx->jpeg_avctx, NULL, NULL);
if (ret < 0)
return ret;

View File

@ -36,6 +36,7 @@
#include <float.h>
#include "libavutil/attributes.h"
#include "libavutil/attributes_internal.h"
#include "libavutil/avstring.h"
#include "libavutil/error.h"
#include "libavutil/intreadwrite.h"
@ -2409,7 +2410,6 @@ again:
static av_cold int tiff_init(AVCodecContext *avctx)
{
TiffContext *s = avctx->priv_data;
const AVCodec *codec;
int ret;
s->width = 0;
@ -2429,17 +2429,15 @@ static av_cold int tiff_init(AVCodecContext *avctx)
return AVERROR(ENOMEM);
/* Prepare everything needed for JPEG decoding */
codec = avcodec_find_decoder(AV_CODEC_ID_MJPEG);
if (!codec)
return AVERROR_BUG;
s->avctx_mjpeg = avcodec_alloc_context3(codec);
EXTERN const FFCodec ff_mjpeg_decoder;
s->avctx_mjpeg = avcodec_alloc_context3(&ff_mjpeg_decoder.p);
if (!s->avctx_mjpeg)
return AVERROR(ENOMEM);
s->avctx_mjpeg->flags = avctx->flags;
s->avctx_mjpeg->flags2 = avctx->flags2;
s->avctx_mjpeg->idct_algo = avctx->idct_algo;
s->avctx_mjpeg->max_pixels = avctx->max_pixels;
ret = avcodec_open2(s->avctx_mjpeg, codec, NULL);
ret = avcodec_open2(s->avctx_mjpeg, NULL, NULL);
if (ret < 0) {
return ret;
}