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
39 additions
and
56 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,42 +3,43 @@ module('H264 Stream'); | ... | @@ -3,42 +3,43 @@ 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 | |||
8 | accessUnitDelimiter = new Uint8Array([ | ||
9 | 0x00, | ||
10 | 0x00, | ||
11 | 0x01, | ||
12 | nalUnitTypes.access_unit_delimiter_rbsp | ||
13 | ]), | ||
14 | seqParamSet = new Uint8Array([ | ||
15 | 0x00, | ||
16 | 0x00, | ||
17 | 0x01, | ||
18 | 0x60 | nalUnitTypes.seq_parameter_set_rbsp, | ||
19 | 0x00, // profile_idc | ||
20 | 0x00, // constraint_set flags | ||
21 | 0x00, // level_idc | ||
22 | // seq_parameter_set_id ue(v) 0 => 1 | ||
23 | // log2_max_frame_num_minus4 ue(v) 1 => 010 | ||
24 | // pic_order_cnt_type ue(v) 0 => 1 | ||
25 | // log2_max_pic_order_cnt_lsb_minus4 ue(v) 1 => 010 | ||
26 | // max_num_ref_frames ue(v) 1 => 010 | ||
27 | // gaps_in_frame_num_value_allowed u(1) 0 | ||
28 | // pic_width_in_mbs_minus1 ue(v) 0 => 1 | ||
29 | // pic_height_in_map_units_minus1 ue(v) 0 => 1 | ||
30 | // frame_mbs_only_flag u(1) 1 | ||
31 | // direct_8x8_inference_flag u(1) 0 | ||
32 | // frame_cropping_flag u(1) 0 | ||
33 | // vui_parameters_present_flag u(1) 0 | ||
34 | // 1010 1010 0100 1110 00(00 0000) | ||
35 | 0xAA, | ||
36 | 0x4E, | ||
37 | 0x00 | ||
38 | ]); | ||
7 | 39 | ||
8 | test('metadata is generated for IDRs after a full NAL unit is written', function() { | 40 | test('metadata is generated for IDRs after a full NAL unit is written', function() { |
9 | var | 41 | var |
10 | h264Stream = new videojs.Hls.H264Stream(), | 42 | h264Stream = new videojs.Hls.H264Stream(), |
11 | accessUnitDelimiter = new Uint8Array([ | ||
12 | 0x00, | ||
13 | 0x00, | ||
14 | 0x01, | ||
15 | nalUnitTypes.access_unit_delimiter_rbsp | ||
16 | ]), | ||
17 | seqParamSet = new Uint8Array([ | ||
18 | 0x00, | ||
19 | 0x00, | ||
20 | 0x01, | ||
21 | 0x60 | nalUnitTypes.seq_parameter_set_rbsp, | ||
22 | 0x00, // profile_idc | ||
23 | 0x00, // constraint_set flags | ||
24 | 0x00, // level_idc | ||
25 | // seq_parameter_set_id ue(v) 0 => 1 | ||
26 | // log2_max_frame_num_minus4 ue(v) 1 => 010 | ||
27 | // pic_order_cnt_type ue(v) 0 => 1 | ||
28 | // log2_max_pic_order_cnt_lsb_minus4 ue(v) 1 => 010 | ||
29 | // max_num_ref_frames ue(v) 1 => 010 | ||
30 | // gaps_in_frame_num_value_allowed u(1) 0 | ||
31 | // pic_width_in_mbs_minus1 ue(v) 0 => 1 | ||
32 | // pic_height_in_map_units_minus1 ue(v) 0 => 1 | ||
33 | // frame_mbs_only_flag u(1) 1 | ||
34 | // direct_8x8_inference_flag u(1) 0 | ||
35 | // frame_cropping_flag u(1) 0 | ||
36 | // vui_parameters_present_flag u(1) 0 | ||
37 | // 1010 1010 0100 1110 00(00 0000) | ||
38 | 0xAA, | ||
39 | 0x4E, | ||
40 | 0x00 | ||
41 | ]), | ||
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