- 論壇徽章:
- 0
|
終于有回應(yīng)得了,先表示感謝,具體說來就是:聲音和圖像可以并發(fā)執(zhí)行,但時(shí)間對(duì)不上號(hào),此刻的聲音不能和此刻的圖像同步,具體程序如下,有會(huì)寫同步的請(qǐng)幫忙給出答案,就是給點(diǎn)指點(diǎn)也好,大概該怎末做,說一下,不勝感激
//---------play avi---------------
/*image thread*/
void *thread3()
{
int filesize;
char *bbuffer=NULL;
bbuffer = (char *)malloc (320*240*4);
char *dataBuf;
mem_file.pfilebuff=bbuffer;
dataBuf=(char*)malloc(320*3*240);
for(;;)
{
if(fread(&filesize,1,4,avfp) == 4)
{
printf("read filesize is : %d !\n",filesize);
}
if(fread(bbuffer,1,filesize,avfp) != filesize)
{
printf("play is over !\n");
break;
}
mem_file.base=0;
mem_file.filesize=filesize;
if(mem_file.filesize<=0)
continue;
if(!mem_file.pfilebuff)
continue;
cinfo.err=jpeg_std_error(&jerr.pub);
jerr.pub.error_exit=my_error_exit;
if (setjmp(jerr.setjmp_buffer))
{
jpeg_destroy_decompress(&cinfo);
goto clearend;
}
jpeg_create_decompress(&cinfo);
jpeg_stdio_src(&cinfo,(FILE *)(&mem_file));
jpeg_read_header(&cinfo,TRUE);
jpeg_start_decompress(&cinfo);
if(dataBuf==NULL)
{
printf("JpegFile :\nOut of memory");
jpeg_destroy_decompress(&cinfo);
goto clearend;
}
row_stride=cinfo.output_width * cinfo.output_components;
width=cinfo.output_width;
height=cinfo.output_height;
buffer=(*cinfo.mem->alloc_sarray)((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);
while(cinfo.output_scanline<cinfo.output_height)
{
jpeg_read_scanlines(&cinfo,buffer,1);
if (cinfo.out_color_components==3)
j_putRGBScanline(buffer[0],cinfo.output_width,dataBuf,cinfo.output_scanline-1);
else if(cinfo.out_color_components==1)
j_putGrayScanlineToRGB(buffer[0],cinfo.output_width,dataBuf,cinfo.output_scanline-1);
}
(void)jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
diff_width=fbdev.fb_width-width;
diff_height=fbdev.fb_height-height;
if(diff_width>0)
{
x= diff_width/2;
}
else
{
x=0;
width=fbdev.fb_width;
}
if(diff_height>0)
{
y=diff_height/2;
}
else
{
y=0;
height=fbdev.fb_height;
}
fbdev.fb_draw(&fbdev,dataBuf,0,0,320,240);
}
clearend:
free(dataBuf);
free(bbuffer);
}
/*sound thread*/
void *thread4()
{
int id;
int arg;
int status;
char buf[4096];
/* if((audiofd = open("/dev/sound/dsp",O_WRONLY)) < 0 )
{
printf("Can't open sound device!\n");
exit(1);
}
*/
/* if((fd = open("/tmp/audio.wav",O_RDWR)) < 0)
{
printf("Can't open output file!\n");
exit (1);
}
*/
arg = SIZE;
status = ioctl(audiofd,SOUND_PCM_WRITE_BITS,&arg);
if(status == -1)
printf("SOUND_PCM_WRITE_BITS ioctl failed\n");
if(arg != SIZE)
printf("unable to set sample size\n");
arg = CHANNELS;
status = ioctl(audiofd,SOUND_PCM_WRITE_CHANNELS,&arg);
if(status == -1)
printf("SOUND_PCM_WRITE_CHANNELS ioctl failed\n");
if(arg != CHANNELS)
printf("unable to set number of channels\n");
//arg = RATE;
arg =22050;
status = ioctl(audiofd,SOUND_PCM_WRITE_RATE,&arg);
if(status == -1)
printf("SOUND_PCM_WRITE_WRITE ioctl failed\n");
while(fread(buf,sizeof(buf),1,audiofp) > 0)
write(audiofd,buf,sizeof(buf));
}
void play_thread_create(void)
{
int temp;
memset(&thread, 0, sizeof(thread)); //comment1
/*創(chuàng)建線程*/
if((temp = pthread_create(&thread[0], NULL, thread3, NULL)) != 0) //comment2
printf(" sorry sir thread 3 failed !\n");
else
printf("my sir thread 3 is successful !\n");
if((temp = pthread_create(&thread[1], NULL, thread4, NULL)) != 0) //comment3
printf("sorry sir thread 4 failed !\n");
else
printf("my sir thread 4 is successful !\n");
}
void play_thread_wait(void)
{
/*等待線程結(jié)束*/
if(thread[0] !=0)
{
pthread_join(thread[0],NULL);
printf("thread 1 was over! \n");
}
if(thread[1] !=0)
{
pthread_join(thread[1],NULL);
printf("thread 2 was over !\n");
}
} |
[ 本帖最后由 dreamice 于 2009-8-23 21:53 編輯 ] |
|