summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJob Bautista <jobbautista9@protonmail.com>2022-06-30 10:31:31 +0800
committerJob Bautista <jobbautista9@protonmail.com>2022-06-30 10:31:31 +0800
commit8a92f69986f3e199b7c11775a0822bf75c1b0236 (patch)
tree2dda291a30f3b860159f14fc1a8df96eb185df0e
parent8c1064bc1cb494e445a6447587afb8942a6b783b (diff)
downloaduxp-8a92f69986f3e199b7c11775a0822bf75c1b0236.tar.gz
Issue #1948 - Update nestegg library.
I separated out the AVC and AAC support code into a patch file so that the upstream code can be updated freely without having to re-add AVC and AAC support again. At least if the upstream changes are not too extensive... This should effectively backport Mozilla bug 1539686, which allows the browser to parse the color information from WebM videos that uses HDR.
-rw-r--r--media/libnestegg/README.md2
-rw-r--r--media/libnestegg/README_MCP2
-rw-r--r--media/libnestegg/include/nestegg.h28
-rw-r--r--media/libnestegg/mcp-avcaacsupport.patch59
-rw-r--r--media/libnestegg/src/nestegg.c172
-rwxr-xr-xmedia/libnestegg/update.sh4
6 files changed, 245 insertions, 22 deletions
diff --git a/media/libnestegg/README.md b/media/libnestegg/README.md
index ce9bd76ff7..2d64a65cc7 100644
--- a/media/libnestegg/README.md
+++ b/media/libnestegg/README.md
@@ -1,4 +1,4 @@
-[![Build Status](https://travis-ci.org/kinetiknz/nestegg.svg?branch=master)](https://travis-ci.org/kinetiknz/nestegg)
+[![Build Status](https://github.com/mozilla/nestegg/actions/workflows/build.yml/badge.svg)](https://github.com/mozilla/nestegg/actions/workflows/build.yml)
See INSTALL for build instructions.
diff --git a/media/libnestegg/README_MCP b/media/libnestegg/README_MCP
index e738fd920b..e799e2bfc2 100644
--- a/media/libnestegg/README_MCP
+++ b/media/libnestegg/README_MCP
@@ -5,4 +5,4 @@ Makefile.in build files for the Mozilla build system.
The nestegg git repository is: https://github.com/kinetiknz/nestegg
-The git commit ID used was f7a0b7cedc893b6683cf15cb210b1656c086d964.
+The git commit ID used was ec6adfbbf979678e3058cc4695257366f39e290b.
diff --git a/media/libnestegg/include/nestegg.h b/media/libnestegg/include/nestegg.h
index 2a9f08f5d7..ede90fdac5 100644
--- a/media/libnestegg/include/nestegg.h
+++ b/media/libnestegg/include/nestegg.h
@@ -72,8 +72,8 @@ extern "C" {
#define NESTEGG_CODEC_VP9 2 /**< Track uses Google On2 VP9 codec. */
#define NESTEGG_CODEC_OPUS 3 /**< Track uses Xiph Opus codec. */
#define NESTEGG_CODEC_AV1 4 /**< Track uses AOMedia AV1 codec. */
-#define NESTEGG_CODEC_AVC1 5 /**< Track uses AVC1 'h264' */
-#define NESTEGG_CODEC_AAC 6 /**< Track uses AAC 'mp4a' */
+#define NESTEGG_CODEC_AVC1 5 /**< Track uses AVC1 'h264' codec. */
+#define NESTEGG_CODEC_AAC 6 /**< Track uses AAC 'mp4a' codec. */
#define NESTEGG_CODEC_UNKNOWN INT_MAX /**< Track uses unknown codec. */
#define NESTEGG_VIDEO_MONO 0 /**< Track is mono video. */
@@ -152,6 +152,30 @@ typedef struct {
unsigned int crop_left; /**< Pixels to crop from the left of the frame. */
unsigned int crop_right; /**< Pixels to crop from the right of the frame. */
unsigned int alpha_mode; /**< 1 if an additional opacity stream is available, otherwise 0. */
+ unsigned int matrix_coefficients; /**< See Table 4 of ISO/IEC 23001-8:2016. */
+ unsigned int range; /**< Clipping of color ranges. */
+ unsigned int transfer_characteristics; /**< See Table 3 of ISO/IEC 23091-4. */
+ unsigned int primaries; /**< See Table 2 of ISO/IEC 23091-4. */
+ double primary_r_chromacity_x; /**< Red X chromaticity coordinate per CIE 1931.
+ NaN means element not present. */
+ double primary_r_chromacity_y; /**< Red Y chromaticity coordinate per CIE 1931.
+ NaN means element not present. */
+ double primary_g_chromacity_x; /**< Green X chromaticity coordinate per CIE 1931.
+ NaN means element not present. */
+ double primary_g_chromacity_y; /**< Green Y chromaticity coordinate per CIE 1931.
+ NaN means element not present. */
+ double primary_b_chromacity_x; /**< Blue X chromaticity coordinate per CIE 1931.
+ NaN means element not present. */
+ double primary_b_chromacity_y; /**< Blue Y chromaticity coordinate per CIE 1931.
+ NaN means element not present. */
+ double white_point_chromaticity_x; /**< White X chromaticity coordinate per CIE 1931.
+ NaN means element not present. */
+ double white_point_chromaticity_y; /**< White Y chromaticity coordinate per CIE 1931.
+ NaN means element not present. */
+ double luminance_max; /**< Maximum luminance in cd/m2.
+ NaN means element not present. */
+ double luminance_min; /**< Minimum luminance in cd/m2.
+ NaN means element not present. */
} nestegg_video_params;
/** Parameters specific to an audio track. */
diff --git a/media/libnestegg/mcp-avcaacsupport.patch b/media/libnestegg/mcp-avcaacsupport.patch
new file mode 100644
index 0000000000..279af76820
--- /dev/null
+++ b/media/libnestegg/mcp-avcaacsupport.patch
@@ -0,0 +1,59 @@
+diff -u /include/nestegg.h /include/nestegg.h
+--- /include/nestegg.h
++++ /include/nestegg.h
+@@ -72,6 +72,8 @@
+ #define NESTEGG_CODEC_VP9 2 /**< Track uses Google On2 VP9 codec. */
+ #define NESTEGG_CODEC_OPUS 3 /**< Track uses Xiph Opus codec. */
+ #define NESTEGG_CODEC_AV1 4 /**< Track uses AOMedia AV1 codec. */
++#define NESTEGG_CODEC_AVC1 5 /**< Track uses AVC1 'h264' codec. */
++#define NESTEGG_CODEC_AAC 6 /**< Track uses AAC 'mp4a' codec. */
+ #define NESTEGG_CODEC_UNKNOWN INT_MAX /**< Track uses unknown codec. */
+
+ #define NESTEGG_VIDEO_MONO 0 /**< Track is mono video. */
+diff -u /src/nestegg.c /src/nestegg.c
+--- /src/nestegg.c
++++ /src/nestegg.c
+@@ -177,6 +177,8 @@
+ #define TRACK_ID_AV1 "V_AV1"
+ #define TRACK_ID_VORBIS "A_VORBIS"
+ #define TRACK_ID_OPUS "A_OPUS"
++#define TRACK_ID_AVC1 "V_MPEG4/ISO/AVC"
++#define TRACK_ID_AAC "A_AAC"
+
+ /* Track Encryption */
+ #define CONTENT_ENC_ALGO_AES 5
+@@ -2482,6 +2484,12 @@
+ if (strcmp(codec_id, TRACK_ID_OPUS) == 0)
+ return NESTEGG_CODEC_OPUS;
+
++ if (strcmp(codec_id, TRACK_ID_AVC1) == 0)
++ return NESTEGG_CODEC_AVC1;
++
++ if (strcmp(codec_id, TRACK_ID_AAC) == 0)
++ return NESTEGG_CODEC_AAC;
++
+ return NESTEGG_CODEC_UNKNOWN;
+ }
+
+@@ -2502,7 +2510,8 @@
+
+ codec_id = nestegg_track_codec_id(ctx, track);
+
+- if (codec_id == NESTEGG_CODEC_OPUS) {
++ if (codec_id == NESTEGG_CODEC_OPUS ||
++ codec_id == NESTEGG_CODEC_AAC) {
+ *count = 1;
+ return 0;
+ }
+@@ -2540,7 +2549,9 @@
+ return -1;
+
+ if (nestegg_track_codec_id(ctx, track) != NESTEGG_CODEC_VORBIS &&
+- nestegg_track_codec_id(ctx, track) != NESTEGG_CODEC_OPUS)
++ nestegg_track_codec_id(ctx, track) != NESTEGG_CODEC_OPUS &&
++ nestegg_track_codec_id(ctx, track) != NESTEGG_CODEC_AVC1 &&
++ nestegg_track_codec_id(ctx, track) != NESTEGG_CODEC_AAC)
+ return -1;
+
+ if (ne_get_binary(entry->codec_private, &codec_private) != 0)
+
diff --git a/media/libnestegg/src/nestegg.c b/media/libnestegg/src/nestegg.c
index 051bc50faf..ae7c73d9d2 100644
--- a/media/libnestegg/src/nestegg.c
+++ b/media/libnestegg/src/nestegg.c
@@ -88,6 +88,7 @@
#define ID_PIXEL_CROP_RIGHT 0x54dd
#define ID_DISPLAY_WIDTH 0x54b0
#define ID_DISPLAY_HEIGHT 0x54ba
+#define ID_COLOUR 0x55b0
/* Audio Elements */
#define ID_AUDIO 0xe1
@@ -116,6 +117,25 @@
#define ID_CONTENT_ENC_AES_SETTINGS 0x47e7
#define ID_AES_SETTINGS_CIPHER_MODE 0x47e8
+/* Colour Elements */
+#define ID_MATRIX_COEFFICIENTS 0x55b1
+#define ID_RANGE 0x55b9
+#define ID_TRANSFER_CHARACTERISTICS 0x55ba
+#define ID_PRIMARIES 0x55bb
+#define ID_MASTERING_METADATA 0x55d0
+
+/* MasteringMetadata Elements */
+#define ID_PRIMARY_R_CHROMATICITY_X 0x55d1
+#define ID_PRIMARY_R_CHROMATICITY_Y 0x55d2
+#define ID_PRIMARY_G_CHROMATICITY_X 0x55d3
+#define ID_PRIMARY_G_CHROMATICITY_Y 0x55d4
+#define ID_PRIMARY_B_CHROMATICITY_X 0x55d5
+#define ID_PRIMARY_B_CHROMATICITY_Y 0x55d6
+#define ID_WHITE_POINT_CHROMATICITY_X 0x55d7
+#define ID_WHITE_POINT_CHROMATICITY_Y 0x55d8
+#define ID_LUMINANCE_MAX 0x55d9
+#define ID_LUMINANCE_MIN 0x55da
+
/* EBML Types */
enum ebml_type_enum {
TYPE_UNKNOWN,
@@ -236,6 +256,27 @@ struct info {
struct ebml_type duration;
};
+struct mastering_metadata {
+ struct ebml_type primary_r_chromacity_x;
+ struct ebml_type primary_r_chromacity_y;
+ struct ebml_type primary_g_chromacity_x;
+ struct ebml_type primary_g_chromacity_y;
+ struct ebml_type primary_b_chromacity_x;
+ struct ebml_type primary_b_chromacity_y;
+ struct ebml_type white_point_chromaticity_x;
+ struct ebml_type white_point_chromaticity_y;
+ struct ebml_type luminance_max;
+ struct ebml_type luminance_min;
+};
+
+struct colour {
+ struct ebml_type matrix_coefficients;
+ struct ebml_type range;
+ struct ebml_type transfer_characteristics;
+ struct ebml_type primaries;
+ struct mastering_metadata mastering_metadata;
+};
+
struct video {
struct ebml_type stereo_mode;
struct ebml_type alpha_mode;
@@ -247,6 +288,7 @@ struct video {
struct ebml_type pixel_crop_right;
struct ebml_type display_width;
struct ebml_type display_height;
+ struct colour colour;
};
struct audio {
@@ -454,6 +496,29 @@ static struct ebml_element_desc ne_info_elements[] = {
E_LAST
};
+static struct ebml_element_desc ne_mastering_metadata_elements[] = {
+ E_FIELD(ID_PRIMARY_R_CHROMATICITY_X, TYPE_FLOAT, struct mastering_metadata, primary_r_chromacity_x),
+ E_FIELD(ID_PRIMARY_R_CHROMATICITY_Y, TYPE_FLOAT, struct mastering_metadata, primary_r_chromacity_y),
+ E_FIELD(ID_PRIMARY_G_CHROMATICITY_X, TYPE_FLOAT, struct mastering_metadata, primary_g_chromacity_x),
+ E_FIELD(ID_PRIMARY_G_CHROMATICITY_Y, TYPE_FLOAT, struct mastering_metadata, primary_g_chromacity_y),
+ E_FIELD(ID_PRIMARY_B_CHROMATICITY_X, TYPE_FLOAT, struct mastering_metadata, primary_b_chromacity_x),
+ E_FIELD(ID_PRIMARY_B_CHROMATICITY_Y, TYPE_FLOAT, struct mastering_metadata, primary_b_chromacity_y),
+ E_FIELD(ID_WHITE_POINT_CHROMATICITY_X, TYPE_FLOAT, struct mastering_metadata, white_point_chromaticity_x),
+ E_FIELD(ID_WHITE_POINT_CHROMATICITY_Y, TYPE_FLOAT, struct mastering_metadata, white_point_chromaticity_y),
+ E_FIELD(ID_LUMINANCE_MAX, TYPE_FLOAT, struct mastering_metadata, luminance_max),
+ E_FIELD(ID_LUMINANCE_MIN, TYPE_FLOAT, struct mastering_metadata, luminance_min),
+ E_LAST
+};
+
+static struct ebml_element_desc ne_colour_elements[] = {
+ E_FIELD(ID_MATRIX_COEFFICIENTS, TYPE_UINT, struct colour, matrix_coefficients),
+ E_FIELD(ID_RANGE, TYPE_UINT, struct colour, range),
+ E_FIELD(ID_TRANSFER_CHARACTERISTICS, TYPE_UINT, struct colour, transfer_characteristics),
+ E_FIELD(ID_PRIMARIES, TYPE_UINT, struct colour, primaries),
+ E_SINGLE_MASTER(ID_MASTERING_METADATA, TYPE_MASTER, struct colour, mastering_metadata),
+ E_LAST
+};
+
static struct ebml_element_desc ne_video_elements[] = {
E_FIELD(ID_STEREO_MODE, TYPE_UINT, struct video, stereo_mode),
E_FIELD(ID_ALPHA_MODE, TYPE_UINT, struct video, alpha_mode),
@@ -465,6 +530,7 @@ static struct ebml_element_desc ne_video_elements[] = {
E_FIELD(ID_PIXEL_CROP_RIGHT, TYPE_UINT, struct video, pixel_crop_right),
E_FIELD(ID_DISPLAY_WIDTH, TYPE_UINT, struct video, display_width),
E_FIELD(ID_DISPLAY_HEIGHT, TYPE_UINT, struct video, display_height),
+ E_SINGLE_MASTER(ID_COLOUR, TYPE_MASTER, struct video, colour),
E_LAST
};
@@ -770,7 +836,15 @@ ne_read_float(nestegg_io * io, double * val, uint64_t length)
{
union {
uint64_t u;
- float f;
+ struct {
+#if defined(__FLOAT_WORD_ORDER__) && __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__
+ uint32_t _pad;
+ float f;
+#else
+ float f;
+ uint32_t _pad;
+#endif
+ } f;
double d;
} value;
int r;
@@ -782,7 +856,7 @@ ne_read_float(nestegg_io * io, double * val, uint64_t length)
if (r != 1)
return r;
if (length == 4)
- *val = value.f;
+ *val = value.f.f;
else
*val = value.d;
return 1;
@@ -2062,7 +2136,10 @@ ne_match_webm(nestegg_io io, int64_t max_offset)
return 0;
}
- ne_ctx_push(ctx, ne_top_level_elements, ctx);
+ if (ne_ctx_push(ctx, ne_top_level_elements, ctx) < 0) {
+ nestegg_destroy(ctx);
+ return -1;
+ }
/* we don't check the return value of ne_parse, that might fail because
max_offset is not on a valid element end point. We only want to check
@@ -2118,7 +2195,10 @@ nestegg_init(nestegg ** context, nestegg_io io, nestegg_log callback, int64_t ma
ctx->log(ctx, NESTEGG_LOG_DEBUG, "ctx %p", ctx);
- ne_ctx_push(ctx, ne_top_level_elements, ctx);
+ if (ne_ctx_push(ctx, ne_top_level_elements, ctx) < 0) {
+ nestegg_destroy(ctx);
+ return -1;
+ }
r = ne_parse(ctx, NULL, max_offset);
while (ctx->ancestor)
@@ -2178,7 +2258,8 @@ void
nestegg_destroy(nestegg * ctx)
{
assert(ctx->ancestor == NULL);
- ne_pool_destroy(ctx->alloc_pool);
+ if (ctx->alloc_pool)
+ ne_pool_destroy(ctx->alloc_pool);
free(ctx->io);
free(ctx);
}
@@ -2366,10 +2447,10 @@ nestegg_track_type(nestegg * ctx, unsigned int track)
if (ne_get_uint(entry->type, &type) != 0)
return -1;
- if (type & TRACK_TYPE_VIDEO)
+ if (type == TRACK_TYPE_VIDEO)
return NESTEGG_TRACK_VIDEO;
- if (type & TRACK_TYPE_AUDIO)
+ if (type == TRACK_TYPE_AUDIO)
return NESTEGG_TRACK_AUDIO;
return NESTEGG_TRACK_UNKNOWN;
@@ -2537,6 +2618,7 @@ nestegg_track_video_params(nestegg * ctx, unsigned int track,
{
struct track_entry * entry;
uint64_t value;
+ double fvalue;
memset(params, 0, sizeof(*params));
@@ -2589,6 +2671,62 @@ nestegg_track_video_params(nestegg * ctx, unsigned int track,
ne_get_uint(entry->video.display_height, &value);
params->display_height = value;
+ value = 2;
+ ne_get_uint(entry->video.colour.matrix_coefficients, &value);
+ params->matrix_coefficients = value;
+
+ value = 0;
+ ne_get_uint(entry->video.colour.range, &value);
+ params->range = value;
+
+ value = 2;
+ ne_get_uint(entry->video.colour.transfer_characteristics, &value);
+ params->transfer_characteristics = value;
+
+ value = 2;
+ ne_get_uint(entry->video.colour.primaries, &value);
+ params->primaries = value;
+
+ fvalue = strtod("NaN", NULL);
+ ne_get_float(entry->video.colour.mastering_metadata.primary_r_chromacity_x, &fvalue);
+ params->primary_r_chromacity_x = fvalue;
+
+ fvalue = strtod("NaN", NULL);
+ ne_get_float(entry->video.colour.mastering_metadata.primary_r_chromacity_y, &fvalue);
+ params->primary_r_chromacity_y = fvalue;
+
+ fvalue = strtod("NaN", NULL);
+ ne_get_float(entry->video.colour.mastering_metadata.primary_g_chromacity_x, &fvalue);
+ params->primary_g_chromacity_x = fvalue;
+
+ fvalue = strtod("NaN", NULL);
+ ne_get_float(entry->video.colour.mastering_metadata.primary_g_chromacity_y, &fvalue);
+ params->primary_g_chromacity_y = fvalue;
+
+ fvalue = strtod("NaN", NULL);
+ ne_get_float(entry->video.colour.mastering_metadata.primary_b_chromacity_x, &fvalue);
+ params->primary_b_chromacity_x = fvalue;
+
+ fvalue = strtod("NaN", NULL);
+ ne_get_float(entry->video.colour.mastering_metadata.primary_b_chromacity_y, &fvalue);
+ params->primary_b_chromacity_y = fvalue;
+
+ fvalue = strtod("NaN", NULL);
+ ne_get_float(entry->video.colour.mastering_metadata.white_point_chromaticity_x, &fvalue);
+ params->white_point_chromaticity_x = fvalue;
+
+ fvalue = strtod("NaN", NULL);
+ ne_get_float(entry->video.colour.mastering_metadata.white_point_chromaticity_y, &fvalue);
+ params->white_point_chromaticity_y = fvalue;
+
+ fvalue = strtod("NaN", NULL);
+ ne_get_float(entry->video.colour.mastering_metadata.luminance_max, &fvalue);
+ params->luminance_max = fvalue;
+
+ fvalue = strtod("NaN", NULL);
+ ne_get_float(entry->video.colour.mastering_metadata.luminance_min, &fvalue);
+ params->luminance_min = fvalue;
+
return 0;
}
@@ -2783,20 +2921,18 @@ nestegg_read_packet(nestegg * ctx, nestegg_packet ** pkt)
if (r != 1)
return r;
- /* Some files have a crc32 element, since it also has to be first it
- conflicts with the timecode spec. Just ignore it */
+ /* Matroska may place a CRC32 before the Timecode. Skip and continue parsing. */
if (id == ID_CRC32) {
- ctx->log(ctx, NESTEGG_LOG_DEBUG,
- "read_packet: skipping crc element in a cluster");
- r = ne_io_read_skip(ctx->io, size);
- if (r != 1)
- return r;
- r = ne_read_element(ctx, &id, &size);
- if (r != 1)
- return r;
+ r = ne_io_read_skip(ctx->io, size);
+ if (r != 1)
+ return r;
+
+ r = ne_read_element(ctx, &id, &size);
+ if (r != 1)
+ return r;
}
- /* Timecode must be the first element in a Cluster, per spec. */
+ /* Timecode must be the first element in a Cluster, per WebM spec. */
if (id != ID_TIMECODE)
return -1;
diff --git a/media/libnestegg/update.sh b/media/libnestegg/update.sh
index 644408e094..dc3324c46b 100755
--- a/media/libnestegg/update.sh
+++ b/media/libnestegg/update.sh
@@ -4,6 +4,10 @@ cp $1/src/nestegg.c src
cp $1/LICENSE .
cp $1/README.md .
cp $1/AUTHORS .
+
+# Patch the imported files.
+patch -p1 < mcp-avcaacsupport.patch
+
if [ -d $1/.git ]; then
rev=$(cd $1 && git rev-parse --verify HEAD)
dirty=$(cd $1 && git diff-index --name-only HEAD)