Google Native Client, sending binary data from NACL to the frontend

微笑、不失礼 提交于 2019-12-22 04:19:08

问题


How do I send binary data, e.g. mp3/mp4 data back to the frontend ?

I know there are two ways of doing it: utilizing the sandbox filesystem provided by NACL and get the url at the frontend; passing the data through the PostMessage() using VarArrayBuffer. It would be great if someone could give me a simple example of how to pass the binary data through PostMessage(). There is a Pong example for NACl FileSystem API but I 'm kind of confused on how to retrieve the file location as url so that the frontend JS could get it through the message.

Here is what I have done so far, using the second method of passing data through PostMessage() and VarArrayBuffer:

  • I successfully retrieved data from online mp4 file and stored it in a char vector vector<char> outputBuffer.

  • Dumped the data into a new char buffer and create VarArrayBuffer to hold the data and pass it to the JS side

    char* binaryBuffer = new char[outputBuffer.size()];
    int increment = 0;
    for (vector<char>::iterator it = outputBuffer.begin(); 
         it != outputBuffer.end(); it++) {
         binaryBuffer[increment] = *it;
    }
    
    pp::VarArrayBuffer outBuffer(binaryBuffer);
    instance_->PostMessage(outBuffer);//instance_ is a NACL module instance
    

So, how should the JS side catch the array buffer? Is it through message.data or something else?

来源:https://stackoverflow.com/questions/12292425/google-native-client-sending-binary-data-from-nacl-to-the-frontend

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!