- 论坛徽章:
- 0
|
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
网上搜了半天,都说是括号没配对,可我硬是没找到这样的问题,极度郁闷。求高手帮忙解决。
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <alsa/asoundlib.h>
- #include <pthread.h>
- #include <signal.h>
- #include "avilib.h"
- #include "ts_alsa.h"
- #include "ts_v4l2.h"
- #include "ts_queue.h"
- char * avifile = "example.avi";
- int actual_fps = 0;
- int actual_rate = 0;
- pthread_t pid;
- /*
- static void printferr()
- {
- printf("there are some error with dev!\n");
- exit(-1);
- }
- */
- void pthread_exit(void *arg)
- {
- if( arg !=NULL )
- AVI_close( (avi_t *)arg );
- }
- void signal_hander(int signal)
- {
- pthread_cancel(pid);
- ts_close_alsa();
- ts_close_v4l2();
- }
- void encode_thread()
- {
- int i = 0;
- char * vbuf = NULL;
- char * abuf = NULL;
- unsigned int vlen = 0;
- unsigned int alen = 0;
- int isKeyFrame = 0;
- avi_t * aviinfo = NULL;
- //register cleanup function
- pthread_cleanup_push( pthread_exit, (void *)aviinfo );
- aviinfo = AVI_open_output_file(avifile);
- AVI_set_video(aviinfo, 640, 480, (double)actual_fps, "YUYV");
- AVI_set_audio(aviinfo, 2, (long)actual_rate, 16,WAVE_FORMAT_PCM, 128);
- while(1)
- {
- //specify a keyframe per ten frames ,it affects the size of file
- if(i>=2)
- {
- isKeyFrame = 1;
- i = -1;
- }
-
- if( get_head_node(&vbuf, &vlen, &abuf, &alen) == 0)
- {
- AVI_write_frame(aviinfo, vbuf, vlen, isKeyFrame);
- AVI_write_audio(aviinfo, abuf, alen);
- discard_head_node();
- }
- i++;
- isKeyFrame = 0;
- }
- }
- int main(int argc, char **argv)
- {
- char * devName = "/dev/video0";
- struct ts_element avbuf;
- //open v4l2 and init it
- ts_open_v4l2(devName);
- actual_fps = ts_init_v4l2();
- ts_enable_v4l2();
- //open alsa and init it
- ts_open_alsa("default",SND_PCM_STREAM_CAPTURE);
- actual_rate = ts_init_alsa(SND_PCM_ACCESS_RW_INTERLEAVED,SND_PCM_FORMAT_S16_LE,44100,2);
- //register signal hander
- signal(SIGINT,signal_hander);
- signal(SIGQUIT,signal_hander);
- //creat queue, init it
- init_queue(5);
- //create thread to encode V & a
- if( pthread_create(&pid, NULL, encode_thread,NULL) != 0)
- {
- perror("Error: cannot create encoding thread, \n");
- }
- int i = 0;
- int frames = 10;
- int av_ratio = actual_rate/actual_fps;
- int cycleNum = av_ratio/frames;
- int tmplen1 = 0;
- char * tmp = (char *)malloc(4*frames);
- if(tmp == NULL)
- {
- printf("a error occurs ,exit...\n");
- exit(-1);
- }
- while(1)
- {
- ts_get_frame( avbuf.vBuf, &avbuf.VideoUsed );
-
- avbuf.AudioUsed = 0;
- for(i = 0; i<cycleNum ; i++)
- {
- ts_read_alsa(tmp, &tmplen1, frames);
- memcpy( &avbuf.aBuf[avbuf.AudioUsed] , tmp , tmplen1 );
- avbuf.AudioUsed += tmplen1;
- }
- in_queue( avbuf.vBuf, avbuf.VideoUsed, avbuf.aBuf, avbuf.AudioUsed);
- }
- return 0;
- }
复制代码 |
最佳答案
查看完整内容
回复 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)); }
|