小学期实践: 在S3C2440上移植Mplayer
tar zvxf libmad-0.15.1b.tar.gz
./configure CC=arm-linux-gcc --host=arm-linux --disable-shared --disable-debugging --prefix=/workspace/micro2440/libmad/mad
make
make install
安装完成后,在/workspace/micro2440/mad/目录下,会生产两个子目录include和lib
可能报错:
checking for C compiler default output file name... configure: error: C compiler cannot create executables
See `config.log' for more details.
----检查交叉工具的安装 我是直接root登录 重新configure一次就行了
---------------------------------------------------------------------------------------
3、编译安装MPlayer
tar jxvf MPlayer-1.0rc2.tar.bz2
cd /workspace/micro2440/mplayer/MPlayer-1.0rc2
./configure --host-cc=gcc --cc=arm-linux-gcc --target=arm --enable-static --disable-win32dll --disable-dvdread --disable-dvdread-internal --disable-dvdnav --disable-libdvdcss-internal --enable-fbdev --disable-mencoder --disable-live --enable-mad --enable-libavcodec_a --disable-live --with-extraincdir=/workspace/micro2440/libmad/mad/include --with-extralibdir=/workspace/micro2440/libmad/mad/lib 2>&1 | tee logfile
make
如果出现不支持pld[r1]指令的问题
在MPlayer-1.0rc2/libmpeg2/motion_comp_arm_s.S文件
和MPlayer-1.0rc2/libavcodec/armv4l/dsputil_arm_s.S文件的开始处写入
#ifndefHAVE_PLD
.macro pldreg
.endm
#endif
重新 make
----------------------------------------------------------------------------------------------
测试运行
./mplayer panda.mpg -framedrop -quiet -vf rotate=1
./mplayer panda.mpg
./mplayerNew_Soul.mp3
#mkdir -p /dev/sound
#ln -s /dev/dsp /dev/sound/
---------------------------------------------------------------------------------------------- mplayer运行在slave模式下,用一个程序控制mplayer
//会打印出一份当前mplayer所支持的所有slave模式的命令
方法一:从控制台输入控制命令(测试使用)
运行mplayer-slave -quiet <movie>,并在控制台窗口输入slave命令。
//-slave启动从模式
//-quiet不输出冗余的信息
例如:
./mplayernew_soul.mp3 -slave -quiet
或者:
./mplayerpanda.mpg -slave -quiet
#mkfifo</tmp/fifofile>
#mplayer -slave -input file=</tmp/fifofile><movie>
//用户可以通过往管道里写入slave命令来实现对应的功能
-----------------------------------------------------------------
任务:
编译命令:
arm-linux-gccmplayer-slave-cmd.c -o mplayer-slave-cmd –lpthread
提示:编译多线程的程序,参数-lpthread不能少
任务1:
1、程序运行之后,在mplayer没有信息输出的情况下,仍然不断输出“the msg read form pipe is”,怎样
修改程序,才能让程序在mplayer有信息输出的情况下,才输出该信息;而mplayer没有信息输出的情况
下,该信息不会出现?
注:这个问题有时一运行就会出现,有时在输入quit命令之后才会出现。
提示:判断管道读取的内容
任务2:
正常的信息输出顺序应该是“pleaseinput you cmd:”和“themsgread form pipe is”交替出现
(蓝色字体为用户输入的命令)
例如:
pleaseinput you cmd:get_time_pos
*get_time_pos
*
themsgread form pipe is ANS_TIME_POSITION=40.6
pleaseinput you cmd:
但是实际会出现下面这种情况:
pleaseinput you cmd:get_time_pos
*get_time_pos
*
pleaseinput you cmd:thmsgread form pipe is ANS_TIME_POSITION=40.6
请修改程序解决这个问题
提示:使用usleep函数,usleep(n)表示sleepn微秒
任务3:
- #include <pthread.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <string.h>
- #define MS 1000 /*usleep()*/
- #define REC_MSG_CHNUM 100 /*received the number of characters message*/
- /**********************全局变量定义区*****************/
- int fd_fifo; //创建有名管道,用于向mplayer发送命令
- int fd_pipe[2]; //创建无名管道, 用于从mplayer读取命令
- pthread_t tid1;
- pthread_t tid2;
- //从标准输入写入命名管道
- void *get_pthread(void *arg)
- {
- char buf[REC_MSG_CHNUM];
- while(0 != strncmp(buf, "quit", 4)) {
- printf("please input you cmd:");
- fflush(stdout); //清空输入缓冲区
- fgets(buf, sizeof(buf), stdin); //从标准输入获取数据
- buf[strlen(buf)] = '\0';
- printf("*%s*\n", buf);
- //Print the message on the screen that is from the writing end ring pipe read
- if (write(fd_fifo, buf, strlen(buf)) != strlen(buf))
- perror("write"); //将命令写入命名管道
- usleep(50*MS); //延时 微妙
- }
- pthread_cancel(tid2); //注销掉tid2
- printf("print pthread exit!\nget pthread exit!\n");
- }
- //输出无名管道的信息
- void *print_pthread(void *arg)
- {
- int size = 0;
- char buf[REC_MSG_CHNUM];
- close(fd_pipe[1]);
- while(1) {
- /*
- size=read(fd_pipe[0], buf, sizeof(buf)); //从无名管道的写端读取信息打印在屏幕上
- buf[size]='\0';
- printf("the msg read form pipe is %s\n",buf);
- */
- if ((size=read(fd_pipe[0], buf, sizeof(buf))) == -1) {
- perror("read pipe");
- exit(0);
- }
- if(size == 0)
- continue;
- buf[size] = '\0';
- printf("the msg read form pipe is: %s\n", buf);
- }
- }
- int main(int argc, char* argv[])
- {
- int fd, ret;
- char buf[100];
- pid_t pid;
- unlink("/tmp/my_fifo"); //如果有名管道存在,则先删除
- mkfifo("/tmp/my_fifo",O_CREAT|0666);
- perror("mkfifo");
- if (pipe(fd_pipe)<0) { //创建无名管道
- perror("pipe error\n");
- exit(-1);
- }
- pid = fork();
- if (pid < 0) {
- perror("fork");
- }
- if (pid == 0) { //子进程播放mplayer
- close(fd_pipe[0]);
- dup2(fd_pipe[1], 1); //将子进程的标准输出重定向到管道的写端
- fd_fifo = open("/tmp/my_fifo",O_RDWR); //打开有名管道
- /*运行mplayer*/ //等同于 ./mplayer -slave -quiet -input file=
- execlp("./mplayer", "mplayer", "-slave", "-quiet", "-input", "file=/tmp/my_fifo", "new.mp3", NULL);
- } else {
- fd_fifo = open("/tmp/my_fifo", O_RDWR);
- if (fd < 0)
- perror("open");
- ret = pthread_create(&tid1, NULL, get_pthread, NULL); //从键盘获取控制信息
- if (ret != 0) {
- printf("Create get thread error\n");
- return ret;
- }
- ret = pthread_create(&tid2, NULL, print_pthread, NULL); //打印从无名管道收到的信息
- if(ret != 0)
- {
- printf("Create print thread error\n");
- return ret;
- }
- pthread_join(tid1, NULL);
- //pthread_join(tid2, NULL);
- printf("\nprocess exit!\n");
- }
- return 0;
- }