Fix indentation
[mplayer/glamo.git] / libvo / vo_mpegpes.c
blob7858256f20987456c625ebf6b2c37f25bd3ce51c
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"
27 #ifdef CONFIG_DVB
28 #ifndef CONFIG_DVB_HEAD
29 #include <poll.h>
31 #include <sys/ioctl.h>
32 #include <stdio.h>
33 #include <time.h>
35 #include <ost/dmx.h>
36 #include <ost/frontend.h>
37 #include <ost/sec.h>
38 #include <ost/video.h>
39 #include <ost/audio.h>
41 #else
42 #define true 1
43 #define false 0
44 #include <poll.h>
46 #include <sys/ioctl.h>
47 #include <stdio.h>
48 #include <time.h>
50 #include <linux/dvb/dmx.h>
51 #include <linux/dvb/frontend.h>
52 #include <linux/dvb/video.h>
53 #include <linux/dvb/audio.h>
54 #endif
55 #endif
57 #include "config.h"
58 #include "video_out.h"
59 #include "video_out_internal.h"
60 #include "libmpdemux/mpeg_packetizer.h"
62 int vo_mpegpes_fd=-1;
63 extern int vo_mpegpes_fd2;
65 static const vo_info_t info =
67 #ifdef CONFIG_DVB
68 "MPEG-PES to DVB card",
69 #else
70 "MPEG-PES file",
71 #endif
72 "mpegpes",
73 "A'rpi",
77 const LIBVO_EXTERN (mpegpes)
79 static int
80 config(uint32_t s_width, uint32_t s_height, uint32_t width, uint32_t height, uint32_t flags, char *title, uint32_t format)
82 #ifdef CONFIG_DVB
83 switch(s_height){
84 case 288:
85 case 576:
86 case 240:
87 case 480:
88 break;
89 default:
90 mp_msg(MSGT_VO,MSGL_ERR,"DVB: height=%d not supported (try 240/480 (ntsc) or 288/576 (pal)\n",s_height);
91 return -1;
93 #endif
94 return 0;
97 static int preinit(const char *arg){
98 #ifdef CONFIG_DVB
99 int card = -1;
100 char vo_file[30], ao_file[30], *tmp;
102 if(arg != NULL){
103 if((tmp = strstr(arg, "card=")) != NULL) {
104 card = atoi(&tmp[5]);
105 if((card < 1) || (card > 4)) {
106 mp_msg(MSGT_VO, MSGL_ERR, "DVB card number must be between 1 and 4\n");
107 return -1;
109 card--;
110 arg = NULL;
114 if(!arg){
115 //|O_NONBLOCK
116 //search the first usable card
117 if(card==-1) {
118 int n;
119 for(n=0; n<4; n++) {
120 sprintf(vo_file, "/dev/dvb/adapter%d/video0", n);
121 if(access(vo_file, F_OK | W_OK)==0) {
122 card = n;
123 break;
127 if(card==-1) {
128 mp_msg(MSGT_VO,MSGL_INFO, "Couldn't find a usable dvb video device, exiting\n");
129 return -1;
131 #ifndef CONFIG_DVB_HEAD
132 mp_msg(MSGT_VO,MSGL_INFO, "Opening /dev/ost/video+audio\n");
133 sprintf(vo_file, "/dev/ost/video");
134 sprintf(ao_file, "/dev/ost/audio");
135 #else
136 mp_msg(MSGT_VO,MSGL_INFO, "Opening /dev/dvb/adapter%d/video0+audio0\n", card);
137 sprintf(vo_file, "/dev/dvb/adapter%d/video0", card);
138 sprintf(ao_file, "/dev/dvb/adapter%d/audio0", card);
139 #endif
140 if((vo_mpegpes_fd = open(vo_file,O_RDWR)) < 0){
141 perror("DVB VIDEO DEVICE: ");
142 return -1;
144 if ( (ioctl(vo_mpegpes_fd,VIDEO_SET_BLANK, false) < 0)){
145 perror("DVB VIDEO SET BLANK: ");
146 return -1;
148 if ( (ioctl(vo_mpegpes_fd,VIDEO_SELECT_SOURCE, VIDEO_SOURCE_MEMORY) < 0)){
149 perror("DVB VIDEO SELECT SOURCE: ");
150 return -1;
152 if ( (ioctl(vo_mpegpes_fd,VIDEO_PLAY) < 0)){
153 perror("DVB VIDEO PLAY: ");
154 return -1;
156 return 0;
158 #endif
159 arg = (arg ? arg : "grab.mpg");
160 mp_msg(MSGT_VO,MSGL_INFO, "Saving PES stream to %s\n", arg);
161 vo_mpegpes_fd=open(arg,O_WRONLY|O_CREAT,0666);
162 if(vo_mpegpes_fd<0){
163 perror("vo_mpegpes");
164 return -1;
166 return 0;
170 static void draw_osd(void)
175 static int my_write(unsigned char* data,int len){
176 int orig_len = len;
177 #ifdef CONFIG_DVB
178 #define NFD 2
179 struct pollfd pfd[NFD];
181 // printf("write %d bytes \n",len);
183 pfd[0].fd = vo_mpegpes_fd;
184 pfd[0].events = POLLOUT;
186 pfd[1].fd = vo_mpegpes_fd2;
187 pfd[1].events = POLLOUT;
189 while(len>0){
190 if (poll(pfd,NFD,1)){
191 if (pfd[0].revents & POLLOUT){
192 int ret=write(vo_mpegpes_fd,data,len);
193 // printf("ret=%d \n",ret);
194 if(ret<=0){
195 perror("write");
196 usleep(0);
197 } else {
198 len-=ret; data+=ret;
200 } else usleep(1000);
204 #else
205 write(vo_mpegpes_fd,data,len); // write to file
206 #endif
207 return orig_len;
210 void send_pes_packet(unsigned char* data,int len,int id,int timestamp){
211 send_mpeg_pes_packet (data, len, id, timestamp, 1, my_write);
214 void send_lpcm_packet(unsigned char* data,int len,int id,unsigned int timestamp,int freq_id){
215 send_mpeg_lpcm_packet(data, len, id, timestamp, freq_id, my_write);
219 static int draw_frame(uint8_t * src[])
221 vo_mpegpes_t *p=(vo_mpegpes_t *)src[0];
222 send_pes_packet(p->data,p->size,p->id,(p->timestamp>0)?p->timestamp:vo_pts); // video data
223 return 0;
226 static void flip_page (void)
230 static int draw_slice(uint8_t *srcimg[], int stride[], int w,int h,int x0,int y0)
232 return 0;
236 static int
237 query_format(uint32_t format)
239 if(format==IMGFMT_MPEGPES) return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_TIMER;
240 return 0;
243 static void
244 uninit(void)
246 if(vo_mpegpes_fd2>=0 && vo_mpegpes_fd2!=vo_mpegpes_fd) close(vo_mpegpes_fd2);
247 vo_mpegpes_fd2=-1;
248 if(vo_mpegpes_fd>=0){ close(vo_mpegpes_fd);vo_mpegpes_fd=-1;}
252 static void check_events(void)
256 static int control(uint32_t request, void *data, ...)
258 switch (request) {
259 case VOCTRL_QUERY_FORMAT:
260 return query_format(*((uint32_t*)data));
262 return VO_NOTIMPL;