zoukankan      html  css  js  c++  java
  • x264与DirectShow集成

    将x264静态库与DirectShow集成后。测试发现有内存泄露。代码如下。

    静态库版本号为,VC++的最后一个版本:x264-snapshot-20091006-2245

    int mainFun()
    {
        x264_param_t param;
        cli_opt_t opt;
        int ret = 0;
        const char* outf    = "d:\\test.264";
        const char* inf        = "d:\\a.yuv";

        SetFun();
        _setmode(_fileno(stdin), _O_BINARY);
        _setmode(_fileno(stdout), _O_BINARY);

        x264_param_default(&param);
        param.i_width    = 640;
        param.i_height    = 480;

        param.rc.i_rc_method    = 0;
        param.rc.i_qp_constant    = 31;

        memset(&opt, 0sizeof(cli_opt_t));
        if (open_file_bsf(outf, &opt.hout))
        {
            fprintf( stderr, "x264 [error]: can't open output file!");;
            exit(0);
        }

        if (open_file_yuv(inf, &opt.hin, &param ))
        {
            fprintf( stderr, "x264 [error]: can't open output file!");;
            exit(0);
        }
        //close_file_yuv( opt.hin );
        ret = Encode( &param, &opt );
        return ret;
    }

     内存泄露情况如下:

    Detected memory leaks!
    Dumping objects ->
    {182} normal block at 0x021A0040, 1500027 bytes long.
     Data: <        d   @   > CD CD CD CD CD CD CD CD 64 E3 16 00 40 00 1A 02
    Object dump complete.
    The program '[1696] StillCap.exe: Native' has exited with code 2 (0x2).
    大约泄露1.5M,通过任务管理器与程序调试状态下,反复跟踪发现,泄露点为
    x264_t *x264_encoder_open( x264_param_t *param )

    {

           //....

           CHECKED_MALLOC( h->nal_buffer, h->out.i_bitstream * 3/2 + 4 );
           //...

    }

    即对没有对nal_buffer进行释放。

    在void    x264_encoder_close  ( x264_t *h ) 函数中加入如下代码,即解决此问题。

    void    x264_encoder_close  ( x264_t *h )
    {
       // ....
            x264_macroblock_cache_end( h->thread[i] );
            x264_free(h->thread[i]->out.p_bitstream );
            x264_free(h->thread[i]->out.nal);
            x264_free(h->nal_buffer);// 此行为新加行。释放到nal的缓存
            x264_free(h->thread[i] );
        }
    }

    此Bug 在VC编译器的console平台下无法发现。

    只有移植MFC的界面程序下方才有提示。

  • 相关阅读:
    POJ 2054 Color a Tree
    UVA12113-Overlapping Squares(二进制枚举)
    UVA690-Pipeline Scheduling(dfs+二进制压缩状态)
    UVA818-Cutting Chains(二进制枚举+dfs判环)
    UVA211-The Domino Effect(dfs)
    UVA225-Golygons(dfs)
    UVA208-Firetruck(并查集+dfs)
    UVA1374-Power Calculus(迭代加深搜索)
    UVA1374-Power Calculus(迭代加深搜索)
    UVA1434-The Rotation Game(迭代加深搜索)
  • 原文地址:https://www.cnblogs.com/cplusplus/p/2457778.html
Copyright © 2011-2022 走看看