Commit 52771413 authored by François Cartegnie's avatar François Cartegnie 🤞

packetizer: mpegvideo: simplify color setup

parent e30314a4
packetizerdir = $(pluginsdir)/packetizer
libpacketizer_copy_plugin_la_SOURCES = packetizer/copy.c
libpacketizer_mpegvideo_plugin_la_SOURCES = packetizer/mpegvideo.c
libpacketizer_mpeg4video_plugin_la_SOURCES = packetizer/mpeg4video.c
libpacketizer_mpegvideo_plugin_la_SOURCES = packetizer/mpegvideo.c \
packetizer/iso_color_tables.h
libpacketizer_mpeg4video_plugin_la_SOURCES = packetizer/mpeg4video.c \
packetizer/iso_color_tables.h
libpacketizer_mjpeg_plugin_la_SOURCES = packetizer/mjpeg.c
libpacketizer_mpeg4audio_plugin_la_SOURCES = packetizer/mpeg4audio.c
libpacketizer_mpegaudio_plugin_la_SOURCES = packetizer/mpegaudio.c
......@@ -11,7 +13,8 @@ libpacketizer_h264_plugin_la_SOURCES = \
packetizer/h264_slice.c packetizer/h264_slice.h \
packetizer/h264.c packetizer/hxxx_nal.h \
packetizer/hxxx_sei.c packetizer/hxxx_sei.h \
packetizer/hxxx_common.c packetizer/hxxx_common.h
packetizer/hxxx_common.c packetizer/hxxx_common.h \
packetizer/iso_color_tables.h
libpacketizer_vc1_plugin_la_SOURCES = packetizer/vc1.c \
packetizer/hxxx_nal.h
libpacketizer_mlp_plugin_la_SOURCES = packetizer/mlp.c
......@@ -21,7 +24,8 @@ libpacketizer_hevc_plugin_la_SOURCES = packetizer/hevc.c \
packetizer/hevc_nal.h packetizer/hevc_nal.c \
packetizer/hxxx_sei.c packetizer/hxxx_sei.h \
packetizer/hxxx_nal.h \
packetizer/hxxx_common.c packetizer/hxxx_common.h
packetizer/hxxx_common.c packetizer/hxxx_common.h \
packetizer/iso_color_tables.h
libpacketizer_a52_plugin_la_SOURCES = packetizer/a52.c packetizer/a52.h
libpacketizer_dts_plugin_la_SOURCES = packetizer/dts.c \
packetizer/dts_header.c packetizer/dts_header.h
......
......@@ -25,6 +25,7 @@
#include "h264_nal.h"
#include "hxxx_nal.h"
#include "iso_color_tables.h"
#include <vlc_bits.h>
#include <vlc_boxes.h>
......@@ -460,9 +461,9 @@ static bool h264_parse_sequence_parameter_set_rbsp( bs_t *p_bs,
}
else
{
p_sps->vui.colour.i_colour_primaries = HXXX_PRIMARIES_UNSPECIFIED;
p_sps->vui.colour.i_transfer_characteristics = HXXX_TRANSFER_UNSPECIFIED;
p_sps->vui.colour.i_matrix_coefficients = HXXX_MATRIX_UNSPECIFIED;
p_sps->vui.colour.i_colour_primaries = ISO_23001_8_CP_UNSPECIFIED;
p_sps->vui.colour.i_transfer_characteristics = ISO_23001_8_TC_UNSPECIFIED;
p_sps->vui.colour.i_matrix_coefficients = ISO_23001_8_MC_UNSPECIFIED;
}
}
......@@ -806,11 +807,11 @@ bool h264_get_colorimetry( const h264_sequence_parameter_set_t *p_sps,
if( !p_sps->vui.b_valid )
return false;
*p_primaries =
hxxx_colour_primaries_to_vlc( p_sps->vui.colour.i_colour_primaries );
iso_23001_8_cp_to_vlc_primaries( p_sps->vui.colour.i_colour_primaries );
*p_transfer =
hxxx_transfer_characteristics_to_vlc( p_sps->vui.colour.i_transfer_characteristics );
iso_23001_8_tc_to_vlc_xfer( p_sps->vui.colour.i_transfer_characteristics );
*p_colorspace =
hxxx_matrix_coeffs_to_vlc( p_sps->vui.colour.i_matrix_coefficients );
iso_23001_8_mc_to_vlc_coeffs( p_sps->vui.colour.i_matrix_coefficients );
*p_full_range = p_sps->vui.colour.b_full_range;
return true;
}
......
......@@ -23,6 +23,7 @@
#include "hevc_nal.h"
#include "hxxx_nal.h"
#include "iso_color_tables.h"
#include <vlc_common.h>
#include <vlc_bits.h>
......@@ -472,9 +473,9 @@ static bool hevc_parse_vui_parameters_rbsp( bs_t *p_bs, hevc_vui_parameters_t *p
}
else
{
p_vui->vs.colour.colour_primaries = HXXX_PRIMARIES_UNSPECIFIED;
p_vui->vs.colour.transfer_characteristics = HXXX_TRANSFER_UNSPECIFIED;
p_vui->vs.colour.matrix_coeffs = HXXX_MATRIX_UNSPECIFIED;
p_vui->vs.colour.colour_primaries = ISO_23001_8_CP_UNSPECIFIED;
p_vui->vs.colour.transfer_characteristics = ISO_23001_8_TC_UNSPECIFIED;
p_vui->vs.colour.matrix_coeffs = ISO_23001_8_MC_UNSPECIFIED;
}
}
......@@ -1179,11 +1180,11 @@ bool hevc_get_colorimetry( const hevc_sequence_parameter_set_t *p_sps,
if( !p_sps->vui_parameters_present_flag )
return false;
*p_primaries =
hxxx_colour_primaries_to_vlc( p_sps->vui.vs.colour.colour_primaries );
iso_23001_8_cp_to_vlc_primaries( p_sps->vui.vs.colour.colour_primaries );
*p_transfer =
hxxx_transfer_characteristics_to_vlc( p_sps->vui.vs.colour.transfer_characteristics );
iso_23001_8_tc_to_vlc_xfer( p_sps->vui.vs.colour.transfer_characteristics );
*p_colorspace =
hxxx_matrix_coeffs_to_vlc( p_sps->vui.vs.colour.matrix_coeffs );
iso_23001_8_mc_to_vlc_coeffs( p_sps->vui.vs.colour.matrix_coeffs );
*p_full_range = p_sps->vui.vs.video_full_range_flag;
return true;
}
......
......@@ -27,157 +27,6 @@
static const uint8_t annexb_startcode4[] = { 0x00, 0x00, 0x00, 0x01 };
#define annexb_startcode3 (&annexb_startcode4[1])
/* Annex E: Colour primaries */
enum hxxx_colour_primaries
{
HXXX_PRIMARIES_RESERVED0 = 0,
HXXX_PRIMARIES_BT709 = 1,
HXXX_PRIMARIES_UNSPECIFIED = 2,
HXXX_PRIMARIES_RESERVED3 = 3,
HXXX_PRIMARIES_BT470M = 4,
HXXX_PRIMARIES_BT470BG = 5,
HXXX_PRIMARIES_BT601_525 = 6,
HXXX_PRIMARIES_SMTPE_240M = 7,
HXXX_PRIMARIES_GENERIC_FILM = 8,
HXXX_PRIMARIES_BT2020 = 9,
HXXX_PRIMARIES_SMPTE_ST_428 = 10,
};
static inline video_color_primaries_t
hxxx_colour_primaries_to_vlc( enum hxxx_colour_primaries i_colour )
{
switch( i_colour )
{
case HXXX_PRIMARIES_BT470BG:
return COLOR_PRIMARIES_BT601_625;
case HXXX_PRIMARIES_BT601_525:
case HXXX_PRIMARIES_SMTPE_240M:
return COLOR_PRIMARIES_BT601_625;
case HXXX_PRIMARIES_BT709:
return COLOR_PRIMARIES_BT709;
case HXXX_PRIMARIES_BT2020:
return COLOR_PRIMARIES_BT2020;
case HXXX_PRIMARIES_BT470M:
case HXXX_PRIMARIES_RESERVED0:
case HXXX_PRIMARIES_UNSPECIFIED:
case HXXX_PRIMARIES_RESERVED3:
case HXXX_PRIMARIES_GENERIC_FILM:
case HXXX_PRIMARIES_SMPTE_ST_428:
default:
return COLOR_PRIMARIES_UNDEF;
}
}
/* Annex E: Transfer characteristics */
enum hxxx_transfer_characteristics
{
HXXX_TRANSFER_RESERVED0 = 0,
HXXX_TRANSFER_BT709 = 1,
HXXX_TRANSFER_UNSPECIFIED = 2,
HXXX_TRANSFER_RESERVED3 = 3,
HXXX_TRANSFER_BT470M = 4,
HXXX_TRANSFER_BT470BG = 5,
HXXX_TRANSFER_BT601_525 = 6,
HXXX_TRANSFER_SMTPE_240M = 7,
HXXX_TRANSFER_LINEAR = 8,
HXXX_TRANSFER_LOG = 9,
HXXX_TRANSFER_LOG_SQRT = 10,
HXXX_TRANSFER_IEC61966_2_4 = 11,
HXXX_TRANSFER_BT1361 = 12,
HXXX_TRANSFER_IEC61966_2_1 = 13,
HXXX_TRANSFER_BT2020_V14 = 14,
HXXX_TRANSFER_BT2020_V15 = 15,
HXXX_TRANSFER_SMPTE_ST_2084 = 16,
HXXX_TRANSFER_SMPTE_ST_428 = 17,
HXXX_TRANSFER_ARIB_STD_B67 = 18,
};
static inline video_transfer_func_t
hxxx_transfer_characteristics_to_vlc( enum hxxx_transfer_characteristics i_transfer )
{
switch( i_transfer )
{
case HXXX_TRANSFER_LINEAR:
return TRANSFER_FUNC_LINEAR;
case HXXX_TRANSFER_BT470M:
return TRANSFER_FUNC_SRGB;
case HXXX_TRANSFER_BT709:
case HXXX_TRANSFER_BT601_525:
case HXXX_TRANSFER_BT2020_V14:
case HXXX_TRANSFER_BT2020_V15:
return TRANSFER_FUNC_BT709;
case HXXX_TRANSFER_SMPTE_ST_2084:
return TRANSFER_FUNC_SMPTE_ST2084;
case HXXX_TRANSFER_ARIB_STD_B67:
return TRANSFER_FUNC_ARIB_B67;
case HXXX_TRANSFER_RESERVED0:
case HXXX_TRANSFER_UNSPECIFIED:
case HXXX_TRANSFER_RESERVED3:
case HXXX_TRANSFER_BT470BG:
case HXXX_TRANSFER_SMTPE_240M:
case HXXX_TRANSFER_LOG:
case HXXX_TRANSFER_LOG_SQRT:
case HXXX_TRANSFER_IEC61966_2_4:
case HXXX_TRANSFER_BT1361:
case HXXX_TRANSFER_IEC61966_2_1:
case HXXX_TRANSFER_SMPTE_ST_428:
default:
return TRANSFER_FUNC_UNDEF;
};
}
/* Annex E: Matrix coefficients */
enum hxxx_matrix_coeffs
{
HXXX_MATRIX_IDENTITY = 0,
HXXX_MATRIX_BT709 = 1,
HXXX_MATRIX_UNSPECIFIED = 2,
HXXX_MATRIX_RESERVED = 3,
HXXX_MATRIX_FCC = 4,
HXXX_MATRIX_BT470BG = 5,
HXXX_MATRIX_BT601_525 = 6,
HXXX_MATRIX_SMTPE_240M = 7,
HXXX_MATRIX_YCGCO = 8,
HXXX_MATRIX_BT2020_NCL = 9,
HXXX_MATRIX_BT2020_CL = 10,
};
static inline video_color_space_t
hxxx_matrix_coeffs_to_vlc( enum hxxx_matrix_coeffs i_transfer )
{
switch( i_transfer )
{
case HXXX_MATRIX_BT470BG:
case HXXX_MATRIX_BT601_525:
return COLOR_SPACE_BT601;
case HXXX_MATRIX_BT709:
return COLOR_SPACE_BT709;
case HXXX_MATRIX_BT2020_NCL:
case HXXX_MATRIX_BT2020_CL:
return COLOR_SPACE_BT2020;
case HXXX_MATRIX_IDENTITY:
case HXXX_MATRIX_UNSPECIFIED:
case HXXX_MATRIX_RESERVED:
case HXXX_MATRIX_FCC:
case HXXX_MATRIX_SMTPE_240M:
case HXXX_MATRIX_YCGCO:
default:
return COLOR_SPACE_UNDEF;
}
}
/* strips any AnnexB startcode [0] 0 0 1 */
static inline bool hxxx_strip_AnnexB_startcode( const uint8_t **pp_data, size_t *pi_data )
{
......
......@@ -41,7 +41,7 @@
#include <vlc_block_helper.h>
#include "packetizer_helper.h"
#include "startcode_helper.h"
#include "hxxx_nal.h" /* colour values/mappings */
#include "iso_color_tables.h"
/*****************************************************************************
* Module descriptor
......@@ -472,9 +472,9 @@ static int ParseVO( decoder_t *p_dec, block_t *p_vo )
if( p_dec->fmt_in.video.primaries == COLOR_PRIMARIES_UNDEF )
{
p_dec->fmt_out.video.primaries = hxxx_colour_primaries_to_vlc( colour_primaries );
p_dec->fmt_out.video.transfer = hxxx_transfer_characteristics_to_vlc( colour_xfer );
p_dec->fmt_out.video.space = hxxx_matrix_coeffs_to_vlc( colour_matrix_coeff );
p_dec->fmt_out.video.primaries = iso_23001_8_cp_to_vlc_primaries( colour_primaries );
p_dec->fmt_out.video.transfer = iso_23001_8_tc_to_vlc_xfer( colour_xfer );
p_dec->fmt_out.video.space = iso_23001_8_mc_to_vlc_coeffs( colour_matrix_coeff );
p_dec->fmt_out.video.b_color_range_full = full_range;
}
}
......
......@@ -54,6 +54,7 @@
#include "../codec/cc.h"
#include "packetizer_helper.h"
#include "startcode_helper.h"
#include "iso_color_tables.h"
#include <limits.h>
......@@ -813,56 +814,12 @@ static block_t *ParseMPEGBlock( decoder_t *p_dec, block_t *p_frag )
if( contains_color_description && p_frag->i_buffer > 11 )
{
uint8_t color_primaries = p_frag->p_buffer[5];
uint8_t color_transfer = p_frag->p_buffer[6];
uint8_t color_matrix = p_frag->p_buffer[7];
switch( color_primaries )
{
case 1:
p_dec->fmt_out.video.primaries = COLOR_PRIMARIES_BT709;
break;
case 4: /* BT.470M */
case 5: /* BT.470BG */
p_dec->fmt_out.video.primaries = COLOR_PRIMARIES_BT601_625;
break;
case 6: /* SMPTE 170M */
case 7: /* SMPTE 240M */
p_dec->fmt_out.video.primaries = COLOR_PRIMARIES_BT601_525;
break;
default:
break;
}
switch( color_transfer )
{
case 1:
p_dec->fmt_out.video.transfer = TRANSFER_FUNC_BT709;
break;
case 4: /* BT.470M assumed gamma 2.2 */
p_dec->fmt_out.video.transfer = TRANSFER_FUNC_SRGB;
break;
case 5: /* BT.470BG */
case 6: /* SMPTE 170M */
p_dec->fmt_out.video.transfer = TRANSFER_FUNC_BT2020;
break;
case 8: /* Linear */
p_dec->fmt_out.video.transfer = TRANSFER_FUNC_LINEAR;
break;
default:
break;
}
switch( color_matrix )
{
case 1:
p_dec->fmt_out.video.space = COLOR_SPACE_BT709;
break;
case 5: /* BT.470BG */
case 6: /* SMPTE 170 M */
case 7: /* SMPTE 240 M */
p_dec->fmt_out.video.space = COLOR_SPACE_BT601;
break;
default:
break;
}
p_dec->fmt_out.video.primaries =
iso_23001_8_cp_to_vlc_primaries( p_frag->p_buffer[5] );
p_dec->fmt_out.video.transfer =
iso_23001_8_tc_to_vlc_xfer( p_frag->p_buffer[6] );
p_dec->fmt_out.video.space =
iso_23001_8_mc_to_vlc_coeffs( p_frag->p_buffer[7] );
}
}
......
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