nvdec: Port to color_{primaries,transfer,matrix}_to_iso

... and update the color information only when upstream was not provided
the information.
This commit is contained in:
Seungha Yang 2019-07-15 23:40:21 +09:00 committed by Sebastian Dröge
parent e01c68524f
commit 8753561015

View file

@ -685,6 +685,8 @@ handle_pending_frames (GstNvDec * nvdec)
if (!gst_pad_has_current_caps (GST_VIDEO_DECODER_SRC_PAD (decoder)) if (!gst_pad_has_current_caps (GST_VIDEO_DECODER_SRC_PAD (decoder))
|| width != nvdec->width || height != nvdec->height || width != nvdec->width || height != nvdec->height
|| fps_n != nvdec->fps_n || fps_d != nvdec->fps_d) { || fps_n != nvdec->fps_n || fps_d != nvdec->fps_d) {
GstStructure *in_s = NULL;
nvdec->width = width; nvdec->width = width;
nvdec->height = height; nvdec->height = height;
nvdec->fps_n = fps_n; nvdec->fps_n = fps_n;
@ -715,95 +717,41 @@ handle_pending_frames (GstNvDec * nvdec)
format->video_signal_description.transfer_characteristics, format->video_signal_description.transfer_characteristics,
format->video_signal_description.color_primaries); format->video_signal_description.color_primaries);
switch (format->video_signal_description.color_primaries) { if (nvdec->input_state->caps)
case 1: in_s = gst_caps_get_structure (nvdec->input_state->caps, 0);
vinfo->colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_BT709;
break;
case 4:
vinfo->colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_BT470M;
break;
case 5:
vinfo->colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_BT470BG;
break;
case 6:
vinfo->colorimetry.primaries =
GST_VIDEO_COLOR_PRIMARIES_SMPTE170M;
break;
case 7:
vinfo->colorimetry.primaries =
GST_VIDEO_COLOR_PRIMARIES_SMPTE240M;
break;
case 8:
vinfo->colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_FILM;
break;
case 9:
vinfo->colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_BT2020;
break;
default:
vinfo->colorimetry.primaries = GST_VIDEO_COLOR_PRIMARIES_UNKNOWN;
} /* Set colorimetry when upstream did not provide it */
if (in_s && !gst_structure_has_field (in_s, "colorimetry")) {
GstVideoColorimetry colorimetry = { 0, };
if (format->video_signal_description.video_full_range_flag) if (format->video_signal_description.video_full_range_flag)
vinfo->colorimetry.range = GST_VIDEO_COLOR_RANGE_0_255; colorimetry.range = GST_VIDEO_COLOR_RANGE_0_255;
else else
vinfo->colorimetry.range = GST_VIDEO_COLOR_RANGE_16_235; colorimetry.range = GST_VIDEO_COLOR_RANGE_16_235;
switch (format->video_signal_description.transfer_characteristics) { colorimetry.primaries =
case 1: gst_video_color_primaries_from_iso
case 6: (format->video_signal_description.color_primaries);
case 16:
vinfo->colorimetry.transfer = GST_VIDEO_TRANSFER_BT709; colorimetry.transfer =
break; gst_video_color_transfer_from_iso
case 4: (format->video_signal_description.transfer_characteristics);
vinfo->colorimetry.transfer = GST_VIDEO_TRANSFER_GAMMA22;
break; colorimetry.matrix =
case 5: gst_video_color_matrix_from_iso
vinfo->colorimetry.transfer = GST_VIDEO_TRANSFER_GAMMA28; (format->video_signal_description.matrix_coefficients);
break;
case 7: /* Use a colorimetry having at least one valid colorimetry entry,
vinfo->colorimetry.transfer = GST_VIDEO_TRANSFER_SMPTE240M; * because we don't know whether the returned
break; * colorimetry (by nvdec) was actually parsed information or not.
case 8: * Otherwise let GstVideoInfo handle it with default colorimetry */
vinfo->colorimetry.transfer = GST_VIDEO_TRANSFER_GAMMA10; if (colorimetry.primaries != GST_VIDEO_COLOR_PRIMARIES_UNKNOWN ||
break; colorimetry.transfer != GST_VIDEO_TRANSFER_UNKNOWN ||
case 9: colorimetry.matrix != GST_VIDEO_COLOR_MATRIX_UNKNOWN) {
vinfo->colorimetry.transfer = GST_VIDEO_TRANSFER_LOG100; GST_DEBUG_OBJECT (decoder,
break; "Found valid colorimetry, update output colorimetry");
case 10: vinfo->colorimetry = colorimetry;
vinfo->colorimetry.transfer = GST_VIDEO_TRANSFER_LOG316;
break;
case 15:
vinfo->colorimetry.transfer = GST_VIDEO_TRANSFER_BT2020_12;
break;
default:
vinfo->colorimetry.transfer = GST_VIDEO_TRANSFER_UNKNOWN;
break;
} }
switch (format->video_signal_description.matrix_coefficients) {
case 0:
vinfo->colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_RGB;
break;
case 1:
vinfo->colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_BT709;
break;
case 4:
vinfo->colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_FCC;
break;
case 5:
case 6:
vinfo->colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_BT601;
break;
case 7:
vinfo->colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_SMPTE240M;
break;
case 9:
case 10:
vinfo->colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_BT2020;
break;
default:
vinfo->colorimetry.matrix = GST_VIDEO_COLOR_MATRIX_UNKNOWN;
break;
} }
state->caps = gst_video_info_to_caps (&state->info); state->caps = gst_video_info_to_caps (&state->info);