I am running a websocket server using autobahn|python. On the server side, I also have a gstreamer pipeline running which I am using to capture webm frames using "appsink". The gstreamer pipeline that is implemented is: gst-launch-1.0 v4l2src ! video/x-raw,width=640,height=480 ! videoconvert ! vp8enc ! webmmux ! appsink name="sink" Everytime, I receive a buffer in the appsink, I send it over a websocket as a binary "message" using sendMessage.
On the client side, I have a complicated flow of received frame_data blob. There is a FileReader, MediaSource and source buffer. whenever a frame_data is received, it is read as buffer using filereader. if the filereader is busy reading the previous frame_data, it will append it to "buffer_pool". once the frame_data is read as buffer, it is appended to "sourceBuffer". if the "sourceBuffer" is still updating the previous chunk, it will be appended to "sourceBufferpool". <script> var buffer_pool = []; var sourceBufferpool = []; function setupVideo() { window.MediaSource = window.MediaSource || window.WebKitMediaSource; if (!!!window.MediaSource) { alert('MediaSource API is not available'); } mediaSource = new MediaSource(); video.src = window.URL.createObjectURL(mediaSource); mediaSource.addEventListener('sourceopen', function (e) { try { sourceBuffer = mediaSource.addSourceBuffer('video/webm; codecs="vp8"'); } catch(e) { console.log('Exception calling addSourceBuffer for video', e); return; } //sourceBuffer.addEventListener('updatestart', function(e) { console.log('updatestart: ' + e.target + mediaSource.readyState); }); //sourceBuffer.addEventListener('updateend', function(e) { console.log('updateend: ' + e.target + mediaSource.readyState); }); sourceBuffer.addEventListener('error', function(e) { console.log('error: ' + e.target + mediaSource.readyState); }); sourceBuffer.addEventListener('abort', function(e) { console.log('abort: ' + e.target + mediaSource.readyState); }); sourceBuffer.addEventListener('update', function() { if (sourceBufferpool.length > 0 && !sourceBuffer.updating) { try { sourceBuffer.appendBuffer(sourceBufferpool.shift()); console.log('update: pooled buffer appended ' + sourceBufferpool.length + mediaSource.readyState); }catch(e){ console.log('Exception calling appendBuffer for video ', e); return; } } },false) if (video.paused) { video.play() } startWSStreaming(); },false) mediaSource.addEventListener('sourceended', function(e) { console.log('sourceended: ' + mediaSource.readyState); }); mediaSource.addEventListener('sourceclose', function(e) { console.log('sourceclose: ' + mediaSource.readyState); }); mediaSource.addEventListener('error', function(e) { console.log('error: ' + mediaSource.readyState); }); } function startWSStreaming() { var reader = new FileReader(); reader.onload = function (evt) { if (sourceBuffer.updating || sourceBufferpool.length > 0){ sourceBufferpool.push(new Uint8Array(evt.target.result)); console.log('update: pooled buffer appended ' + sourceBufferpool.length + mediaSource.readyState); }else{ sourceBuffer.appendBuffer(new Uint8Array(evt.target.result)); console.log('update: direct buffer appended ' + sourceBufferpool.length + mediaSource.readyState); } } reader.onloadend = function (evt) { if (buffer_pool.length > 0) { var chunk = new Blob([buffer_pool.shift()], {type: 'video/webm'}); evt.target.readAsArrayBuffer(chunk); console.log('Processed buffer pool: current size ' + buffer_pool.length); } } ws = new WebSocket("ws://localhost:9000/"); ws.onopen = function () { document.getElementById("MSG1").innerHTML = 'Websocket opened <br>'; } ws.onmessage = function(e) { myBuffer = e.data; if (reader.readyState == 1 || buffer_pool.length > 0) { buffer_pool.push(myBuffer); console.log('Received buffer pooled: current size ' + buffer_pool.length); }else{ var chunk = new Blob([myBuffer], {type: 'video/webm'}); reader.readAsArrayBuffer(chunk); console.log('First buffer processed'); } } } </script> now, the end result is, I see only one frame on a browser window and then the video freezes. After checking chrome://media-internals/, I get the following clue:
so the questions:
please help! |
Thanks Tobias! for your response.I just happened to check that the code I wrote is working smoothly when I connect the client using Mozilla Firefox. the video feed is smooth. but the problem is with Chrome. For more details, please see http://stackoverflow.com/questions/29089786/mediasource-api-not-working-on-chrome-but-works-smoothly-on-firefoxIn conclusion, there is no issue from the autobahn client (to feed live video chunks), autobahn server (to forward the websocket messages to the connected clients) and the JS client. The issue is on Chrome side. I will post my question on chrome community.To let you know, i am using a python client with IPushProducer implementation and gstreamer pipeline to send the video. On the server side, again the IPushProducer model is used to forward the video frames for each of the connected client. I have become fan of Autobahn now. due to its simplicity and ease of developing the application. :)
--
You received this message because you are subscribed to the Google Groups "Autobahn" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autobahnws+...@googlegroups.com.
To post to this group, send email to autob...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/autobahnws/198c105b-261c-4d03-ab37-082faa714c0b%40googlegroups.com.