Commit efec857c authored by Jan Ekström's avatar Jan Ekström Committed by Michael Niedermayer

utvideoenc: Enable support for multiple slices and use them

The official Ut Video decoder only threads with slices, thus until
now any files encoded by the libavcodec encoder have only been
decodable with a single thread. The default slice count is now
set to subsampled_height / 120.

Also sets slices to 1 for the Ut Video encoder tests to keep them
green.
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 92225877
...@@ -58,7 +58,7 @@ static av_cold int utvideo_encode_close(AVCodecContext *avctx) ...@@ -58,7 +58,7 @@ static av_cold int utvideo_encode_close(AVCodecContext *avctx)
static av_cold int utvideo_encode_init(AVCodecContext *avctx) static av_cold int utvideo_encode_init(AVCodecContext *avctx)
{ {
UtvideoContext *c = avctx->priv_data; UtvideoContext *c = avctx->priv_data;
int i; int i, subsampled_height;
uint32_t original_format; uint32_t original_format;
c->avctx = avctx; c->avctx = avctx;
...@@ -132,6 +132,26 @@ static av_cold int utvideo_encode_init(AVCodecContext *avctx) ...@@ -132,6 +132,26 @@ static av_cold int utvideo_encode_init(AVCodecContext *avctx)
return AVERROR_OPTION_NOT_FOUND; return AVERROR_OPTION_NOT_FOUND;
} }
/*
* Check the asked slice count for obviously invalid
* values (> 256 or negative).
*/
if (avctx->slices > 256 || avctx->slices < 0) {
av_log(avctx, AV_LOG_ERROR,
"Slice count %d is not supported in Ut Video (theoretical range is 0-256).\n",
avctx->slices);
return AVERROR(EINVAL);
}
/* Check that the slice count is not larger than the subsampled height */
subsampled_height = avctx->height >> av_pix_fmt_desc_get(avctx->pix_fmt)->log2_chroma_h;
if (avctx->slices > subsampled_height) {
av_log(avctx, AV_LOG_ERROR,
"Slice count %d is larger than the subsampling-applied height %d.\n",
avctx->slices, subsampled_height);
return AVERROR(EINVAL);
}
avctx->coded_frame = av_frame_alloc(); avctx->coded_frame = av_frame_alloc();
if (!avctx->coded_frame) { if (!avctx->coded_frame) {
...@@ -181,9 +201,20 @@ static av_cold int utvideo_encode_init(AVCodecContext *avctx) ...@@ -181,9 +201,20 @@ static av_cold int utvideo_encode_init(AVCodecContext *avctx)
/* /*
* Set how many slices are going to be used. * Set how many slices are going to be used.
* Set one slice for now. * By default uses multiple slices depending on the subsampled height.
* This enables multithreading in the official decoder.
*/ */
c->slices = 1; if (!avctx->slices) {
c->slices = subsampled_height / 120;
if (!c->slices) {
c->slices = 1;
} else if (c->slices > 256) {
c->slices = 256;
}
} else {
c->slices = avctx->slices;
}
/* Set compression mode */ /* Set compression mode */
c->compression = COMP_HUFF; c->compression = COMP_HUFF;
......
...@@ -28,7 +28,7 @@ fate-utvideo_yuv422_median: CMD = framecrc -i $(TARGET_SAMPLES)/utvideo/utvideo_ ...@@ -28,7 +28,7 @@ fate-utvideo_yuv422_median: CMD = framecrc -i $(TARGET_SAMPLES)/utvideo/utvideo_
FATE_SAMPLES_AVCONV-$(call DEMDEC, AVI, UTVIDEO) += $(FATE_UTVIDEO) FATE_SAMPLES_AVCONV-$(call DEMDEC, AVI, UTVIDEO) += $(FATE_UTVIDEO)
fate-utvideo: $(FATE_UTVIDEO) fate-utvideo: $(FATE_UTVIDEO)
fate-utvideoenc%: CMD = framemd5 -f image2 -vcodec pgmyuv -i $(TARGET_PATH)/tests/vsynth1/%02d.pgm -vcodec utvideo -sws_flags +accurate_rnd+bitexact ${OPTS} fate-utvideoenc%: CMD = framemd5 -f image2 -vcodec pgmyuv -i $(TARGET_PATH)/tests/vsynth1/%02d.pgm -vcodec utvideo -slices 1 -sws_flags +accurate_rnd+bitexact ${OPTS}
FATE_UTVIDEOENC += fate-utvideoenc_rgba_left FATE_UTVIDEOENC += fate-utvideoenc_rgba_left
fate-utvideoenc_rgba_left: OPTS = -pix_fmt rgba -pred left fate-utvideoenc_rgba_left: OPTS = -pix_fmt rgba -pred left
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment