c++ - Libjpeg 错误 - 在状态 205 中调用不当

标签 c++ c windows-mobile libjpeg

我正在使用 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;
}

如有任何帮助,我们将不胜感激。非常感谢!

//编辑

我意识到我在原来的帖子中遗漏了很多信息。这里有一些(可能)有用的细节:

  • 我使用的是 VS2008,但出于多种原因我没有使用内置的调试器或模拟器。相反,使用自定义的类似 dos 的命令提示符,直接在 Windows Mobile 设备上部署和测试 exe 文件。
  • libjpeg 最初读取和写入文件,但我使用了一个补丁(和自定义错误处理程序),可以直接从缓冲区读取数据,而无需打开文件。可以查到代码here ,它使用这样定义的“扩展错误处理程序”:
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/

相关文章:

c++ - 当指数为整数时,pow() 函数是否比简单乘法慢?

c++ - 两个不同的 .cpp 文件中的 C/C++ 作用域

windows-mobile - 如何在 Windows Mobile 6 应用程序中使用相机

C++ 变量参数错误

c++ - 在 C++ 中使用访问器从对象返回数组

c++ - 将 unsigned int 类型转换为 unsigned long int C++

c# - WCF 异步调用返回 10054 错误 : "An existing connection was forcibly closed by the remote host"

memory - Windows Mobile 内存损坏

c++ - 有没有一种方法可以在不增加二进制大小的情况下使用 C++ 中的异常?

Python/Ctypes - 访问指针(数组)时出现段错误