Verify metadata is only added on the first frame when available
Update tests to ensure metadata is only added when an SPS has been encountered.
Showing
2 changed files
with
12 additions
and
29 deletions
... | @@ -80,7 +80,8 @@ | ... | @@ -80,7 +80,8 @@ |
80 | 80 | ||
81 | // Check if keyframe and the length of tags. | 81 | // Check if keyframe and the length of tags. |
82 | // This makes sure we write metadata on the first frame of a segment. | 82 | // This makes sure we write metadata on the first frame of a segment. |
83 | if (this._oldExtraData.extraDataExists() && (this._h264Frame.keyFrame || this.tags.length === 0)) { | 83 | if (this._oldExtraData.extraDataExists() && |
84 | (this._h264Frame.keyFrame || this.tags.length === 0)) { | ||
84 | // Push extra data on every IDR frame in case we did a stream change + seek | 85 | // Push extra data on every IDR frame in case we did a stream change + seek |
85 | this.tags.push(this._oldExtraData.metaDataTag(this._h264Frame.pts)); | 86 | this.tags.push(this._oldExtraData.metaDataTag(this._h264Frame.pts)); |
86 | this.tags.push(this._oldExtraData.extraDataTag(this._h264Frame.pts)); | 87 | this.tags.push(this._oldExtraData.extraDataTag(this._h264Frame.pts)); | ... | ... |
... | @@ -3,11 +3,8 @@ module('H264 Stream'); | ... | @@ -3,11 +3,8 @@ module('H264 Stream'); |
3 | 3 | ||
4 | var | 4 | var |
5 | nalUnitTypes = window.videojs.Hls.NALUnitType, | 5 | nalUnitTypes = window.videojs.Hls.NALUnitType, |
6 | FlvTag = window.videojs.Hls.FlvTag; | 6 | FlvTag = window.videojs.Hls.FlvTag, |
7 | 7 | ||
8 | test('metadata is generated for IDRs after a full NAL unit is written', function() { | ||
9 | var | ||
10 | h264Stream = new videojs.Hls.H264Stream(), | ||
11 | accessUnitDelimiter = new Uint8Array([ | 8 | accessUnitDelimiter = new Uint8Array([ |
12 | 0x00, | 9 | 0x00, |
13 | 0x00, | 10 | 0x00, |
... | @@ -38,7 +35,11 @@ test('metadata is generated for IDRs after a full NAL unit is written', function | ... | @@ -38,7 +35,11 @@ test('metadata is generated for IDRs after a full NAL unit is written', function |
38 | 0xAA, | 35 | 0xAA, |
39 | 0x4E, | 36 | 0x4E, |
40 | 0x00 | 37 | 0x00 |
41 | ]), | 38 | ]); |
39 | |||
40 | test('metadata is generated for IDRs after a full NAL unit is written', function() { | ||
41 | var | ||
42 | h264Stream = new videojs.Hls.H264Stream(), | ||
42 | idr = new Uint8Array([ | 43 | idr = new Uint8Array([ |
43 | 0x00, | 44 | 0x00, |
44 | 0x00, | 45 | 0x00, |
... | @@ -65,13 +66,7 @@ test('starting PTS values can be negative', function() { | ... | @@ -65,13 +66,7 @@ test('starting PTS values can be negative', function() { |
65 | H264ExtraData = videojs.Hls.H264ExtraData, | 66 | H264ExtraData = videojs.Hls.H264ExtraData, |
66 | oldExtraData = H264ExtraData.prototype.extraDataTag, | 67 | oldExtraData = H264ExtraData.prototype.extraDataTag, |
67 | oldMetadata = H264ExtraData.prototype.metaDataTag, | 68 | oldMetadata = H264ExtraData.prototype.metaDataTag, |
68 | h264Stream, | 69 | h264Stream; |
69 | accessUnitDelimiter = new Uint8Array([ | ||
70 | 0x00, | ||
71 | 0x00, | ||
72 | 0x01, | ||
73 | nalUnitTypes.access_unit_delimiter_rbsp | ||
74 | ]); | ||
75 | 70 | ||
76 | H264ExtraData.prototype.extraDataTag = function() { | 71 | H264ExtraData.prototype.extraDataTag = function() { |
77 | return 'extraDataTag'; | 72 | return 'extraDataTag'; |
... | @@ -92,10 +87,6 @@ test('starting PTS values can be negative', function() { | ... | @@ -92,10 +87,6 @@ test('starting PTS values can be negative', function() { |
92 | // flush out the last tag | 87 | // flush out the last tag |
93 | h264Stream.writeBytes(accessUnitDelimiter, 0, accessUnitDelimiter.byteLength); | 88 | h264Stream.writeBytes(accessUnitDelimiter, 0, accessUnitDelimiter.byteLength); |
94 | 89 | ||
95 | // shift the metadata and extradata tags out, since we don't care about them here | ||
96 | h264Stream.tags.shift(); | ||
97 | h264Stream.tags.shift(); | ||
98 | |||
99 | strictEqual(h264Stream.tags.length, 3, 'three tags are ready'); | 90 | strictEqual(h264Stream.tags.length, 3, 'three tags are ready'); |
100 | strictEqual(h264Stream.tags[0].pts, 0, 'the first PTS is zero'); | 91 | strictEqual(h264Stream.tags[0].pts, 0, 'the first PTS is zero'); |
101 | strictEqual(h264Stream.tags[0].dts, 0, 'the first DTS is zero'); | 92 | strictEqual(h264Stream.tags[0].dts, 0, 'the first DTS is zero'); |
... | @@ -114,13 +105,7 @@ test('make sure we add metadata and extra data at the beginning of a stream', fu | ... | @@ -114,13 +105,7 @@ test('make sure we add metadata and extra data at the beginning of a stream', fu |
114 | H264ExtraData = videojs.Hls.H264ExtraData, | 105 | H264ExtraData = videojs.Hls.H264ExtraData, |
115 | oldExtraData = H264ExtraData.prototype.extraDataTag, | 106 | oldExtraData = H264ExtraData.prototype.extraDataTag, |
116 | oldMetadata = H264ExtraData.prototype.metaDataTag, | 107 | oldMetadata = H264ExtraData.prototype.metaDataTag, |
117 | h264Stream, | 108 | h264Stream; |
118 | accessUnitDelimiter = new Uint8Array([ | ||
119 | 0x00, | ||
120 | 0x00, | ||
121 | 0x01, | ||
122 | nalUnitTypes.access_unit_delimiter_rbsp | ||
123 | ]); | ||
124 | 109 | ||
125 | H264ExtraData.prototype.extraDataTag = function() { | 110 | H264ExtraData.prototype.extraDataTag = function() { |
126 | return 'extraDataTag'; | 111 | return 'extraDataTag'; |
... | @@ -133,6 +118,8 @@ test('make sure we add metadata and extra data at the beginning of a stream', fu | ... | @@ -133,6 +118,8 @@ test('make sure we add metadata and extra data at the beginning of a stream', fu |
133 | 118 | ||
134 | h264Stream.setTimeStampOffset(0); | 119 | h264Stream.setTimeStampOffset(0); |
135 | h264Stream.setNextTimeStamp(0, 0, true); | 120 | h264Stream.setNextTimeStamp(0, 0, true); |
121 | // the sps provides the metadata for the stream | ||
122 | h264Stream.writeBytes(seqParamSet, 0, seqParamSet.byteLength); | ||
136 | h264Stream.writeBytes(accessUnitDelimiter, 0, accessUnitDelimiter.byteLength); | 123 | h264Stream.writeBytes(accessUnitDelimiter, 0, accessUnitDelimiter.byteLength); |
137 | 124 | ||
138 | // make sure that keyFrame is set to false but that we don't have any tags currently written out | 125 | // make sure that keyFrame is set to false but that we don't have any tags currently written out |
... | @@ -148,11 +135,6 @@ test('make sure we add metadata and extra data at the beginning of a stream', fu | ... | @@ -148,11 +135,6 @@ test('make sure we add metadata and extra data at the beginning of a stream', fu |
148 | strictEqual(h264Stream.tags[0], 'metaDataTag', 'the first tag is the metaDataTag'); | 135 | strictEqual(h264Stream.tags[0], 'metaDataTag', 'the first tag is the metaDataTag'); |
149 | strictEqual(h264Stream.tags[1], 'extraDataTag', 'the second tag is the extraDataTag'); | 136 | strictEqual(h264Stream.tags[1], 'extraDataTag', 'the second tag is the extraDataTag'); |
150 | 137 | ||
151 | strictEqual(h264Stream.tags[2].pts, 0, 'the first PTS is 0'); | ||
152 | strictEqual(h264Stream.tags[2].dts, 0, 'the first DTS is 0'); | ||
153 | strictEqual(h264Stream.tags[3].pts, 5, 'the second PTS is 5'); | ||
154 | strictEqual(h264Stream.tags[3].dts, 5, 'the second DTS is 5'); | ||
155 | |||
156 | H264ExtraData.prototype.extraDataTag = oldExtraData; | 138 | H264ExtraData.prototype.extraDataTag = oldExtraData; |
157 | H264ExtraData.prototype.metaDataTag = oldMetadata; | 139 | H264ExtraData.prototype.metaDataTag = oldMetadata; |
158 | }); | 140 | }); | ... | ... |
-
Please register or sign in to post a comment