本例子工程代碼下載地址:http://download.csdn.net/detail/y601500359/9862413
javascript
例子源碼在你nacl_sdk安裝目錄下,好比個人是:E:\SDK\nacl_sdk\pepper_49\examples\api\media_stream_videohtml
一、新建一個名爲media_stream_video的Win32項目,類型選DLL;java
二、去掉預編譯頭文件stdafx.h和stdafx.cpp,去掉dllmain.cpp文件;web
三、在項目屬性–>配置屬性–>C/C++–>預編譯頭,把預編譯頭選項的值設置爲不使用預編譯頭。chrome
四、刪除自動生成的media_stream_video.cpp。api
五、在「配置屬性–>C/C++–>代碼生成–>運行庫」中設置爲MT六、將例子下的media_stream_video.cc,複製到剛剛建立的工程目錄;app
七、添加media_stream_video.cc到工程ide
八、設置包含的nacl_sdk頭文件目錄;post
九、將nacl_sdk安裝目錄下的lib文件copy到咱們的工程:我是在工程目錄建了一個lib文件夾
this個人目錄是:E:\SDK\nacl_sdk\pepper_49\lib\win_x86_32_host,注意debug文件夾下的對應咱們的debug工程,release對應release,
將lib添加進工程
設置lib路徑
十、編譯:平臺選擇x86 或者 PPAPI都行
一、在工程目錄新建一個名爲:media_stream_video.html的腳本,js腳本以下:
<!DOCTYPE html> <html> <!-- Copyright 2014 The Chromium Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. --> <head> <title>Media Stream Video Example</title> <script type="text/javascript"> var plugin; var stream; function handleMessage(message) { console.log(message); } function success(s) { stream = s; plugin.postMessage({command: 'init', track: stream.getVideoTracks()[0]}); } function failure(e) { console.log(e); } function initialize() { plugin = document.getElementById('plugin'); plugin.addEventListener('message', handleMessage, false); var constraints = { audio: false, video: { mandatory: { minWidth: 640, minHeight: 320, minFrameRate: 30 }, optional: [] } }; navigator.webkitGetUserMedia(constraints, success, failure); } function changeFormat(format) { plugin.postMessage({command:'format', format: format}); } function changeSize(width, height) { plugin.postMessage({command:'size', width: width, height: height}); } document.addEventListener('DOMContentLoaded', initialize, false); </script> </head> <body> <h1>Pepper MediaStream Video API Example</h1><br> This example demonstrates receiving frames from a video MediaStreamTrack and rendering them in a plugin.<br> Left side shows YUV frames. Right side shows BGRA frames. <embed id="plugin" type="application/x-ppapi-example-media-stream-video" width="640" height="240"/> <h2>Format:</h2><br> <button onclick="changeFormat('YV12')" >YV12</button> <button onclick="changeFormat('I420')" >I420</button> <button onclick="changeFormat('BGRA')" >BGRA</button> <button onclick="changeFormat('DEFAULT')" >DEFAULT</button> <h2>Size:</h2><br> <button onclick="changeSize(72, 72)" >72 x 72</button> <button onclick="changeSize(640, 360)" >640 x 360</button> <button onclick="changeSize(1280, 720)" >1280 x 720</button> <button onclick="changeSize(0, 0)" >DEFAULT</button> </body> </html>
二、運行命令:
chrome --register-pepper-plugins="E:\\TestPro\media_stream_video\Debug\media_stream_video.dll#ppexample##1.0.0;application/x-ppapi-example-media-stream-video" file:///E:/TestPro/media_stream_video/media_stream_video.html![]()
爲何插件沒有被加載呢,緣由是咱們的chrome設置有問題,由於咱們須要渲染,設置如圖:
而後顯示結果如圖: