Use memset to initialize huge arrays.
[mplayer.git] / libvo / vo_mpegpes.c
blob94fe08f6f28d4a9cdc5f98d2956ccde6adfc6439
1 /*
2 * based on: test_av.c - test program for new API
4 * Copyright (C) 2000 Ralph Metzler <ralph@convergence.de>
5 * & Marcus Metzler <marcus@convergence.de>
6 * for convergence integrated media GmbH
8 * MPEG-PS multiplexer, part of FFmpeg
9 * Copyright Gerard Lantau (see http://ffmpeg.org)
11 * This file is part of MPlayer.
13 * MPlayer is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * MPlayer is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include "config.h"
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <errno.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <unistd.h>
38 #include "mp_msg.h"
40 #ifdef CONFIG_DVB
41 #ifndef CONFIG_DVB_HEAD
42 #include <poll.h>
44 #include <sys/ioctl.h>
45 #include <stdio.h>
46 #include <time.h>
48 #include <ost/dmx.h>
49 #include <ost/frontend.h>
50 #include <ost/sec.h>
51 #include <ost/video.h>
52 #include <ost/audio.h>
54 #else
55 #define true 1
56 #define false 0
57 #include <poll.h>
59 #include <sys/ioctl.h>
60 #include <stdio.h>
61 #include <time.h>
63 #include <linux/dvb/dmx.h>
64 #include <linux/dvb/frontend.h>
65 #include <linux/dvb/video.h>
66 #include <linux/dvb/audio.h>
67 #endif
68 #endif
70 #include "config.h"
71 #include "video_out.h"
72 #include "video_out_internal.h"
73 #include "libmpdemux/mpeg_packetizer.h"
75 int vo_mpegpes_fd=-1;
76 extern int vo_mpegpes_fd2;
78 static const vo_info_t info =
80 #ifdef CONFIG_DVB
81 "MPEG-PES to DVB card",
82 #else
83 "MPEG-PES file",
84 #endif
85 "mpegpes",
86 "A'rpi",
90 const LIBVO_EXTERN (mpegpes)
92 static int
93 config(uint32_t s_width, uint32_t s_height, uint32_t width, uint32_t height, uint32_t flags, char *title, uint32_t format)
95 #ifdef CONFIG_DVB
96 switch(s_height){
97 case 288:
98 case 576:
99 case 240:
100 case 480:
101 break;
102 default:
103 mp_msg(MSGT_VO,MSGL_ERR,"DVB: height=%d not supported (try 240/480 (ntsc) or 288/576 (pal)\n",s_height);
104 return -1;
106 #endif
107 return 0;
110 static int preinit(const char *arg){
111 #ifdef CONFIG_DVB
112 int card = -1;
113 char vo_file[30], ao_file[30], *tmp;
115 if(arg != NULL){
116 if((tmp = strstr(arg, "card=")) != NULL) {
117 card = atoi(&tmp[5]);
118 if((card < 1) || (card > 4)) {
119 mp_msg(MSGT_VO, MSGL_ERR, "DVB card number must be between 1 and 4\n");
120 return -1;
122 card--;
123 arg = NULL;
127 if(!arg){
128 //|O_NONBLOCK
129 //search the first usable card
130 if(card==-1) {
131 int n;
132 for(n=0; n<4; n++) {
133 sprintf(vo_file, "/dev/dvb/adapter%d/video0", n);
134 if(access(vo_file, F_OK | W_OK)==0) {
135 card = n;
136 break;
140 if(card==-1) {
141 mp_msg(MSGT_VO,MSGL_INFO, "Couldn't find a usable dvb video device, exiting\n");
142 return -1;
144 #ifndef CONFIG_DVB_HEAD
145 mp_msg(MSGT_VO,MSGL_INFO, "Opening /dev/ost/video+audio\n");
146 sprintf(vo_file, "/dev/ost/video");
147 sprintf(ao_file, "/dev/ost/audio");
148 #else
149 mp_msg(MSGT_VO,MSGL_INFO, "Opening /dev/dvb/adapter%d/video0+audio0\n", card);
150 sprintf(vo_file, "/dev/dvb/adapter%d/video0", card);
151 sprintf(ao_file, "/dev/dvb/adapter%d/audio0", card);
152 #endif
153 if((vo_mpegpes_fd = open(vo_file,O_RDWR)) < 0){
154 perror("DVB VIDEO DEVICE: ");
155 return -1;
157 if ( (ioctl(vo_mpegpes_fd,VIDEO_SET_BLANK, false) < 0)){
158 perror("DVB VIDEO SET BLANK: ");
159 return -1;
161 if ( (ioctl(vo_mpegpes_fd,VIDEO_SELECT_SOURCE, VIDEO_SOURCE_MEMORY) < 0)){
162 perror("DVB VIDEO SELECT SOURCE: ");
163 return -1;
165 if ( (ioctl(vo_mpegpes_fd,VIDEO_PLAY) < 0)){
166 perror("DVB VIDEO PLAY: ");
167 return -1;
169 return 0;
171 #endif
172 arg = (arg ? arg : "grab.mpg");
173 mp_msg(MSGT_VO,MSGL_INFO, "Saving PES stream to %s\n", arg);
174 vo_mpegpes_fd=open(arg,O_WRONLY|O_CREAT,0666);
175 if(vo_mpegpes_fd<0){
176 perror("vo_mpegpes");
177 return -1;
179 return 0;
183 static void draw_osd(void)
188 static int my_write(unsigned char* data,int len){
189 int orig_len = len;
190 #ifdef CONFIG_DVB
191 #define NFD 2
192 struct pollfd pfd[NFD];
194 // printf("write %d bytes \n",len);
196 pfd[0].fd = vo_mpegpes_fd;
197 pfd[0].events = POLLOUT;
199 pfd[1].fd = vo_mpegpes_fd2;
200 pfd[1].events = POLLOUT;
202 while(len>0){
203 if (poll(pfd,NFD,1)){
204 if (pfd[0].revents & POLLOUT){
205 int ret=write(vo_mpegpes_fd,data,len);
206 // printf("ret=%d \n",ret);
207 if(ret<=0){
208 perror("write");
209 usleep(0);
210 } else {
211 len-=ret; data+=ret;
213 } else usleep(1000);
217 #else
218 write(vo_mpegpes_fd,data,len); // write to file
219 #endif
220 return orig_len;
223 void send_pes_packet(unsigned char* data,int len,int id,int timestamp){
224 send_mpeg_pes_packet (data, len, id, timestamp, 1, my_write);
227 void send_lpcm_packet(unsigned char* data,int len,int id,unsigned int timestamp,int freq_id){
228 send_mpeg_lpcm_packet(data, len, id, timestamp, freq_id, my_write);
232 static int draw_frame(uint8_t * src[])
234 vo_mpegpes_t *p=(vo_mpegpes_t *)src[0];
235 send_pes_packet(p->data,p->size,p->id,(p->timestamp>0)?p->timestamp:vo_pts); // video data
236 return 0;
239 static void flip_page (void)
243 static int draw_slice(uint8_t *srcimg[], int stride[], int w,int h,int x0,int y0)
245 return 0;
249 static int
250 query_format(uint32_t format)
252 if(format==IMGFMT_MPEGPES) return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_TIMER;
253 return 0;
256 static void
257 uninit(void)
259 if(vo_mpegpes_fd2>=0 && vo_mpegpes_fd2!=vo_mpegpes_fd) close(vo_mpegpes_fd2);
260 vo_mpegpes_fd2=-1;
261 if(vo_mpegpes_fd>=0){ close(vo_mpegpes_fd);vo_mpegpes_fd=-1;}
265 static void check_events(void)
269 static int control(uint32_t request, void *data, ...)
271 switch (request) {
272 case VOCTRL_QUERY_FORMAT:
273 return query_format(*((uint32_t*)data));
275 return VO_NOTIMPL;