Comment out the correct #endif directive.
[mplayer/greg.git] / libvo / vo_mpegpes.c
blob05e81631f72e4e5dd36e4618c3dd4aeea40c2010
1 /*
2 * Based on:
4 * test_av.c - Test program for new API
6 * Copyright (C) 2000 Ralph Metzler <ralph@convergence.de>
7 * & Marcus Metzler <marcus@convergence.de>
8 * for convergence integrated media GmbH
10 * libav - MPEG-PS multiplexer, part of ffmpeg
11 * Copyright Gerard Lantau (see http://ffmpeg.sf.net)
15 #include "config.h"
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <errno.h>
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <fcntl.h>
23 #include <unistd.h>
25 #include "mp_msg.h"
26 #ifdef HAVE_DVB_HEAD
27 #define HAVE_DVB 1
28 #endif
29 #ifdef HAVE_DVB
30 #ifndef HAVE_DVB_HEAD
31 #include <sys/poll.h>
33 #include <sys/ioctl.h>
34 #include <stdio.h>
35 #include <time.h>
37 #include <ost/dmx.h>
38 #include <ost/frontend.h>
39 #include <ost/sec.h>
40 #include <ost/video.h>
41 #include <ost/audio.h>
43 #else
44 #define true 1
45 #define false 0
46 #include <sys/poll.h>
48 #include <sys/ioctl.h>
49 #include <stdio.h>
50 #include <time.h>
52 #include <linux/dvb/dmx.h>
53 #include <linux/dvb/frontend.h>
54 #include <linux/dvb/video.h>
55 #include <linux/dvb/audio.h>
56 #endif
57 #endif
59 #include "config.h"
60 #include "video_out.h"
61 #include "video_out_internal.h"
62 #include "libmpdemux/mpeg_packetizer.h"
64 int vo_mpegpes_fd=-1;
65 extern int vo_mpegpes_fd2;
67 static const vo_info_t info =
69 #ifdef HAVE_DVB
70 "Mpeg-PES to DVB card",
71 #else
72 "Mpeg-PES file",
73 #endif
74 "mpegpes",
75 "A'rpi",
79 const LIBVO_EXTERN (mpegpes)
81 static int
82 config(uint32_t s_width, uint32_t s_height, uint32_t width, uint32_t height, uint32_t flags, char *title, uint32_t format)
84 #ifdef HAVE_DVB
85 switch(s_height){
86 case 288:
87 case 576:
88 case 240:
89 case 480:
90 break;
91 default:
92 mp_msg(MSGT_VO,MSGL_ERR,"DVB: height=%d not supported (try 240/480 (ntsc) or 288/576 (pal)\n",s_height);
93 return -1;
95 #endif
96 return 0;
99 static int preinit(const char *arg){
100 #ifdef HAVE_DVB
101 int card = 0;
102 char vo_file[30], ao_file[30], *tmp;
104 if(arg != NULL){
105 if((tmp = strstr(arg, "card=")) != NULL) {
106 card = atoi(&tmp[5]);
107 if((card < 1) || (card > 4)) {
108 mp_msg(MSGT_VO, MSGL_ERR, "DVB card number must be between 1 and 4\n");
109 return -1;
111 card--;
112 arg = NULL;
116 if(!arg){
117 //|O_NONBLOCK
118 #ifndef HAVE_DVB_HEAD
119 mp_msg(MSGT_VO,MSGL_INFO, "Opening /dev/ost/video+audio\n");
120 sprintf(vo_file, "/dev/ost/video");
121 sprintf(ao_file, "/dev/ost/audio");
122 #else
123 mp_msg(MSGT_VO,MSGL_INFO, "Opening /dev/dvb/adapter%d/video0+audio0\n", card);
124 sprintf(vo_file, "/dev/dvb/adapter%d/video0", card);
125 sprintf(ao_file, "/dev/dvb/adapter%d/audio0", card);
126 #endif
127 if((vo_mpegpes_fd = open(vo_file,O_RDWR)) < 0){
128 perror("DVB VIDEO DEVICE: ");
129 return -1;
131 if ( (ioctl(vo_mpegpes_fd,VIDEO_SET_BLANK, false) < 0)){
132 perror("DVB VIDEO SET BLANK: ");
133 return -1;
135 if ( (ioctl(vo_mpegpes_fd,VIDEO_SELECT_SOURCE, VIDEO_SOURCE_MEMORY) < 0)){
136 perror("DVB VIDEO SELECT SOURCE: ");
137 return -1;
139 if ( (ioctl(vo_mpegpes_fd,VIDEO_PLAY) < 0)){
140 perror("DVB VIDEO PLAY: ");
141 return -1;
143 return 0;
145 #endif
146 arg = (arg ? arg : "grab.mpg");
147 mp_msg(MSGT_VO,MSGL_INFO, "Saving PES stream to %s\n", arg);
148 vo_mpegpes_fd=open(arg,O_WRONLY|O_CREAT,0666);
149 if(vo_mpegpes_fd<0){
150 perror("vo_mpegpes");
151 return -1;
153 return 0;
157 static void draw_osd(void)
162 static int my_write(unsigned char* data,int len){
163 int orig_len = len;
164 #ifdef HAVE_DVB
165 #define NFD 2
166 struct pollfd pfd[NFD];
168 // printf("write %d bytes \n",len);
170 pfd[0].fd = vo_mpegpes_fd;
171 pfd[0].events = POLLOUT;
173 pfd[1].fd = vo_mpegpes_fd2;
174 pfd[1].events = POLLOUT;
176 while(len>0){
177 if (poll(pfd,NFD,1)){
178 if (pfd[0].revents & POLLOUT){
179 int ret=write(vo_mpegpes_fd,data,len);
180 // printf("ret=%d \n",ret);
181 if(ret<=0){
182 perror("write");
183 usleep(0);
184 } else {
185 len-=ret; data+=ret;
187 } else usleep(1000);
191 #else
192 write(vo_mpegpes_fd,data,len); // write to file
193 #endif
194 return orig_len;
197 void send_pes_packet(unsigned char* data,int len,int id,int timestamp){
198 send_mpeg_pes_packet (data, len, id, timestamp, 1, my_write);
201 void send_lpcm_packet(unsigned char* data,int len,int id,unsigned int timestamp,int freq_id){
202 send_mpeg_lpcm_packet(data, len, id, timestamp, freq_id, my_write);
206 static int draw_frame(uint8_t * src[])
208 vo_mpegpes_t *p=(vo_mpegpes_t *)src[0];
209 send_pes_packet(p->data,p->size,p->id,(p->timestamp>0)?p->timestamp:vo_pts); // video data
210 return 0;
213 static void flip_page (void)
217 static int draw_slice(uint8_t *srcimg[], int stride[], int w,int h,int x0,int y0)
219 return 0;
223 static int
224 query_format(uint32_t format)
226 if(format==IMGFMT_MPEGPES) return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_TIMER;
227 return 0;
230 static void
231 uninit(void)
233 if(vo_mpegpes_fd2>=0 && vo_mpegpes_fd2!=vo_mpegpes_fd) close(vo_mpegpes_fd2);
234 vo_mpegpes_fd2=-1;
235 if(vo_mpegpes_fd>=0){ close(vo_mpegpes_fd);vo_mpegpes_fd=-1;}
239 static void check_events(void)
243 static int control(uint32_t request, void *data, ...)
245 switch (request) {
246 case VOCTRL_QUERY_FORMAT:
247 return query_format(*((uint32_t*)data));
249 return VO_NOTIMPL;