Project1

标题: C++求优化。。 [打印本页]

作者: yangff    时间: 2011-11-5 17:49
标题: C++求优化。。
本帖最后由 yangff 于 2011-11-5 17:49 编辑
  1. int __declspec(dllexport) NextFrame(int Bitmap,int playerHandle)
  2. {
  3.         int * pBitmap=(int *)Bitmap;
  4.         if (GetNextFrame(pFormatCtx, pCodecCtx, videoStream, pFrame))
  5.         {
  6.                 //struct SwsContext * img_convert_ctx;
  7.                 //img_convert_ctx=sws_getContext( pCodecCtx->width/12, pCodecCtx->height/12,PIX_FMT_RGB32,pCodecCtx->width,pCodecCtx->height,PIX_FMT_YUV420P,2,NULL,NULL,NULL);
  8.                 uint8_t *data = malloc (3*pCodecCtx->width*pCodecCtx->height);
  9.                 uint8_t *src[3]= {data, data+pCodecCtx->width*pCodecCtx->height, data+pCodecCtx->width*pCodecCtx->height+pCodecCtx->width*pCodecCtx->height};
  10.                 //int stride[3]={pCodecCtx->width, pCodecCtx->width, pCodecCtx->width};
  11.                 //sws_scale(img_convert_ctx,(const uint8_t*  const*)pFrame->data,pFrame->linesize,0,pCodecCtx->height,src,stride);
  12.                 int p=0;
  13.                 int r,g,b=0;
  14.                 double y,u,v;
  15.                 int off=pCodecCtx->width*pCodecCtx->height;
  16.                 int off1=pCodecCtx->width*pCodecCtx->height*1;
  17.                 frame(pCodecCtx->height,pCodecCtx->width,data,pFrame);
  18.                 //pBitmap[pCodecCtx->width*pCodecCtx->height-1]=0xffffaaff;
  19.             for (int i=pCodecCtx->height-1;i>=0;i--){
  20.                 for (int j=0;j<pCodecCtx->width;j++)
  21.                 {        //if (i*pCodecCtx->width+j<pCodecCtx->height*pCodecCtx->width)
  22.                         pBitmap[p]=0xff000000 ;
  23.                         y=(double)src[0][i*pCodecCtx->width+j];//pFrame->pp;//data[0][p+off];
  24.                     u=(double)src[1][(i/2*pCodecCtx->width+j)/2];//pFrame->pp;//data[0][p+off1];
  25.                         v=(double)src[2][(i/2*pCodecCtx->width+j)/2];//pFrame->pp//data[0][p+off1+off];
  26.                         r=(int)(1.164f*(y-16)+1.596f*(v-128));
  27.                         g=(int)(1.164f*(y-16)-0.813f*(v - 128) - 0.391f*(u - 128));
  28.                         b=(int)(1.164f*(y-16)+2.018f*(u - 128));
  29.                         if (r>255) r=255; if (r<0) r=0;
  30.                         if (g>255) g=255; if (g<0) g=0;
  31.                         if (b>255) b=255; if (b<0) b=0;
  32.                         pBitmap[p]|= b; //b
  33.                         pBitmap[p]|= g << 8; // g
  34.                         pBitmap[p]|= r << 16; // r
  35.                         // | data[((j+i*pCodecCtx->width+pCodecCtx->width*pCodecCtx->height) << 8)];// | data[((j+i*pCodecCtx->width+pCodecCtx->width*pCodecCtx->height*2) << 16)] | (0xff << 24);
  36.                         p++;
  37.                 }}
  38.                 free(data);
  39.                 return 1;        }
  40.                
  41.         return -1;
  42. }
复制代码

作者: dengtao49    时间: 2012-3-20 14:19
坑爹啊,C++发这里
作者: 414447674    时间: 2012-3-20 14:22
就是啊, 这里不是让你发C++的地方
作者: 熊的选民    时间: 2012-3-20 19:53
那个frame是什么,为什么要建个临时data
还有Bitmap应该是个数组吧,不然怎么能转指针。楼主试着执行过这段代码吗?
作者: yangff    时间: 2012-3-20 20:21
熊的选民 发表于 2012-3-20 19:53
那个frame是什么,为什么要建个临时data
还有Bitmap应该是个数组吧,不然怎么能转指针。楼主试着执行过这段 ...

ffmpeg的解码代码。。具体可以看sample,主要是yuv到rgba32效率蛋疼啊
作者: link006007    时间: 2012-3-21 12:52
本帖最后由 link006007 于 2012-3-21 12:53 编辑

不知道该解码数学原理的,优化基本天方夜谭。。。。。。。。。
如果只是从语言语法上来优化,推荐intel或者其他编译器厂商自带的优化工具,优化库和优化选项,编译器知道的比大部分“可能是高手”程序员知道的要多的多。。。
intel有一个ipp库,以前写一个g729解码,效率很淡疼,后来找了个ipp版本的,立马感觉就不一样了。。




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1