New upstream version 6.0

Signed-off-by: nyanmisaka <nst799610810@gmail.com>
This commit is contained in:
nyanmisaka
2023-03-02 23:02:27 +08:00
parent 797cae8267
commit a37e362e0f
2280 changed files with 112730 additions and 85641 deletions
+44 -31
View File
@@ -31,13 +31,11 @@
#include "libavutil/thread.h"
#include "avcodec.h"
#include "get_bits.h"
#include "bytestream.h"
#include "codec_internal.h"
#include "internal.h"
#include "decode.h"
#include "golomb.h"
#include "dirac_arith.h"
#include "dirac_vlc.h"
#include "mpeg12data.h"
#include "mpegpicture.h"
#include "mpegvideoencdsp.h"
#include "dirac_dwt.h"
@@ -79,6 +77,7 @@ typedef struct {
uint8_t *hpel[3][4];
uint8_t *hpel_base[3][4];
int reference;
unsigned picture_number;
} DiracFrame;
typedef struct {
@@ -254,13 +253,13 @@ static inline int divide3(int x)
return (int)((x+1U)*21845 + 10922) >> 16;
}
static DiracFrame *remove_frame(DiracFrame *framelist[], int picnum)
static DiracFrame *remove_frame(DiracFrame *framelist[], unsigned picnum)
{
DiracFrame *remove_pic = NULL;
int i, remove_idx = -1;
for (i = 0; framelist[i]; i++)
if (framelist[i]->avframe->display_picture_number == picnum) {
if (framelist[i]->picture_number == picnum) {
remove_pic = framelist[i];
remove_idx = i;
}
@@ -486,7 +485,7 @@ UNPACK_ARITH(10, int32_t)
* Decode the coeffs in the rectangle defined by left, right, top, bottom
* [DIRAC_STD] 13.4.3.2 Codeblock unpacking loop. codeblock()
*/
static inline int codeblock(DiracContext *s, SubBand *b,
static inline int codeblock(const DiracContext *s, SubBand *b,
GetBitContext *gb, DiracArith *c,
int left, int right, int top, int bottom,
int blockcnt_one, int is_arith)
@@ -596,7 +595,8 @@ INTRA_DC_PRED(10, uint32_t)
* Dirac Specification ->
* 13.4.2 Non-skipped subbands. subband_coeffs()
*/
static av_always_inline int decode_subband_internal(DiracContext *s, SubBand *b, int is_arith)
static av_always_inline int decode_subband_internal(const DiracContext *s,
SubBand *b, int is_arith)
{
int cb_x, cb_y, left, right, top, bottom;
DiracArith c;
@@ -640,13 +640,13 @@ static av_always_inline int decode_subband_internal(DiracContext *s, SubBand *b,
static int decode_subband_arith(AVCodecContext *avctx, void *b)
{
DiracContext *s = avctx->priv_data;
const DiracContext *s = avctx->priv_data;
return decode_subband_internal(s, b, 1);
}
static int decode_subband_golomb(AVCodecContext *avctx, void *arg)
{
DiracContext *s = avctx->priv_data;
const DiracContext *s = avctx->priv_data;
SubBand **b = arg;
return decode_subband_internal(s, *b, 0);
}
@@ -721,9 +721,9 @@ static int decode_component(DiracContext *s, int comp)
return; \
} \
static void decode_subband(DiracContext *s, GetBitContext *gb, int quant,
static void decode_subband(const DiracContext *s, GetBitContext *gb, int quant,
int slice_x, int slice_y, int bits_end,
SubBand *b1, SubBand *b2)
const SubBand *b1, const SubBand *b2)
{
int left = b1->width * slice_x / s->num_x;
int right = b1->width *(slice_x+1) / s->num_x;
@@ -775,7 +775,7 @@ static void decode_subband(DiracContext *s, GetBitContext *gb, int quant,
*/
static int decode_lowdelay_slice(AVCodecContext *avctx, void *arg)
{
DiracContext *s = avctx->priv_data;
const DiracContext *s = avctx->priv_data;
DiracSlice *slice = arg;
GetBitContext *gb = &slice->gb;
enum dirac_subband orientation;
@@ -819,13 +819,13 @@ typedef struct SliceCoeffs {
int tot;
} SliceCoeffs;
static int subband_coeffs(DiracContext *s, int x, int y, int p,
static int subband_coeffs(const DiracContext *s, int x, int y, int p,
SliceCoeffs c[MAX_DWT_LEVELS])
{
int level, coef = 0;
for (level = 0; level < s->wavelet_depth; level++) {
SliceCoeffs *o = &c[level];
SubBand *b = &s->plane[p].band[level][3]; /* orientation doens't matter */
const SubBand *b = &s->plane[p].band[level][3]; /* orientation doens't matter */
o->top = b->height * y / s->num_y;
o->left = b->width * x / s->num_x;
o->tot_h = ((b->width * (x + 1)) / s->num_x) - o->left;
@@ -840,7 +840,7 @@ static int subband_coeffs(DiracContext *s, int x, int y, int p,
* VC-2 Specification ->
* 13.5.3 hq_slice(sx,sy)
*/
static int decode_hq_slice(DiracContext *s, DiracSlice *slice, uint8_t *tmp_buf)
static int decode_hq_slice(const DiracContext *s, DiracSlice *slice, uint8_t *tmp_buf)
{
int i, level, orientation, quant_idx;
int qfactor[MAX_DWT_LEVELS][4], qoffset[MAX_DWT_LEVELS][4];
@@ -917,7 +917,7 @@ static int decode_hq_slice(DiracContext *s, DiracSlice *slice, uint8_t *tmp_buf)
static int decode_hq_slice_row(AVCodecContext *avctx, void *arg, int jobnr, int threadnr)
{
int i;
DiracContext *s = avctx->priv_data;
const DiracContext *s = avctx->priv_data;
DiracSlice *slices = ((DiracSlice *)arg) + s->num_x*jobnr;
uint8_t *thread_buf = &s->thread_buf[s->thread_buf_size*threadnr];
for (i = 0; i < s->num_x; i++)
@@ -2003,7 +2003,7 @@ static int dirac_decode_picture_header(DiracContext *s)
GetBitContext *gb = &s->gb;
/* [DIRAC_STD] 11.1.1 Picture Header. picture_header() PICTURE_NUM */
picnum = s->current_picture->avframe->display_picture_number = get_bits_long(gb, 32);
picnum = s->current_picture->picture_number = get_bits_long(gb, 32);
av_log(s->avctx,AV_LOG_DEBUG,"PICTURE_NUM: %d\n",picnum);
@@ -2022,9 +2022,9 @@ static int dirac_decode_picture_header(DiracContext *s)
/* Jordi: this is needed if the referenced picture hasn't yet arrived */
for (j = 0; j < MAX_REFERENCE_FRAMES && refdist; j++)
if (s->ref_frames[j]
&& FFABS(s->ref_frames[j]->avframe->display_picture_number - refnum) < refdist) {
&& FFABS(s->ref_frames[j]->picture_number - refnum) < refdist) {
s->ref_pics[i] = s->ref_frames[j];
refdist = FFABS(s->ref_frames[j]->avframe->display_picture_number - refnum);
refdist = FFABS(s->ref_frames[j]->picture_number - refnum);
}
if (!s->ref_pics[i] || refdist)
@@ -2063,7 +2063,7 @@ static int dirac_decode_picture_header(DiracContext *s)
/* if reference array is full, remove the oldest as per the spec */
while (add_frame(s->ref_frames, MAX_REFERENCE_FRAMES, s->current_picture)) {
av_log(s->avctx, AV_LOG_ERROR, "Reference frame overflow\n");
remove_frame(s->ref_frames, s->ref_frames[0]->avframe->display_picture_number)->reference &= DELAYED_PIC_REF;
remove_frame(s->ref_frames, s->ref_frames[0]->picture_number)->reference &= DELAYED_PIC_REF;
}
}
@@ -2091,7 +2091,7 @@ static int get_delayed_pic(DiracContext *s, AVFrame *picture, int *got_frame)
/* find frame with lowest picture number */
for (i = 1; s->delay_frames[i]; i++)
if (s->delay_frames[i]->avframe->display_picture_number < out->avframe->display_picture_number) {
if (s->delay_frames[i]->picture_number < out->picture_number) {
out = s->delay_frames[i];
out_idx = i;
}
@@ -2103,6 +2103,11 @@ static int get_delayed_pic(DiracContext *s, AVFrame *picture, int *got_frame)
out->reference ^= DELAYED_PIC_REF;
if((ret = av_frame_ref(picture, out->avframe)) < 0)
return ret;
#if FF_API_FRAME_PICTURE_NUMBER
FF_DISABLE_DEPRECATION_WARNINGS
picture->display_picture_number = out->picture_number;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
*got_frame = 1;
}
@@ -2319,19 +2324,19 @@ static int dirac_decode_frame(AVCodecContext *avctx, AVFrame *picture,
if (!s->current_picture)
return buf_size;
if (s->current_picture->avframe->display_picture_number > s->frame_number) {
if (s->current_picture->picture_number > s->frame_number) {
DiracFrame *delayed_frame = remove_frame(s->delay_frames, s->frame_number);
s->current_picture->reference |= DELAYED_PIC_REF;
if (add_frame(s->delay_frames, MAX_DELAY, s->current_picture)) {
int min_num = s->delay_frames[0]->avframe->display_picture_number;
unsigned min_num = s->delay_frames[0]->picture_number;
/* Too many delayed frames, so we display the frame with the lowest pts */
av_log(avctx, AV_LOG_ERROR, "Delay frame overflow\n");
for (i = 1; s->delay_frames[i]; i++)
if (s->delay_frames[i]->avframe->display_picture_number < min_num)
min_num = s->delay_frames[i]->avframe->display_picture_number;
if (s->delay_frames[i]->picture_number < min_num)
min_num = s->delay_frames[i]->picture_number;
delayed_frame = remove_frame(s->delay_frames, min_num);
add_frame(s->delay_frames, MAX_DELAY, s->current_picture);
@@ -2341,24 +2346,33 @@ static int dirac_decode_frame(AVCodecContext *avctx, AVFrame *picture,
delayed_frame->reference ^= DELAYED_PIC_REF;
if((ret = av_frame_ref(picture, delayed_frame->avframe)) < 0)
return ret;
s->frame_number = delayed_frame->picture_number + 1LL;
#if FF_API_FRAME_PICTURE_NUMBER
FF_DISABLE_DEPRECATION_WARNINGS
picture->display_picture_number = delayed_frame->picture_number;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
*got_frame = 1;
}
} else if (s->current_picture->avframe->display_picture_number == s->frame_number) {
} else if (s->current_picture->picture_number == s->frame_number) {
/* The right frame at the right time :-) */
if((ret = av_frame_ref(picture, s->current_picture->avframe)) < 0)
return ret;
s->frame_number = s->current_picture->picture_number + 1LL;
#if FF_API_FRAME_PICTURE_NUMBER
FF_DISABLE_DEPRECATION_WARNINGS
picture->display_picture_number = s->current_picture->picture_number;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
*got_frame = 1;
}
if (*got_frame)
s->frame_number = picture->display_picture_number + 1LL;
return buf_idx;
}
const FFCodec ff_dirac_decoder = {
.p.name = "dirac",
.p.long_name = NULL_IF_CONFIG_SMALL("BBC Dirac VC-2"),
CODEC_LONG_NAME("BBC Dirac VC-2"),
.p.type = AVMEDIA_TYPE_VIDEO,
.p.id = AV_CODEC_ID_DIRAC,
.priv_data_size = sizeof(DiracContext),
@@ -2366,6 +2380,5 @@ const FFCodec ff_dirac_decoder = {
.close = dirac_decode_end,
FF_CODEC_DECODE_CB(dirac_decode_frame),
.p.capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_DR1,
.caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
.flush = dirac_decode_flush,
};