预览模式: 普通 | 列表

边下边看的实现方式

    最近折腾了一阵子的边下边看,总算是有点眉目,能支持一部分格式的边下边看了。

    这不是啥新技术,很多下载程序都有边下边看,但是它们的支持并不好。为了支持更多的文件格式,下载工具使用的是http服务器的方式来提供播放数据。这可以兼容更多的播放器,然而致命的弱点就是拖动进度条时,很可能就无限期挂起。这种方式的实现,具体可以参与easyMule的源码。

    另外一种方式就是使用directshow的filter来做。为了实现对未知视频文件的边下边看,需要source filter与splitter filter,这里最好的示例就是微软在windows sdk中的memfile项目。尽管memfile有些bug,但是非常值得参考(虽然memfile的bug并不多,确是折磨了我一阵子,主要是刚开始没有耐心仔细阅读directshow的基础文档导致的)。这种方案的优势是对进度条的拖动支持很好,但是其弱点就是无法支持各种格式。不过对大部分应用而言,应当也够了。除了memfile外,如果需要rmvb,avi,mkv等格式的便下边看,可以去看看hc-mpc中的解码器部分,以便查阅为啥ms的memfile不能工作。

    不过上面的方法到目前而言,也有问题我还没有解决,那就是缓冲百分比的问题。主要是每个格式的处理不同。譬如realmedia的文件,刚开始启动播放的时候,它除了读取文件头外,还需要读取文件尾。而要做一个各种格式都适合的方式,是很难的。(播放位置,以及缓冲区长度倒是可以用比特率来大概的计算出来)。

查看更多...

Tags: 边下边看 DirectShow

分类:C/C++ | 固定链接 | 评论: 2 | 引用: 0 | 查看次数: 42

CppE4X更新

    这次更新比较大,同时修改了字符集转换函数,这样在其他工程里使用LinCharSet.h的时候不会产生编译/链接问题。

    解决了很多bug,同时考虑到使用方便的问题,增加了一部分更加方便处理的函数。

    文档依然没有做。

    release cppe4x v2;

查看更多...

分类:CppE4X | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 279

字符集转换(更新)

当工程中混用stl与非stl模式的时候,原来的代码容易产生问题。

主要原因是因为stl与非stl版本的函数名相同。故此稍作修改,让他们可以一定程度并存下来。

C++代码
  1. #pragma once   
  2.   
  3. #include <malloc.h>   
  4. #include <windows.h>   
  5.   
  6. #define USE_LIN_CHAR_SET_VARIANT char* _lin_dst = 0; wchar_t* _lin_wdst = 0; int _lin_dst_size = 0;   
  7.   
  8. #define LIN_CHAR_SET_NO_WARNING  _lin_dst; _lin_wdst;_lin_dst_size;   
  9.   
  10. #define USE_LIN_CHAR_SET USE_LIN_CHAR_SET_VARIANT;LIN_CHAR_SET_NO_WARNING   
  11.   
  12.   
  13. #ifdef LIN_CHAR_SET_USE_STL   
  14.   
  15. #include <string>   
  16. std::string _w2a_s( const std::wstring& pwcsSrc, int codepage)   
  17. {   
  18.     USE_LIN_CHAR_SET;   
  19.     _lin_dst_size = pwcsSrc.size()*3;   
  20.     _lin_dst = new (std::nothrowchar[ _lin_dst_size];   
  21.     if( _lin_dst == 0) return std::string();   
  22.   
  23.     _lin_dst_size = WideCharToMultiByte( codepage, 0, pwcsSrc.c_str(), pwcsSrc.length(), _lin_dst, _lin_dst_size, 0, 0);   
  24.   
  25.     if( _lin_dst_size == 0)    
  26.     {   
  27.         delete[] _lin_dst;   
  28.         return std::string();   
  29.     }   
  30.   
  31.     _lin_dst[_lin_dst_size] = 0;   
  32.     std::string result = _lin_dst;   
  33.     delete[] _lin_dst;   
  34.     return result;   
  35. }   
  36.   
  37. std::wstring _a2w_s( const std::string& pszSrc, int codepage)   
  38. {   
  39.     USE_LIN_CHAR_SET;   
  40.     _lin_dst_size = pszSrc.size()*2;   
  41.     _lin_wdst = new (std::nothrowwchar_t [ _lin_dst_size];   
  42.     if( _lin_wdst == 0) return std::wstring();   
  43.   
  44.     _lin_dst_size = MultiByteToWideChar( codepage, 0, pszSrc.c_str(), pszSrc.length(), _lin_wdst,_lin_dst_size);   
  45.   
  46.     if( _lin_dst_size == 0)   
  47.     {   
  48.         delete[] _lin_wdst;   
  49.         return std::wstring();   
  50.     }   
  51.   
  52.     _lin_wdst[_lin_dst_size] = 0;   
  53.     std::wstring result = _lin_wdst;   
  54.     delete[] _lin_wdst;   
  55.     return result;   
  56. }   
  57.   
  58. #define _utf82w( pszSrc) _a2w_s( pszSrc, CP_UTF8)   
  59. #define _w2utf8( pszSrc) _w2a_s( pszSrc, CP_UTF8)   
  60.   
  61. #define _utf72w( pszSrc) _a2w_s( pszSrc, CP_UTF7)   
  62. #define _w2utf7( pszSrc) _w2a_s( pszSrc, CP_UTF7)   
  63.   
  64.   
  65. // 导出的宏   
  66. #define a2w(pszSrc) _a2w_s(pszSrc, CP_ACP)   
  67. #define w2a(tcsSrc) _w2a_s(tcsSrc, CP_ACP)   
  68.   
  69. #else   
  70. #define _w2a( pwcsSrc, codepage) ( pwcsSrc == 0? 0:( \   
  71.     (_lin_dst = (char*)_alloca( ((_lin_dst_size = (int)wcslen( pwcsSrc))+ 1)*3))== 0? 0 : (\   
  72.     (_lin_dst_size = WideCharToMultiByte( codepage, 0, pwcsSrc, _lin_dst_size, _lin_dst, _lin_dst_size*3, 0, 0))==0? \   
  73.     ((_lin_dst[0]=0)==0 ? _lin_dst:0): (\   
  74.     (_lin_dst[_lin_dst_size] = 0) == 0? _lin_dst : 0))))   
  75.   
  76. #define _a2w( pszSrc, codepage) (pszSrc == 0? 0 : (\   
  77.     (_lin_wdst = (wchar_t*)_alloca( ((_lin_dst_size = (int)strlen( pszSrc)) + 1)*2)) == 0? 0 : (\   
  78.     (_lin_dst_size = MultiByteToWideChar( codepage, 0, pszSrc, _lin_dst_size, _lin_wdst,_lin_dst_size + sizeof(wchar_t))) == 0? \   
  79.     ((_lin_wdst[0]=0)==0? _lin_wdst:0) : (\   
  80.     (_lin_wdst[ _lin_dst_size] = 0) == 0? _lin_wdst: 0))))   
  81.   
  82. #define _utf82w( pszSrc) _a2w( pszSrc, CP_UTF8)   
  83. #define _w2utf8( pszSrc) _w2a( pszSrc, CP_UTF8)   
  84.   
  85. #define _utf72w( pszSrc) _a2w( pszSrc, CP_UTF7)   
  86. #define _w2utf7( pszSrc) _w2a( pszSrc, CP_UTF7)   
  87.   
  88.   
  89. // 导出的宏   
  90. #define a2w(pszSrc) _a2w(pszSrc, CP_ACP)   
  91. #define w2a(tcsSrc) _w2a(tcsSrc, CP_ACP)   
  92.   
  93. #endif   
  94.   
  95. #ifdef UNICODE   
  96. #define a2t(pszSrc) a2w(pszSrc)   
  97. #define t2a(tcsSrc) w2a(tcsSrc)   
  98. #define w2t(wcsSrc) wcsSrc;   
  99. #define t2w(tcsSrc) tcsSrc;   
  100. #else   
  101. #define a2t(pszSrc) pszSrc   
  102. #define t2a(tcsSrc) tcsSrc   
  103. #define w2t(wcsSrc) wta(wcsSrc)   
  104. #define t2w(tcsSrc) a2w(tcsSrc)   
  105. #endif   
  106.   
  107. #define w2utf8(wcsSrc) _w2utf8(wcsSrc)   
  108. #define utf82w(pszSrc) _utf82w(pszSrc)   
  109. #define w2utf7(wcsSrc) _w2utf7(wcsSrc)   
  110. #define utf72w(pszSrc) _utf72w(pszSrc)   
  111.   
  112. #define a2utf8(pszSrc) w2utf8(a2w(pszSrc))   
  113. #define a2utf7(pszSrc) w2utf7(a2w(pszSrc))   
  114. #define utf82a(pszSrc) w2a(utf82w(pszSrc))   
  115. #define utf72a(pszSrc) w2a(utf72w(pszSrc))   
  116. #define t2utf8(tcsSrc) w2utf8(tcsSrc)   
  117. #define t2utf7(tcsSrc) w2utf7(tcsSrc)   
  118. #define utf82t(pszSrc) w2t(utf82w(pszSrc))   
  119. #define utf72t(pszSrc) w2t(utf72w(pszSrc))   
分类:C/C++ | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 226

单眼与距离识别

    前阵子有人说,人的单眼是没法测定物体和人的距离的。而对于此,我的想法是不同的。

    如果把人眼看成是范焦镜头(手机上大量使用的(不带AF功能的)摄像头大部分使用的范焦镜头),那么这个说法也许正确。然而人眼不是范焦的。

    想想DC的对焦功能,如果使用单反,镜头是更是有对焦环,对焦环上的刻度,会指示出当前对焦点和相机机身之间的距离。相机只需要使用一个镜头,就能识别到物品与相机的距离,关键原因就在于对焦,只有位于对焦点(及其附近)的物体,才会产生清晰的影像。对焦和精确对焦却又是不同。当使用大光圈的时候,精确对焦尤其重要,因为差以毫厘,就可能导致影像的模糊。

    人眼也是如此,我们看东西的时候,眼球需要对焦,才能看到清晰的画面。这个时侯,就算只用单眼,我们也能够察觉出物体与自己之间的距离及变化。

分类:生活日志 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 285

delay load

    以前就想过delay load可以用来做一些偷懒工作,不过却一直没啥机会使用,真到可用之处,却忘了这个东西。

    昨晚突然想起来,我可以用这个功能来根据配置文件加载不同的摄像头sdk,今天在touchwin的代码上进行了试验,结果就是: 可行。

    这样也蛮不错,以后维护后台的时候,可以少维护2个版本了。

    而且,我不需要改动任何代码,仅仅只是修改了一下link选项

Tags: delay load

分类:C/C++ | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 333

binfstream

以前写了一个不知道放哪去了,就重写了一个:

C++代码
  1.   
  2. class binfstream : public std::fstream   
  3. {   
  4. public:   
  5.     // 一个比较丑陋的构造函数 ^_^   
  6.     binfstream( const char* file_name, int open_mode = std::fstream::in)   
  7.         : std::fstream(file_name, open_mode | std::fstream::binary | ( (open_mode & std::fstream::out ) == 0 ? 0 : std::fstream::trunc) )   
  8.     {   
  9.   
  10.     }   
  11.   
  12.     ~binfstream()   
  13.     {   
  14.     }   
  15.   
  16.     // input   
  17.     template<typename T>   
  18.     binfstream& operator << (const T& t)   
  19.     {   
  20.         write( reinterpret_cast<const char*>(&t), sizeof T);   
  21.         return *this;   
  22.     }   
  23.   
  24.     binfstream& operator << ( const char* t)   
  25.     {   
  26.         write( t, strlen(t) + 1);   
  27.         return *this;   
  28.     }   
  29.   
  30.     binfstream& operator << ( const std::string s)   
  31.     {   
  32.         return operator << ( s.c_str());   
  33.     }   
  34.   
  35.     // output   
  36.     template<typename T>   
  37.     binfstream& operator >> (T& t)   
  38.     {   
  39.         read( reinterpret_cast<char*>(&t), sizeof T);   
  40.         return *this;   
  41.     }   
  42.   
  43.     binfstream& operator >> ( std::string &str)   
  44.     {   
  45.         char cur_char;   
  46.         while( read( &cur_char, sizeof cur_char ) )   
  47.         {   
  48.             if( cur_char == 0) break;   
  49.             str.push_back( cur_char);   
  50.         }   
  51.         return *this;   
  52.     }   
  53.   
  54. };  

使用自然是以简单为主:

C++代码
  1. #include <iostream>   
  2. #include <fstream>   
  3. #include <string>   
  4. #include "binfstream.h"   
  5.   
  6. int main( int argc, char* argv[])   
  7. {   
  8.     binfstream f( "d:\\log.txt", std::fstream::in | std::fstream::out);   
  9.   
  10.     f << 3 << std::string("hello") << "world" << 1.133;   
  11.     int i;   
  12.     std::string s1;   
  13.     std::string s2;   
  14.     double d;   
  15.   
  16.     f.seekp( std::fstream::beg);   
  17.   
  18.     f >> i >> s1 >> s2>> d;   
  19.        
  20.     std::cout << i << s1 << s2 << d;   
  21.   
  22.     return 0;   
  23. }   

其中operator << 和 >> 并没有写为友元,主要是因为我。。想 偷懒

Tags: fstream

分类:C/C++ | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 295

getline

getline原来也可以用于做字符串分割,我太out了

C++代码
  1. stringstream ss( input);      
  2. string str;      
  3. while( !ss.eof())      
  4. {      
  5.     getline( ss, str, ',');      
  6.     results.push_back( str);      
  7. }      
  8. return results.size();    

 

Tags: stringstream getline

分类:C/C++ | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 498

cppe4x

    源码已经上传到google code,以下是project链接 http://code.google.com/p/cppe4x   

cppe4x简介:
  1.     cppe4x是一个简单的C++跨平台XML解析器,基于DOM和XPath方式实现,其目标是快速的构建xml应用。    
  2.   
  3.     cppe4x非常适合快速的构建测试程序以及配置文件的读写。当前仅支持UTF8格式的XML文件。同时,cppe4x在Microsoft Windows平台下会自动进行utf8与ansi编码的双向转换。    
  4.   
  5.     cppe4x最初的目标是构建与ActionScript3?中的E4X语法类似的接口,但由于C++与AS3语法的巨大差异,目前的cppe4x无法完全实现该目标。尽管如此,cppe4x还是尽量的保持了操作的简洁和有效性。

    这个xml解析器的代码并不长,但是前前后后却花了好几个月的时间,结构也数次调整。也正因如此,方知一个库的构建,是如此的困难。现在,依然有很多不满意的地方。程序和文档的完善,尚需时日。

Tags: cppe4x xml e4x

分类:CppE4X | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 299