NPAPI:NPN_RequestRead的基本用法 [英] NPAPI: Basic usage of NPN_RequestRead

查看:212
本文介绍了NPAPI:NPN_RequestRead的基本用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解 NPN_RequestRead 应在编写 NPAPI 插件时使用。文档看起来很清楚,但至今我仍然无法使插件工作。



这是我的目标:使用NPAPI实现一个JPEG 2000插件。要有一个正确的实施,我需要访问JPEG 2000流使用随机访问。在我的情况下,图像是巨大的(100000x100000 RGB),但可以有效地显示使用前几个字节(感谢多分辨!!)

据我可以告诉我不能使插件停止GET。我不能在Firefox中使用本地文件访问,因为它似乎被打破。不过,我可以使用本地apache2安装,并使用 NPP_NewStream(... seekable = true)模式:

  $ HEAD http://localhost/test.jp2 | grep Accept-Ranges 
Accept-Ranges:bytes

由于可寻找设置为 true ,我使用 * stype = NP_SEEK 创建插件。从这一点看来,我应该能够停止GET:

  NPError NPP_NewStream(NPP实例,NPMIMEType类型,NPStream * stream,NPBool seekable,uint16_t * stype)
[...]
NPByteRange范围;
range.offset = 0;
range.length = 0;
range.next = NULL;
NPError e = s_pBrowserFunctions-> requestread(stream,& range);

但是 requestread 会返回一个错误。我有更多的机会:

pre $ int32_t NPP_Write(NPP instance,NPStream * stream,int32_t offset,int32_t len, void * buffer)
[...]
NPByteRange范围;
range.offset = 0;
range.length = 0;
range.next = NULL;
NPError e = s_pBrowserFunctions-> requestread(stream,& range);

但是,从网络控制台,我可以看到整个流已经被下载。



有没有人有使用NPN_RequestRead API的NPAPI的最小范例?

解决方案

您请求的是0字节( .length = 0 )。



Firefox因此会跳过这个范围。由于没有其他有效的范围,所以没有实际的请求,因此Firefox返回一个错误。

nsPluginStreamListenerPeer.cpp ,剥离无关的部分:

  int32_t requestCnt = 0; 
for(NPByteRange * range = aRangeList; range!= nullptr; range = range-> next){
// XXX零长度?
if(!range-> length)
continue;

// ...
requestCnt ++;
}
// ...
* numRequests = requestCnt;
// ...
if(numRequests == 0)
return NS_ERROR_FAILURE;

所以,您需要实际请求



(无可否认,这个实现看起来有些破碎/有限,例如你不能请求 bytes = 0 -


I am trying to understand how NPN_RequestRead should be used when writing an NPAPI plugin. The documentation looked at first pretty clear but I still cannot make the plugin work so far.

Here is my goal: implement a JPEG 2000 plugin using NPAPI. To have a proper implementation I need to access the JPEG 2000 stream using random access. In my case images are huge (100000x100000 RGB), but can efficiently be displayed using the first few bytes (thanks to multiresolution !).

As far I can tell I cannot make the plugin stop the GET. I cannot use local file access in firefox since it appears to be broken. However I can use a local apache2 installation and have the plugin be called with NPP_NewStream( ... seekable=true ) mode:

$ HEAD http://localhost/test.jp2 | grep Accept-Ranges
Accept-Ranges: bytes

Since seekable is set to true, I create the plugin with *stype = NP_SEEK. It seems that from this point I should be able to stop the GET with:

NPError NPP_NewStream(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype)
[...]
NPByteRange range;
range.offset = 0;
range.length = 0;
range.next = NULL;
NPError e = s_pBrowserFunctions->requestread(stream, &range);

However the requestread returns an error. I've had a little more chance with:

int32_t NPP_Write(NPP instance, NPStream* stream, int32_t offset, int32_t len, void* buffer)
[...]
NPByteRange range;
range.offset = 0;
range.length = 0;
range.next = NULL;
NPError e = s_pBrowserFunctions->requestread(stream, &range);

But still, from the network console I can see that the entire stream has been downloaded.

Does anyone has a minimal example of a working NPAPI using the NPN_RequestRead API ?

解决方案

You're requesting 0 bytes (.length = 0).

Firefox will therefore skip the range. Since there are no other valid ranges, there are no actual requests and hence Firefox returns an error.

From nsPluginStreamListenerPeer.cpp, unrelated parts stripped:

int32_t requestCnt = 0;
for (NPByteRange * range = aRangeList; range != nullptr; range = range->next) {
  // XXX zero length?
  if (!range->length)
    continue;

  // ...
  requestCnt++;
}
// ...
*numRequests  = requestCnt;
// ...
if (numRequests == 0)
  return NS_ERROR_FAILURE;

So, you'll need to actually request something!

(Admittedly, the implementation looks kinda broken/lmited, e.g. you cannot request bytes=0- with it)

这篇关于NPAPI:NPN_RequestRead的基本用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆