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).
Unified · Split
| @@ -27,6 +27,7 @@ · 26 unmodified lines | |||
| 27 | 27 | ||
| 28 | #define BITSTREAM_READER_LE | 28 | #define BITSTREAM_READER_LE |
| 29 | 29 | ||
| 30 | #include "libavutil/attributes_internal.h" | ||
| 30 | #include "libavutil/intfloat.h" | 31 | #include "libavutil/intfloat.h" |
| 31 | #include "libavutil/display.h" | 32 | #include "libavutil/display.h" |
| 32 | #include "avcodec.h" | 33 | #include "avcodec.h" |
| @@ -51,7 +52,6 @@ typedef struct CRIContext { · 18 unmodified lines | |||
| 51 | static av_cold int cri_decode_init(AVCodecContext *avctx) | 52 | static av_cold int cri_decode_init(AVCodecContext *avctx) |
| 52 | { | 53 | { |
| 53 | CRIContext *s = avctx->priv_data; | 54 | CRIContext *s = avctx->priv_data; |
| 54 | const AVCodec *codec; | ||
| 55 | int ret; | 55 | int ret; |
| 56 | 56 | ||
| 57 | s->jpgframe = av_frame_alloc(); | 57 | s->jpgframe = av_frame_alloc(); |
| @@ -62,16 +62,14 @@ static av_cold int cri_decode_init(AVCodecContext *avctx) · 4 unmodified lines | |||
| 62 | if (!s->jpkt) | 62 | if (!s->jpkt) |
| 63 | return AVERROR(ENOMEM); | 63 | return AVERROR(ENOMEM); |
| 64 | 64 | ||
| 65 | codec = avcodec_find_decoder(AV_CODEC_ID_MJPEG); | 65 | EXTERN const FFCodec ff_mjpeg_decoder; |
| 66 | if (!codec) | 66 | s->jpeg_avctx = avcodec_alloc_context3(&ff_mjpeg_decoder.p); |
| 67 | return AVERROR_BUG; | ||
| 68 | s->jpeg_avctx = avcodec_alloc_context3(codec); | ||
| 69 | if (!s->jpeg_avctx) | 67 | if (!s->jpeg_avctx) |
| 70 | return AVERROR(ENOMEM); | 68 | return AVERROR(ENOMEM); |
| 71 | s->jpeg_avctx->flags = avctx->flags; | 69 | s->jpeg_avctx->flags = avctx->flags; |
| 72 | s->jpeg_avctx->flags2 = avctx->flags2; | 70 | s->jpeg_avctx->flags2 = avctx->flags2; |
| 73 | s->jpeg_avctx->idct_algo = avctx->idct_algo; | 71 | s->jpeg_avctx->idct_algo = avctx->idct_algo; |
| 74 | ret = avcodec_open2(s->jpeg_avctx, codec, NULL); | 72 | ret = avcodec_open2(s->jpeg_avctx, NULL, NULL); |
| 75 | if (ret < 0) | 73 | if (ret < 0) |
| 76 | return ret; | 74 | return ret; |
| 77 | 75 | ||
| @@ -36,6 +36,7 @@ · 35 unmodified lines | |||
| 36 | #include <stdint.h> | 36 | #include <stdint.h> |
| 37 | #include <zlib.h> | 37 | #include <zlib.h> |
| 38 | 38 | ||
| 39 | #include "libavutil/attributes_internal.h" | ||
| 39 | #include "libavutil/imgutils.h" | 40 | #include "libavutil/imgutils.h" |
| 40 | #include "libavutil/mem.h" | 41 | #include "libavutil/mem.h" |
| 41 | 42 | ||
| @@ -95,7 +96,6 @@ static av_cold int tdsc_close(AVCodecContext *avctx) · 53 unmodified lines | |||
| 95 | static av_cold int tdsc_init(AVCodecContext *avctx) | 96 | static av_cold int tdsc_init(AVCodecContext *avctx) |
| 96 | { | 97 | { |
| 97 | TDSCContext *ctx = avctx->priv_data; | 98 | TDSCContext *ctx = avctx->priv_data; |
| 98 | const AVCodec *codec; | ||
| 99 | int ret; | 99 | int ret; |
| 100 | 100 | ||
| 101 | avctx->pix_fmt = AV_PIX_FMT_BGR24; | 101 | avctx->pix_fmt = AV_PIX_FMT_BGR24; |
| @@ -120,16 +120,14 @@ static av_cold int tdsc_init(AVCodecContext *avctx) · 18 unmodified lines | |||
| 120 | return AVERROR(ENOMEM); | 120 | return AVERROR(ENOMEM); |
| 121 | 121 | ||
| 122 | /* Prepare everything needed for JPEG decoding */ | 122 | /* Prepare everything needed for JPEG decoding */ |
| 123 | codec = avcodec_find_decoder(AV_CODEC_ID_MJPEG); | 123 | EXTERN const FFCodec ff_mjpeg_decoder; |
| 124 | if (!codec) | 124 | ctx->jpeg_avctx = avcodec_alloc_context3(&ff_mjpeg_decoder.p); |
| 125 | return AVERROR_BUG; | ||
| 126 | ctx->jpeg_avctx = avcodec_alloc_context3(codec); | ||
| 127 | if (!ctx->jpeg_avctx) | 125 | if (!ctx->jpeg_avctx) |
| 128 | return AVERROR(ENOMEM); | 126 | return AVERROR(ENOMEM); |
| 129 | ctx->jpeg_avctx->flags = avctx->flags; | 127 | ctx->jpeg_avctx->flags = avctx->flags; |
| 130 | ctx->jpeg_avctx->flags2 = avctx->flags2; | 128 | ctx->jpeg_avctx->flags2 = avctx->flags2; |
| 131 | ctx->jpeg_avctx->idct_algo = avctx->idct_algo; | 129 | ctx->jpeg_avctx->idct_algo = avctx->idct_algo; |
| 132 | ret = avcodec_open2(ctx->jpeg_avctx, codec, NULL); | 130 | ret = avcodec_open2(ctx->jpeg_avctx, NULL, NULL); |
| 133 | if (ret < 0) | 131 | if (ret < 0) |
| 134 | return ret; | 132 | return ret; |
| 135 | 133 | ||
| @@ -36,6 +36,7 @@ · 35 unmodified lines | |||
| 36 | #include <float.h> | 36 | #include <float.h> |
| 37 | 37 | ||
| 38 | #include "libavutil/attributes.h" | 38 | #include "libavutil/attributes.h" |
| 39 | #include "libavutil/attributes_internal.h" | ||
| 39 | #include "libavutil/avstring.h" | 40 | #include "libavutil/avstring.h" |
| 40 | #include "libavutil/error.h" | 41 | #include "libavutil/error.h" |
| 41 | #include "libavutil/intreadwrite.h" | 42 | #include "libavutil/intreadwrite.h" |
| @@ -2409,7 +2410,6 @@ again: · 2367 unmodified lines | |||
| 2409 | static av_cold int tiff_init(AVCodecContext *avctx) | 2410 | static av_cold int tiff_init(AVCodecContext *avctx) |
| 2410 | { | 2411 | { |
| 2411 | TiffContext *s = avctx->priv_data; | 2412 | TiffContext *s = avctx->priv_data; |
| 2412 | const AVCodec *codec; | ||
| 2413 | int ret; | 2413 | int ret; |
| 2414 | 2414 | ||
| 2415 | s->width = 0; | 2415 | s->width = 0; |
| @@ -2429,17 +2429,15 @@ static av_cold int tiff_init(AVCodecContext *avctx) · 13 unmodified lines | |||
| 2429 | return AVERROR(ENOMEM); | 2429 | return AVERROR(ENOMEM); |
| 2430 | 2430 | ||
| 2431 | /* Prepare everything needed for JPEG decoding */ | 2431 | /* Prepare everything needed for JPEG decoding */ |
| 2432 | codec = avcodec_find_decoder(AV_CODEC_ID_MJPEG); | 2432 | EXTERN const FFCodec ff_mjpeg_decoder; |
| 2433 | if (!codec) | 2433 | s->avctx_mjpeg = avcodec_alloc_context3(&ff_mjpeg_decoder.p); |
| 2434 | return AVERROR_BUG; | ||
| 2435 | s->avctx_mjpeg = avcodec_alloc_context3(codec); | ||
| 2436 | if (!s->avctx_mjpeg) | 2434 | if (!s->avctx_mjpeg) |
| 2437 | return AVERROR(ENOMEM); | 2435 | return AVERROR(ENOMEM); |
| 2438 | s->avctx_mjpeg->flags = avctx->flags; | 2436 | s->avctx_mjpeg->flags = avctx->flags; |
| 2439 | s->avctx_mjpeg->flags2 = avctx->flags2; | 2437 | s->avctx_mjpeg->flags2 = avctx->flags2; |
| 2440 | s->avctx_mjpeg->idct_algo = avctx->idct_algo; | 2438 | s->avctx_mjpeg->idct_algo = avctx->idct_algo; |
| 2441 | s->avctx_mjpeg->max_pixels = avctx->max_pixels; | 2439 | s->avctx_mjpeg->max_pixels = avctx->max_pixels; |
| 2442 | ret = avcodec_open2(s->avctx_mjpeg, codec, NULL); | 2440 | ret = avcodec_open2(s->avctx_mjpeg, NULL, NULL); |
| 2443 | if (ret < 0) { | 2441 | if (ret < 0) { |
| 2444 | return ret; | 2442 | return ret; |
| 2445 | } | 2443 | } |