嵌入式6818利用线程实现视频播放器
- 基于粤嵌6818的视频播放器
-
- 一、创建管道文件
- 二、利用slave命令写入管道文件
- 三、进行视频播放功能
基于粤嵌6818的视频播放器
一、创建管道文件
int create_fifo()
{
int ret=access("/tmp/fifo",F_OK);
{
if(ret == 0)
{
printf("fifo has exist\n");
}
else if(ret == -1)
{
mkfifo("/tmp/fifo",0777);
}
}
int fifo_fd=open("/tmp/fifo",O_RDWR);
if(fifo_fd == -1)
{
perror("open fifo failed");
return -1;
}
return fifo_fd;
}
二、利用slave命令写入管道文件
int slave_write_cmd(int fifo_fd,char *cmd)
{
write(fifo_fd,cmd,strlen(cmd));
return 0;
}
三、进行视频播放功能
void show_video()
{
BmpNode *list=D_R_List_Create();
Search_Dir_Avi(list,"./avi");
BmpNode *p=list->next;
Show_Bmp(800, 480,0, 0, "./video.bmp");
fifo_fd=create_fifo();
int video_stop_cont_flags=1;
int play_flag = 0;
pid_t pid;
pid = fork();
if(pid==0)
{
while(1)
{
execl("./mplayer", "./mplayer", "-slave", "-quiet", "input file=/tmp/fifo", "zoom", "-x", "700", "-y", "420", "geometry", "0:0", "p->data", NULL);
}
}
while(1)
{
Get_Slide();
if(ts_x1>370 && ts_x1<425 && ts_y1>420 && ts_y1<480)
{
if(play_flag == 0)
{
kill(pid, SIGSTOP);
play_flag = 1;
}
else
{
kill(pid, SIGCONT);
play_flag = 0;
}
}
if(ts_x1>700 && ts_x1<800 && ts_y1>0 && ts_y1<60)
{
kill(pid , SIGKILL);
Show_Bmp(800, 480, 0, 0, "func.bmp");
close(fifo_fd);
break;
}
if(ts_x1>250 && ts_x1<300 && ts_y1>420 && ts_y1<480)
{
kill(pid , SIGKILL);
p=p->prev;
if(p==list)
{
p=p->prev;
}
pid = fork();
if(pid == 0)
{
execl("./mplayer", "./mplayer", "-slave", "-quiet", "input file=/tmp/fifo", "zoom", "-x", "700", "-y", "420", "geometry", "0:0", "p->data", NULL);
}
}
if(ts_x1>500&&ts_x1<550 && ts_y1>420&&ts_y1<480)
{
kill(pid , SIGKILL);
p=p->next;;
if(p==list)
{
p=p->next;
}
pid = fork();
if(pid == 0)
{
execl("./mplayer", "./mplayer", "-slave", "-quiet", "input file=/tmp/fifo", "zoom", "-x", "700", "-y", "420", "geometry", "0:0", "p->data", NULL);
}
}
if(ts_x1>440&&ts_x1<490 && ts_y1>420&&ts_y1<480)
{
slave_write_cmd(fifo_fd,"seek +5\n");
}
if(ts_x1>310&&ts_x1<360 && ts_y1>420&&ts_y1<480)
{
slave_write_cmd(fifo_fd,"seek -5\n");
}
if(ts_x1>70&&ts_x1<110 && ts_y1>420&&ts_y1<480)
{
slave_write_cmd(fifo_fd,"volume +200\n");
}
if(ts_x1>120&&ts_x1<160 && ts_y1>420&&ts_y1<480)
{
slave_write_cmd(fifo_fd,"volume -200\n");
}
if(ts_x1>560&&ts_x1<610 && ts_y1>420&&ts_y1<480)
{
if(video_stop_cont_flags == 1)
{
slave_write_cmd(fifo_fd,"pause\n");
video_stop_cont_flags=2;
}
else if(video_stop_cont_flags == 2)
{
slave_write_cmd(fifo_fd,"pause\n");
video_stop_cont_flags=1;
}
}
if(ts_x1>690&&ts_x1<740 && ts_y1>420&&ts_y1<480)
{
slave_write_cmd(fifo_fd,"mute\n");
}
}
}