Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
videojs-contrib-hls
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
5b21807c
authored
2015-05-05 16:41:08 -0400
by
David LaPalomento
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Add PRIV handling
Create a specialized parser for PRIV frames.
1 parent
2a97d7fd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
5 deletions
src/metadata-stream.js
test/metadata-stream_test.js
src/metadata-stream.js
View file @
5b21807
...
...
@@ -6,13 +6,24 @@
(
function
(
window
,
videojs
,
undefined
)
{
'use strict'
;
var
parseString
=
function
(
bytes
,
start
,
end
)
{
// return the string representation of the specified byte range,
// interpreted as UTf-8.
parseUtf8
=
function
(
bytes
,
start
,
end
)
{
var
i
,
result
=
''
;
for
(
i
=
start
;
i
<
end
;
i
++
)
{
result
+=
'%'
+
(
'00'
+
bytes
[
i
].
toString
(
16
)).
slice
(
-
2
);
}
return
window
.
decodeURIComponent
(
result
);
},
// return the string representation of the specified byte range,
// interpreted as ISO-8859-1.
parseIso88591
=
function
(
bytes
,
start
,
end
)
{
var
i
,
result
=
''
;
for
(
i
=
start
;
i
<
end
;
i
++
)
{
result
+=
'%'
+
(
'00'
+
bytes
[
i
].
toString
(
16
)).
slice
(
-
2
);
}
return
window
.
unescape
(
result
);
},
tagParsers
=
{
'TXXX'
:
function
(
tag
)
{
var
i
;
...
...
@@ -24,8 +35,8 @@
for
(
i
=
1
;
i
<
tag
.
data
.
length
;
i
++
)
{
if
(
tag
.
data
[
i
]
===
0
)
{
// parse the text fields
tag
.
description
=
parse
String
(
tag
.
data
,
1
,
i
);
tag
.
value
=
parse
String
(
tag
.
data
,
i
+
1
,
tag
.
data
.
length
);
tag
.
description
=
parse
Utf8
(
tag
.
data
,
1
,
i
);
tag
.
value
=
parse
Utf8
(
tag
.
data
,
i
+
1
,
tag
.
data
.
length
);
break
;
}
}
...
...
@@ -40,11 +51,23 @@
for
(
i
=
1
;
i
<
tag
.
data
.
length
;
i
++
)
{
if
(
tag
.
data
[
i
]
===
0
)
{
// parse the description and URL fields
tag
.
description
=
parseString
(
tag
.
data
,
1
,
i
);
tag
.
url
=
parseString
(
tag
.
data
,
i
+
1
,
tag
.
data
.
length
);
tag
.
description
=
parseUtf8
(
tag
.
data
,
1
,
i
);
tag
.
url
=
parseUtf8
(
tag
.
data
,
i
+
1
,
tag
.
data
.
length
);
break
;
}
}
},
'PRIV'
:
function
(
tag
)
{
var
i
;
for
(
i
=
0
;
i
<
tag
.
data
.
length
;
i
++
)
{
if
(
tag
.
data
[
i
]
===
0
)
{
// parse the description and URL fields
tag
.
owner
=
parseIso88591
(
tag
.
data
,
0
,
i
);
break
;
}
}
tag
.
privateData
=
tag
.
data
.
subarray
(
i
+
1
);
}
},
MetadataStream
;
...
...
test/metadata-stream_test.js
View file @
5b21807
...
...
@@ -227,6 +227,7 @@
equal
(
events
.
length
,
1
,
'parsed one tag'
);
equal
(
events
[
0
].
frames
.
length
,
1
,
'parsed one frame'
);
equal
(
events
[
0
].
frames
[
0
].
id
,
'TXXX'
,
'parsed the frame id'
);
equal
(
events
[
0
].
frames
[
0
].
description
,
'get done'
,
'parsed the description'
);
equal
(
events
[
0
].
frames
[
0
].
value
,
'{ "key": "value" }'
,
'parsed the value'
);
});
...
...
@@ -252,6 +253,7 @@
equal
(
events
.
length
,
1
,
'parsed one tag'
);
equal
(
events
[
0
].
frames
.
length
,
1
,
'parsed one frame'
);
equal
(
events
[
0
].
frames
[
0
].
id
,
'WXXX'
,
'parsed the frame id'
);
equal
(
events
[
0
].
frames
[
0
].
description
,
''
,
'parsed the description'
);
equal
(
events
[
0
].
frames
[
0
].
url
,
url
,
'parsed the value'
);
});
...
...
@@ -280,6 +282,37 @@
'parsed the single-digit character'
);
});
test
(
'parses PRIV tags'
,
function
()
{
var
events
=
[],
payload
=
stringToInts
(
'arbitrary data may be included in the payload '
+
'of a PRIV frame'
);
metadataStream
.
on
(
'data'
,
function
(
event
)
{
events
.
push
(
event
);
});
metadataStream
.
push
({
trackId
:
7
,
pts
:
1000
,
dts
:
900
,
// header
data
:
new
Uint8Array
(
id3Tag
(
id3Frame
(
'PRIV'
,
stringToCString
(
'priv-owner@example.com'
),
payload
)))
});
equal
(
events
.
length
,
1
,
'parsed a tag'
);
equal
(
events
[
0
].
frames
.
length
,
1
,
'parsed a frame'
);
equal
(
events
[
0
].
frames
[
0
].
id
,
'PRIV'
,
'frame id is PRIV'
);
equal
(
events
[
0
].
frames
[
0
].
owner
,
'priv-owner@example.com'
,
'parsed the owner'
);
deepEqual
(
events
[
0
].
frames
[
0
].
privateData
,
new
Uint8Array
(
payload
),
'parsed the frame private data'
);
});
// https://html.spec.whatwg.org/multipage/embedded-content.html#steps-to-expose-a-media-resource-specific-text-track
test
(
'constructs the dispatch type'
,
function
()
{
metadataStream
=
new
videojs
.
Hls
.
MetadataStream
({
...
...
Please
register
or
sign in
to post a comment