- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用 libjpeg(Windows Mobile 6.5 上的 C/C++ 编程),以便在将它们插入 DirectShow 图形之前解码来自 IP 摄像机的图像(以 MJPEG 流发送)。
直到现在,我一直在使用一个函数:接收流、手动解析它(为了找到 JPEG 数据的起点和终点)、解码数据(即初始化 libjpeg 结构、读取JPEG header ,进行实际解码...),最后将其插入图表中。这工作正常,但为了使事情更顺利和更整洁,我想使用一个函数来接收,调用另一个函数(后来,一个线程)来解码/推送。
因此,作为第一步,我没有在流中找到数据后立即执行所有 JPEG 工作,而是简单地调用另一个负责 JPEG 结构初始化/ header 读取/解码/推送的函数。
这就是我遇到无法破译的错误的地方:“在状态 205 中对 jpeg 库的不正确调用”。
//编辑清晰
目前,我的代码如下所示:
void receive1() { while(1) { if(recvfrom(/* ... */) > 0) { /* parse the received data for JPEG start and end */ /* decode the JPEG */ //Declarations struct jpeg_decompress_struct cinfo; struct my_error_mgr jerr; // Step 1: allocation / initialization cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; if(setjmp(jerr.setjmp_buffer)) { printf("--ERROR LIBJPEG\n"); /* quit with error code */ } // Next steps : proceed with the decoding and displaying... jpeg_create_decompress(&cinfo); /* ... */ } }}
我想让我的代码看起来像:
void receive2() { while(1) { if(recvfrom(/* ... */) > 0) { /* parse the received data for JPEG start and end */ decode(data); } }} int decode(char* data) { /* decode the JPEG */ //Declarations struct jpeg_decompress_struct cinfo; struct my_error_mgr jerr; // Step 1: allocation / initialization cinfo.err = jpeg_std_error(&jerr.pub); jerr.pub.error_exit = my_error_exit; if(setjmp(jerr.setjmp_buffer)) // This is where the "state 205" error occurs { printf("--ERROR LIBJPEG\n"); /* quit with error code */ } // Next steps : proceed with the decoding and displaying... jpeg_create_decompress(&cinfo); /* ... */ return 0;}
如有任何帮助,我们将不胜感激。非常感谢!
//编辑
我意识到我在原来的帖子中遗漏了很多信息。这里有一些(可能)有用的细节:
typedef struct my_error_mgr * my_error_ptr; struct my_error_mgr { struct jpeg_error_mgr pub; jmp_buf setjmp_buffer;}; METHODDEF(void) my_error_exit (j_common_ptr cinfo){ my_error_ptr myerr = (my_error_ptr) cinfo->err; /* Always display the message. */ (*cinfo->err->output_message) (cinfo); /* Return control to the setjmp point */ longjmp(myerr->setjmp_buffer, 1);}
最佳答案
205 是 0xCD,这是 VS 在 Debug模式下放入初始化内存的标准值,所以我认为你的 cinfo
在调用解码器时没有正确初始化。使用时贴出代码。
此外,您使用的 setjump()
让我认为它是 IJG 库。请小心使用它,因为它不是标准功能。当您进行调用时,它会记住线程和堆栈的确切状态,并且能够从任何地方返回到该位置,除非该状态不再有效,例如:
int init_fn(){
if (setjump(my_state)){
// ERROR!
};
return 0;
};
int decode(){
init_fn();
do_work();
};
此处保存的状态在您调用实际解码器时无效。对于 MT 情况,您必须从与 longjmp()
相同的线程调用 setjump()
。
关于c++ - Libjpeg 错误 - 在状态 205 中调用不当,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4013296/
我正在编写一个 native iOS 7 应用程序,需要从 JSON api(由我控制)检索数据。 JSON 输出示例如下: { "id" : "544", "name" : "1900 Green
我是一名优秀的程序员,十分优秀!