2009-02-08 03:27:30 +00:00
|
|
|
/*
|
|
|
|
* based on: test_av.c - test program for new API
|
2001-09-09 18:50:35 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2000 Ralph Metzler <ralph@convergence.de>
|
|
|
|
* & Marcus Metzler <marcus@convergence.de>
|
|
|
|
* for convergence integrated media GmbH
|
|
|
|
*
|
2009-02-08 03:27:30 +00:00
|
|
|
* MPEG-PS multiplexer, part of FFmpeg
|
|
|
|
* Copyright Gerard Lantau (see http://ffmpeg.org)
|
|
|
|
*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2001-09-09 18:50:35 +00:00
|
|
|
*
|
2009-02-08 03:27:30 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2001-09-09 18:50:35 +00:00
|
|
|
*/
|
2001-09-08 20:48:02 +00:00
|
|
|
|
2002-05-30 11:59:24 +00:00
|
|
|
#include "config.h"
|
2001-09-08 20:48:02 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2002-02-17 08:24:43 +00:00
|
|
|
#include <errno.h>
|
2001-09-09 18:50:35 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2002-05-30 11:59:24 +00:00
|
|
|
#include <unistd.h>
|
2001-09-09 18:50:35 +00:00
|
|
|
|
2002-04-28 00:24:15 +00:00
|
|
|
#include "mp_msg.h"
|
2008-08-02 21:39:29 +00:00
|
|
|
|
2008-08-14 15:48:11 +00:00
|
|
|
#ifdef CONFIG_DVB
|
|
|
|
#ifndef CONFIG_DVB_HEAD
|
2008-08-14 15:54:53 +00:00
|
|
|
#include <poll.h>
|
2001-10-03 23:34:15 +00:00
|
|
|
|
2001-09-09 18:50:35 +00:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include <ost/dmx.h>
|
|
|
|
#include <ost/frontend.h>
|
|
|
|
#include <ost/sec.h>
|
|
|
|
#include <ost/video.h>
|
|
|
|
#include <ost/audio.h>
|
|
|
|
|
2002-12-28 12:04:58 +00:00
|
|
|
#else
|
|
|
|
#define true 1
|
|
|
|
#define false 0
|
2008-08-14 15:54:53 +00:00
|
|
|
#include <poll.h>
|
2002-12-28 12:04:58 +00:00
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include <linux/dvb/dmx.h>
|
|
|
|
#include <linux/dvb/frontend.h>
|
|
|
|
#include <linux/dvb/video.h>
|
|
|
|
#include <linux/dvb/audio.h>
|
|
|
|
#endif
|
2001-09-09 18:50:35 +00:00
|
|
|
#endif
|
|
|
|
|
2001-09-08 20:48:02 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "video_out.h"
|
|
|
|
#include "video_out_internal.h"
|
2006-07-22 09:45:34 +00:00
|
|
|
#include "libmpdemux/mpeg_packetizer.h"
|
2001-09-08 20:48:02 +00:00
|
|
|
|
2001-09-08 23:27:51 +00:00
|
|
|
int vo_mpegpes_fd=-1;
|
2006-07-26 21:40:43 +00:00
|
|
|
extern int vo_mpegpes_fd2;
|
2001-09-08 23:27:51 +00:00
|
|
|
|
2007-12-02 14:06:03 +00:00
|
|
|
static const vo_info_t info =
|
2001-09-08 20:48:02 +00:00
|
|
|
{
|
2008-08-14 15:48:11 +00:00
|
|
|
#ifdef CONFIG_DVB
|
2008-08-02 20:35:29 +00:00
|
|
|
"MPEG-PES to DVB card",
|
2001-09-09 18:50:35 +00:00
|
|
|
#else
|
2008-08-02 20:35:29 +00:00
|
|
|
"MPEG-PES file",
|
2001-09-09 18:50:35 +00:00
|
|
|
#endif
|
|
|
|
"mpegpes",
|
2001-09-08 20:48:02 +00:00
|
|
|
"A'rpi",
|
|
|
|
""
|
|
|
|
};
|
|
|
|
|
2007-12-02 14:39:15 +00:00
|
|
|
const LIBVO_EXTERN (mpegpes)
|
2002-11-11 15:22:10 +00:00
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int
|
2005-04-18 15:52:38 +00:00
|
|
|
config(uint32_t s_width, uint32_t s_height, uint32_t width, uint32_t height, uint32_t flags, char *title, uint32_t format)
|
2001-09-08 20:48:02 +00:00
|
|
|
{
|
2008-08-14 15:48:11 +00:00
|
|
|
#ifdef CONFIG_DVB
|
2002-04-28 00:24:15 +00:00
|
|
|
switch(s_height){
|
|
|
|
case 288:
|
|
|
|
case 576:
|
|
|
|
case 240:
|
|
|
|
case 480:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mp_msg(MSGT_VO,MSGL_ERR,"DVB: height=%d not supported (try 240/480 (ntsc) or 288/576 (pal)\n",s_height);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int preinit(const char *arg){
|
2008-08-14 15:48:11 +00:00
|
|
|
#ifdef CONFIG_DVB
|
2008-01-02 20:34:48 +00:00
|
|
|
int card = -1;
|
2004-08-19 09:51:07 +00:00
|
|
|
char vo_file[30], ao_file[30], *tmp;
|
|
|
|
|
|
|
|
if(arg != NULL){
|
|
|
|
if((tmp = strstr(arg, "card=")) != NULL) {
|
|
|
|
card = atoi(&tmp[5]);
|
|
|
|
if((card < 1) || (card > 4)) {
|
|
|
|
mp_msg(MSGT_VO, MSGL_ERR, "DVB card number must be between 1 and 4\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
card--;
|
|
|
|
arg = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-08 23:11:49 +00:00
|
|
|
if(!arg){
|
2001-09-09 18:50:35 +00:00
|
|
|
//|O_NONBLOCK
|
2008-01-02 20:34:48 +00:00
|
|
|
//search the first usable card
|
|
|
|
if(card==-1) {
|
|
|
|
int n;
|
|
|
|
for(n=0; n<4; n++) {
|
|
|
|
sprintf(vo_file, "/dev/dvb/adapter%d/video0", n);
|
|
|
|
if(access(vo_file, F_OK | W_OK)==0) {
|
|
|
|
card = n;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(card==-1) {
|
|
|
|
mp_msg(MSGT_VO,MSGL_INFO, "Couldn't find a usable dvb video device, exiting\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2008-08-14 15:48:11 +00:00
|
|
|
#ifndef CONFIG_DVB_HEAD
|
2004-08-19 09:51:07 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_INFO, "Opening /dev/ost/video+audio\n");
|
|
|
|
sprintf(vo_file, "/dev/ost/video");
|
|
|
|
sprintf(ao_file, "/dev/ost/audio");
|
2002-12-28 12:04:58 +00:00
|
|
|
#else
|
2004-08-19 09:51:07 +00:00
|
|
|
mp_msg(MSGT_VO,MSGL_INFO, "Opening /dev/dvb/adapter%d/video0+audio0\n", card);
|
|
|
|
sprintf(vo_file, "/dev/dvb/adapter%d/video0", card);
|
|
|
|
sprintf(ao_file, "/dev/dvb/adapter%d/audio0", card);
|
|
|
|
#endif
|
|
|
|
if((vo_mpegpes_fd = open(vo_file,O_RDWR)) < 0){
|
2002-12-28 12:04:58 +00:00
|
|
|
perror("DVB VIDEO DEVICE: ");
|
|
|
|
return -1;
|
|
|
|
}
|
2001-09-09 18:50:35 +00:00
|
|
|
if ( (ioctl(vo_mpegpes_fd,VIDEO_SET_BLANK, false) < 0)){
|
|
|
|
perror("DVB VIDEO SET BLANK: ");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if ( (ioctl(vo_mpegpes_fd,VIDEO_SELECT_SOURCE, VIDEO_SOURCE_MEMORY) < 0)){
|
|
|
|
perror("DVB VIDEO SELECT SOURCE: ");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if ( (ioctl(vo_mpegpes_fd,VIDEO_PLAY) < 0)){
|
|
|
|
perror("DVB VIDEO PLAY: ");
|
|
|
|
return -1;
|
|
|
|
}
|
2002-10-08 23:11:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2004-08-19 09:51:07 +00:00
|
|
|
arg = (arg ? arg : "grab.mpg");
|
|
|
|
mp_msg(MSGT_VO,MSGL_INFO, "Saving PES stream to %s\n", arg);
|
|
|
|
vo_mpegpes_fd=open(arg,O_WRONLY|O_CREAT,0666);
|
2001-09-08 23:27:51 +00:00
|
|
|
if(vo_mpegpes_fd<0){
|
|
|
|
perror("vo_mpegpes");
|
|
|
|
return -1;
|
|
|
|
}
|
2001-09-08 20:48:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void draw_osd(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-09-09 18:50:35 +00:00
|
|
|
|
2006-07-22 10:07:04 +00:00
|
|
|
static int my_write(unsigned char* data,int len){
|
2006-07-22 13:54:33 +00:00
|
|
|
int orig_len = len;
|
2008-08-14 15:48:11 +00:00
|
|
|
#ifdef CONFIG_DVB
|
2001-10-03 23:34:15 +00:00
|
|
|
#define NFD 2
|
2001-09-09 18:50:35 +00:00
|
|
|
struct pollfd pfd[NFD];
|
|
|
|
|
|
|
|
// printf("write %d bytes \n",len);
|
|
|
|
|
|
|
|
pfd[0].fd = vo_mpegpes_fd;
|
|
|
|
pfd[0].events = POLLOUT;
|
|
|
|
|
|
|
|
pfd[1].fd = vo_mpegpes_fd2;
|
|
|
|
pfd[1].events = POLLOUT;
|
|
|
|
|
2001-09-08 23:27:51 +00:00
|
|
|
while(len>0){
|
2001-09-09 18:50:35 +00:00
|
|
|
if (poll(pfd,NFD,1)){
|
|
|
|
if (pfd[0].revents & POLLOUT){
|
|
|
|
int ret=write(vo_mpegpes_fd,data,len);
|
|
|
|
// printf("ret=%d \n",ret);
|
|
|
|
if(ret<=0){
|
|
|
|
perror("write");
|
|
|
|
usleep(0);
|
|
|
|
} else {
|
|
|
|
len-=ret; data+=ret;
|
|
|
|
}
|
|
|
|
} else usleep(1000);
|
|
|
|
}
|
2001-09-08 23:27:51 +00:00
|
|
|
}
|
2001-10-03 23:34:15 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
write(vo_mpegpes_fd,data,len); // write to file
|
|
|
|
#endif
|
2006-07-22 10:07:04 +00:00
|
|
|
return orig_len;
|
2001-09-08 23:27:51 +00:00
|
|
|
}
|
2001-09-08 20:48:02 +00:00
|
|
|
|
2001-11-05 02:55:00 +00:00
|
|
|
void send_pes_packet(unsigned char* data,int len,int id,int timestamp){
|
2006-07-22 09:45:34 +00:00
|
|
|
send_mpeg_pes_packet (data, len, id, timestamp, 1, my_write);
|
2001-09-09 18:50:35 +00:00
|
|
|
}
|
|
|
|
|
2002-01-22 02:14:40 +00:00
|
|
|
void send_lpcm_packet(unsigned char* data,int len,int id,unsigned int timestamp,int freq_id){
|
2006-07-23 09:32:04 +00:00
|
|
|
send_mpeg_lpcm_packet(data, len, id, timestamp, freq_id, my_write);
|
2001-11-05 02:55:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int draw_frame(uint8_t * src[])
|
2001-09-09 18:50:35 +00:00
|
|
|
{
|
|
|
|
vo_mpegpes_t *p=(vo_mpegpes_t *)src[0];
|
2002-04-28 00:24:15 +00:00
|
|
|
send_pes_packet(p->data,p->size,p->id,(p->timestamp>0)?p->timestamp:vo_pts); // video data
|
2001-09-08 20:48:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-09-22 18:50:09 +00:00
|
|
|
static void flip_page (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int draw_slice(uint8_t *srcimg[], int stride[], int w,int h,int x0,int y0)
|
2001-09-22 18:50:09 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int
|
2001-09-08 20:48:02 +00:00
|
|
|
query_format(uint32_t format)
|
|
|
|
{
|
2005-04-18 15:52:38 +00:00
|
|
|
if(format==IMGFMT_MPEGPES) return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_TIMER;
|
2001-09-08 20:48:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
uninit(void)
|
|
|
|
{
|
2002-10-08 23:11:49 +00:00
|
|
|
if(vo_mpegpes_fd2>=0 && vo_mpegpes_fd2!=vo_mpegpes_fd) close(vo_mpegpes_fd2);
|
|
|
|
vo_mpegpes_fd2=-1;
|
2001-09-09 18:50:35 +00:00
|
|
|
if(vo_mpegpes_fd>=0){ close(vo_mpegpes_fd);vo_mpegpes_fd=-1;}
|
2001-09-08 20:48:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void check_events(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-08-05 01:24:37 +00:00
|
|
|
static int control(uint32_t request, void *data, ...)
|
2002-01-26 16:01:26 +00:00
|
|
|
{
|
2002-02-09 00:47:26 +00:00
|
|
|
switch (request) {
|
|
|
|
case VOCTRL_QUERY_FORMAT:
|
|
|
|
return query_format(*((uint32_t*)data));
|
|
|
|
}
|
|
|
|
return VO_NOTIMPL;
|
2002-01-26 16:01:26 +00:00
|
|
|
}
|