[Spice-devel] [PATCH spice-html5 v2 4/4] Display: Add support for the VP9 codec type
Tomáš Bohdálek
tom.bohdalek at gmail.com
Tue Sep 12 07:43:24 UTC 2017
---
display.js | 27 +++++++++++++++++++++------
spiceconn.js | 2 ++
webm.js | 13 +++++++++++--
3 files changed, 34 insertions(+), 8 deletions(-)
diff --git a/display.js b/display.js
index 0868f91..d711ced 100644
--- a/display.js
+++ b/display.js
@@ -543,7 +543,8 @@ SpiceDisplayConn.prototype.process_channel_message = function(msg)
else
this.streams[m.id] = m;
- if (m.codec_type == SPICE_VIDEO_CODEC_TYPE_VP8)
+ if (m.codec_type == SPICE_VIDEO_CODEC_TYPE_VP8 ||
+ m.codec_type == SPICE_VIDEO_CODEC_TYPE_VP9)
{
var media = new MediaSource();
var v = document.createElement("video");
@@ -606,7 +607,8 @@ SpiceDisplayConn.prototype.process_channel_message = function(msg)
if (this.streams[m.base.id].codec_type === SPICE_VIDEO_CODEC_TYPE_MJPEG)
process_mjpeg_stream_data(this, m, time_until_due);
- if (this.streams[m.base.id].codec_type === SPICE_VIDEO_CODEC_TYPE_VP8)
+ if (this.streams[m.base.id].codec_type === SPICE_VIDEO_CODEC_TYPE_VP8 ||
+ this.streams[m.base.id].codec_type === SPICE_VIDEO_CODEC_TYPE_VP9)
process_video_stream_data(this.streams[m.base.id], m);
return true;
@@ -640,7 +642,8 @@ SpiceDisplayConn.prototype.process_channel_message = function(msg)
var m = new SpiceMsgDisplayStreamDestroy(msg.data);
STREAM_DEBUG > 0 && console.log(this.type + ": MsgStreamDestroy id" + m.id);
- if (this.streams[m.id].codec_type == SPICE_VIDEO_CODEC_TYPE_VP8)
+ if (this.streams[m.id].codec_type == SPICE_VIDEO_CODEC_TYPE_VP8 ||
+ this.streams[m.id].codec_type == SPICE_VIDEO_CODEC_TYPE_VP9)
{
document.getElementById(this.parent.screen_id).removeChild(this.streams[m.id].video);
this.streams[m.id].source_buffer = null;
@@ -1036,14 +1039,25 @@ function handle_video_source_open(e)
{
var stream = this.stream;
var p = this.spiceconn;
+ var codec_type = this.stream.codec_type;
if (stream.source_buffer)
return;
- var s = this.addSourceBuffer(SPICE_VP8_CODEC);
+ switch (codec_type)
+ {
+ case SPICE_VIDEO_CODEC_TYPE_VP8:
+ codec_type = SPICE_VP8_CODEC;
+ break;
+ case SPICE_VIDEO_CODEC_TYPE_VP9:
+ codec_type = SPICE_VP9_CODEC;
+ break;
+ }
+
+ var s = this.addSourceBuffer(codec_type);
if (! s)
{
- p.log_err('Codec ' + SPICE_VP8_CODEC + ' not available.');
+ p.log_err('Codec ' + codec_type + ' not available.');
return;
}
@@ -1054,7 +1068,8 @@ function handle_video_source_open(e)
listen_for_video_events(stream);
var h = new webm_Header();
- var te = new webm_VideoTrackEntry(this.stream.stream_width, this.stream.stream_height);
+ var te = new webm_VideoTrackEntry(this.stream.stream_width, this.stream.stream_height,
+ this.stream.codec_type);
var t = new webm_Tracks(te);
var mb = new ArrayBuffer(h.buffer_size() + t.buffer_size())
diff --git a/spiceconn.js b/spiceconn.js
index 3948ae5..ef4aadc 100644
--- a/spiceconn.js
+++ b/spiceconn.js
@@ -147,6 +147,8 @@ SpiceConn.prototype =
(1 << SPICE_DISPLAY_CAP_CODEC_MJPEG);
if ('MediaSource' in window && MediaSource.isTypeSupported(SPICE_VP8_CODEC))
caps |= (1 << SPICE_DISPLAY_CAP_CODEC_VP8);
+ if ('MediaSource' in window && MediaSource.isTypeSupported(SPICE_VP9_CODEC))
+ caps |= (1 << SPICE_DISPLAY_CAP_CODEC_VP9);
msg.channel_caps.push(caps);
}
diff --git a/webm.js b/webm.js
index 789da14..4447195 100644
--- a/webm.js
+++ b/webm.js
@@ -88,6 +88,7 @@ var EXPECTED_PACKET_DURATION = 10;
var GAP_DETECTION_THRESHOLD = 50;
var SPICE_VP8_CODEC = 'video/webm; codecs="vp8"';
+var SPICE_VP9_CODEC = 'video/webm; codecs="vp9"';
/*----------------------------------------------------------------------------
** EBML utility functions
@@ -467,7 +468,7 @@ webm_AudioTrackEntry.prototype =
},
}
-function webm_VideoTrackEntry(width, height)
+function webm_VideoTrackEntry(width, height, codec_type)
{
this.id = WEBM_TRACK_ENTRY;
this.number = 1;
@@ -482,8 +483,16 @@ function webm_VideoTrackEntry(width, height)
this.codec_decode_all = 0; // fixme - check
this.seek_pre_roll = 0; // 80000000; // fixme - check
this.codec_delay = 80000000; // Must match codec_private.preskip
- this.codec_id = "V_VP8";
this.video = new webm_Video(width, height);
+ switch (codec_type)
+ {
+ case SPICE_VIDEO_CODEC_TYPE_VP8:
+ this.codec_id = "V_VP8";
+ break;
+ case SPICE_VIDEO_CODEC_TYPE_VP9:
+ this.codec_id = "V_VP9";
+ break;
+ }
}
webm_VideoTrackEntry.prototype =
--
2.9.5
More information about the Spice-devel
mailing list