5c4a7c05 by David LaPalomento

Merge pull request #270 from videojs/segment-keyframe

Always write out metadata at the start of segments and refactor of h264stream
2 parents 81700409 52f3b9b3
...@@ -283,7 +283,9 @@ ...@@ -283,7 +283,9 @@
283 newExtraData = new H264ExtraData(); 283 newExtraData = new H264ExtraData();
284 } 284 }
285 285
286 if (h264Frame.keyFrame) { 286 // Check if keyframe and the length of tags.
287 // This makes sure we write metadata on the first frame of a segment.
288 if (h264Frame.keyFrame || this.tags.length === 0) {
287 // Push extra data on every IDR frame in case we did a stream change + seek 289 // Push extra data on every IDR frame in case we did a stream change + seek
288 this.tags.push(oldExtraData.metaDataTag(h264Frame.pts)); 290 this.tags.push(oldExtraData.metaDataTag(h264Frame.pts));
289 this.tags.push(oldExtraData.extraDataTag(h264Frame.pts)); 291 this.tags.push(oldExtraData.extraDataTag(h264Frame.pts));
......
...@@ -70,6 +70,9 @@ test('starting PTS values can be negative', function() { ...@@ -70,6 +70,9 @@ test('starting PTS values can be negative', function() {
70 nalUnitTypes.access_unit_delimiter_rbsp 70 nalUnitTypes.access_unit_delimiter_rbsp
71 ]); 71 ]);
72 72
73 // add a "tag" to the stream so that it doesn't try and parse metadata
74 h264Stream.tags.push('spacer tag');
75
73 h264Stream.setTimeStampOffset(-100); 76 h264Stream.setTimeStampOffset(-100);
74 h264Stream.setNextTimeStamp(-100, -100, true); 77 h264Stream.setNextTimeStamp(-100, -100, true);
75 h264Stream.writeBytes(accessUnitDelimiter, 0, accessUnitDelimiter.byteLength); 78 h264Stream.writeBytes(accessUnitDelimiter, 0, accessUnitDelimiter.byteLength);
...@@ -80,6 +83,8 @@ test('starting PTS values can be negative', function() { ...@@ -80,6 +83,8 @@ test('starting PTS values can be negative', function() {
80 // flush out the last tag 83 // flush out the last tag
81 h264Stream.writeBytes(accessUnitDelimiter, 0, accessUnitDelimiter.byteLength); 84 h264Stream.writeBytes(accessUnitDelimiter, 0, accessUnitDelimiter.byteLength);
82 85
86 h264Stream.tags.shift();
87
83 strictEqual(h264Stream.tags.length, 3, 'three tags are ready'); 88 strictEqual(h264Stream.tags.length, 3, 'three tags are ready');
84 strictEqual(h264Stream.tags[0].pts, 0, 'the first PTS is zero'); 89 strictEqual(h264Stream.tags[0].pts, 0, 'the first PTS is zero');
85 strictEqual(h264Stream.tags[0].dts, 0, 'the first DTS is zero'); 90 strictEqual(h264Stream.tags[0].dts, 0, 'the first DTS is zero');
......