PPAPI开发之路(二)在VS 2013上编译media_stream_video例子

本例子工程代码下载地址:http://download.****.net/detail/y601500359/9862413

一、源码路径

例子源码在你nacl_sdk安装目录下,比如我的是:E:\SDK\nacl_sdk\pepper_49\examples\api\media_stream_video

二、新建vs项目

1、新建一个名为media_stream_video的Win32项目,类型选DLL;

PPAPI开发之路(二)在VS 2013上编译media_stream_video例子


PPAPI开发之路(二)在VS 2013上编译media_stream_video例子

2、去掉预编译头文件stdafx.h和stdafx.cpp,去掉dllmain.cpp文件;

3、在项目属性–>配置属性–>C/C++–>预编译头,把预编译头选项的值设置为不使用预编译头。

4、删除自动生成的media_stream_video.cpp。

5、在“配置属性–>C/C++–>代码生成–>运行库”中设置为MT

6、将例子下的media_stream_video.cc,复制到刚刚创建的工程目录;

PPAPI开发之路(二)在VS 2013上编译media_stream_video例子

7、添加media_stream_video.cc到工程

PPAPI开发之路(二)在VS 2013上编译media_stream_video例子

8、设置包含的nacl_sdk头文件目录;

PPAPI开发之路(二)在VS 2013上编译media_stream_video例子

9、将nacl_sdk安装目录下的lib文件copy到我们的工程:我是在工程目录建了一个lib文件夹

我的目录是:E:\SDK\nacl_sdk\pepper_49\lib\win_x86_32_host,注意debug文件夹下的对应我们的debug工程,release对应release,

PPAPI开发之路(二)在VS 2013上编译media_stream_video例子

将lib添加进工程

PPAPI开发之路(二)在VS 2013上编译media_stream_video例子

设置lib路径

PPAPI开发之路(二)在VS 2013上编译media_stream_video例子

10、编译:平台选择x86 或者 PPAPI都行

PPAPI开发之路(二)在VS 2013上编译media_stream_video例子

三、本地调试PPAPI插件

1、在工程目录新建一个名为:media_stream_video.html的脚本,js脚本如下:

[html] view plain copy
  1. <!DOCTYPE html>  
  2. <html>  
  3.   <!--  
  4.   Copyright 2014 The Chromium Authors. All rights reserved.  
  5.   Use of this source code is governed by a BSD-style license that can be  
  6.   found in the LICENSE file.  
  7.   -->  
  8. <head>  
  9.   <title>Media Stream Video Example</title>  
  10.   <script type="text/javascript">  
  11.     var plugin;  
  12.     var stream;  
  13.   
  14.     function handleMessage(message) {  
  15.       console.log(message);  
  16.     }  
  17.   
  18.     function success(s) {  
  19.       stream = s;  
  20.       plugin.postMessage({command: 'init', track: stream.getVideoTracks()[0]});  
  21.     }  
  22.   
  23.     function failure(e) {  
  24.       console.log(e);  
  25.     }  
  26.   
  27.     function initialize() {  
  28.       plugin = document.getElementById('plugin');  
  29.       plugin.addEventListener('message', handleMessage, false);  
  30.       var constraints = {  
  31.         audio: false,  
  32.         video: {  
  33.           mandatory: {  
  34.             minWidth: 640,  
  35.             minHeight: 320,  
  36.             minFrameRate: 30  
  37.           },  
  38.           optional: []  
  39.         }  
  40.       };  
  41.   
  42.       navigator.webkitGetUserMedia(constraints, success, failure);  
  43.     }  
  44.   
  45.     function changeFormat(format) {  
  46.       plugin.postMessage({command:'format', format: format});  
  47.     }  
  48.   
  49.     function changeSize(width, height) {  
  50.       plugin.postMessage({command:'size', width: width, height: height});  
  51.     }  
  52.     document.addEventListener('DOMContentLoaded', initialize, false);  
  53.   </script>  
  54. </head>  
  55.   
  56. <body>  
  57.   <h1>Pepper MediaStream Video API Example</h1><br>  
  58.   This example demonstrates receiving frames from a video MediaStreamTrack and  
  59.   rendering them in a plugin.<br>  
  60.   Left side shows YUV frames. Right side shows BGRA frames.  
  61.   <embed id="plugin" type="application/x-ppapi-example-media-stream-video"  
  62.   width="640" height="240"/>  
  63.   <h2>Format:</h2><br>  
  64.   <button onclick="changeFormat('YV12')" >YV12</button>  
  65.   <button onclick="changeFormat('I420')" >I420</button>  
  66.   <button onclick="changeFormat('BGRA')" >BGRA</button>  
  67.   <button onclick="changeFormat('DEFAULT')" >DEFAULT</button>  
  68.   <h2>Size:</h2><br>  
  69.   <button onclick="changeSize(72, 72)" >72 x 72</button>  
  70.   <button onclick="changeSize(640, 360)" >640 x 360</button>  
  71.   <button onclick="changeSize(1280, 720)" >1280 x 720</button>  
  72.   <button onclick="changeSize(0, 0)" >DEFAULT</button>  
  73. </body>  
  74. </html>  



2、运行命令:

[html] view plain copy
  1.   
[html] view plain copy
  1. 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  
PPAPI开发之路(二)在VS 2013上编译media_stream_video例子



为什么插件没有被加载呢,原因是我们的chrome设置有问题,因为我们需要渲染,设置如图:

PPAPI开发之路(二)在VS 2013上编译media_stream_video例子

然后显示结果如图:

PPAPI开发之路(二)在VS 2013上编译media_stream_video例子



版权声明:本文为博主原创文章,未经博主允许不得转载。