代码之家  ›  专栏  ›  技术社区  ›  BlueCookie

libjpeg错误-状态205中的不正确调用

  •  1
  • BlueCookie  · 技术社区  · 15 年前

    我使用LIJPEG(Windows Mobile 6.5上的C/C++编程),以便从IP摄像机(在MJPEG流中发送)中解码图像,然后将它们推到DirectShow图中。

    到目前为止,我一直在使用一个函数:接收流、手动解析流(以便找到jpeg数据的起点和终点)、解码数据(即初始化libjpeg结构、读取jpeg头、进行实际解码…)并最终将其推送到图形中。h.这可以正常工作,但是为了使事情更顺利和整洁,我想使用一个接收函数,它调用另一个函数(稍后是线程)进行解码/推送。

    因此,作为第一步,我不需要在找到流中的数据后立即执行所有的jpeg工作,而只需要调用另一个函数来负责jpeg结构的init/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,但出于许多原因,我不使用内置的调试器或模拟器。相反,该exe文件是直接部署和测试在Windows Mobile设备上,使用自定义的类似DOS的命令提示。
    • 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);
    }
    2 回复  |  直到 15 年前
        1
  •  1
  •   ruslik    15 年前

    205是0xcd,这是vs在单元化内存调试模式下的标准值,因此我认为 cinfo 在您调用解码器时未正确初始化。使用代码时将其发布。

    此外,还有 setjump() 你在用,让我觉得它是ijg图书馆。小心点,因为它不是标准函数。当您进行调用并能够从任何位置返回到该位置时,它会记住线程和堆栈的确切状态,除非此状态不再有效,如:

    int init_fn(){
         if (setjump(my_state)){
            // ERROR!
         };
    return 0;
    };
    
    int decode(){
         init_fn();
         do_work();
    };
    

    这里保存的状态在您调用实际解码器时无效。对于mt case,您必须调用 设置跳转() 从同一个线程 longjmp()

        2
  •  0
  •   BlueCookie    15 年前

    找到了我问题的答案,部分原因是Ruslik。结果发现,我在这两个函数之间初始化cinfo和jerr确实很糟糕。

    但当我纠正这一点时,我仍然有“状态205”的错误,并认为它在同一个地方。在日志中,我发现了稍后在代码执行中要发出的错误消息,这是由函数指针的问题引起的。我自己的错误…

    不管怎样,还是非常感谢!

    推荐文章