vo_gl: fix image corruption with PBOs when playing 10 bit video
[mplayer.git] / libvo / vo_mpegpes.c
blobcae6278e8f474b4f43fcbf338e4b201afaf8d8aa
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 #define true 1
42 #define false 0
43 #include <poll.h>
45 #include <sys/ioctl.h>
46 #include <stdio.h>
47 #include <time.h>
49 #include <linux/dvb/dmx.h>
50 #include <linux/dvb/frontend.h>
51 #include <linux/dvb/video.h>
52 #include <linux/dvb/audio.h>
53 #endif
55 #include "config.h"
56 #include "video_out.h"
57 #include "video_out_internal.h"
58 #include "libmpdemux/mpeg_packetizer.h"
60 int vo_mpegpes_fd=-1;
61 extern int ao_mpegpes_fd;
63 static const vo_info_t info =
65 #ifdef CONFIG_DVB
66 "MPEG-PES to DVB card",
67 #else
68 "MPEG-PES file",
69 #endif
70 "mpegpes",
71 "A'rpi",
75 const LIBVO_EXTERN (mpegpes)
77 static int
78 config(uint32_t s_width, uint32_t s_height, uint32_t width, uint32_t height, uint32_t flags, char *title, uint32_t format)
80 #ifdef CONFIG_DVB
81 switch(s_height){
82 case 288:
83 case 576:
84 case 240:
85 case 480:
86 break;
87 default:
88 mp_msg(MSGT_VO,MSGL_ERR,"DVB: height=%d not supported (try 240/480 (ntsc) or 288/576 (pal)\n",s_height);
89 return -1;
91 #endif
92 return 0;
95 static int preinit(const char *arg){
96 #ifdef CONFIG_DVB
97 int card = -1;
98 char vo_file[30], ao_file[30], *tmp;
100 if(arg != NULL){
101 if((tmp = strstr(arg, "card=")) != NULL) {
102 card = atoi(&tmp[5]);
103 if((card < 1) || (card > 4)) {
104 mp_msg(MSGT_VO, MSGL_ERR, "DVB card number must be between 1 and 4\n");
105 return -1;
107 card--;
108 arg = NULL;
112 if(!arg){
113 //|O_NONBLOCK
114 //search the first usable card
115 if(card==-1) {
116 int n;
117 for(n=0; n<4; n++) {
118 sprintf(vo_file, "/dev/dvb/adapter%d/video0", n);
119 if(access(vo_file, F_OK | W_OK)==0) {
120 card = n;
121 break;
125 if(card==-1) {
126 mp_msg(MSGT_VO,MSGL_INFO, "Couldn't find a usable dvb video device, exiting\n");
127 return -1;
129 mp_msg(MSGT_VO,MSGL_INFO, "Opening /dev/dvb/adapter%d/video0+audio0\n", card);
130 sprintf(vo_file, "/dev/dvb/adapter%d/video0", card);
131 sprintf(ao_file, "/dev/dvb/adapter%d/audio0", card);
132 if((vo_mpegpes_fd = open(vo_file,O_RDWR)) < 0){
133 perror("DVB VIDEO DEVICE: ");
134 return -1;
136 if ( (ioctl(vo_mpegpes_fd,VIDEO_SET_BLANK, false) < 0)){
137 perror("DVB VIDEO SET BLANK: ");
138 return -1;
140 if ( (ioctl(vo_mpegpes_fd,VIDEO_SELECT_SOURCE, VIDEO_SOURCE_MEMORY) < 0)){
141 perror("DVB VIDEO SELECT SOURCE: ");
142 return -1;
144 if ( (ioctl(vo_mpegpes_fd,VIDEO_PLAY) < 0)){
145 perror("DVB VIDEO PLAY: ");
146 return -1;
148 return 0;
150 #endif
151 arg = (arg ? arg : "grab.mpg");
152 mp_msg(MSGT_VO,MSGL_INFO, "Saving PES stream to %s\n", arg);
153 vo_mpegpes_fd=open(arg,O_WRONLY|O_CREAT,0666);
154 if(vo_mpegpes_fd<0){
155 perror("vo_mpegpes");
156 return -1;
158 return 0;
162 static void draw_osd(void)
167 static int my_write(const unsigned char* data,int len){
168 int orig_len = len;
169 #ifdef CONFIG_DVB
170 #define NFD 2
171 struct pollfd pfd[NFD];
173 // printf("write %d bytes \n",len);
175 pfd[0].fd = vo_mpegpes_fd;
176 pfd[0].events = POLLOUT;
178 pfd[1].fd = ao_mpegpes_fd;
179 pfd[1].events = POLLOUT;
181 while(len>0){
182 if (poll(pfd,NFD,1)){
183 if (pfd[0].revents & POLLOUT){
184 int ret=write(vo_mpegpes_fd,data,len);
185 // printf("ret=%d \n",ret);
186 if(ret<=0){
187 perror("write");
188 usleep(0);
189 } else {
190 len-=ret; data+=ret;
192 } else usleep(1000);
196 #else
197 write(vo_mpegpes_fd,data,len); // write to file
198 #endif
199 return orig_len;
202 static void send_pes_packet(unsigned char* data, int len, int id, int timestamp)
204 send_mpeg_pes_packet (data, len, id, timestamp, 1, my_write);
207 static int draw_frame(uint8_t * src[])
209 vo_mpegpes_t *p=(vo_mpegpes_t *)src[0];
210 send_pes_packet(p->data,p->size,p->id,(p->timestamp>0)?p->timestamp:vo_pts); // video data
211 return 0;
214 static void flip_page (void)
218 static int draw_slice(uint8_t *srcimg[], int stride[], int w,int h,int x0,int y0)
220 return 0;
224 static int
225 query_format(uint32_t format)
227 if(format==IMGFMT_MPEGPES) return VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_TIMER;
228 return 0;
231 static void
232 uninit(void)
234 if(ao_mpegpes_fd >= 0 && ao_mpegpes_fd != vo_mpegpes_fd) close(ao_mpegpes_fd);
235 ao_mpegpes_fd = -1;
236 if(vo_mpegpes_fd>=0){ close(vo_mpegpes_fd);vo_mpegpes_fd=-1;}
240 static void check_events(void)
244 static int control(uint32_t request, void *data)
246 switch (request) {
247 case VOCTRL_QUERY_FORMAT:
248 return query_format(*((uint32_t*)data));
250 return VO_NOTIMPL;