1876
|
1 //#define HAVE_DVB
|
|
2 #define PES_MAX_SIZE 2048
|
|
3 /*
|
|
4 * Based on:
|
|
5 *
|
|
6 * test_av.c - Test program for new API
|
|
7 *
|
|
8 * Copyright (C) 2000 Ralph Metzler <ralph@convergence.de>
|
|
9 * & Marcus Metzler <marcus@convergence.de>
|
|
10 * for convergence integrated media GmbH
|
|
11 *
|
|
12 * libav - MPEG-PS multiplexer, part of ffmpeg
|
|
13 * Copyright Gerard Lantau (see http://ffmpeg.sf.net)
|
|
14 *
|
|
15 */
|
1871
|
16
|
|
17 #include <stdio.h>
|
|
18 #include <stdlib.h>
|
|
19 #include <string.h>
|
|
20
|
1876
|
21 #include <sys/types.h>
|
|
22 #include <sys/stat.h>
|
|
23 #include <fcntl.h>
|
|
24 #include <sys/poll.h>
|
|
25
|
|
26 #ifdef HAVE_DVB
|
|
27
|
|
28 #include <sys/ioctl.h>
|
|
29 #include <stdio.h>
|
|
30 #include <time.h>
|
|
31 #include <unistd.h>
|
|
32
|
|
33 #include <ost/dmx.h>
|
|
34 #include <ost/frontend.h>
|
|
35 #include <ost/sec.h>
|
|
36 #include <ost/video.h>
|
|
37 #include <ost/audio.h>
|
|
38
|
|
39 #endif
|
|
40
|
1871
|
41 #include "config.h"
|
|
42 #include "video_out.h"
|
|
43 #include "video_out_internal.h"
|
|
44
|
|
45 LIBVO_EXTERN (mpegpes)
|
|
46
|
1872
|
47 int vo_mpegpes_fd=-1;
|
1876
|
48 int vo_mpegpes_fd2=-1;
|
1872
|
49
|
1871
|
50 static vo_info_t vo_info =
|
|
51 {
|
1876
|
52 #ifdef HAVE_DVB
|
|
53 "Mpeg-PES to DVB card",
|
|
54 #else
|
1871
|
55 "Mpeg-PES file",
|
1876
|
56 #endif
|
|
57 "mpegpes",
|
1871
|
58 "A'rpi",
|
|
59 ""
|
|
60 };
|
|
61
|
|
62 static uint32_t
|
|
63 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
|
|
64 {
|
1876
|
65 #ifdef HAVE_DVB
|
|
66 //|O_NONBLOCK
|
|
67 if((vo_mpegpes_fd = open("/dev/ost/video",O_RDWR)) < 0){
|
|
68 perror("DVB VIDEO DEVICE: ");
|
|
69 return -1;
|
|
70 }
|
|
71 if((vo_mpegpes_fd2 = open("/dev/ost/audio",O_RDWR|O_NONBLOCK)) < 0){
|
|
72 perror("DVB AUDIO DEVICE: ");
|
|
73 return -1;
|
|
74 }
|
|
75 if ( (ioctl(vo_mpegpes_fd,VIDEO_SET_BLANK, false) < 0)){
|
|
76 perror("DVB VIDEO SET BLANK: ");
|
|
77 return -1;
|
|
78 }
|
|
79 if ( (ioctl(vo_mpegpes_fd,VIDEO_SELECT_SOURCE, VIDEO_SOURCE_MEMORY) < 0)){
|
|
80 perror("DVB VIDEO SELECT SOURCE: ");
|
|
81 return -1;
|
|
82 }
|
|
83 #if 1
|
|
84 if ( (ioctl(vo_mpegpes_fd2,AUDIO_SELECT_SOURCE, AUDIO_SOURCE_MEMORY) < 0)){
|
|
85 perror("DVB AUDIO SELECT SOURCE: ");
|
|
86 return -1;
|
|
87 }
|
|
88 if ( (ioctl(vo_mpegpes_fd2,AUDIO_PLAY) < 0)){
|
|
89 perror("DVB AUDIO PLAY: ");
|
|
90 return -1;
|
|
91 }
|
|
92 #else
|
|
93 if ( (ioctl(vo_mpegpes_fd2,AUDIO_STOP,0) < 0)){
|
|
94 perror("DVB AUDIO STOP: ");
|
|
95 return -1;
|
|
96 }
|
|
97 #endif
|
|
98 if ( (ioctl(vo_mpegpes_fd,VIDEO_PLAY) < 0)){
|
|
99 perror("DVB VIDEO PLAY: ");
|
|
100 return -1;
|
|
101 }
|
|
102 if ( (ioctl(vo_mpegpes_fd2,AUDIO_SET_AV_SYNC, false) < 0)){
|
|
103 perror("DVB AUDIO SET AV SYNC: ");
|
|
104 return -1;
|
|
105 }
|
|
106 if ( (ioctl(vo_mpegpes_fd2,AUDIO_SET_MUTE, false) < 0)){
|
|
107 perror("DVB AUDIO SET MUTE: ");
|
|
108 return -1;
|
|
109 }
|
|
110
|
|
111 #else
|
|
112 vo_mpegpes_fd=open("grab.mpg",O_WRONLY|O_CREAT);
|
1872
|
113 if(vo_mpegpes_fd<0){
|
|
114 perror("vo_mpegpes");
|
|
115 return -1;
|
|
116 }
|
1876
|
117 #endif
|
1871
|
118 return 0;
|
|
119 }
|
|
120
|
|
121 static const vo_info_t*
|
|
122 get_info(void)
|
|
123 {
|
|
124 return &vo_info;
|
|
125 }
|
|
126
|
|
127 static void draw_osd(void)
|
|
128 {
|
|
129 }
|
|
130
|
|
131 static void flip_page (void)
|
|
132 {
|
|
133 }
|
|
134
|
|
135 static uint32_t draw_slice(uint8_t *srcimg[], int stride[], int w,int h,int x,int y)
|
|
136 {
|
|
137 return 0;
|
|
138 }
|
|
139
|
1876
|
140 #define NFD 2
|
|
141
|
1872
|
142 static void my_write(unsigned char* data,int len){
|
1876
|
143 struct pollfd pfd[NFD];
|
|
144
|
|
145 // printf("write %d bytes \n",len);
|
|
146
|
|
147 pfd[0].fd = vo_mpegpes_fd;
|
|
148 pfd[0].events = POLLOUT;
|
|
149
|
|
150 pfd[1].fd = vo_mpegpes_fd2;
|
|
151 pfd[1].events = POLLOUT;
|
|
152
|
1872
|
153 while(len>0){
|
1876
|
154 if (poll(pfd,NFD,1)){
|
|
155 if (pfd[0].revents & POLLOUT){
|
|
156 int ret=write(vo_mpegpes_fd,data,len);
|
|
157 // printf("ret=%d \n",ret);
|
|
158 if(ret<=0){
|
|
159 perror("write");
|
|
160 usleep(0);
|
|
161 } else {
|
|
162 len-=ret; data+=ret;
|
|
163 }
|
|
164 } else usleep(1000);
|
|
165 }
|
1872
|
166 }
|
|
167 }
|
1871
|
168
|
1876
|
169 static unsigned char pes_header[PES_MAX_SIZE];
|
|
170
|
|
171 static void send_pes_packet(unsigned char* data,int len,int id,int timestamp){
|
|
172 int x;
|
|
173
|
|
174 pes_header[0]=pes_header[1]=0;
|
|
175 pes_header[2]=id>>8; pes_header[3]=id&255;
|
|
176
|
|
177 while(1){
|
|
178 int payload_size=len+5; // data + PTS
|
|
179 if(6+payload_size>PES_MAX_SIZE) payload_size=PES_MAX_SIZE-6;
|
|
180
|
|
181 // construct PES header: (code from ffmpeg's libav)
|
|
182 // startcode:
|
|
183 // packetsize:
|
|
184 pes_header[4]=(payload_size)>>8;
|
|
185 pes_header[5]=(payload_size)&255;
|
|
186 // stuffing:
|
|
187 // presentation time stamp:
|
|
188 x=(0x02 << 4) | (((timestamp >> 30) & 0x07) << 1) | 1;
|
|
189 pes_header[6]=x;
|
|
190 x=((((timestamp >> 15) & 0x7fff) << 1) | 1);
|
|
191 pes_header[7]=x>>8; pes_header[8]=x&255;
|
|
192 x=((((timestamp) & 0x7fff) << 1) | 1);
|
|
193 pes_header[9]=x>>8; pes_header[10]=x&255;
|
|
194
|
|
195 payload_size-=5;
|
|
196 memcpy(&pes_header[6+5],data,payload_size);
|
|
197 my_write(pes_header,6+5+payload_size);
|
|
198
|
|
199 len-=payload_size; data+=payload_size;
|
|
200 if(len<=0) break;
|
|
201 }
|
|
202
|
|
203 // printf("PES: draw frame! pts=%d size=%d \n",timestamp,len);
|
|
204
|
|
205 }
|
|
206
|
1871
|
207 static uint32_t draw_frame(uint8_t * src[])
|
|
208 {
|
1872
|
209 vo_mpegpes_t *p=(vo_mpegpes_t *)src[0];
|
1876
|
210 unsigned char *data=p->data;
|
|
211 // int tmp=-1;
|
|
212 send_pes_packet(p->data,p->size,p->id,p->timestamp); // video data
|
|
213 // send_pes_packet(&tmp,0,0x1C0,p->timestamp+30000); // fake audio data
|
1871
|
214
|
|
215 return 0;
|
|
216 }
|
|
217
|
|
218 static uint32_t
|
|
219 query_format(uint32_t format)
|
|
220 {
|
|
221 if(format==IMGFMT_MPEGPES) return 1;
|
|
222 return 0;
|
|
223 }
|
|
224
|
|
225 static void
|
|
226 uninit(void)
|
|
227 {
|
1876
|
228 if(vo_mpegpes_fd>=0){ close(vo_mpegpes_fd);vo_mpegpes_fd=-1;}
|
|
229 if(vo_mpegpes_fd2>=0){ close(vo_mpegpes_fd2);vo_mpegpes_fd2=-1;}
|
1871
|
230 }
|
|
231
|
|
232
|
|
233 static void check_events(void)
|
|
234 {
|
|
235 }
|
|
236
|