Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
89ef08c9
Commit
89ef08c9
authored
Mar 28, 2014
by
Vittorio Giovara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DNxHD: K&R formatting cosmetics
parent
a7448064
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
319 additions
and
210 deletions
+319
-210
dnxhd_parser.c
libavcodec/dnxhd_parser.c
+5
-5
dnxhddata.c
libavcodec/dnxhddata.c
+1
-1
dnxhddec.c
libavcodec/dnxhddec.c
+31
-22
dnxhdenc.c
libavcodec/dnxhdenc.c
+282
-182
No files found.
libavcodec/dnxhd_parser.c
View file @
89ef08c9
...
@@ -37,7 +37,7 @@ static int dnxhd_find_frame_end(ParseContext *pc,
...
@@ -37,7 +37,7 @@ static int dnxhd_find_frame_end(ParseContext *pc,
if
(
!
pic_found
)
{
if
(
!
pic_found
)
{
for
(
i
=
0
;
i
<
buf_size
;
i
++
)
{
for
(
i
=
0
;
i
<
buf_size
;
i
++
)
{
state
=
(
state
<<
8
)
|
buf
[
i
];
state
=
(
state
<<
8
)
|
buf
[
i
];
if
((
state
&
0xffffffffffLL
)
==
DNXHD_HEADER_PREFIX
)
{
if
((
state
&
0xffffffffffLL
)
==
DNXHD_HEADER_PREFIX
)
{
i
++
;
i
++
;
pic_found
=
1
;
pic_found
=
1
;
...
@@ -50,11 +50,11 @@ static int dnxhd_find_frame_end(ParseContext *pc,
...
@@ -50,11 +50,11 @@ static int dnxhd_find_frame_end(ParseContext *pc,
if
(
!
buf_size
)
/* EOF considered as end of frame */
if
(
!
buf_size
)
/* EOF considered as end of frame */
return
0
;
return
0
;
for
(;
i
<
buf_size
;
i
++
)
{
for
(;
i
<
buf_size
;
i
++
)
{
state
=
(
state
<<
8
)
|
buf
[
i
];
state
=
(
state
<<
8
)
|
buf
[
i
];
if
((
state
&
0xffffffffffLL
)
==
DNXHD_HEADER_PREFIX
)
{
if
((
state
&
0xffffffffffLL
)
==
DNXHD_HEADER_PREFIX
)
{
pc
->
frame_start_found
=
0
;
pc
->
frame_start_found
=
0
;
pc
->
state64
=
-
1
;
pc
->
state64
=
-
1
;
return
i
-
4
;
return
i
-
4
;
}
}
}
}
}
}
...
...
libavcodec/dnxhddata.c
View file @
89ef08c9
...
@@ -1165,7 +1165,7 @@ int ff_dnxhd_get_cid_table(int cid)
...
@@ -1165,7 +1165,7 @@ int ff_dnxhd_get_cid_table(int cid)
int
ff_dnxhd_find_cid
(
AVCodecContext
*
avctx
,
int
bit_depth
)
int
ff_dnxhd_find_cid
(
AVCodecContext
*
avctx
,
int
bit_depth
)
{
{
int
i
,
j
;
int
i
,
j
;
int
mbs
=
avctx
->
bit_rate
/
1000000
;
int
mbs
=
avctx
->
bit_rate
/
1000000
;
if
(
!
mbs
)
if
(
!
mbs
)
return
0
;
return
0
;
for
(
i
=
0
;
i
<
FF_ARRAY_ELEMS
(
ff_dnxhd_cid_table
);
i
++
)
{
for
(
i
=
0
;
i
<
FF_ARRAY_ELEMS
(
ff_dnxhd_cid_table
);
i
++
)
{
...
...
libavcodec/dnxhddec.c
View file @
89ef08c9
...
@@ -53,9 +53,12 @@ typedef struct DNXHDContext {
...
@@ -53,9 +53,12 @@ typedef struct DNXHDContext {
#define DNXHD_VLC_BITS 9
#define DNXHD_VLC_BITS 9
#define DNXHD_DC_VLC_BITS 7
#define DNXHD_DC_VLC_BITS 7
static
void
dnxhd_decode_dct_block_8
(
DNXHDContext
*
ctx
,
int16_t
*
block
,
int
n
,
int
qscale
);
static
void
dnxhd_decode_dct_block_8
(
DNXHDContext
*
ctx
,
int16_t
*
block
,
static
void
dnxhd_decode_dct_block_10
(
DNXHDContext
*
ctx
,
int16_t
*
block
,
int
n
,
int
qscale
);
int
n
,
int
qscale
);
static
void
dnxhd_decode_dct_block_10_444
(
DNXHDContext
*
ctx
,
int16_t
*
block
,
int
n
,
int
qscale
);
static
void
dnxhd_decode_dct_block_10
(
DNXHDContext
*
ctx
,
int16_t
*
block
,
int
n
,
int
qscale
);
static
void
dnxhd_decode_dct_block_10_444
(
DNXHDContext
*
ctx
,
int16_t
*
block
,
int
n
,
int
qscale
);
static
av_cold
int
dnxhd_decode_init
(
AVCodecContext
*
avctx
)
static
av_cold
int
dnxhd_decode_init
(
AVCodecContext
*
avctx
)
{
{
...
@@ -90,14 +93,16 @@ static int dnxhd_init_vlc(DNXHDContext *ctx, int cid)
...
@@ -90,14 +93,16 @@ static int dnxhd_init_vlc(DNXHDContext *ctx, int cid)
ctx
->
cid_table
->
run_bits
,
1
,
1
,
ctx
->
cid_table
->
run_bits
,
1
,
1
,
ctx
->
cid_table
->
run_codes
,
2
,
2
,
0
);
ctx
->
cid_table
->
run_codes
,
2
,
2
,
0
);
ff_init_scantable
(
ctx
->
dsp
.
idct_permutation
,
&
ctx
->
scantable
,
ff_zigzag_direct
);
ff_init_scantable
(
ctx
->
dsp
.
idct_permutation
,
&
ctx
->
scantable
,
ff_zigzag_direct
);
ctx
->
cid
=
cid
;
ctx
->
cid
=
cid
;
}
}
return
0
;
return
0
;
}
}
static
int
dnxhd_decode_header
(
DNXHDContext
*
ctx
,
AVFrame
*
frame
,
static
int
dnxhd_decode_header
(
DNXHDContext
*
ctx
,
AVFrame
*
frame
,
const
uint8_t
*
buf
,
int
buf_size
,
int
first_field
)
const
uint8_t
*
buf
,
int
buf_size
,
int
first_field
)
{
{
static
const
uint8_t
header_prefix
[]
=
{
0x00
,
0x00
,
0x02
,
0x80
,
0x01
};
static
const
uint8_t
header_prefix
[]
=
{
0x00
,
0x00
,
0x02
,
0x80
,
0x01
};
static
const
uint8_t
header_prefix444
[]
=
{
0x00
,
0x00
,
0x02
,
0x80
,
0x02
};
static
const
uint8_t
header_prefix444
[]
=
{
0x00
,
0x00
,
0x02
,
0x80
,
0x02
};
...
@@ -114,7 +119,8 @@ static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame,
...
@@ -114,7 +119,8 @@ static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame,
ctx
->
cur_field
=
buf
[
5
]
&
1
;
ctx
->
cur_field
=
buf
[
5
]
&
1
;
frame
->
interlaced_frame
=
1
;
frame
->
interlaced_frame
=
1
;
frame
->
top_field_first
=
first_field
^
ctx
->
cur_field
;
frame
->
top_field_first
=
first_field
^
ctx
->
cur_field
;
av_log
(
ctx
->
avctx
,
AV_LOG_DEBUG
,
"interlaced %d, cur field %d
\n
"
,
buf
[
5
]
&
3
,
ctx
->
cur_field
);
av_log
(
ctx
->
avctx
,
AV_LOG_DEBUG
,
"interlaced %d, cur field %d
\n
"
,
buf
[
5
]
&
3
,
ctx
->
cur_field
);
}
}
ctx
->
height
=
AV_RB16
(
buf
+
0x18
);
ctx
->
height
=
AV_RB16
(
buf
+
0x18
);
...
@@ -161,22 +167,24 @@ static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame,
...
@@ -161,22 +167,24 @@ static int dnxhd_decode_header(DNXHDContext *ctx, AVFrame *frame,
return
AVERROR_INVALIDDATA
;
return
AVERROR_INVALIDDATA
;
}
}
ctx
->
mb_width
=
ctx
->
width
>>
4
;
ctx
->
mb_width
=
ctx
->
width
>>
4
;
ctx
->
mb_height
=
buf
[
0x16d
];
ctx
->
mb_height
=
buf
[
0x16d
];
av_dlog
(
ctx
->
avctx
,
"mb width %d, mb height %d
\n
"
,
ctx
->
mb_width
,
ctx
->
mb_height
);
av_dlog
(
ctx
->
avctx
,
"mb width %d, mb height %d
\n
"
,
ctx
->
mb_width
,
ctx
->
mb_height
);
if
((
ctx
->
height
+
15
)
>>
4
==
ctx
->
mb_height
&&
frame
->
interlaced_frame
)
if
((
ctx
->
height
+
15
)
>>
4
==
ctx
->
mb_height
&&
frame
->
interlaced_frame
)
ctx
->
height
<<=
1
;
ctx
->
height
<<=
1
;
if
(
ctx
->
mb_height
>
68
||
if
(
ctx
->
mb_height
>
68
||
(
ctx
->
mb_height
<<
frame
->
interlaced_frame
)
>
(
ctx
->
height
+
15
)
>>
4
)
{
(
ctx
->
mb_height
<<
frame
->
interlaced_frame
)
>
(
ctx
->
height
+
15
)
>>
4
)
{
av_log
(
ctx
->
avctx
,
AV_LOG_ERROR
,
"mb height too big: %d
\n
"
,
ctx
->
mb_height
);
av_log
(
ctx
->
avctx
,
AV_LOG_ERROR
,
"mb height too big: %d
\n
"
,
ctx
->
mb_height
);
return
AVERROR_INVALIDDATA
;
return
AVERROR_INVALIDDATA
;
}
}
for
(
i
=
0
;
i
<
ctx
->
mb_height
;
i
++
)
{
for
(
i
=
0
;
i
<
ctx
->
mb_height
;
i
++
)
{
ctx
->
mb_scan_index
[
i
]
=
AV_RB32
(
buf
+
0x170
+
(
i
<<
2
));
ctx
->
mb_scan_index
[
i
]
=
AV_RB32
(
buf
+
0x170
+
(
i
<<
2
));
av_dlog
(
ctx
->
avctx
,
"mb scan index %d
\n
"
,
ctx
->
mb_scan_index
[
i
]);
av_dlog
(
ctx
->
avctx
,
"mb scan index %d
\n
"
,
ctx
->
mb_scan_index
[
i
]);
if
(
buf_size
<
ctx
->
mb_scan_index
[
i
]
+
0x280
)
{
if
(
buf_size
<
ctx
->
mb_scan_index
[
i
]
+
0x280
)
{
av_log
(
ctx
->
avctx
,
AV_LOG_ERROR
,
"invalid mb scan index
\n
"
);
av_log
(
ctx
->
avctx
,
AV_LOG_ERROR
,
"invalid mb scan index
\n
"
);
...
@@ -200,8 +208,8 @@ static av_always_inline void dnxhd_decode_dct_block(DNXHDContext *ctx,
...
@@ -200,8 +208,8 @@ static av_always_inline void dnxhd_decode_dct_block(DNXHDContext *ctx,
OPEN_READER
(
bs
,
&
ctx
->
gb
);
OPEN_READER
(
bs
,
&
ctx
->
gb
);
if
(
!
ctx
->
is_444
)
{
if
(
!
ctx
->
is_444
)
{
if
(
n
&
2
)
{
if
(
n
&
2
)
{
component
=
1
+
(
n
&
1
);
component
=
1
+
(
n
&
1
);
weight_matrix
=
ctx
->
cid_table
->
chroma_weight
;
weight_matrix
=
ctx
->
cid_table
->
chroma_weight
;
}
else
{
}
else
{
component
=
0
;
component
=
0
;
...
@@ -256,12 +264,12 @@ static av_always_inline void dnxhd_decode_dct_block(DNXHDContext *ctx,
...
@@ -256,12 +264,12 @@ static av_always_inline void dnxhd_decode_dct_block(DNXHDContext *ctx,
}
}
j
=
ctx
->
scantable
.
permutated
[
i
];
j
=
ctx
->
scantable
.
permutated
[
i
];
level
=
(
2
*
level
+
1
)
*
qscale
*
weight_matrix
[
i
];
level
=
(
2
*
level
+
1
)
*
qscale
*
weight_matrix
[
i
];
if
(
level_bias
<
32
||
weight_matrix
[
i
]
!=
level_bias
)
if
(
level_bias
<
32
||
weight_matrix
[
i
]
!=
level_bias
)
level
+=
level_bias
;
level
+=
level_bias
;
level
>>=
level_shift
;
level
>>=
level_shift
;
block
[
j
]
=
(
level
^
sign
)
-
sign
;
block
[
j
]
=
(
level
^
sign
)
-
sign
;
}
}
CLOSE_READER
(
bs
,
&
ctx
->
gb
);
CLOSE_READER
(
bs
,
&
ctx
->
gb
);
...
@@ -285,7 +293,8 @@ static void dnxhd_decode_dct_block_10_444(DNXHDContext *ctx, int16_t *block,
...
@@ -285,7 +293,8 @@ static void dnxhd_decode_dct_block_10_444(DNXHDContext *ctx, int16_t *block,
dnxhd_decode_dct_block
(
ctx
,
block
,
n
,
qscale
,
6
,
32
,
6
);
dnxhd_decode_dct_block
(
ctx
,
block
,
n
,
qscale
,
6
,
32
,
6
);
}
}
static
int
dnxhd_decode_macroblock
(
DNXHDContext
*
ctx
,
AVFrame
*
frame
,
int
x
,
int
y
)
static
int
dnxhd_decode_macroblock
(
DNXHDContext
*
ctx
,
AVFrame
*
frame
,
int
x
,
int
y
)
{
{
int
shift1
=
ctx
->
bit_depth
==
10
;
int
shift1
=
ctx
->
bit_depth
==
10
;
int
dct_linesize_luma
=
frame
->
linesize
[
0
];
int
dct_linesize_luma
=
frame
->
linesize
[
0
];
...
@@ -378,8 +387,8 @@ static int dnxhd_decode_macroblocks(DNXHDContext *ctx, AVFrame *frame,
...
@@ -378,8 +387,8 @@ static int dnxhd_decode_macroblocks(DNXHDContext *ctx, AVFrame *frame,
return
0
;
return
0
;
}
}
static
int
dnxhd_decode_frame
(
AVCodecContext
*
avctx
,
void
*
data
,
int
*
got_frame
,
static
int
dnxhd_decode_frame
(
AVCodecContext
*
avctx
,
void
*
data
,
AVPacket
*
avpkt
)
int
*
got_frame
,
AVPacket
*
avpkt
)
{
{
const
uint8_t
*
buf
=
avpkt
->
data
;
const
uint8_t
*
buf
=
avpkt
->
data
;
int
buf_size
=
avpkt
->
size
;
int
buf_size
=
avpkt
->
size
;
...
@@ -390,7 +399,7 @@ static int dnxhd_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
...
@@ -390,7 +399,7 @@ static int dnxhd_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
av_dlog
(
avctx
,
"frame size %d
\n
"
,
buf_size
);
av_dlog
(
avctx
,
"frame size %d
\n
"
,
buf_size
);
decode_coding_unit:
decode_coding_unit:
if
((
ret
=
dnxhd_decode_header
(
ctx
,
picture
,
buf
,
buf_size
,
first_field
))
<
0
)
if
((
ret
=
dnxhd_decode_header
(
ctx
,
picture
,
buf
,
buf_size
,
first_field
))
<
0
)
return
ret
;
return
ret
;
...
...
libavcodec/dnxhdenc.c
View file @
89ef08c9
...
@@ -23,37 +23,50 @@
...
@@ -23,37 +23,50 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
*/
#define RC_VARIANCE 1 // use variance or ssd for fast rc
#include "libavutil/attributes.h"
#include "libavutil/attributes.h"
#include "libavutil/internal.h"
#include "libavutil/internal.h"
#include "libavutil/opt.h"
#include "libavutil/opt.h"
#include "libavutil/timer.h"
#include "libavutil/timer.h"
#include "avcodec.h"
#include "avcodec.h"
#include "dsputil.h"
#include "dsputil.h"
#include "internal.h"
#include "internal.h"
#include "mpegvideo.h"
#include "mpegvideo.h"
#include "dnxhdenc.h"
#include "dnxhdenc.h"
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
// The largest value that will not lead to overflow for 10bit samples.
#define DNX10BIT_QMAT_SHIFT 18 // The largest value that will not lead to overflow for 10bit samples.
#define DNX10BIT_QMAT_SHIFT 18
#define RC_VARIANCE 1 // use variance or ssd for fast rc
#define LAMBDA_FRAC_BITS 10
static
const
AVOption
options
[]
=
{
#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
{
"nitris_compat"
,
"encode with Avid Nitris compatibility"
,
offsetof
(
DNXHDEncContext
,
nitris_compat
),
AV_OPT_TYPE_INT
,
{.
i64
=
0
},
0
,
1
,
VE
},
static
const
AVOption
options
[]
=
{
{
NULL
}
{
"nitris_compat"
,
"encode with Avid Nitris compatibility"
,
offsetof
(
DNXHDEncContext
,
nitris_compat
),
AV_OPT_TYPE_INT
,
{
.
i64
=
0
},
0
,
1
,
VE
},
{
NULL
}
};
};
static
const
AVClass
class
=
{
"dnxhd"
,
av_default_item_name
,
options
,
LIBAVUTIL_VERSION_INT
};
#define LAMBDA_FRAC_BITS 10
static
const
AVClass
class
=
{
"dnxhd"
,
av_default_item_name
,
options
,
LIBAVUTIL_VERSION_INT
};
static
void
dnxhd_8bit_get_pixels_8x4_sym
(
int16_t
*
restrict
block
,
const
uint8_t
*
pixels
,
int
line_size
)
static
void
dnxhd_8bit_get_pixels_8x4_sym
(
int16_t
*
restrict
block
,
const
uint8_t
*
pixels
,
int
line_size
)
{
{
int
i
;
int
i
;
for
(
i
=
0
;
i
<
4
;
i
++
)
{
for
(
i
=
0
;
i
<
4
;
i
++
)
{
block
[
0
]
=
pixels
[
0
];
block
[
1
]
=
pixels
[
1
];
block
[
0
]
=
pixels
[
0
];
block
[
2
]
=
pixels
[
2
];
block
[
3
]
=
pixels
[
3
];
block
[
1
]
=
pixels
[
1
];
block
[
4
]
=
pixels
[
4
];
block
[
5
]
=
pixels
[
5
];
block
[
2
]
=
pixels
[
2
];
block
[
6
]
=
pixels
[
6
];
block
[
7
]
=
pixels
[
7
];
block
[
3
]
=
pixels
[
3
];
block
[
4
]
=
pixels
[
4
];
block
[
5
]
=
pixels
[
5
];
block
[
6
]
=
pixels
[
6
];
block
[
7
]
=
pixels
[
7
];
pixels
+=
line_size
;
pixels
+=
line_size
;
block
+=
8
;
block
+=
8
;
}
}
...
@@ -63,7 +76,10 @@ static void dnxhd_8bit_get_pixels_8x4_sym(int16_t *restrict block, const uint8_t
...
@@ -63,7 +76,10 @@ static void dnxhd_8bit_get_pixels_8x4_sym(int16_t *restrict block, const uint8_t
memcpy
(
block
+
24
,
block
-
32
,
sizeof
(
*
block
)
*
8
);
memcpy
(
block
+
24
,
block
-
32
,
sizeof
(
*
block
)
*
8
);
}
}
static
av_always_inline
void
dnxhd_10bit_get_pixels_8x4_sym
(
int16_t
*
restrict
block
,
const
uint8_t
*
pixels
,
int
line_size
)
static
av_always_inline
void
dnxhd_10bit_get_pixels_8x4_sym
(
int16_t
*
restrict
block
,
const
uint8_t
*
pixels
,
int
line_size
)
{
{
int
i
;
int
i
;
...
@@ -71,7 +87,7 @@ static av_always_inline void dnxhd_10bit_get_pixels_8x4_sym(int16_t *restrict bl
...
@@ -71,7 +87,7 @@ static av_always_inline void dnxhd_10bit_get_pixels_8x4_sym(int16_t *restrict bl
for
(
i
=
0
;
i
<
4
;
i
++
)
{
for
(
i
=
0
;
i
<
4
;
i
++
)
{
memcpy
(
block
+
i
*
8
,
pixels
+
i
*
line_size
,
8
*
sizeof
(
*
block
));
memcpy
(
block
+
i
*
8
,
pixels
+
i
*
line_size
,
8
*
sizeof
(
*
block
));
memcpy
(
block
-
(
i
+
1
)
*
8
,
pixels
+
i
*
line_size
,
8
*
sizeof
(
*
block
));
memcpy
(
block
-
(
i
+
1
)
*
8
,
pixels
+
i
*
line_size
,
8
*
sizeof
(
*
block
));
}
}
}
}
...
@@ -104,24 +120,28 @@ static int dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int16_t *block,
...
@@ -104,24 +120,28 @@ static int dnxhd_10bit_dct_quantize(MpegEncContext *ctx, int16_t *block,
static
av_cold
int
dnxhd_init_vlc
(
DNXHDEncContext
*
ctx
)
static
av_cold
int
dnxhd_init_vlc
(
DNXHDEncContext
*
ctx
)
{
{
int
i
,
j
,
level
,
run
;
int
i
,
j
,
level
,
run
;
int
max_level
=
1
<<
(
ctx
->
cid_table
->
bit_depth
+
2
);
int
max_level
=
1
<<
(
ctx
->
cid_table
->
bit_depth
+
2
);
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
vlc_codes
,
max_level
*
4
*
sizeof
(
*
ctx
->
vlc_codes
),
fail
);
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
vlc_codes
,
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
vlc_bits
,
max_level
*
4
*
sizeof
(
*
ctx
->
vlc_bits
)
,
fail
);
max_level
*
4
*
sizeof
(
*
ctx
->
vlc_codes
),
fail
);
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
run_codes
,
63
*
2
,
fail
);
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
vlc_bits
,
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
run_bits
,
63
,
fail
);
max_level
*
4
*
sizeof
(
*
ctx
->
vlc_bits
),
fail
);
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
run_codes
,
ctx
->
vlc_codes
+=
max_level
*
2
;
63
*
2
,
fail
);
ctx
->
vlc_bits
+=
max_level
*
2
;
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
run_bits
,
63
,
fail
);
ctx
->
vlc_codes
+=
max_level
*
2
;
ctx
->
vlc_bits
+=
max_level
*
2
;
for
(
level
=
-
max_level
;
level
<
max_level
;
level
++
)
{
for
(
level
=
-
max_level
;
level
<
max_level
;
level
++
)
{
for
(
run
=
0
;
run
<
2
;
run
++
)
{
for
(
run
=
0
;
run
<
2
;
run
++
)
{
int
index
=
(
level
<<
1
)
|
run
;
int
index
=
(
level
<<
1
)
|
run
;
int
sign
,
offset
=
0
,
alevel
=
level
;
int
sign
,
offset
=
0
,
alevel
=
level
;
MASK_ABS
(
sign
,
alevel
);
MASK_ABS
(
sign
,
alevel
);
if
(
alevel
>
64
)
{
if
(
alevel
>
64
)
{
offset
=
(
alevel
-
1
)
>>
6
;
offset
=
(
alevel
-
1
)
>>
6
;
alevel
-=
offset
<<
6
;
alevel
-=
offset
<<
6
;
}
}
for
(
j
=
0
;
j
<
257
;
j
++
)
{
for
(
j
=
0
;
j
<
257
;
j
++
)
{
if
(
ctx
->
cid_table
->
ac_level
[
j
]
==
alevel
&&
if
(
ctx
->
cid_table
->
ac_level
[
j
]
==
alevel
&&
...
@@ -129,19 +149,21 @@ static av_cold int dnxhd_init_vlc(DNXHDEncContext *ctx)
...
@@ -129,19 +149,21 @@ static av_cold int dnxhd_init_vlc(DNXHDEncContext *ctx)
(
!
run
||
(
ctx
->
cid_table
->
ac_run_flag
[
j
]
&&
run
)))
{
(
!
run
||
(
ctx
->
cid_table
->
ac_run_flag
[
j
]
&&
run
)))
{
assert
(
!
ctx
->
vlc_codes
[
index
]);
assert
(
!
ctx
->
vlc_codes
[
index
]);
if
(
alevel
)
{
if
(
alevel
)
{
ctx
->
vlc_codes
[
index
]
=
(
ctx
->
cid_table
->
ac_codes
[
j
]
<<
1
)
|
(
sign
&
1
);
ctx
->
vlc_codes
[
index
]
=
ctx
->
vlc_bits
[
index
]
=
ctx
->
cid_table
->
ac_bits
[
j
]
+
1
;
(
ctx
->
cid_table
->
ac_codes
[
j
]
<<
1
)
|
(
sign
&
1
);
ctx
->
vlc_bits
[
index
]
=
ctx
->
cid_table
->
ac_bits
[
j
]
+
1
;
}
else
{
}
else
{
ctx
->
vlc_codes
[
index
]
=
ctx
->
cid_table
->
ac_codes
[
j
];
ctx
->
vlc_codes
[
index
]
=
ctx
->
cid_table
->
ac_codes
[
j
];
ctx
->
vlc_bits
[
index
]
=
ctx
->
cid_table
->
ac_bits
[
j
];
ctx
->
vlc_bits
[
index
]
=
ctx
->
cid_table
->
ac_bits
[
j
];
}
}
break
;
break
;
}
}
}
}
assert
(
!
alevel
||
j
<
257
);
assert
(
!
alevel
||
j
<
257
);
if
(
offset
)
{
if
(
offset
)
{
ctx
->
vlc_codes
[
index
]
=
(
ctx
->
vlc_codes
[
index
]
<<
ctx
->
cid_table
->
index_bits
)
|
offset
;
ctx
->
vlc_codes
[
index
]
=
ctx
->
vlc_bits
[
index
]
+=
ctx
->
cid_table
->
index_bits
;
(
ctx
->
vlc_codes
[
index
]
<<
ctx
->
cid_table
->
index_bits
)
|
offset
;
ctx
->
vlc_bits
[
index
]
+=
ctx
->
cid_table
->
index_bits
;
}
}
}
}
}
}
...
@@ -149,45 +171,56 @@ static av_cold int dnxhd_init_vlc(DNXHDEncContext *ctx)
...
@@ -149,45 +171,56 @@ static av_cold int dnxhd_init_vlc(DNXHDEncContext *ctx)
int
run
=
ctx
->
cid_table
->
run
[
i
];
int
run
=
ctx
->
cid_table
->
run
[
i
];
assert
(
run
<
63
);
assert
(
run
<
63
);
ctx
->
run_codes
[
run
]
=
ctx
->
cid_table
->
run_codes
[
i
];
ctx
->
run_codes
[
run
]
=
ctx
->
cid_table
->
run_codes
[
i
];
ctx
->
run_bits
[
run
]
=
ctx
->
cid_table
->
run_bits
[
i
];
ctx
->
run_bits
[
run
]
=
ctx
->
cid_table
->
run_bits
[
i
];
}
}
return
0
;
return
0
;
fail:
fail:
return
AVERROR
(
ENOMEM
);
return
AVERROR
(
ENOMEM
);
}
}
static
av_cold
int
dnxhd_init_qmat
(
DNXHDEncContext
*
ctx
,
int
lbias
,
int
cbias
)
static
av_cold
int
dnxhd_init_qmat
(
DNXHDEncContext
*
ctx
,
int
lbias
,
int
cbias
)
{
{
// init first elem to 1 to avoid div by 0 in convert_matrix
// init first elem to 1 to avoid div by 0 in convert_matrix
uint16_t
weight_matrix
[
64
]
=
{
1
,
};
// convert_matrix needs uint16_t*
uint16_t
weight_matrix
[
64
]
=
{
1
,
};
// convert_matrix needs uint16_t*
int
qscale
,
i
;
int
qscale
,
i
;
const
uint8_t
*
luma_weight_table
=
ctx
->
cid_table
->
luma_weight
;
const
uint8_t
*
luma_weight_table
=
ctx
->
cid_table
->
luma_weight
;
const
uint8_t
*
chroma_weight_table
=
ctx
->
cid_table
->
chroma_weight
;
const
uint8_t
*
chroma_weight_table
=
ctx
->
cid_table
->
chroma_weight
;
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
qmatrix_l
,
(
ctx
->
m
.
avctx
->
qmax
+
1
)
*
64
*
sizeof
(
int
),
fail
);
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
qmatrix_l
,
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
qmatrix_c
,
(
ctx
->
m
.
avctx
->
qmax
+
1
)
*
64
*
sizeof
(
int
),
fail
);
(
ctx
->
m
.
avctx
->
qmax
+
1
)
*
64
*
sizeof
(
int
),
fail
);
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
qmatrix_l16
,
(
ctx
->
m
.
avctx
->
qmax
+
1
)
*
64
*
2
*
sizeof
(
uint16_t
),
fail
);
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
qmatrix_c
,
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
qmatrix_c16
,
(
ctx
->
m
.
avctx
->
qmax
+
1
)
*
64
*
2
*
sizeof
(
uint16_t
),
fail
);
(
ctx
->
m
.
avctx
->
qmax
+
1
)
*
64
*
sizeof
(
int
),
fail
);
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
qmatrix_l16
,
(
ctx
->
m
.
avctx
->
qmax
+
1
)
*
64
*
2
*
sizeof
(
uint16_t
),
fail
);
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
qmatrix_c16
,
(
ctx
->
m
.
avctx
->
qmax
+
1
)
*
64
*
2
*
sizeof
(
uint16_t
),
fail
);
if
(
ctx
->
cid_table
->
bit_depth
==
8
)
{
if
(
ctx
->
cid_table
->
bit_depth
==
8
)
{
for
(
i
=
1
;
i
<
64
;
i
++
)
{
for
(
i
=
1
;
i
<
64
;
i
++
)
{
int
j
=
ctx
->
m
.
dsp
.
idct_permutation
[
ff_zigzag_direct
[
i
]];
int
j
=
ctx
->
m
.
dsp
.
idct_permutation
[
ff_zigzag_direct
[
i
]];
weight_matrix
[
j
]
=
ctx
->
cid_table
->
luma_weight
[
i
];
weight_matrix
[
j
]
=
ctx
->
cid_table
->
luma_weight
[
i
];
}
}
ff_convert_matrix
(
&
ctx
->
m
.
dsp
,
ctx
->
qmatrix_l
,
ctx
->
qmatrix_l16
,
weight_matrix
,
ff_convert_matrix
(
&
ctx
->
m
.
dsp
,
ctx
->
qmatrix_l
,
ctx
->
qmatrix_l16
,
ctx
->
m
.
intra_quant_bias
,
1
,
ctx
->
m
.
avctx
->
qmax
,
1
);
weight_matrix
,
ctx
->
m
.
intra_quant_bias
,
1
,
ctx
->
m
.
avctx
->
qmax
,
1
);
for
(
i
=
1
;
i
<
64
;
i
++
)
{
for
(
i
=
1
;
i
<
64
;
i
++
)
{
int
j
=
ctx
->
m
.
dsp
.
idct_permutation
[
ff_zigzag_direct
[
i
]];
int
j
=
ctx
->
m
.
dsp
.
idct_permutation
[
ff_zigzag_direct
[
i
]];
weight_matrix
[
j
]
=
ctx
->
cid_table
->
chroma_weight
[
i
];
weight_matrix
[
j
]
=
ctx
->
cid_table
->
chroma_weight
[
i
];
}
}
ff_convert_matrix
(
&
ctx
->
m
.
dsp
,
ctx
->
qmatrix_c
,
ctx
->
qmatrix_c16
,
weight_matrix
,
ff_convert_matrix
(
&
ctx
->
m
.
dsp
,
ctx
->
qmatrix_c
,
ctx
->
qmatrix_c16
,
ctx
->
m
.
intra_quant_bias
,
1
,
ctx
->
m
.
avctx
->
qmax
,
1
);
weight_matrix
,
ctx
->
m
.
intra_quant_bias
,
1
,
ctx
->
m
.
avctx
->
qmax
,
1
);
for
(
qscale
=
1
;
qscale
<=
ctx
->
m
.
avctx
->
qmax
;
qscale
++
)
{
for
(
qscale
=
1
;
qscale
<=
ctx
->
m
.
avctx
->
qmax
;
qscale
++
)
{
for
(
i
=
0
;
i
<
64
;
i
++
)
{
for
(
i
=
0
;
i
<
64
;
i
++
)
{
ctx
->
qmatrix_l
[
qscale
]
[
i
]
<<=
2
;
ctx
->
qmatrix_c
[
qscale
]
[
i
]
<<=
2
;
ctx
->
qmatrix_l
[
qscale
][
i
]
<<=
2
;
ctx
->
qmatrix_l16
[
qscale
][
0
][
i
]
<<=
2
;
ctx
->
qmatrix_l16
[
qscale
][
1
][
i
]
<<=
2
;
ctx
->
qmatrix_c
[
qscale
][
i
]
<<=
2
;
ctx
->
qmatrix_c16
[
qscale
][
0
][
i
]
<<=
2
;
ctx
->
qmatrix_c16
[
qscale
][
1
][
i
]
<<=
2
;
ctx
->
qmatrix_l16
[
qscale
][
0
][
i
]
<<=
2
;
ctx
->
qmatrix_l16
[
qscale
][
1
][
i
]
<<=
2
;
ctx
->
qmatrix_c16
[
qscale
][
0
][
i
]
<<=
2
;
ctx
->
qmatrix_c16
[
qscale
][
1
][
i
]
<<=
2
;
}
}
}
}
}
else
{
}
else
{
...
@@ -196,36 +229,44 @@ static av_cold int dnxhd_init_qmat(DNXHDEncContext *ctx, int lbias, int cbias)
...
@@ -196,36 +229,44 @@ static av_cold int dnxhd_init_qmat(DNXHDEncContext *ctx, int lbias, int cbias)
for
(
i
=
1
;
i
<
64
;
i
++
)
{
for
(
i
=
1
;
i
<
64
;
i
++
)
{
int
j
=
ctx
->
m
.
dsp
.
idct_permutation
[
ff_zigzag_direct
[
i
]];
int
j
=
ctx
->
m
.
dsp
.
idct_permutation
[
ff_zigzag_direct
[
i
]];
// The quantization formula from the VC-3 standard is:
/* The quantization formula from the VC-3 standard is:
// quantized = sign(block[i]) * floor(abs(block[i]/s) * p / (qscale * weight_table[i]))
* quantized = sign(block[i]) * floor(abs(block[i]/s) * p /
// Where p is 32 for 8-bit samples and 8 for 10-bit ones.
* (qscale * weight_table[i]))
// The s factor compensates scaling of DCT coefficients done by the DCT routines,
* Where p is 32 for 8-bit samples and 8 for 10-bit ones.
// and therefore is not present in standard. It's 8 for 8-bit samples and 4 for 10-bit ones.
* The s factor compensates scaling of DCT coefficients done by
// We want values of ctx->qtmatrix_l and ctx->qtmatrix_r to be:
* the DCT routines, and therefore is not present in standard.
// ((1 << DNX10BIT_QMAT_SHIFT) * (p / s)) / (qscale * weight_table[i])
* It's 8 for 8-bit samples and 4 for 10-bit ones.
// For 10-bit samples, p / s == 2
* We want values of ctx->qtmatrix_l and ctx->qtmatrix_r to be:
ctx
->
qmatrix_l
[
qscale
][
j
]
=
(
1
<<
(
DNX10BIT_QMAT_SHIFT
+
1
))
/
(
qscale
*
luma_weight_table
[
i
]);
* ((1 << DNX10BIT_QMAT_SHIFT) * (p / s)) /
ctx
->
qmatrix_c
[
qscale
][
j
]
=
(
1
<<
(
DNX10BIT_QMAT_SHIFT
+
1
))
/
(
qscale
*
chroma_weight_table
[
i
]);
* (qscale * weight_table[i])
* For 10-bit samples, p / s == 2 */
ctx
->
qmatrix_l
[
qscale
][
j
]
=
(
1
<<
(
DNX10BIT_QMAT_SHIFT
+
1
))
/
(
qscale
*
luma_weight_table
[
i
]);
ctx
->
qmatrix_c
[
qscale
][
j
]
=
(
1
<<
(
DNX10BIT_QMAT_SHIFT
+
1
))
/
(
qscale
*
chroma_weight_table
[
i
]);
}
}
}
}
}
}
return
0
;
return
0
;
fail:
fail:
return
AVERROR
(
ENOMEM
);
return
AVERROR
(
ENOMEM
);
}
}
static
av_cold
int
dnxhd_init_rc
(
DNXHDEncContext
*
ctx
)
static
av_cold
int
dnxhd_init_rc
(
DNXHDEncContext
*
ctx
)
{
{
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
mb_rc
,
8160
*
ctx
->
m
.
avctx
->
qmax
*
sizeof
(
RCEntry
),
fail
);
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
mb_rc
,
8160
*
ctx
->
m
.
avctx
->
qmax
*
sizeof
(
RCEntry
),
fail
);
if
(
ctx
->
m
.
avctx
->
mb_decision
!=
FF_MB_DECISION_RD
)
if
(
ctx
->
m
.
avctx
->
mb_decision
!=
FF_MB_DECISION_RD
)
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
mb_cmp
,
ctx
->
m
.
mb_num
*
sizeof
(
RCCMPEntry
),
fail
);
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
mb_cmp
,
ctx
->
m
.
mb_num
*
sizeof
(
RCCMPEntry
),
fail
);
ctx
->
frame_bits
=
(
ctx
->
cid_table
->
coding_unit_size
-
640
-
4
-
ctx
->
min_padding
)
*
8
;
ctx
->
frame_bits
=
(
ctx
->
cid_table
->
coding_unit_size
-
640
-
4
-
ctx
->
min_padding
)
*
8
;
ctx
->
qscale
=
1
;
ctx
->
qscale
=
1
;
ctx
->
lambda
=
2
<<
LAMBDA_FRAC_BITS
;
// qscale 2
ctx
->
lambda
=
2
<<
LAMBDA_FRAC_BITS
;
// qscale 2
return
0
;
return
0
;
fail:
fail:
return
AVERROR
(
ENOMEM
);
return
AVERROR
(
ENOMEM
);
}
}
...
@@ -242,13 +283,15 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx)
...
@@ -242,13 +283,15 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx)
bit_depth
=
10
;
bit_depth
=
10
;
break
;
break
;
default:
default:
av_log
(
avctx
,
AV_LOG_ERROR
,
"pixel format is incompatible with DNxHD
\n
"
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"pixel format is incompatible with DNxHD
\n
"
);
return
AVERROR
(
EINVAL
);
return
AVERROR
(
EINVAL
);
}
}
ctx
->
cid
=
ff_dnxhd_find_cid
(
avctx
,
bit_depth
);
ctx
->
cid
=
ff_dnxhd_find_cid
(
avctx
,
bit_depth
);
if
(
!
ctx
->
cid
)
{
if
(
!
ctx
->
cid
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"video parameters incompatible with DNxHD
\n
"
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"video parameters incompatible with DNxHD
\n
"
);
return
AVERROR
(
EINVAL
);
return
AVERROR
(
EINVAL
);
}
}
av_log
(
avctx
,
AV_LOG_DEBUG
,
"cid %d
\n
"
,
ctx
->
cid
);
av_log
(
avctx
,
AV_LOG_DEBUG
,
"cid %d
\n
"
,
ctx
->
cid
);
...
@@ -291,10 +334,12 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx)
...
@@ -291,10 +334,12 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx)
if
(
avctx
->
intra_quant_bias
!=
FF_DEFAULT_QUANT_BIAS
)
if
(
avctx
->
intra_quant_bias
!=
FF_DEFAULT_QUANT_BIAS
)
ctx
->
m
.
intra_quant_bias
=
avctx
->
intra_quant_bias
;
ctx
->
m
.
intra_quant_bias
=
avctx
->
intra_quant_bias
;
if
((
ret
=
dnxhd_init_qmat
(
ctx
,
ctx
->
m
.
intra_quant_bias
,
0
))
<
0
)
// XXX tune lbias/cbias
// XXX tune lbias/cbias
if
((
ret
=
dnxhd_init_qmat
(
ctx
,
ctx
->
m
.
intra_quant_bias
,
0
))
<
0
)
return
ret
;
return
ret
;
// Avid Nitris hardware decoder requires a minimum amount of padding in the coding unit payload
/* Avid Nitris hardware decoder requires a minimum amount of padding
* in the coding unit payload */
if
(
ctx
->
nitris_compat
)
if
(
ctx
->
nitris_compat
)
ctx
->
min_padding
=
1600
;
ctx
->
min_padding
=
1600
;
...
@@ -303,10 +348,14 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx)
...
@@ -303,10 +348,14 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx)
if
((
ret
=
dnxhd_init_rc
(
ctx
))
<
0
)
if
((
ret
=
dnxhd_init_rc
(
ctx
))
<
0
)
return
ret
;
return
ret
;
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
slice_size
,
ctx
->
m
.
mb_height
*
sizeof
(
uint32_t
),
fail
);
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
slice_size
,
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
slice_offs
,
ctx
->
m
.
mb_height
*
sizeof
(
uint32_t
),
fail
);
ctx
->
m
.
mb_height
*
sizeof
(
uint32_t
),
fail
);
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
mb_bits
,
ctx
->
m
.
mb_num
*
sizeof
(
uint16_t
),
fail
);
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
slice_offs
,
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
mb_qscale
,
ctx
->
m
.
mb_num
*
sizeof
(
uint8_t
),
fail
);
ctx
->
m
.
mb_height
*
sizeof
(
uint32_t
),
fail
);
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
mb_bits
,
ctx
->
m
.
mb_num
*
sizeof
(
uint16_t
),
fail
);
FF_ALLOCZ_OR_GOTO
(
ctx
->
m
.
avctx
,
ctx
->
mb_qscale
,
ctx
->
m
.
mb_num
*
sizeof
(
uint8_t
),
fail
);
avctx
->
coded_frame
=
av_frame_alloc
();
avctx
->
coded_frame
=
av_frame_alloc
();
if
(
!
avctx
->
coded_frame
)
if
(
!
avctx
->
coded_frame
)
...
@@ -327,27 +376,27 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx)
...
@@ -327,27 +376,27 @@ static av_cold int dnxhd_encode_init(AVCodecContext *avctx)
}
}
return
0
;
return
0
;
fail:
//
for FF_ALLOCZ_OR_GOTO
fail:
//
for FF_ALLOCZ_OR_GOTO
return
AVERROR
(
ENOMEM
);
return
AVERROR
(
ENOMEM
);
}
}
static
int
dnxhd_write_header
(
AVCodecContext
*
avctx
,
uint8_t
*
buf
)
static
int
dnxhd_write_header
(
AVCodecContext
*
avctx
,
uint8_t
*
buf
)
{
{
DNXHDEncContext
*
ctx
=
avctx
->
priv_data
;
DNXHDEncContext
*
ctx
=
avctx
->
priv_data
;
const
uint8_t
header_prefix
[
5
]
=
{
0x00
,
0x00
,
0x02
,
0x80
,
0x01
};
const
uint8_t
header_prefix
[
5
]
=
{
0x00
,
0x00
,
0x02
,
0x80
,
0x01
};
memset
(
buf
,
0
,
640
);
memset
(
buf
,
0
,
640
);
memcpy
(
buf
,
header_prefix
,
5
);
memcpy
(
buf
,
header_prefix
,
5
);
buf
[
5
]
=
ctx
->
interlaced
?
ctx
->
cur_field
+
2
:
0x01
;
buf
[
5
]
=
ctx
->
interlaced
?
ctx
->
cur_field
+
2
:
0x01
;
buf
[
6
]
=
0x80
;
// crc flag off
buf
[
6
]
=
0x80
;
// crc flag off
buf
[
7
]
=
0xa0
;
// reserved
buf
[
7
]
=
0xa0
;
// reserved
AV_WB16
(
buf
+
0x18
,
avctx
->
height
>>
ctx
->
interlaced
);
// ALPF
AV_WB16
(
buf
+
0x18
,
avctx
->
height
>>
ctx
->
interlaced
);
// ALPF
AV_WB16
(
buf
+
0x1a
,
avctx
->
width
);
// SPL
AV_WB16
(
buf
+
0x1a
,
avctx
->
width
);
// SPL
AV_WB16
(
buf
+
0x1d
,
avctx
->
height
>>
ctx
->
interlaced
);
// NAL
AV_WB16
(
buf
+
0x1d
,
avctx
->
height
>>
ctx
->
interlaced
);
// NAL
buf
[
0x21
]
=
ctx
->
cid_table
->
bit_depth
==
10
?
0x58
:
0x38
;
buf
[
0x21
]
=
ctx
->
cid_table
->
bit_depth
==
10
?
0x58
:
0x38
;
buf
[
0x22
]
=
0x88
+
(
ctx
->
interlaced
<<
2
);
buf
[
0x22
]
=
0x88
+
(
ctx
->
interlaced
<<
2
);
AV_WB32
(
buf
+
0x28
,
ctx
->
cid
);
// CID
AV_WB32
(
buf
+
0x28
,
ctx
->
cid
);
// CID
buf
[
0x2c
]
=
ctx
->
interlaced
?
0
:
0x80
;
buf
[
0x2c
]
=
ctx
->
interlaced
?
0
:
0x80
;
...
@@ -366,16 +415,19 @@ static av_always_inline void dnxhd_encode_dc(DNXHDEncContext *ctx, int diff)
...
@@ -366,16 +415,19 @@ static av_always_inline void dnxhd_encode_dc(DNXHDEncContext *ctx, int diff)
{
{
int
nbits
;
int
nbits
;
if
(
diff
<
0
)
{
if
(
diff
<
0
)
{
nbits
=
av_log2_16bit
(
-
2
*
diff
);
nbits
=
av_log2_16bit
(
-
2
*
diff
);
diff
--
;
diff
--
;
}
else
{
}
else
{
nbits
=
av_log2_16bit
(
2
*
diff
);
nbits
=
av_log2_16bit
(
2
*
diff
);
}
}
put_bits
(
&
ctx
->
m
.
pb
,
ctx
->
cid_table
->
dc_bits
[
nbits
]
+
nbits
,
put_bits
(
&
ctx
->
m
.
pb
,
ctx
->
cid_table
->
dc_bits
[
nbits
]
+
nbits
,
(
ctx
->
cid_table
->
dc_codes
[
nbits
]
<<
nbits
)
+
(
diff
&
((
1
<<
nbits
)
-
1
)));
(
ctx
->
cid_table
->
dc_codes
[
nbits
]
<<
nbits
)
+
(
diff
&
((
1
<<
nbits
)
-
1
)));
}
}
static
av_always_inline
void
dnxhd_encode_block
(
DNXHDEncContext
*
ctx
,
int16_t
*
block
,
int
last_index
,
int
n
)
static
av_always_inline
void
dnxhd_encode_block
(
DNXHDEncContext
*
ctx
,
int16_t
*
block
,
int
last_index
,
int
n
)
{
{
int
last_non_zero
=
0
;
int
last_non_zero
=
0
;
int
slevel
,
i
,
j
;
int
slevel
,
i
,
j
;
...
@@ -388,30 +440,34 @@ static av_always_inline void dnxhd_encode_block(DNXHDEncContext *ctx, int16_t *b
...
@@ -388,30 +440,34 @@ static av_always_inline void dnxhd_encode_block(DNXHDEncContext *ctx, int16_t *b
slevel
=
block
[
j
];
slevel
=
block
[
j
];
if
(
slevel
)
{
if
(
slevel
)
{
int
run_level
=
i
-
last_non_zero
-
1
;
int
run_level
=
i
-
last_non_zero
-
1
;
int
rlevel
=
(
slevel
<<
1
)
|
!!
run_level
;
int
rlevel
=
(
slevel
<<
1
)
|
!!
run_level
;
put_bits
(
&
ctx
->
m
.
pb
,
ctx
->
vlc_bits
[
rlevel
],
ctx
->
vlc_codes
[
rlevel
]);
put_bits
(
&
ctx
->
m
.
pb
,
ctx
->
vlc_bits
[
rlevel
],
ctx
->
vlc_codes
[
rlevel
]);
if
(
run_level
)
if
(
run_level
)
put_bits
(
&
ctx
->
m
.
pb
,
ctx
->
run_bits
[
run_level
],
ctx
->
run_codes
[
run_level
]);
put_bits
(
&
ctx
->
m
.
pb
,
ctx
->
run_bits
[
run_level
],
ctx
->
run_codes
[
run_level
]);
last_non_zero
=
i
;
last_non_zero
=
i
;
}
}
}
}
put_bits
(
&
ctx
->
m
.
pb
,
ctx
->
vlc_bits
[
0
],
ctx
->
vlc_codes
[
0
]);
// EOB
put_bits
(
&
ctx
->
m
.
pb
,
ctx
->
vlc_bits
[
0
],
ctx
->
vlc_codes
[
0
]);
// EOB
}
}
static
av_always_inline
void
dnxhd_unquantize_c
(
DNXHDEncContext
*
ctx
,
int16_t
*
block
,
int
n
,
int
qscale
,
int
last_index
)
static
av_always_inline
void
dnxhd_unquantize_c
(
DNXHDEncContext
*
ctx
,
int16_t
*
block
,
int
n
,
int
qscale
,
int
last_index
)
{
{
const
uint8_t
*
weight_matrix
;
const
uint8_t
*
weight_matrix
;
int
level
;
int
level
;
int
i
;
int
i
;
weight_matrix
=
(
n
&
2
)
?
ctx
->
cid_table
->
chroma_weight
:
ctx
->
cid_table
->
luma_weight
;
weight_matrix
=
(
n
&
2
)
?
ctx
->
cid_table
->
chroma_weight
:
ctx
->
cid_table
->
luma_weight
;
for
(
i
=
1
;
i
<=
last_index
;
i
++
)
{
for
(
i
=
1
;
i
<=
last_index
;
i
++
)
{
int
j
=
ctx
->
m
.
intra_scantable
.
permutated
[
i
];
int
j
=
ctx
->
m
.
intra_scantable
.
permutated
[
i
];
level
=
block
[
j
];
level
=
block
[
j
];
if
(
level
)
{
if
(
level
)
{
if
(
level
<
0
)
{
if
(
level
<
0
)
{
level
=
(
1
-
2
*
level
)
*
qscale
*
weight_matrix
[
i
];
level
=
(
1
-
2
*
level
)
*
qscale
*
weight_matrix
[
i
];
if
(
ctx
->
cid_table
->
bit_depth
==
10
)
{
if
(
ctx
->
cid_table
->
bit_depth
==
10
)
{
if
(
weight_matrix
[
i
]
!=
8
)
if
(
weight_matrix
[
i
]
!=
8
)
level
+=
8
;
level
+=
8
;
...
@@ -423,7 +479,7 @@ static av_always_inline void dnxhd_unquantize_c(DNXHDEncContext *ctx, int16_t *b
...
@@ -423,7 +479,7 @@ static av_always_inline void dnxhd_unquantize_c(DNXHDEncContext *ctx, int16_t *b
}
}
level
=
-
level
;
level
=
-
level
;
}
else
{
}
else
{
level
=
(
2
*
level
+
1
)
*
qscale
*
weight_matrix
[
i
];
level
=
(
2
*
level
+
1
)
*
qscale
*
weight_matrix
[
i
];
if
(
ctx
->
cid_table
->
bit_depth
==
10
)
{
if
(
ctx
->
cid_table
->
bit_depth
==
10
)
{
if
(
weight_matrix
[
i
]
!=
8
)
if
(
weight_matrix
[
i
]
!=
8
)
level
+=
8
;
level
+=
8
;
...
@@ -448,7 +504,8 @@ static av_always_inline int dnxhd_ssd_block(int16_t *qblock, int16_t *block)
...
@@ -448,7 +504,8 @@ static av_always_inline int dnxhd_ssd_block(int16_t *qblock, int16_t *block)
return
score
;
return
score
;
}
}
static
av_always_inline
int
dnxhd_calc_ac_bits
(
DNXHDEncContext
*
ctx
,
int16_t
*
block
,
int
last_index
)
static
av_always_inline
int
dnxhd_calc_ac_bits
(
DNXHDEncContext
*
ctx
,
int16_t
*
block
,
int
last_index
)
{
{
int
last_non_zero
=
0
;
int
last_non_zero
=
0
;
int
bits
=
0
;
int
bits
=
0
;
...
@@ -458,20 +515,25 @@ static av_always_inline int dnxhd_calc_ac_bits(DNXHDEncContext *ctx, int16_t *bl
...
@@ -458,20 +515,25 @@ static av_always_inline int dnxhd_calc_ac_bits(DNXHDEncContext *ctx, int16_t *bl
level
=
block
[
j
];
level
=
block
[
j
];
if
(
level
)
{
if
(
level
)
{
int
run_level
=
i
-
last_non_zero
-
1
;
int
run_level
=
i
-
last_non_zero
-
1
;
bits
+=
ctx
->
vlc_bits
[(
level
<<
1
)
|!!
run_level
]
+
ctx
->
run_bits
[
run_level
];
bits
+=
ctx
->
vlc_bits
[(
level
<<
1
)
|
!!
run_level
]
+
ctx
->
run_bits
[
run_level
];
last_non_zero
=
i
;
last_non_zero
=
i
;
}
}
}
}
return
bits
;
return
bits
;
}
}
static
av_always_inline
void
dnxhd_get_blocks
(
DNXHDEncContext
*
ctx
,
int
mb_x
,
int
mb_y
)
static
av_always_inline
void
dnxhd_get_blocks
(
DNXHDEncContext
*
ctx
,
int
mb_x
,
int
mb_y
)
{
{
const
int
bs
=
ctx
->
block_width_l2
;
const
int
bs
=
ctx
->
block_width_l2
;
const
int
bw
=
1
<<
bs
;
const
int
bw
=
1
<<
bs
;
const
uint8_t
*
ptr_y
=
ctx
->
thread
[
0
]
->
src
[
0
]
+
((
mb_y
<<
4
)
*
ctx
->
m
.
linesize
)
+
(
mb_x
<<
bs
+
1
);
const
uint8_t
*
ptr_y
=
ctx
->
thread
[
0
]
->
src
[
0
]
+
const
uint8_t
*
ptr_u
=
ctx
->
thread
[
0
]
->
src
[
1
]
+
((
mb_y
<<
4
)
*
ctx
->
m
.
uvlinesize
)
+
(
mb_x
<<
bs
);
((
mb_y
<<
4
)
*
ctx
->
m
.
linesize
)
+
(
mb_x
<<
bs
+
1
);
const
uint8_t
*
ptr_v
=
ctx
->
thread
[
0
]
->
src
[
2
]
+
((
mb_y
<<
4
)
*
ctx
->
m
.
uvlinesize
)
+
(
mb_x
<<
bs
);
const
uint8_t
*
ptr_u
=
ctx
->
thread
[
0
]
->
src
[
1
]
+
((
mb_y
<<
4
)
*
ctx
->
m
.
uvlinesize
)
+
(
mb_x
<<
bs
);
const
uint8_t
*
ptr_v
=
ctx
->
thread
[
0
]
->
src
[
2
]
+
((
mb_y
<<
4
)
*
ctx
->
m
.
uvlinesize
)
+
(
mb_x
<<
bs
);
DSPContext
*
dsp
=
&
ctx
->
m
.
dsp
;
DSPContext
*
dsp
=
&
ctx
->
m
.
dsp
;
dsp
->
get_pixels
(
ctx
->
blocks
[
0
],
ptr_y
,
ctx
->
m
.
linesize
);
dsp
->
get_pixels
(
ctx
->
blocks
[
0
],
ptr_y
,
ctx
->
m
.
linesize
);
...
@@ -479,12 +541,20 @@ static av_always_inline void dnxhd_get_blocks(DNXHDEncContext *ctx, int mb_x, in
...
@@ -479,12 +541,20 @@ static av_always_inline void dnxhd_get_blocks(DNXHDEncContext *ctx, int mb_x, in
dsp
->
get_pixels
(
ctx
->
blocks
[
2
],
ptr_u
,
ctx
->
m
.
uvlinesize
);
dsp
->
get_pixels
(
ctx
->
blocks
[
2
],
ptr_u
,
ctx
->
m
.
uvlinesize
);
dsp
->
get_pixels
(
ctx
->
blocks
[
3
],
ptr_v
,
ctx
->
m
.
uvlinesize
);
dsp
->
get_pixels
(
ctx
->
blocks
[
3
],
ptr_v
,
ctx
->
m
.
uvlinesize
);
if
(
mb_y
+
1
==
ctx
->
m
.
mb_height
&&
ctx
->
m
.
avctx
->
height
==
1080
)
{
if
(
mb_y
+
1
==
ctx
->
m
.
mb_height
&&
ctx
->
m
.
avctx
->
height
==
1080
)
{
if
(
ctx
->
interlaced
)
{
if
(
ctx
->
interlaced
)
{
ctx
->
get_pixels_8x4_sym
(
ctx
->
blocks
[
4
],
ptr_y
+
ctx
->
dct_y_offset
,
ctx
->
m
.
linesize
);
ctx
->
get_pixels_8x4_sym
(
ctx
->
blocks
[
4
],
ctx
->
get_pixels_8x4_sym
(
ctx
->
blocks
[
5
],
ptr_y
+
ctx
->
dct_y_offset
+
bw
,
ctx
->
m
.
linesize
);
ptr_y
+
ctx
->
dct_y_offset
,
ctx
->
get_pixels_8x4_sym
(
ctx
->
blocks
[
6
],
ptr_u
+
ctx
->
dct_uv_offset
,
ctx
->
m
.
uvlinesize
);
ctx
->
m
.
linesize
);
ctx
->
get_pixels_8x4_sym
(
ctx
->
blocks
[
7
],
ptr_v
+
ctx
->
dct_uv_offset
,
ctx
->
m
.
uvlinesize
);
ctx
->
get_pixels_8x4_sym
(
ctx
->
blocks
[
5
],
ptr_y
+
ctx
->
dct_y_offset
+
bw
,
ctx
->
m
.
linesize
);
ctx
->
get_pixels_8x4_sym
(
ctx
->
blocks
[
6
],
ptr_u
+
ctx
->
dct_uv_offset
,
ctx
->
m
.
uvlinesize
);
ctx
->
get_pixels_8x4_sym
(
ctx
->
blocks
[
7
],
ptr_v
+
ctx
->
dct_uv_offset
,
ctx
->
m
.
uvlinesize
);
}
else
{
}
else
{
dsp
->
clear_block
(
ctx
->
blocks
[
4
]);
dsp
->
clear_block
(
ctx
->
blocks
[
4
]);
dsp
->
clear_block
(
ctx
->
blocks
[
5
]);
dsp
->
clear_block
(
ctx
->
blocks
[
5
]);
...
@@ -492,19 +562,24 @@ static av_always_inline void dnxhd_get_blocks(DNXHDEncContext *ctx, int mb_x, in
...
@@ -492,19 +562,24 @@ static av_always_inline void dnxhd_get_blocks(DNXHDEncContext *ctx, int mb_x, in
dsp
->
clear_block
(
ctx
->
blocks
[
7
]);
dsp
->
clear_block
(
ctx
->
blocks
[
7
]);
}
}
}
else
{
}
else
{
dsp
->
get_pixels
(
ctx
->
blocks
[
4
],
ptr_y
+
ctx
->
dct_y_offset
,
ctx
->
m
.
linesize
);
dsp
->
get_pixels
(
ctx
->
blocks
[
4
],
dsp
->
get_pixels
(
ctx
->
blocks
[
5
],
ptr_y
+
ctx
->
dct_y_offset
+
bw
,
ctx
->
m
.
linesize
);
ptr_y
+
ctx
->
dct_y_offset
,
ctx
->
m
.
linesize
);
dsp
->
get_pixels
(
ctx
->
blocks
[
6
],
ptr_u
+
ctx
->
dct_uv_offset
,
ctx
->
m
.
uvlinesize
);
dsp
->
get_pixels
(
ctx
->
blocks
[
5
],
dsp
->
get_pixels
(
ctx
->
blocks
[
7
],
ptr_v
+
ctx
->
dct_uv_offset
,
ctx
->
m
.
uvlinesize
);
ptr_y
+
ctx
->
dct_y_offset
+
bw
,
ctx
->
m
.
linesize
);
dsp
->
get_pixels
(
ctx
->
blocks
[
6
],
ptr_u
+
ctx
->
dct_uv_offset
,
ctx
->
m
.
uvlinesize
);
dsp
->
get_pixels
(
ctx
->
blocks
[
7
],
ptr_v
+
ctx
->
dct_uv_offset
,
ctx
->
m
.
uvlinesize
);
}
}
}
}
static
av_always_inline
int
dnxhd_switch_matrix
(
DNXHDEncContext
*
ctx
,
int
i
)
static
av_always_inline
int
dnxhd_switch_matrix
(
DNXHDEncContext
*
ctx
,
int
i
)
{
{
if
(
i
&
2
)
{
if
(
i
&
2
)
{
ctx
->
m
.
q_intra_matrix16
=
ctx
->
qmatrix_c16
;
ctx
->
m
.
q_intra_matrix16
=
ctx
->
qmatrix_c16
;
ctx
->
m
.
q_intra_matrix
=
ctx
->
qmatrix_c
;
ctx
->
m
.
q_intra_matrix
=
ctx
->
qmatrix_c
;
return
1
+
(
i
&
1
);
return
1
+
(
i
&
1
);
}
else
{
}
else
{
ctx
->
m
.
q_intra_matrix16
=
ctx
->
qmatrix_l16
;
ctx
->
m
.
q_intra_matrix16
=
ctx
->
qmatrix_l16
;
ctx
->
m
.
q_intra_matrix
=
ctx
->
qmatrix_l
;
ctx
->
m
.
q_intra_matrix
=
ctx
->
qmatrix_l
;
...
@@ -512,7 +587,8 @@ static av_always_inline int dnxhd_switch_matrix(DNXHDEncContext *ctx, int i)
...
@@ -512,7 +587,8 @@ static av_always_inline int dnxhd_switch_matrix(DNXHDEncContext *ctx, int i)
}
}
}
}
static
int
dnxhd_calc_bits_thread
(
AVCodecContext
*
avctx
,
void
*
arg
,
int
jobnr
,
int
threadnr
)
static
int
dnxhd_calc_bits_thread
(
AVCodecContext
*
avctx
,
void
*
arg
,
int
jobnr
,
int
threadnr
)
{
{
DNXHDEncContext
*
ctx
=
avctx
->
priv_data
;
DNXHDEncContext
*
ctx
=
avctx
->
priv_data
;
int
mb_y
=
jobnr
,
mb_x
;
int
mb_y
=
jobnr
,
mb_x
;
...
@@ -538,13 +614,16 @@ static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg, int jobnr, i
...
@@ -538,13 +614,16 @@ static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg, int jobnr, i
int
overflow
,
nbits
,
diff
,
last_index
;
int
overflow
,
nbits
,
diff
,
last_index
;
int
n
=
dnxhd_switch_matrix
(
ctx
,
i
);
int
n
=
dnxhd_switch_matrix
(
ctx
,
i
);
memcpy
(
block
,
src_block
,
64
*
sizeof
(
*
block
));
memcpy
(
block
,
src_block
,
64
*
sizeof
(
*
block
));
last_index
=
ctx
->
m
.
dct_quantize
(
&
ctx
->
m
,
block
,
i
,
qscale
,
&
overflow
);
last_index
=
ctx
->
m
.
dct_quantize
(
&
ctx
->
m
,
block
,
i
,
qscale
,
&
overflow
);
ac_bits
+=
dnxhd_calc_ac_bits
(
ctx
,
block
,
last_index
);
ac_bits
+=
dnxhd_calc_ac_bits
(
ctx
,
block
,
last_index
);
diff
=
block
[
0
]
-
ctx
->
m
.
last_dc
[
n
];
diff
=
block
[
0
]
-
ctx
->
m
.
last_dc
[
n
];
if
(
diff
<
0
)
nbits
=
av_log2_16bit
(
-
2
*
diff
);
if
(
diff
<
0
)
else
nbits
=
av_log2_16bit
(
2
*
diff
);
nbits
=
av_log2_16bit
(
-
2
*
diff
);
else
nbits
=
av_log2_16bit
(
2
*
diff
);
assert
(
nbits
<
ctx
->
cid_table
->
bit_depth
+
4
);
assert
(
nbits
<
ctx
->
cid_table
->
bit_depth
+
4
);
dc_bits
+=
ctx
->
cid_table
->
dc_bits
[
nbits
]
+
nbits
;
dc_bits
+=
ctx
->
cid_table
->
dc_bits
[
nbits
]
+
nbits
;
...
@@ -558,17 +637,20 @@ static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg, int jobnr, i
...
@@ -558,17 +637,20 @@ static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg, int jobnr, i
}
}
}
}
ctx
->
mb_rc
[
qscale
][
mb
].
ssd
=
ssd
;
ctx
->
mb_rc
[
qscale
][
mb
].
ssd
=
ssd
;
ctx
->
mb_rc
[
qscale
][
mb
].
bits
=
ac_bits
+
dc_bits
+
12
+
8
*
ctx
->
vlc_bits
[
0
];
ctx
->
mb_rc
[
qscale
][
mb
].
bits
=
ac_bits
+
dc_bits
+
12
+
8
*
ctx
->
vlc_bits
[
0
];
}
}
return
0
;
return
0
;
}
}
static
int
dnxhd_encode_thread
(
AVCodecContext
*
avctx
,
void
*
arg
,
int
jobnr
,
int
threadnr
)
static
int
dnxhd_encode_thread
(
AVCodecContext
*
avctx
,
void
*
arg
,
int
jobnr
,
int
threadnr
)
{
{
DNXHDEncContext
*
ctx
=
avctx
->
priv_data
;
DNXHDEncContext
*
ctx
=
avctx
->
priv_data
;
int
mb_y
=
jobnr
,
mb_x
;
int
mb_y
=
jobnr
,
mb_x
;
ctx
=
ctx
->
thread
[
threadnr
];
ctx
=
ctx
->
thread
[
threadnr
];
init_put_bits
(
&
ctx
->
m
.
pb
,
(
uint8_t
*
)
arg
+
640
+
ctx
->
slice_offs
[
jobnr
],
ctx
->
slice_size
[
jobnr
]);
init_put_bits
(
&
ctx
->
m
.
pb
,
(
uint8_t
*
)
arg
+
640
+
ctx
->
slice_offs
[
jobnr
],
ctx
->
slice_size
[
jobnr
]);
ctx
->
m
.
last_dc
[
0
]
=
ctx
->
m
.
last_dc
[
0
]
=
ctx
->
m
.
last_dc
[
1
]
=
ctx
->
m
.
last_dc
[
1
]
=
...
@@ -578,7 +660,7 @@ static int dnxhd_encode_thread(AVCodecContext *avctx, void *arg, int jobnr, int
...
@@ -578,7 +660,7 @@ static int dnxhd_encode_thread(AVCodecContext *avctx, void *arg, int jobnr, int
int
qscale
=
ctx
->
mb_qscale
[
mb
];
int
qscale
=
ctx
->
mb_qscale
[
mb
];
int
i
;
int
i
;
put_bits
(
&
ctx
->
m
.
pb
,
12
,
qscale
<<
1
);
put_bits
(
&
ctx
->
m
.
pb
,
12
,
qscale
<<
1
);
dnxhd_get_blocks
(
ctx
,
mb_x
,
mb_y
);
dnxhd_get_blocks
(
ctx
,
mb_x
,
mb_y
);
...
@@ -587,13 +669,13 @@ static int dnxhd_encode_thread(AVCodecContext *avctx, void *arg, int jobnr, int
...
@@ -587,13 +669,13 @@ static int dnxhd_encode_thread(AVCodecContext *avctx, void *arg, int jobnr, int
int
overflow
,
n
=
dnxhd_switch_matrix
(
ctx
,
i
);
int
overflow
,
n
=
dnxhd_switch_matrix
(
ctx
,
i
);
int
last_index
=
ctx
->
m
.
dct_quantize
(
&
ctx
->
m
,
block
,
i
,
int
last_index
=
ctx
->
m
.
dct_quantize
(
&
ctx
->
m
,
block
,
i
,
qscale
,
&
overflow
);
qscale
,
&
overflow
);
//START_TIMER;
//
START_TIMER;
dnxhd_encode_block
(
ctx
,
block
,
last_index
,
n
);
dnxhd_encode_block
(
ctx
,
block
,
last_index
,
n
);
//STOP_TIMER("encode_block");
//
STOP_TIMER("encode_block");
}
}
}
}
if
(
put_bits_count
(
&
ctx
->
m
.
pb
)
&
31
)
if
(
put_bits_count
(
&
ctx
->
m
.
pb
)
&
31
)
put_bits
(
&
ctx
->
m
.
pb
,
32
-
(
put_bits_count
(
&
ctx
->
m
.
pb
)
&
31
),
0
);
put_bits
(
&
ctx
->
m
.
pb
,
32
-
(
put_bits_count
(
&
ctx
->
m
.
pb
)
&
31
),
0
);
flush_put_bits
(
&
ctx
->
m
.
pb
);
flush_put_bits
(
&
ctx
->
m
.
pb
);
return
0
;
return
0
;
}
}
...
@@ -610,14 +692,15 @@ static void dnxhd_setup_threads_slices(DNXHDEncContext *ctx)
...
@@ -610,14 +692,15 @@ static void dnxhd_setup_threads_slices(DNXHDEncContext *ctx)
unsigned
mb
=
mb_y
*
ctx
->
m
.
mb_width
+
mb_x
;
unsigned
mb
=
mb_y
*
ctx
->
m
.
mb_width
+
mb_x
;
ctx
->
slice_size
[
mb_y
]
+=
ctx
->
mb_bits
[
mb
];
ctx
->
slice_size
[
mb_y
]
+=
ctx
->
mb_bits
[
mb
];
}
}
ctx
->
slice_size
[
mb_y
]
=
(
ctx
->
slice_size
[
mb_y
]
+
31
)
&
~
31
;
ctx
->
slice_size
[
mb_y
]
=
(
ctx
->
slice_size
[
mb_y
]
+
31
)
&
~
31
;
ctx
->
slice_size
[
mb_y
]
>>=
3
;
ctx
->
slice_size
[
mb_y
]
>>=
3
;
thread_size
=
ctx
->
slice_size
[
mb_y
];
thread_size
=
ctx
->
slice_size
[
mb_y
];
offset
+=
thread_size
;
offset
+=
thread_size
;
}
}
}
}
static
int
dnxhd_mb_var_thread
(
AVCodecContext
*
avctx
,
void
*
arg
,
int
jobnr
,
int
threadnr
)
static
int
dnxhd_mb_var_thread
(
AVCodecContext
*
avctx
,
void
*
arg
,
int
jobnr
,
int
threadnr
)
{
{
DNXHDEncContext
*
ctx
=
avctx
->
priv_data
;
DNXHDEncContext
*
ctx
=
avctx
->
priv_data
;
int
mb_y
=
jobnr
,
mb_x
,
x
,
y
;
int
mb_y
=
jobnr
,
mb_x
,
x
,
y
;
...
@@ -626,7 +709,7 @@ static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg, int jobnr, int
...
@@ -626,7 +709,7 @@ static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg, int jobnr, int
ctx
=
ctx
->
thread
[
threadnr
];
ctx
=
ctx
->
thread
[
threadnr
];
if
(
ctx
->
cid_table
->
bit_depth
==
8
)
{
if
(
ctx
->
cid_table
->
bit_depth
==
8
)
{
uint8_t
*
pix
=
ctx
->
thread
[
0
]
->
src
[
0
]
+
((
mb_y
<<
4
)
*
ctx
->
m
.
linesize
);
uint8_t
*
pix
=
ctx
->
thread
[
0
]
->
src
[
0
]
+
((
mb_y
<<
4
)
*
ctx
->
m
.
linesize
);
for
(
mb_x
=
0
;
mb_x
<
ctx
->
m
.
mb_width
;
++
mb_x
,
pix
+=
16
)
{
for
(
mb_x
=
0
;
mb_x
<
ctx
->
m
.
mb_width
;
++
mb_x
,
pix
+=
16
)
{
unsigned
mb
=
mb_y
*
ctx
->
m
.
mb_width
+
mb_x
;
unsigned
mb
=
mb_y
*
ctx
->
m
.
mb_width
+
mb_x
;
int
sum
;
int
sum
;
...
@@ -647,7 +730,7 @@ static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg, int jobnr, int
...
@@ -647,7 +730,7 @@ static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg, int jobnr, int
}
}
}
}
}
}
varc
=
(
varc
-
(((
unsigned
)
sum
*
sum
)
>>
8
)
+
128
)
>>
8
;
varc
=
(
varc
-
(((
unsigned
)
sum
*
sum
)
>>
8
)
+
128
)
>>
8
;
ctx
->
mb_cmp
[
mb
].
value
=
varc
;
ctx
->
mb_cmp
[
mb
].
value
=
varc
;
ctx
->
mb_cmp
[
mb
].
mb
=
mb
;
ctx
->
mb_cmp
[
mb
].
mb
=
mb
;
...
@@ -655,7 +738,8 @@ static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg, int jobnr, int
...
@@ -655,7 +738,8 @@ static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg, int jobnr, int
}
else
{
// 10-bit
}
else
{
// 10-bit
int
const
linesize
=
ctx
->
m
.
linesize
>>
1
;
int
const
linesize
=
ctx
->
m
.
linesize
>>
1
;
for
(
mb_x
=
0
;
mb_x
<
ctx
->
m
.
mb_width
;
++
mb_x
)
{
for
(
mb_x
=
0
;
mb_x
<
ctx
->
m
.
mb_width
;
++
mb_x
)
{
uint16_t
*
pix
=
(
uint16_t
*
)
ctx
->
thread
[
0
]
->
src
[
0
]
+
((
mb_y
<<
4
)
*
linesize
)
+
(
mb_x
<<
4
);
uint16_t
*
pix
=
(
uint16_t
*
)
ctx
->
thread
[
0
]
->
src
[
0
]
+
((
mb_y
<<
4
)
*
linesize
)
+
(
mb_x
<<
4
);
unsigned
mb
=
mb_y
*
ctx
->
m
.
mb_width
+
mb_x
;
unsigned
mb
=
mb_y
*
ctx
->
m
.
mb_width
+
mb_x
;
int
sum
=
0
;
int
sum
=
0
;
int
sqsum
=
0
;
int
sqsum
=
0
;
...
@@ -665,7 +749,7 @@ static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg, int jobnr, int
...
@@ -665,7 +749,7 @@ static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg, int jobnr, int
for
(
i
=
0
;
i
<
16
;
++
i
)
{
for
(
i
=
0
;
i
<
16
;
++
i
)
{
for
(
j
=
0
;
j
<
16
;
++
j
)
{
for
(
j
=
0
;
j
<
16
;
++
j
)
{
// Turn 16-bit pixels into 10-bit ones.
// Turn 16-bit pixels into 10-bit ones.
int
const
sample
=
(
unsigned
)
pix
[
j
]
>>
6
;
int
const
sample
=
(
unsigned
)
pix
[
j
]
>>
6
;
sum
+=
sample
;
sum
+=
sample
;
sqsum
+=
sample
*
sample
;
sqsum
+=
sample
*
sample
;
// 2^10 * 2^10 * 16 * 16 = 2^28, which is less than INT_MAX
// 2^10 * 2^10 * 16 * 16 = 2^28, which is less than INT_MAX
...
@@ -689,9 +773,10 @@ static int dnxhd_encode_rdo(AVCodecContext *avctx, DNXHDEncContext *ctx)
...
@@ -689,9 +773,10 @@ static int dnxhd_encode_rdo(AVCodecContext *avctx, DNXHDEncContext *ctx)
for
(
q
=
1
;
q
<
avctx
->
qmax
;
q
++
)
{
for
(
q
=
1
;
q
<
avctx
->
qmax
;
q
++
)
{
ctx
->
qscale
=
q
;
ctx
->
qscale
=
q
;
avctx
->
execute2
(
avctx
,
dnxhd_calc_bits_thread
,
NULL
,
NULL
,
ctx
->
m
.
mb_height
);
avctx
->
execute2
(
avctx
,
dnxhd_calc_bits_thread
,
NULL
,
NULL
,
ctx
->
m
.
mb_height
);
}
}
up_step
=
down_step
=
2
<<
LAMBDA_FRAC_BITS
;
up_step
=
down_step
=
2
<<
LAMBDA_FRAC_BITS
;
lambda
=
ctx
->
lambda
;
lambda
=
ctx
->
lambda
;
for
(;;)
{
for
(;;)
{
...
@@ -705,10 +790,10 @@ static int dnxhd_encode_rdo(AVCodecContext *avctx, DNXHDEncContext *ctx)
...
@@ -705,10 +790,10 @@ static int dnxhd_encode_rdo(AVCodecContext *avctx, DNXHDEncContext *ctx)
for
(
x
=
0
;
x
<
ctx
->
m
.
mb_width
;
x
++
)
{
for
(
x
=
0
;
x
<
ctx
->
m
.
mb_width
;
x
++
)
{
unsigned
min
=
UINT_MAX
;
unsigned
min
=
UINT_MAX
;
int
qscale
=
1
;
int
qscale
=
1
;
int
mb
=
y
*
ctx
->
m
.
mb_width
+
x
;
int
mb
=
y
*
ctx
->
m
.
mb_width
+
x
;
for
(
q
=
1
;
q
<
avctx
->
qmax
;
q
++
)
{
for
(
q
=
1
;
q
<
avctx
->
qmax
;
q
++
)
{
unsigned
score
=
ctx
->
mb_rc
[
q
][
mb
].
bits
*
lambda
+
unsigned
score
=
ctx
->
mb_rc
[
q
][
mb
].
bits
*
lambda
+
((
unsigned
)
ctx
->
mb_rc
[
q
][
mb
].
ssd
<<
LAMBDA_FRAC_BITS
);
((
unsigned
)
ctx
->
mb_rc
[
q
][
mb
].
ssd
<<
LAMBDA_FRAC_BITS
);
if
(
score
<
min
)
{
if
(
score
<
min
)
{
min
=
score
;
min
=
score
;
qscale
=
q
;
qscale
=
q
;
...
@@ -718,11 +803,12 @@ static int dnxhd_encode_rdo(AVCodecContext *avctx, DNXHDEncContext *ctx)
...
@@ -718,11 +803,12 @@ static int dnxhd_encode_rdo(AVCodecContext *avctx, DNXHDEncContext *ctx)
ctx
->
mb_qscale
[
mb
]
=
qscale
;
ctx
->
mb_qscale
[
mb
]
=
qscale
;
ctx
->
mb_bits
[
mb
]
=
ctx
->
mb_rc
[
qscale
][
mb
].
bits
;
ctx
->
mb_bits
[
mb
]
=
ctx
->
mb_rc
[
qscale
][
mb
].
bits
;
}
}
bits
=
(
bits
+
31
)
&
~
31
;
// padding
bits
=
(
bits
+
31
)
&
~
31
;
// padding
if
(
bits
>
ctx
->
frame_bits
)
if
(
bits
>
ctx
->
frame_bits
)
break
;
break
;
}
}
//av_dlog(ctx->m.avctx, "lambda %d, up %u, down %u, bits %d, frame %d\n",
// av_dlog(ctx->m.avctx,
// "lambda %d, up %u, down %u, bits %d, frame %d\n",
// lambda, last_higher, last_lower, bits, ctx->frame_bits);
// lambda, last_higher, last_lower, bits, ctx->frame_bits);
if
(
end
)
{
if
(
end
)
{
if
(
bits
>
ctx
->
frame_bits
)
if
(
bits
>
ctx
->
frame_bits
)
...
@@ -772,7 +858,8 @@ static int dnxhd_find_qscale(DNXHDEncContext *ctx)
...
@@ -772,7 +858,8 @@ static int dnxhd_find_qscale(DNXHDEncContext *ctx)
bits
=
0
;
bits
=
0
;
ctx
->
qscale
=
qscale
;
ctx
->
qscale
=
qscale
;
// XXX avoid recalculating bits
// XXX avoid recalculating bits
ctx
->
m
.
avctx
->
execute2
(
ctx
->
m
.
avctx
,
dnxhd_calc_bits_thread
,
NULL
,
NULL
,
ctx
->
m
.
mb_height
);
ctx
->
m
.
avctx
->
execute2
(
ctx
->
m
.
avctx
,
dnxhd_calc_bits_thread
,
NULL
,
NULL
,
ctx
->
m
.
mb_height
);
for
(
y
=
0
;
y
<
ctx
->
m
.
mb_height
;
y
++
)
{
for
(
y
=
0
;
y
<
ctx
->
m
.
mb_height
;
y
++
)
{
for
(
x
=
0
;
x
<
ctx
->
m
.
mb_width
;
x
++
)
for
(
x
=
0
;
x
<
ctx
->
m
.
mb_width
;
x
++
)
bits
+=
ctx
->
mb_rc
[
qscale
][
y
*
ctx
->
m
.
mb_width
+
x
].
bits
;
bits
+=
ctx
->
mb_rc
[
qscale
][
y
*
ctx
->
m
.
mb_width
+
x
].
bits
;
...
@@ -780,8 +867,10 @@ static int dnxhd_find_qscale(DNXHDEncContext *ctx)
...
@@ -780,8 +867,10 @@ static int dnxhd_find_qscale(DNXHDEncContext *ctx)
if
(
bits
>
ctx
->
frame_bits
)
if
(
bits
>
ctx
->
frame_bits
)
break
;
break
;
}
}
//av_dlog(ctx->m.avctx, "%d, qscale %d, bits %d, frame %d, higher %d, lower %d\n",
// av_dlog(ctx->m.avctx,
// ctx->m.avctx->frame_number, qscale, bits, ctx->frame_bits, last_higher, last_lower);
// "%d, qscale %d, bits %d, frame %d, higher %d, lower %d\n",
// ctx->m.avctx->frame_number, qscale, bits, ctx->frame_bits,
// last_higher, last_lower);
if
(
bits
<
ctx
->
frame_bits
)
{
if
(
bits
<
ctx
->
frame_bits
)
{
if
(
qscale
==
1
)
if
(
qscale
==
1
)
return
1
;
return
1
;
...
@@ -791,7 +880,7 @@ static int dnxhd_find_qscale(DNXHDEncContext *ctx)
...
@@ -791,7 +880,7 @@ static int dnxhd_find_qscale(DNXHDEncContext *ctx)
}
}
last_lower
=
FFMIN
(
qscale
,
last_lower
);
last_lower
=
FFMIN
(
qscale
,
last_lower
);
if
(
last_higher
!=
0
)
if
(
last_higher
!=
0
)
qscale
=
(
qscale
+
last_higher
)
>>
1
;
qscale
=
(
qscale
+
last_higher
)
>>
1
;
else
else
qscale
-=
down_step
++
;
qscale
-=
down_step
++
;
if
(
qscale
<
1
)
if
(
qscale
<
1
)
...
@@ -802,7 +891,7 @@ static int dnxhd_find_qscale(DNXHDEncContext *ctx)
...
@@ -802,7 +891,7 @@ static int dnxhd_find_qscale(DNXHDEncContext *ctx)
break
;
break
;
last_higher
=
FFMAX
(
qscale
,
last_higher
);
last_higher
=
FFMAX
(
qscale
,
last_higher
);
if
(
last_lower
!=
INT_MAX
)
if
(
last_lower
!=
INT_MAX
)
qscale
=
(
qscale
+
last_lower
)
>>
1
;
qscale
=
(
qscale
+
last_lower
)
>>
1
;
else
else
qscale
+=
up_step
++
;
qscale
+=
up_step
++
;
down_step
=
1
;
down_step
=
1
;
...
@@ -826,7 +915,8 @@ static inline int get_bucket(int value, int shift)
...
@@ -826,7 +915,8 @@ static inline int get_bucket(int value, int shift)
return
NBUCKETS
-
1
-
value
;
return
NBUCKETS
-
1
-
value
;
}
}
static
void
radix_count
(
const
RCCMPEntry
*
data
,
int
size
,
int
buckets
[
RADIX_PASSES
][
NBUCKETS
])
static
void
radix_count
(
const
RCCMPEntry
*
data
,
int
size
,
int
buckets
[
RADIX_PASSES
][
NBUCKETS
])
{
{
int
i
,
j
;
int
i
,
j
;
memset
(
buckets
,
0
,
sizeof
(
buckets
[
0
][
0
])
*
RADIX_PASSES
*
NBUCKETS
);
memset
(
buckets
,
0
,
sizeof
(
buckets
[
0
][
0
])
*
RADIX_PASSES
*
NBUCKETS
);
...
@@ -846,7 +936,8 @@ static void radix_count(const RCCMPEntry *data, int size, int buckets[RADIX_PASS
...
@@ -846,7 +936,8 @@ static void radix_count(const RCCMPEntry *data, int size, int buckets[RADIX_PASS
}
}
}
}
static
void
radix_sort_pass
(
RCCMPEntry
*
dst
,
const
RCCMPEntry
*
data
,
int
size
,
int
buckets
[
NBUCKETS
],
int
pass
)
static
void
radix_sort_pass
(
RCCMPEntry
*
dst
,
const
RCCMPEntry
*
data
,
int
size
,
int
buckets
[
NBUCKETS
],
int
pass
)
{
{
int
shift
=
pass
*
BUCKET_BITS
;
int
shift
=
pass
*
BUCKET_BITS
;
int
i
;
int
i
;
...
@@ -879,30 +970,35 @@ static int dnxhd_encode_fast(AVCodecContext *avctx, DNXHDEncContext *ctx)
...
@@ -879,30 +970,35 @@ static int dnxhd_encode_fast(AVCodecContext *avctx, DNXHDEncContext *ctx)
return
ret
;
return
ret
;
for
(
y
=
0
;
y
<
ctx
->
m
.
mb_height
;
y
++
)
{
for
(
y
=
0
;
y
<
ctx
->
m
.
mb_height
;
y
++
)
{
for
(
x
=
0
;
x
<
ctx
->
m
.
mb_width
;
x
++
)
{
for
(
x
=
0
;
x
<
ctx
->
m
.
mb_width
;
x
++
)
{
int
mb
=
y
*
ctx
->
m
.
mb_width
+
x
;
int
mb
=
y
*
ctx
->
m
.
mb_width
+
x
;
int
delta_bits
;
int
delta_bits
;
ctx
->
mb_qscale
[
mb
]
=
ctx
->
qscale
;
ctx
->
mb_qscale
[
mb
]
=
ctx
->
qscale
;
ctx
->
mb_bits
[
mb
]
=
ctx
->
mb_rc
[
ctx
->
qscale
][
mb
].
bits
;
ctx
->
mb_bits
[
mb
]
=
ctx
->
mb_rc
[
ctx
->
qscale
][
mb
].
bits
;
max_bits
+=
ctx
->
mb_rc
[
ctx
->
qscale
][
mb
].
bits
;
max_bits
+=
ctx
->
mb_rc
[
ctx
->
qscale
][
mb
].
bits
;
if
(
!
RC_VARIANCE
)
{
if
(
!
RC_VARIANCE
)
{
delta_bits
=
ctx
->
mb_rc
[
ctx
->
qscale
][
mb
].
bits
-
ctx
->
mb_rc
[
ctx
->
qscale
+
1
][
mb
].
bits
;
delta_bits
=
ctx
->
mb_rc
[
ctx
->
qscale
][
mb
].
bits
-
ctx
->
mb_rc
[
ctx
->
qscale
+
1
][
mb
].
bits
;
ctx
->
mb_cmp
[
mb
].
mb
=
mb
;
ctx
->
mb_cmp
[
mb
].
mb
=
mb
;
ctx
->
mb_cmp
[
mb
].
value
=
delta_bits
?
ctx
->
mb_cmp
[
mb
].
value
=
((
ctx
->
mb_rc
[
ctx
->
qscale
][
mb
].
ssd
-
ctx
->
mb_rc
[
ctx
->
qscale
+
1
][
mb
].
ssd
)
*
100
)
/
delta_bits
delta_bits
?
((
ctx
->
mb_rc
[
ctx
->
qscale
][
mb
].
ssd
-
:
INT_MIN
;
//avoid increasing qscale
ctx
->
mb_rc
[
ctx
->
qscale
+
1
][
mb
].
ssd
)
*
100
)
/
delta_bits
:
INT_MIN
;
// avoid increasing qscale
}
}
}
}
max_bits
+=
31
;
//worst padding
max_bits
+=
31
;
//
worst padding
}
}
if
(
!
ret
)
{
if
(
!
ret
)
{
if
(
RC_VARIANCE
)
if
(
RC_VARIANCE
)
avctx
->
execute2
(
avctx
,
dnxhd_mb_var_thread
,
NULL
,
NULL
,
ctx
->
m
.
mb_height
);
avctx
->
execute2
(
avctx
,
dnxhd_mb_var_thread
,
NULL
,
NULL
,
ctx
->
m
.
mb_height
);
radix_sort
(
ctx
->
mb_cmp
,
ctx
->
m
.
mb_num
);
radix_sort
(
ctx
->
mb_cmp
,
ctx
->
m
.
mb_num
);
for
(
x
=
0
;
x
<
ctx
->
m
.
mb_num
&&
max_bits
>
ctx
->
frame_bits
;
x
++
)
{
for
(
x
=
0
;
x
<
ctx
->
m
.
mb_num
&&
max_bits
>
ctx
->
frame_bits
;
x
++
)
{
int
mb
=
ctx
->
mb_cmp
[
x
].
mb
;
int
mb
=
ctx
->
mb_cmp
[
x
].
mb
;
max_bits
-=
ctx
->
mb_rc
[
ctx
->
qscale
][
mb
].
bits
-
ctx
->
mb_rc
[
ctx
->
qscale
+
1
][
mb
].
bits
;
max_bits
-=
ctx
->
mb_rc
[
ctx
->
qscale
][
mb
].
bits
-
ctx
->
mb_qscale
[
mb
]
=
ctx
->
qscale
+
1
;
ctx
->
mb_rc
[
ctx
->
qscale
+
1
][
mb
].
bits
;
ctx
->
mb_bits
[
mb
]
=
ctx
->
mb_rc
[
ctx
->
qscale
+
1
][
mb
].
bits
;
ctx
->
mb_qscale
[
mb
]
=
ctx
->
qscale
+
1
;
ctx
->
mb_bits
[
mb
]
=
ctx
->
mb_rc
[
ctx
->
qscale
+
1
][
mb
].
bits
;
}
}
}
}
return
0
;
return
0
;
...
@@ -932,14 +1028,15 @@ static int dnxhd_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
...
@@ -932,14 +1028,15 @@ static int dnxhd_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
uint8_t
*
buf
;
uint8_t
*
buf
;
if
((
ret
=
ff_alloc_packet
(
pkt
,
ctx
->
cid_table
->
frame_size
))
<
0
)
{
if
((
ret
=
ff_alloc_packet
(
pkt
,
ctx
->
cid_table
->
frame_size
))
<
0
)
{
av_log
(
avctx
,
AV_LOG_ERROR
,
"output buffer is too small to compress picture
\n
"
);
av_log
(
avctx
,
AV_LOG_ERROR
,
"output buffer is too small to compress picture
\n
"
);
return
ret
;
return
ret
;
}
}
buf
=
pkt
->
data
;
buf
=
pkt
->
data
;
dnxhd_load_picture
(
ctx
,
frame
);
dnxhd_load_picture
(
ctx
,
frame
);
encode_coding_unit:
encode_coding_unit:
for
(
i
=
0
;
i
<
3
;
i
++
)
{
for
(
i
=
0
;
i
<
3
;
i
++
)
{
ctx
->
src
[
i
]
=
frame
->
data
[
i
];
ctx
->
src
[
i
]
=
frame
->
data
[
i
];
if
(
ctx
->
interlaced
&&
ctx
->
cur_field
)
if
(
ctx
->
interlaced
&&
ctx
->
cur_field
)
...
@@ -970,7 +1067,8 @@ static int dnxhd_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
...
@@ -970,7 +1067,8 @@ static int dnxhd_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
avctx
->
execute2
(
avctx
,
dnxhd_encode_thread
,
buf
,
NULL
,
ctx
->
m
.
mb_height
);
avctx
->
execute2
(
avctx
,
dnxhd_encode_thread
,
buf
,
NULL
,
ctx
->
m
.
mb_height
);
assert
(
640
+
offset
+
4
<=
ctx
->
cid_table
->
coding_unit_size
);
assert
(
640
+
offset
+
4
<=
ctx
->
cid_table
->
coding_unit_size
);
memset
(
buf
+
640
+
offset
,
0
,
ctx
->
cid_table
->
coding_unit_size
-
4
-
offset
-
640
);
memset
(
buf
+
640
+
offset
,
0
,
ctx
->
cid_table
->
coding_unit_size
-
4
-
offset
-
640
);
AV_WB32
(
buf
+
ctx
->
cid_table
->
coding_unit_size
-
4
,
0x600DC0DE
);
// EOF
AV_WB32
(
buf
+
ctx
->
cid_table
->
coding_unit_size
-
4
,
0x600DC0DE
);
// EOF
...
@@ -991,11 +1089,11 @@ static int dnxhd_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
...
@@ -991,11 +1089,11 @@ static int dnxhd_encode_picture(AVCodecContext *avctx, AVPacket *pkt,
static
av_cold
int
dnxhd_encode_end
(
AVCodecContext
*
avctx
)
static
av_cold
int
dnxhd_encode_end
(
AVCodecContext
*
avctx
)
{
{
DNXHDEncContext
*
ctx
=
avctx
->
priv_data
;
DNXHDEncContext
*
ctx
=
avctx
->
priv_data
;
int
max_level
=
1
<<
(
ctx
->
cid_table
->
bit_depth
+
2
);
int
max_level
=
1
<<
(
ctx
->
cid_table
->
bit_depth
+
2
);
int
i
;
int
i
;
av_free
(
ctx
->
vlc_codes
-
max_level
*
2
);
av_free
(
ctx
->
vlc_codes
-
max_level
*
2
);
av_free
(
ctx
->
vlc_bits
-
max_level
*
2
);
av_free
(
ctx
->
vlc_bits
-
max_level
*
2
);
av_freep
(
&
ctx
->
run_codes
);
av_freep
(
&
ctx
->
run_codes
);
av_freep
(
&
ctx
->
run_bits
);
av_freep
(
&
ctx
->
run_bits
);
...
@@ -1029,8 +1127,10 @@ AVCodec ff_dnxhd_encoder = {
...
@@ -1029,8 +1127,10 @@ AVCodec ff_dnxhd_encoder = {
.
encode2
=
dnxhd_encode_picture
,
.
encode2
=
dnxhd_encode_picture
,
.
close
=
dnxhd_encode_end
,
.
close
=
dnxhd_encode_end
,
.
capabilities
=
CODEC_CAP_SLICE_THREADS
,
.
capabilities
=
CODEC_CAP_SLICE_THREADS
,
.
pix_fmts
=
(
const
enum
AVPixelFormat
[]){
AV_PIX_FMT_YUV422P
,
.
pix_fmts
=
(
const
enum
AVPixelFormat
[])
{
AV_PIX_FMT_YUV422P
,
AV_PIX_FMT_YUV422P10
,
AV_PIX_FMT_YUV422P10
,
AV_PIX_FMT_NONE
},
AV_PIX_FMT_NONE
},
.
priv_class
=
&
class
,
.
priv_class
=
&
class
,
};
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment