You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
mjpegdec: Add hwaccel hooks
Also adds some extra fields to the main context structure that may be needed by a hwaccel decoder.
This commit is contained in:
@@ -36,6 +36,7 @@
|
|||||||
#include "avcodec.h"
|
#include "avcodec.h"
|
||||||
#include "blockdsp.h"
|
#include "blockdsp.h"
|
||||||
#include "copy_block.h"
|
#include "copy_block.h"
|
||||||
|
#include "hwaccel.h"
|
||||||
#include "idctdsp.h"
|
#include "idctdsp.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "jpegtables.h"
|
#include "jpegtables.h"
|
||||||
@@ -147,6 +148,7 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
|
|||||||
s->org_height = avctx->coded_height;
|
s->org_height = avctx->coded_height;
|
||||||
avctx->chroma_sample_location = AVCHROMA_LOC_CENTER;
|
avctx->chroma_sample_location = AVCHROMA_LOC_CENTER;
|
||||||
avctx->colorspace = AVCOL_SPC_BT470BG;
|
avctx->colorspace = AVCOL_SPC_BT470BG;
|
||||||
|
s->hwaccel_pix_fmt = s->hwaccel_sw_pix_fmt = AV_PIX_FMT_NONE;
|
||||||
|
|
||||||
if ((ret = build_basic_mjpeg_vlc(s)) < 0)
|
if ((ret = build_basic_mjpeg_vlc(s)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
@@ -279,13 +281,18 @@ int ff_mjpeg_decode_dht(MJpegDecodeContext *s)
|
|||||||
code_max + 1, 0, 0)) < 0)
|
code_max + 1, 0, 0)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 16; i++)
|
||||||
|
s->raw_huffman_lengths[class][index][i] = bits_table[i + 1];
|
||||||
|
for (i = 0; i < 256; i++)
|
||||||
|
s->raw_huffman_values[class][index][i] = val_table[i];
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
|
int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
|
||||||
{
|
{
|
||||||
int len, nb_components, i, width, height, bits, ret;
|
int len, nb_components, i, width, height, bits, ret, size_change;
|
||||||
unsigned pix_fmt_id;
|
unsigned pix_fmt_id;
|
||||||
int h_count[MAX_COMPONENTS] = { 0 };
|
int h_count[MAX_COMPONENTS] = { 0 };
|
||||||
int v_count[MAX_COMPONENTS] = { 0 };
|
int v_count[MAX_COMPONENTS] = { 0 };
|
||||||
@@ -392,6 +399,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
|
|||||||
if (width != s->width || height != s->height || bits != s->bits ||
|
if (width != s->width || height != s->height || bits != s->bits ||
|
||||||
memcmp(s->h_count, h_count, sizeof(h_count)) ||
|
memcmp(s->h_count, h_count, sizeof(h_count)) ||
|
||||||
memcmp(s->v_count, v_count, sizeof(v_count))) {
|
memcmp(s->v_count, v_count, sizeof(v_count))) {
|
||||||
|
size_change = 1;
|
||||||
|
|
||||||
s->width = width;
|
s->width = width;
|
||||||
s->height = height;
|
s->height = height;
|
||||||
@@ -418,6 +426,8 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
s->first_picture = 0;
|
s->first_picture = 0;
|
||||||
|
} else {
|
||||||
|
size_change = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s->got_picture && s->interlaced && (s->bottom_field == !s->interlace_polarity)) {
|
if (s->got_picture && s->interlaced && (s->bottom_field == !s->interlace_polarity)) {
|
||||||
@@ -636,6 +646,21 @@ unk_pixfmt:
|
|||||||
return AVERROR_BUG;
|
return AVERROR_BUG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (s->avctx->pix_fmt == s->hwaccel_sw_pix_fmt && !size_change) {
|
||||||
|
s->avctx->pix_fmt = s->hwaccel_pix_fmt;
|
||||||
|
} else {
|
||||||
|
enum AVPixelFormat pix_fmts[] = {
|
||||||
|
s->avctx->pix_fmt,
|
||||||
|
AV_PIX_FMT_NONE,
|
||||||
|
};
|
||||||
|
s->hwaccel_pix_fmt = ff_get_format(s->avctx, pix_fmts);
|
||||||
|
if (s->hwaccel_pix_fmt < 0)
|
||||||
|
return AVERROR(EINVAL);
|
||||||
|
|
||||||
|
s->hwaccel_sw_pix_fmt = s->avctx->pix_fmt;
|
||||||
|
s->avctx->pix_fmt = s->hwaccel_pix_fmt;
|
||||||
|
}
|
||||||
|
|
||||||
if (s->avctx->skip_frame == AVDISCARD_ALL) {
|
if (s->avctx->skip_frame == AVDISCARD_ALL) {
|
||||||
s->picture_ptr->pict_type = AV_PICTURE_TYPE_I;
|
s->picture_ptr->pict_type = AV_PICTURE_TYPE_I;
|
||||||
s->picture_ptr->key_frame = 1;
|
s->picture_ptr->key_frame = 1;
|
||||||
@@ -683,6 +708,19 @@ unk_pixfmt:
|
|||||||
}
|
}
|
||||||
memset(s->coefs_finished, 0, sizeof(s->coefs_finished));
|
memset(s->coefs_finished, 0, sizeof(s->coefs_finished));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (s->avctx->hwaccel) {
|
||||||
|
s->hwaccel_picture_private =
|
||||||
|
av_mallocz(s->avctx->hwaccel->frame_priv_data_size);
|
||||||
|
if (!s->hwaccel_picture_private)
|
||||||
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
|
ret = s->avctx->hwaccel->start_frame(s->avctx, s->raw_image_buffer,
|
||||||
|
s->raw_image_buffer_size);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1510,7 +1548,6 @@ int ff_mjpeg_decode_sos(MJpegDecodeContext *s, const uint8_t *mb_bitmask,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
av_assert0(s->picture_ptr->data[0]);
|
|
||||||
/* XXX: verify len field validity */
|
/* XXX: verify len field validity */
|
||||||
len = get_bits(&s->gb, 16);
|
len = get_bits(&s->gb, 16);
|
||||||
nb_components = get_bits(&s->gb, 8);
|
nb_components = get_bits(&s->gb, 8);
|
||||||
@@ -1600,7 +1637,18 @@ next_field:
|
|||||||
for (i = 0; i < nb_components; i++)
|
for (i = 0; i < nb_components; i++)
|
||||||
s->last_dc[i] = (4 << s->bits);
|
s->last_dc[i] = (4 << s->bits);
|
||||||
|
|
||||||
if (s->lossless) {
|
if (s->avctx->hwaccel) {
|
||||||
|
int bytes_to_start = get_bits_count(&s->gb) / 8;
|
||||||
|
av_assert0(bytes_to_start >= 0 &&
|
||||||
|
s->raw_scan_buffer_size >= bytes_to_start);
|
||||||
|
|
||||||
|
ret = s->avctx->hwaccel->decode_slice(s->avctx,
|
||||||
|
s->raw_scan_buffer + bytes_to_start,
|
||||||
|
s->raw_scan_buffer_size - bytes_to_start);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
} else if (s->lossless) {
|
||||||
av_assert0(s->picture_ptr == s->picture);
|
av_assert0(s->picture_ptr == s->picture);
|
||||||
if (CONFIG_JPEGLS_DECODER && s->ls) {
|
if (CONFIG_JPEGLS_DECODER && s->ls) {
|
||||||
// for () {
|
// for () {
|
||||||
@@ -2278,6 +2326,8 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
|
|||||||
case SOI:
|
case SOI:
|
||||||
s->restart_interval = 0;
|
s->restart_interval = 0;
|
||||||
s->restart_count = 0;
|
s->restart_count = 0;
|
||||||
|
s->raw_image_buffer = buf_ptr;
|
||||||
|
s->raw_image_buffer_size = buf_end - buf_ptr;
|
||||||
/* nothing to do on SOI */
|
/* nothing to do on SOI */
|
||||||
break;
|
break;
|
||||||
case DHT:
|
case DHT:
|
||||||
@@ -2331,7 +2381,8 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
|
|||||||
break;
|
break;
|
||||||
case EOI:
|
case EOI:
|
||||||
eoi_parser:
|
eoi_parser:
|
||||||
if (avctx->skip_frame != AVDISCARD_ALL && s->progressive && s->cur_scan && s->got_picture)
|
if (!avctx->hwaccel && avctx->skip_frame != AVDISCARD_ALL &&
|
||||||
|
s->progressive && s->cur_scan && s->got_picture)
|
||||||
mjpeg_idct_scan_progressive_ac(s);
|
mjpeg_idct_scan_progressive_ac(s);
|
||||||
s->cur_scan = 0;
|
s->cur_scan = 0;
|
||||||
if (!s->got_picture) {
|
if (!s->got_picture) {
|
||||||
@@ -2349,6 +2400,13 @@ eoi_parser:
|
|||||||
s->got_picture = 0;
|
s->got_picture = 0;
|
||||||
goto the_end_no_picture;
|
goto the_end_no_picture;
|
||||||
}
|
}
|
||||||
|
if (s->avctx->hwaccel) {
|
||||||
|
ret = s->avctx->hwaccel->end_frame(s->avctx);
|
||||||
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
av_freep(&s->hwaccel_picture_private);
|
||||||
|
}
|
||||||
if ((ret = av_frame_ref(frame, s->picture_ptr)) < 0)
|
if ((ret = av_frame_ref(frame, s->picture_ptr)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
*got_frame = 1;
|
*got_frame = 1;
|
||||||
@@ -2371,6 +2429,9 @@ eoi_parser:
|
|||||||
|
|
||||||
goto the_end;
|
goto the_end;
|
||||||
case SOS:
|
case SOS:
|
||||||
|
s->raw_scan_buffer = buf_ptr;
|
||||||
|
s->raw_scan_buffer_size = buf_end - buf_ptr;
|
||||||
|
|
||||||
s->cur_scan++;
|
s->cur_scan++;
|
||||||
if (avctx->skip_frame == AVDISCARD_ALL) {
|
if (avctx->skip_frame == AVDISCARD_ALL) {
|
||||||
skip_bits(&s->gb, get_bits_left(&s->gb));
|
skip_bits(&s->gb, get_bits_left(&s->gb));
|
||||||
@@ -2673,6 +2734,8 @@ av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx)
|
|||||||
|
|
||||||
reset_icc_profile(s);
|
reset_icc_profile(s);
|
||||||
|
|
||||||
|
av_freep(&s->hwaccel_picture_private);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2713,6 +2776,9 @@ AVCodec ff_mjpeg_decoder = {
|
|||||||
.priv_class = &mjpegdec_class,
|
.priv_class = &mjpegdec_class,
|
||||||
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
|
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE |
|
||||||
FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
|
FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
|
||||||
|
.hw_configs = (const AVCodecHWConfigInternal*[]) {
|
||||||
|
NULL
|
||||||
|
},
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
#if CONFIG_THP_DECODER
|
#if CONFIG_THP_DECODER
|
||||||
|
@@ -137,6 +137,19 @@ typedef struct MJpegDecodeContext {
|
|||||||
int *iccdatalens;
|
int *iccdatalens;
|
||||||
int iccnum;
|
int iccnum;
|
||||||
int iccread;
|
int iccread;
|
||||||
|
|
||||||
|
// Raw stream data for hwaccel use.
|
||||||
|
const uint8_t *raw_image_buffer;
|
||||||
|
size_t raw_image_buffer_size;
|
||||||
|
const uint8_t *raw_scan_buffer;
|
||||||
|
size_t raw_scan_buffer_size;
|
||||||
|
|
||||||
|
uint8_t raw_huffman_lengths[2][4][16];
|
||||||
|
uint8_t raw_huffman_values[2][4][256];
|
||||||
|
|
||||||
|
enum AVPixelFormat hwaccel_sw_pix_fmt;
|
||||||
|
enum AVPixelFormat hwaccel_pix_fmt;
|
||||||
|
void *hwaccel_picture_private;
|
||||||
} MJpegDecodeContext;
|
} MJpegDecodeContext;
|
||||||
|
|
||||||
int ff_mjpeg_decode_init(AVCodecContext *avctx);
|
int ff_mjpeg_decode_init(AVCodecContext *avctx);
|
||||||
|
Reference in New Issue
Block a user