[vlc-commits] [Git][videolan/vlc][master] mediacodec: set color keys in media format explicitly
Steve Lhomme (@robUx4)
gitlab at videolan.org
Fri Sep 20 06:40:46 UTC 2024
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
55e0779f by Mangal Kushwah at 2024-09-20T06:25:48+00:00
mediacodec: set color keys in media format explicitly
Fixes issues where by default mediacodec sets wrong keys for video.
See #26948
- - - - -
4 changed files:
- modules/codec/omxil/mediacodec.c
- modules/codec/omxil/mediacodec.h
- modules/codec/omxil/mediacodec_jni.c
- modules/codec/omxil/mediacodec_ndk.c
Changes:
=====================================
modules/codec/omxil/mediacodec.c
=====================================
@@ -468,6 +468,57 @@ static int StartMediaCodec(decoder_t *p_dec)
args.video.p_surface = p_sys->video.p_surface;
args.video.p_jsurface = p_sys->video.p_jsurface;
+ switch (p_dec->fmt_out.video.primaries)
+ {
+ case COLOR_RANGE_FULL:
+ args.video.color_range = MC_COLOR_RANGE_FULL;
+ break;
+ case COLOR_RANGE_LIMITED:
+ args.video.color_range = MC_COLOR_RANGE_LIMITED;
+ break;
+ default:
+ args.video.color_range = MC_COLOR_RANGE_UNSPECIFIED;
+ break;
+ }
+
+ switch (p_dec->fmt_out.video.primaries)
+ {
+ case COLOR_PRIMARIES_BT601_525:
+ args.video.color_standard = MC_COLOR_STANDARD_BT601_NTSC;
+ break;
+ case COLOR_PRIMARIES_BT601_625:
+ args.video.color_standard = MC_COLOR_STANDARD_BT601_PAL;
+ break;
+ case COLOR_PRIMARIES_BT709:
+ args.video.color_standard = MC_COLOR_STANDARD_BT709;
+ break;
+ case COLOR_PRIMARIES_BT2020:
+ args.video.color_standard = MC_COLOR_STANDARD_BT2020;
+ break;
+ default:
+ args.video.color_standard = MC_COLOR_STANDARD_UNSPECIFIED;
+ break;
+ }
+
+ switch (p_dec->fmt_out.video.transfer)
+ {
+ case TRANSFER_FUNC_LINEAR:
+ args.video.color_transfer = MC_COLOR_TRANSFER_LINEAR;
+ break;
+ case TRANSFER_FUNC_SMPTE_ST2084:
+ args.video.color_transfer = MC_COLOR_TRANSFER_ST2084;
+ break;
+ case TRANSFER_FUNC_HLG:
+ args.video.color_transfer = MC_COLOR_TRANSFER_HLG;
+ break;
+ case TRANSFER_FUNC_BT709:
+ args.video.color_transfer = MC_COLOR_TRANSFER_SDR_VIDEO;
+ break;
+ default:
+ args.video.color_transfer = MC_COLOR_TRANSFER_UNSPECIFIED;
+ break;
+ }
+
args.video.b_tunneled_playback = args.video.p_surface ?
var_InheritBool(p_dec, CFG_PREFIX "tunneled-playback") : false;
if (p_sys->b_adaptive)
=====================================
modules/codec/omxil/mediacodec.h
=====================================
@@ -49,6 +49,33 @@ int MediaCodecNdk_Init(mc_api*);
#define MC_API_VIDEO_QUIRKS_ADAPTIVE 0x1000
#define MC_API_VIDEO_QUIRKS_IGNORE_SIZE 0x2000
+/* cf. https://github.com/FFmpeg/FFmpeg/blob/00f5a34c9a5f0adee28aca11971918d6aca48745/libavcodec/mediacodec_wrapper.h#L348
+ * cf. https://developer.android.com/reference/android/media/MediaFormat#constants_1*/
+enum mc_media_format_color_range_t
+{
+ MC_COLOR_RANGE_UNSPECIFIED = 0x0,
+ MC_COLOR_RANGE_FULL = 0x1,
+ MC_COLOR_RANGE_LIMITED = 0x2,
+};
+
+enum mc_media_format_color_standard_t
+{
+ MC_COLOR_STANDARD_UNSPECIFIED = 0x0,
+ MC_COLOR_STANDARD_BT709 = 0x1,
+ MC_COLOR_STANDARD_BT601_PAL = 0x2,
+ MC_COLOR_STANDARD_BT601_NTSC = 0x4,
+ MC_COLOR_STANDARD_BT2020 = 0x6,
+};
+
+enum mc_media_format_color_transfer_t
+{
+ MC_COLOR_TRANSFER_UNSPECIFIED = 0x0,
+ MC_COLOR_TRANSFER_LINEAR = 0x1,
+ MC_COLOR_TRANSFER_SDR_VIDEO = 0x3,
+ MC_COLOR_TRANSFER_ST2084 = 0x6,
+ MC_COLOR_TRANSFER_HLG = 0x7,
+};
+
struct mc_api_out
{
enum {
@@ -100,6 +127,9 @@ union mc_api_args
bool b_tunneled_playback;
bool b_adaptive_playback;
bool b_low_latency;
+ enum mc_media_format_color_transfer_t color_transfer;
+ enum mc_media_format_color_range_t color_range;
+ enum mc_media_format_color_standard_t color_standard;
} video;
struct
{
=====================================
modules/codec/omxil/mediacodec_jni.c
=====================================
@@ -578,6 +578,10 @@ static int ConfigureDecoder(mc_api *api, union mc_api_args* p_args)
if (p_args->video.b_low_latency)
SET_INTEGER(jformat, "low-latency", 1);
+ SET_INTEGER(jformat, "color-range", p_args->video.color_range);
+ SET_INTEGER(jformat, "color-standard", p_args->video.color_standard);
+ SET_INTEGER(jformat, "color-transfer", p_args->video.color_transfer);
+
if (b_direct_rendering)
{
/* feature-tunneled-playback available since API 21 */
=====================================
modules/codec/omxil/mediacodec_ndk.c
=====================================
@@ -277,6 +277,11 @@ static int ConfigureDecoder(mc_api *api, union mc_api_args *p_args)
syms.AMediaFormat.setInt32(p_sys->p_format, "width", p_args->video.i_width);
syms.AMediaFormat.setInt32(p_sys->p_format, "height", p_args->video.i_height);
syms.AMediaFormat.setInt32(p_sys->p_format, "rotation-degrees", p_args->video.i_angle);
+
+ syms.AMediaFormat.setInt32(p_sys->p_format, "color-range", p_args->video.color_range);
+ syms.AMediaFormat.setInt32(p_sys->p_format, "color-standard", p_args->video.color_standard);
+ syms.AMediaFormat.setInt32(p_sys->p_format, "color-transfer", p_args->video.color_transfer);
+
if (p_args->video.p_surface)
{
p_anw = p_args->video.p_surface;
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/55e0779f98b71ab135a4c0c78c2cb91b16a72547
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/55e0779f98b71ab135a4c0c78c2cb91b16a72547
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list