Prewarm FontDatabase on process swap
[WebKit-https.git] / Tools / gstreamer / patches / gst-plugins-good-0009-matroskademux-Parse-successive-Tracks-elements.patch
1 From 0e60076a390fd3ef53d350940b2c695ff7bbe008 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Alicia=20Boya=20Garc=C3=ADa?= <aboya@igalia.com>
3 Date: Fri, 21 Sep 2018 20:38:02 +0200
4 Subject: [PATCH 9/9] matroskademux: Parse successive Tracks elements
5
6 This patch allows matroskademux to parse a second Tracks element,
7 erroring out if the tracks are not compatible (different number, type or
8 codec) and emitting new caps and tag events should they have changed.
9
10 https://bugzilla.gnome.org/show_bug.cgi?id=793333
11 ---
12  gst/matroska/matroska-demux.c | 111 +++++++++++++++++++++++++++++++++-
13  1 file changed, 109 insertions(+), 2 deletions(-)
14
15 diff --git a/gst/matroska/matroska-demux.c b/gst/matroska/matroska-demux.c
16 index 0e2157a15..77176fb62 100644
17 --- a/gst/matroska/matroska-demux.c
18 +++ b/gst/matroska/matroska-demux.c
19 @@ -3132,6 +3132,113 @@ gst_matroska_demux_parse_tracks (GstMatroskaDemux * demux, GstEbmlRead * ebml)
20    return ret;
21  }
22  
23 +static GstFlowReturn
24 +gst_matroska_demux_update_tracks (GstMatroskaDemux * demux, GstEbmlRead * ebml)
25 +{
26 +  GstFlowReturn ret = GST_FLOW_OK;
27 +  guint num_tracks_found = 0;
28 +  guint32 id;
29 +
30 +  GST_INFO_OBJECT (demux, "Reparsing Tracks element");
31 +
32 +  DEBUG_ELEMENT_START (demux, ebml, "Tracks");
33 +
34 +  if ((ret = gst_ebml_read_master (ebml, &id)) != GST_FLOW_OK) {
35 +    DEBUG_ELEMENT_STOP (demux, ebml, "Tracks", ret);
36 +    return ret;
37 +  }
38 +
39 +  while (ret == GST_FLOW_OK && gst_ebml_read_has_remaining (ebml, 1, TRUE)) {
40 +    if ((ret = gst_ebml_peek_id (ebml, &id)) != GST_FLOW_OK)
41 +      break;
42 +
43 +    switch (id) {
44 +        /* one track within the "all-tracks" header */
45 +      case GST_MATROSKA_ID_TRACKENTRY:{
46 +        GstMatroskaTrackContext *new_track;
47 +        gint old_track_index;
48 +        GstMatroskaTrackContext *old_track;
49 +        ret = gst_matroska_demux_parse_stream (demux, ebml, &new_track);
50 +        if (new_track == NULL)
51 +          break;
52 +        num_tracks_found++;
53 +
54 +        if (gst_matroska_read_common_tracknumber_unique (&demux->common,
55 +                new_track->num)) {
56 +          GST_ERROR_OBJECT (demux,
57 +              "Unexpected new TrackNumber: %" G_GUINT64_FORMAT, new_track->num);
58 +          goto track_mismatch_error;
59 +        }
60 +
61 +        old_track_index =
62 +            gst_matroska_read_common_stream_from_num (&demux->common,
63 +            new_track->num);
64 +        g_assert (old_track_index != -1);
65 +        old_track = g_ptr_array_index (demux->common.src, old_track_index);
66 +
67 +        if (old_track->type != new_track->type) {
68 +          GST_ERROR_OBJECT (demux,
69 +              "Mismatch reparsing track %" G_GUINT64_FORMAT
70 +              " on track type. Expected %d, found %d", new_track->num,
71 +              old_track->type, new_track->type);
72 +          goto track_mismatch_error;
73 +        }
74 +
75 +        if (g_strcmp0 (old_track->codec_id, new_track->codec_id) != 0) {
76 +          GST_ERROR_OBJECT (demux,
77 +              "Mismatch reparsing track %" G_GUINT64_FORMAT
78 +              " on codec id. Expected '%s', found '%s'", new_track->num,
79 +              old_track->codec_id, new_track->codec_id);
80 +          goto track_mismatch_error;
81 +        }
82 +
83 +        /* The new track matches the old track. No problems on our side.
84 +         * Let's make it replace the old track. */
85 +        new_track->pad = old_track->pad;
86 +        new_track->index = old_track->index;
87 +        new_track->pos = old_track->pos;
88 +        g_ptr_array_index (demux->common.src, old_track_index) = new_track;
89 +        gst_pad_set_element_private (new_track->pad, new_track);
90 +
91 +        if (!gst_caps_is_equal (old_track->caps, new_track->caps)) {
92 +          gst_pad_set_caps (new_track->pad, new_track->caps);
93 +        }
94 +
95 +        if (!gst_tag_list_is_equal (old_track->tags, new_track->tags)) {
96 +          GST_DEBUG_OBJECT (old_track->pad, "Sending tags %p: %"
97 +              GST_PTR_FORMAT, new_track->tags, new_track->tags);
98 +          gst_pad_push_event (new_track->pad,
99 +              gst_event_new_tag (gst_tag_list_copy (new_track->tags)));
100 +        }
101 +
102 +        gst_matroska_track_free (old_track);
103 +        break;
104 +
105 +      track_mismatch_error:
106 +        gst_matroska_track_free (new_track);
107 +        new_track = NULL;
108 +        ret = GST_FLOW_ERROR;
109 +        break;
110 +      }
111 +
112 +      default:
113 +        ret = gst_matroska_read_common_parse_skip (&demux->common, ebml,
114 +            "Track", id);
115 +        break;
116 +    }
117 +  }
118 +  DEBUG_ELEMENT_STOP (demux, ebml, "Tracks", ret);
119 +
120 +  if (ret != GST_FLOW_ERROR && demux->common.num_streams != num_tracks_found) {
121 +    GST_ERROR_OBJECT (demux,
122 +        "Mismatch on the number of tracks. Expected %du tracks, found %du",
123 +        demux->common.num_streams, num_tracks_found);
124 +    ret = GST_FLOW_ERROR;
125 +  }
126 +
127 +  return ret;
128 +}
129 +
130  /*
131   * Read signed/unsigned "EBML" numbers.
132   * Return: number of bytes processed.
133 @@ -5031,11 +5138,11 @@ gst_matroska_demux_parse_id (GstMatroskaDemux * demux, guint32 id,
134            }
135            break;
136          case GST_MATROSKA_ID_TRACKS:
137 +          GST_READ_CHECK (gst_matroska_demux_take (demux, read, &ebml));
138            if (!demux->tracks_parsed) {
139 -            GST_READ_CHECK (gst_matroska_demux_take (demux, read, &ebml));
140              ret = gst_matroska_demux_parse_tracks (demux, &ebml);
141            } else {
142 -            GST_READ_CHECK (gst_matroska_demux_flush (demux, read));
143 +            ret = gst_matroska_demux_update_tracks (demux, &ebml);
144            }
145            break;
146          case GST_MATROSKA_ID_CLUSTER:
147 -- 
148 2.17.1
149