The way it is currently designed is fundamentally unsafe and cannot be reasonably fixed without completely rewriting it.tags/n2.7
@@ -28,6 +28,7 @@ | |||||
#include "libavutil/avassert.h" | #include "libavutil/avassert.h" | ||||
#include "libavutil/display.h" | #include "libavutil/display.h" | ||||
#include "libavutil/imgutils.h" | #include "libavutil/imgutils.h" | ||||
#include "libavutil/opt.h" | |||||
#include "libavutil/stereo3d.h" | #include "libavutil/stereo3d.h" | ||||
#include "libavutil/timer.h" | #include "libavutil/timer.h" | ||||
#include "internal.h" | #include "internal.h" | ||||
@@ -666,6 +667,12 @@ av_cold int ff_h264_decode_init(AVCodecContext *avctx) | |||||
avctx->internal->allocate_progress = 1; | avctx->internal->allocate_progress = 1; | ||||
if (h->enable_er) { | |||||
av_log(avctx, AV_LOG_WARNING, | |||||
"Error resilience is enabled. It is unsafe and unsupported and may crash. " | |||||
"Use it at your own risk\n"); | |||||
} | |||||
return 0; | return 0; | ||||
} | } | ||||
@@ -1786,6 +1793,20 @@ static av_cold int h264_decode_end(AVCodecContext *avctx) | |||||
return 0; | return 0; | ||||
} | } | ||||
#define OFFSET(x) offsetof(H264Context, x) | |||||
#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM | |||||
static const AVOption h264_options[] = { | |||||
{ "enable_er", "Enable error resilience on damaged frames (unsafe)", OFFSET(enable_er), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VD }, | |||||
{ NULL }, | |||||
}; | |||||
static const AVClass h264_class = { | |||||
.class_name = "h264", | |||||
.item_name = av_default_item_name, | |||||
.option = h264_options, | |||||
.version = LIBAVUTIL_VERSION_INT, | |||||
}; | |||||
static const AVProfile profiles[] = { | static const AVProfile profiles[] = { | ||||
{ FF_PROFILE_H264_BASELINE, "Baseline" }, | { FF_PROFILE_H264_BASELINE, "Baseline" }, | ||||
{ FF_PROFILE_H264_CONSTRAINED_BASELINE, "Constrained Baseline" }, | { FF_PROFILE_H264_CONSTRAINED_BASELINE, "Constrained Baseline" }, | ||||
@@ -1819,4 +1840,5 @@ AVCodec ff_h264_decoder = { | |||||
.init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy), | .init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy), | ||||
.update_thread_context = ONLY_IF_THREADS_ENABLED(ff_h264_update_thread_context), | .update_thread_context = ONLY_IF_THREADS_ENABLED(ff_h264_update_thread_context), | ||||
.profiles = NULL_IF_CONFIG_SMALL(profiles), | .profiles = NULL_IF_CONFIG_SMALL(profiles), | ||||
.priv_class = &h264_class, | |||||
}; | }; |
@@ -727,6 +727,8 @@ typedef struct H264Context { | |||||
int cur_chroma_format_idc; | int cur_chroma_format_idc; | ||||
int enable_er; | |||||
AVBufferPool *qscale_table_pool; | AVBufferPool *qscale_table_pool; | ||||
AVBufferPool *mb_type_pool; | AVBufferPool *mb_type_pool; | ||||
AVBufferPool *motion_val_pool; | AVBufferPool *motion_val_pool; | ||||
@@ -184,7 +184,7 @@ int ff_h264_field_end(H264Context *h, H264SliceContext *sl, int in_setup) | |||||
* past end by one (callers fault) and resync_mb_y != 0 | * past end by one (callers fault) and resync_mb_y != 0 | ||||
* causes problems for the first MB line, too. | * causes problems for the first MB line, too. | ||||
*/ | */ | ||||
if (!FIELD_PICTURE(h)) { | |||||
if (!FIELD_PICTURE(h) && h->enable_er) { | |||||
h264_set_erpic(&sl->er.cur_pic, h->cur_pic_ptr); | h264_set_erpic(&sl->er.cur_pic, h->cur_pic_ptr); | ||||
h264_set_erpic(&sl->er.last_pic, | h264_set_erpic(&sl->er.last_pic, | ||||
sl->ref_count[0] ? sl->ref_list[0][0].parent : NULL); | sl->ref_count[0] ? sl->ref_list[0][0].parent : NULL); | ||||
@@ -530,6 +530,7 @@ int ff_h264_update_thread_context(AVCodecContext *dst, | |||||
return ret; | return ret; | ||||
} | } | ||||
h->enable_er = h1->enable_er; | |||||
h->workaround_bugs = h1->workaround_bugs; | h->workaround_bugs = h1->workaround_bugs; | ||||
h->low_delay = h1->low_delay; | h->low_delay = h1->low_delay; | ||||
h->droppable = h1->droppable; | h->droppable = h1->droppable; | ||||
@@ -633,7 +634,7 @@ static int h264_frame_start(H264Context *h) | |||||
if ((ret = ff_h264_ref_picture(h, &h->cur_pic, h->cur_pic_ptr)) < 0) | if ((ret = ff_h264_ref_picture(h, &h->cur_pic, h->cur_pic_ptr)) < 0) | ||||
return ret; | return ret; | ||||
if (CONFIG_ERROR_RESILIENCE) | |||||
if (CONFIG_ERROR_RESILIENCE && h->enable_er) | |||||
ff_er_frame_start(&h->slice_ctx[0].er); | ff_er_frame_start(&h->slice_ctx[0].er); | ||||
for (i = 0; i < 16; i++) { | for (i = 0; i < 16; i++) { | ||||
@@ -2061,6 +2062,9 @@ static void er_add_slice(H264SliceContext *sl, | |||||
#if CONFIG_ERROR_RESILIENCE | #if CONFIG_ERROR_RESILIENCE | ||||
ERContext *er = &sl->er; | ERContext *er = &sl->er; | ||||
if (!sl->h264->enable_er) | |||||
return; | |||||
er->ref_count = sl->ref_count[0]; | er->ref_count = sl->ref_count[0]; | ||||
ff_er_add_slice(er, startx, starty, endx, endy, status); | ff_er_add_slice(er, startx, starty, endx, endy, status); | ||||
#endif | #endif | ||||