免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6757 | 回复: 4
打印 上一主题 下一主题

expected declaration or statement at end of input [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-04-23 11:45 |只看该作者 |倒序浏览
10可用积分
本帖最后由 也是菜鸟 于 2010-04-23 11:46 编辑

gcc -c main.c
结果:
main.c: In function ‘encode_thread’:
main.c:70: error: expected ‘while’ before ‘int’
main.c:118: error: expected declaration or statement at end of input
main.c:118: error: expected declaration or statement at end of input

网上搜了半天,都说是括号没配对,可我硬是没找到这样的问题,极度郁闷。求高手帮忙解决。

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <alsa/asoundlib.h>
  5. #include <pthread.h>
  6. #include <signal.h>
  7. #include "avilib.h"
  8. #include "ts_alsa.h"
  9. #include "ts_v4l2.h"
  10. #include "ts_queue.h"

  11. char * avifile = "example.avi";
  12. int actual_fps = 0;
  13. int actual_rate = 0;
  14. pthread_t  pid;
  15. /*
  16. static void printferr()
  17. {
  18. printf("there are some error with dev!\n");
  19. exit(-1);
  20. }
  21. */
  22. void pthread_exit(void *arg)
  23. {
  24. if( arg !=NULL )
  25.   AVI_close( (avi_t *)arg );
  26. }
  27. void signal_hander(int signal)
  28. {
  29. pthread_cancel(pid);
  30. ts_close_alsa();
  31. ts_close_v4l2();
  32. }

  33. void encode_thread()
  34. {
  35. int i = 0;
  36. char * vbuf = NULL;
  37. char * abuf = NULL;
  38. unsigned int vlen = 0;
  39. unsigned int alen = 0;
  40. int isKeyFrame = 0;
  41. avi_t * aviinfo = NULL;
  42. //register cleanup function
  43. pthread_cleanup_push( pthread_exit, (void *)aviinfo );
  44. aviinfo = AVI_open_output_file(avifile);
  45. AVI_set_video(aviinfo, 640, 480, (double)actual_fps, "YUYV");
  46. AVI_set_audio(aviinfo, 2, (long)actual_rate, 16,WAVE_FORMAT_PCM, 128);
  47. while(1)
  48. {
  49.   //specify a keyframe per ten frames ,it affects the size of file
  50.   if(i>=2)
  51.   {
  52.    isKeyFrame = 1;
  53.    i = -1;
  54.   }
  55.   
  56.   if( get_head_node(&vbuf, &vlen, &abuf, &alen) == 0)
  57.   {
  58.    AVI_write_frame(aviinfo, vbuf, vlen, isKeyFrame);
  59.    AVI_write_audio(aviinfo, abuf, alen);
  60.    discard_head_node();
  61.   }
  62.   i++;
  63.   isKeyFrame = 0;
  64. }
  65. }

  66. int main(int argc, char **argv)
  67. {
  68. char * devName = "/dev/video0";
  69. struct ts_element avbuf;
  70. //open v4l2 and init it
  71. ts_open_v4l2(devName);
  72. actual_fps = ts_init_v4l2();
  73. ts_enable_v4l2();
  74. //open alsa and init it
  75. ts_open_alsa("default",SND_PCM_STREAM_CAPTURE);
  76. actual_rate = ts_init_alsa(SND_PCM_ACCESS_RW_INTERLEAVED,SND_PCM_FORMAT_S16_LE,44100,2);
  77. //register signal hander
  78. signal(SIGINT,signal_hander);
  79. signal(SIGQUIT,signal_hander);

  80. //creat queue, init it
  81. init_queue(5);
  82. //create thread to encode V & a
  83. if( pthread_create(&pid, NULL, encode_thread,NULL) != 0)
  84. {
  85.   perror("Error: cannot create encoding thread, \n");
  86. }
  87. int i = 0;
  88. int frames = 10;
  89. int av_ratio = actual_rate/actual_fps;
  90. int cycleNum = av_ratio/frames;

  91. int tmplen1 = 0;
  92. char * tmp = (char *)malloc(4*frames);
  93. if(tmp == NULL)
  94. {
  95.   printf("a error occurs ,exit...\n");
  96.   exit(-1);
  97. }
  98. while(1)
  99. {
  100.   ts_get_frame( avbuf.vBuf, &avbuf.VideoUsed );
  101.   
  102.   avbuf.AudioUsed = 0;
  103.   for(i = 0; i<cycleNum ; i++)
  104.   {
  105.    ts_read_alsa(tmp, &tmplen1, frames);
  106.    memcpy( &avbuf.aBuf[avbuf.AudioUsed] ,  tmp , tmplen1 );
  107.    avbuf.AudioUsed += tmplen1;
  108.   }
  109.   in_queue( avbuf.vBuf, avbuf.VideoUsed,  avbuf.aBuf, avbuf.AudioUsed);
  110. }
  111. return 0;
  112. }
复制代码

最佳答案

查看完整内容

回复 1# 也是菜鸟 pthread_cleanup_push后面必要要跟上pthread_cleanup_pop。pthread_cleanup_push和pthread_cleanup_pop都是宏定义:#define pthread_cleanup_push(routine,arg) \ { struct _pthread_cleanup_buffer _buffer; \ _pthread_cleanup_push (&_buffer, (routine), (arg));#define pthread_cleanup_pop(execute) \ _pthread_cleanup_pop (&_buffer, (execute)); }

论坛徽章:
4
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:56:11IT运维版块每日发帖之星
日期:2016-08-11 06:20:00IT运维版块每日发帖之星
日期:2016-08-15 06:20:00
2 [报告]
发表于 2010-04-23 11:45 |只看该作者
回复 1# 也是菜鸟

pthread_cleanup_push后面必要要跟上pthread_cleanup_pop。

pthread_cleanup_push和pthread_cleanup_pop都是宏定义:
#define pthread_cleanup_push(routine,arg) \
  { struct _pthread_cleanup_buffer _buffer;                                   \
    _pthread_cleanup_push (&_buffer, (routine), (arg));


#define pthread_cleanup_pop(execute) \
    _pthread_cleanup_pop (&_buffer, (execute)); }

论坛徽章:
0
3 [报告]
发表于 2010-04-23 12:44 |只看该作者
本帖最后由 也是菜鸟 于 2010-04-23 12:56 编辑
回复  也是菜鸟

pthread_cleanup_push后面必要要跟上pthread_cleanup_pop。

pthread_cleanup_push和 ...
happy_fish100 发表于 2010-04-23 12:04



    说的是啊,我第一次用这函数(严格说,是宏,汗。。。),没记牢要配对。我试试先。

论坛徽章:
0
4 [报告]
发表于 2010-04-23 12:49 |只看该作者
cc -E 看下预处理以后的结果,应该是宏展开的时候出问题了

论坛徽章:
0
5 [报告]
发表于 2010-04-23 12:55 |只看该作者
谢谢两位的回答,我加了个pthread_cleanuop_pop(1);后问题没有了。
继续鼓捣。。。。。。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP