annotate libvo/vo_mpegpes.c @ 5161:b9ba9cefcd7d

Mp4S fixed
author arpi
date Sun, 17 Mar 2002 14:21:07 +0000
parents 5823cde0dfdf
children b16820598c1b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
1 // Don't change for DVB card, it must be 2048
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
2 #define PES_MAX_SIZE 2048
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
3
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
4 // 100=best >=80 very good >=50 fast
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
5 #define QUALITY 90
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
6
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
7 // #undef if you don't want mpeg1 transcoder (you'll be limited to mpeg1/2 playback only)
5141
5823cde0dfdf fame enabeld
arpi
parents: 5092
diff changeset
8 #define USE_LIBFAME
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
9
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
10 /*
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
11 * Based on:
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
12 *
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
13 * test_av.c - Test program for new API
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
14 *
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
15 * Copyright (C) 2000 Ralph Metzler <ralph@convergence.de>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
16 * & Marcus Metzler <marcus@convergence.de>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
17 * for convergence integrated media GmbH
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
18 *
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
19 * libav - MPEG-PS multiplexer, part of ffmpeg
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
20 * Copyright Gerard Lantau (see http://ffmpeg.sf.net)
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
21 *
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
22 */
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
23
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
24 #include <stdio.h>
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
25 #include <stdlib.h>
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
26 #include <string.h>
4737
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
27 #include <errno.h>
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
28 #include <sys/types.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
29 #include <sys/stat.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
30 #include <fcntl.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
31
2727
a44484066941 autodetecting for dvb-cards
jaf
parents: 2709
diff changeset
32 #include "config.h"
a44484066941 autodetecting for dvb-cards
jaf
parents: 2709
diff changeset
33
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
34 #ifdef HAVE_DVB
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
35
2066
2b14cad013b7 using poll() only for DVB card - not required for file write
arpi
parents: 1986
diff changeset
36 #include <sys/poll.h>
2b14cad013b7 using poll() only for DVB card - not required for file write
arpi
parents: 1986
diff changeset
37
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
38 #include <sys/ioctl.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
39 #include <stdio.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
40 #include <time.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
41 #include <unistd.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
42
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
43 #include <ost/dmx.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
44 #include <ost/frontend.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
45 #include <ost/sec.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
46 #include <ost/video.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
47 #include <ost/audio.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
48
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
49 #endif
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
50
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
51 #include "config.h"
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
52 #include "video_out.h"
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
53 #include "video_out_internal.h"
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
54
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
55 LIBVO_EXTERN (mpegpes)
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
56
1872
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
57 int vo_mpegpes_fd=-1;
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
58 int vo_mpegpes_fd2=-1;
1872
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
59
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
60 #ifdef USE_LIBFAME
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
61
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
62 #include "../libfame/fame.h"
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
63
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
64 static unsigned char *picture_buf=NULL;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
65 static unsigned char *outbuf=NULL;
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
66 static int outbuf_size = 1000000;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
67
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
68 static int s_pos_x,s_pos_y;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
69 static int d_pos_x,d_pos_y;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
70
1943
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
71 static int osd_w,osd_h;
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
72
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
73 static fame_parameters_t params;
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
74 static fame_yuv_t yuv;
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
75 static fame_context_t *ctx=NULL;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
76
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
77 #endif
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
78
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
79 static vo_info_t vo_info =
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
80 {
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
81 #ifdef HAVE_DVB
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
82 "Mpeg-PES to DVB card",
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
83 #else
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
84 "Mpeg-PES file",
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
85 #endif
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
86 "mpegpes",
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
87 "A'rpi",
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
88 ""
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
89 };
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
90
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
91 static uint32_t
4433
df8e0f71cc3c new info for tuning
nick
parents: 4352
diff changeset
92 config(uint32_t s_width, uint32_t s_height, uint32_t width, uint32_t height, uint32_t fullscreen, char *title, uint32_t format,const vo_tune_info_t *info)
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
93 {
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
94 #ifdef HAVE_DVB
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
95 //|O_NONBLOCK
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
96 if((vo_mpegpes_fd = open("/dev/ost/video",O_RDWR)) < 0){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
97 perror("DVB VIDEO DEVICE: ");
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
98 return -1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
99 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
100 if((vo_mpegpes_fd2 = open("/dev/ost/audio",O_RDWR|O_NONBLOCK)) < 0){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
101 perror("DVB AUDIO DEVICE: ");
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
102 return -1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
103 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
104 if ( (ioctl(vo_mpegpes_fd,VIDEO_SET_BLANK, false) < 0)){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
105 perror("DVB VIDEO SET BLANK: ");
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
106 return -1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
107 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
108 if ( (ioctl(vo_mpegpes_fd,VIDEO_SELECT_SOURCE, VIDEO_SOURCE_MEMORY) < 0)){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
109 perror("DVB VIDEO SELECT SOURCE: ");
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
110 return -1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
111 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
112 #if 1
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
113 if ( (ioctl(vo_mpegpes_fd2,AUDIO_SELECT_SOURCE, AUDIO_SOURCE_MEMORY) < 0)){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
114 perror("DVB AUDIO SELECT SOURCE: ");
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
115 return -1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
116 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
117 if ( (ioctl(vo_mpegpes_fd2,AUDIO_PLAY) < 0)){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
118 perror("DVB AUDIO PLAY: ");
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
119 return -1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
120 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
121 #else
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
122 if ( (ioctl(vo_mpegpes_fd2,AUDIO_STOP,0) < 0)){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
123 perror("DVB AUDIO STOP: ");
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
124 return -1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
125 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
126 #endif
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
127 if ( (ioctl(vo_mpegpes_fd,VIDEO_PLAY) < 0)){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
128 perror("DVB VIDEO PLAY: ");
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
129 return -1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
130 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
131 if ( (ioctl(vo_mpegpes_fd2,AUDIO_SET_AV_SYNC, false) < 0)){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
132 perror("DVB AUDIO SET AV SYNC: ");
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
133 return -1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
134 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
135 if ( (ioctl(vo_mpegpes_fd2,AUDIO_SET_MUTE, false) < 0)){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
136 perror("DVB AUDIO SET MUTE: ");
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
137 return -1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
138 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
139
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
140 #else
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
141 vo_mpegpes_fd=open("grab.mpg",O_WRONLY|O_CREAT);
1872
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
142 if(vo_mpegpes_fd<0){
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
143 perror("vo_mpegpes");
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
144 return -1;
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
145 }
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
146 #endif
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
147
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
148 #ifdef USE_LIBFAME
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
149 picture_buf=NULL;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
150 if(format==IMGFMT_YV12){
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
151 int size;
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
152
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
153 ctx=fame_open();
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
154 if(!ctx){
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
155 printf("FATAL: cannot open libFAME!\n");
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
156 return -1;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
157 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
158
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
159 params.width=720;
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
160 params.height=576;
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
161 //params.coding="IPPPPP"; // seems to be buggy and eats more cpu
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
162 params.coding="I";
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
163 params.quality=QUALITY; // 100=best >=80 very good >=50 fast
5078
18c5dc6db592 10l? frames_per_sequence==GOPsize... so it should be few seconds
arpi
parents: 5059
diff changeset
164 params.bitrate=0; // 6*1000000 // bitrate (X bits/sec), 0=VBR
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
165 params.slices_per_frame=1;
5078
18c5dc6db592 10l? frames_per_sequence==GOPsize... so it should be few seconds
arpi
parents: 5059
diff changeset
166 params.frames_per_sequence=25; //0xffffffff;
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
167 params.frame_rate_num=25;
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
168 params.frame_rate_den=1;
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
169 params.shape_quality=100;
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
170 params.search_range=8; // for "IPPP" only
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
171 params.verbose=0;
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
172 params.profile=NULL; // TODO
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
173
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
174 #if 0
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
175 params.width=width;
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
176 params.height=height;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
177 #else
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
178 if(width<=352 && height<=288){
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
179 params.width=352;
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
180 params.height=288;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
181 } else
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
182 if(width<=352 && height<=576){
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
183 params.width=352;
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
184 params.height=576;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
185 } else
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
186 if(width<=480 && height<=576){
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
187 params.width=480;
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
188 params.height=576;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
189 } else
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
190 if(width<=544 && height<=576){
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
191 params.width=544;
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
192 params.height=576;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
193 } else {
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
194 params.width=704;
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
195 params.height=576;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
196 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
197 #endif
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
198
1943
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
199 osd_w=s_width;
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
200 d_pos_x=(params.width-(int)s_width)/2;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
201 if(d_pos_x<0){
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
202 s_pos_x=-d_pos_x;d_pos_x=0;
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
203 osd_w=params.width;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
204 } else s_pos_x=0;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
205
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
206 d_pos_y=(params.height-(int)s_height)/2;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
207 if(d_pos_y<0){
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
208 s_pos_y=-d_pos_y;d_pos_y=0;
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
209 osd_h=params.height;
5080
f333b10ec34f place subtitles under the image
arpi
parents: 5078
diff changeset
210 } else {
f333b10ec34f place subtitles under the image
arpi
parents: 5078
diff changeset
211 s_pos_y=0;
f333b10ec34f place subtitles under the image
arpi
parents: 5078
diff changeset
212 osd_h=s_height+d_pos_y;
f333b10ec34f place subtitles under the image
arpi
parents: 5078
diff changeset
213 // if(d_pos_y) osd clear: s_height+d_pos_y .. params.height
f333b10ec34f place subtitles under the image
arpi
parents: 5078
diff changeset
214 }
1943
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
215
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
216 printf("[vo] position mapping: %d;%d => %d;%d\n",s_pos_x,s_pos_y,d_pos_x,d_pos_y);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
217
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
218 /* open it */
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
219
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
220 outbuf_size=10000+width*height; // must be enough!
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
221 outbuf = malloc(outbuf_size);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
222
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
223 fame_init(ctx,&params,outbuf,outbuf_size);
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
224
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
225 size = params.width*params.height;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
226 picture_buf = malloc((size * 3) / 2); /* size for YUV 420 */
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
227
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
228 memset(picture_buf,0,size); // clear Y
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
229 memset(picture_buf+size,128,size/2); // clear UV
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
230
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
231 yuv.w=params.width;
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
232 yuv.h=params.height;
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
233 yuv.y=picture_buf;
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
234 yuv.u=yuv.y+size;
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
235 yuv.v=yuv.u+size/4;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
236
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
237 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
238 #endif
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
239 return 0;
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
240 }
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
241
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
242 static const vo_info_t*
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
243 get_info(void)
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
244 {
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
245 return &vo_info;
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
246 }
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
247
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
248 #ifdef USE_LIBFAME
1943
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
249 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
250 int x,y;
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
251 vo_draw_alpha_yv12(w,h,src,srca,stride,
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
252 yuv.y+(x0+d_pos_x)+(y0+d_pos_y)*yuv.w,yuv.w);
1943
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
253 }
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
254 #endif
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
255
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
256 static void draw_osd(void)
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
257 {
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
258 #ifdef USE_LIBFAME
1943
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
259 if(picture_buf){ // YV12 only:
5080
f333b10ec34f place subtitles under the image
arpi
parents: 5078
diff changeset
260 // if(d_pos_y) osd clear: s_height+d_pos_y .. params.height
f333b10ec34f place subtitles under the image
arpi
parents: 5078
diff changeset
261 if(d_pos_y){
f333b10ec34f place subtitles under the image
arpi
parents: 5078
diff changeset
262 memset(yuv.y+osd_h*yuv.w,0,(params.height-osd_h)*yuv.w);
f333b10ec34f place subtitles under the image
arpi
parents: 5078
diff changeset
263 }
1943
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
264 vo_draw_text(osd_w,osd_h,draw_alpha);
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
265 }
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
266 #endif
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
267 }
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
268
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
269
1872
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
270 static void my_write(unsigned char* data,int len){
2066
2b14cad013b7 using poll() only for DVB card - not required for file write
arpi
parents: 1986
diff changeset
271 #ifdef HAVE_DVB
2b14cad013b7 using poll() only for DVB card - not required for file write
arpi
parents: 1986
diff changeset
272 #define NFD 2
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
273 struct pollfd pfd[NFD];
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
274
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
275 // printf("write %d bytes \n",len);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
276
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
277 pfd[0].fd = vo_mpegpes_fd;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
278 pfd[0].events = POLLOUT;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
279
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
280 pfd[1].fd = vo_mpegpes_fd2;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
281 pfd[1].events = POLLOUT;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
282
1872
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
283 while(len>0){
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
284 if (poll(pfd,NFD,1)){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
285 if (pfd[0].revents & POLLOUT){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
286 int ret=write(vo_mpegpes_fd,data,len);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
287 // printf("ret=%d \n",ret);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
288 if(ret<=0){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
289 perror("write");
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
290 usleep(0);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
291 } else {
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
292 len-=ret; data+=ret;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
293 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
294 } else usleep(1000);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
295 }
1872
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
296 }
2066
2b14cad013b7 using poll() only for DVB card - not required for file write
arpi
parents: 1986
diff changeset
297
2b14cad013b7 using poll() only for DVB card - not required for file write
arpi
parents: 1986
diff changeset
298 #else
2b14cad013b7 using poll() only for DVB card - not required for file write
arpi
parents: 1986
diff changeset
299 write(vo_mpegpes_fd,data,len); // write to file
2b14cad013b7 using poll() only for DVB card - not required for file write
arpi
parents: 1986
diff changeset
300 #endif
1872
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
301 }
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
302
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
303 static unsigned char pes_header[PES_MAX_SIZE];
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
304
2706
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
305 void send_pes_packet(unsigned char* data,int len,int id,int timestamp){
4306
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
306 int ptslen=timestamp?5:1;
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
307
4306
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
308 // startcode:
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
309 pes_header[0]=pes_header[1]=0;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
310 pes_header[2]=id>>8; pes_header[3]=id&255;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
311
4306
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
312 while(len>0){
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
313 int payload_size=len; // data + PTS
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
314 if(6+ptslen+payload_size>PES_MAX_SIZE) payload_size=PES_MAX_SIZE-(6+ptslen);
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
315
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
316 // construct PES header: (code from ffmpeg's libav)
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
317 // packetsize:
4306
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
318 pes_header[4]=(ptslen+payload_size)>>8;
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
319 pes_header[5]=(ptslen+payload_size)&255;
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
320
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
321 if(ptslen==5){
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
322 int x;
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
323 // presentation time stamp:
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
324 x=(0x02 << 4) | (((timestamp >> 30) & 0x07) << 1) | 1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
325 pes_header[6]=x;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
326 x=((((timestamp >> 15) & 0x7fff) << 1) | 1);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
327 pes_header[7]=x>>8; pes_header[8]=x&255;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
328 x=((((timestamp) & 0x7fff) << 1) | 1);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
329 pes_header[9]=x>>8; pes_header[10]=x&255;
4306
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
330 } else {
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
331 // stuffing and header bits:
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
332 pes_header[6]=0x0f;
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
333 }
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
334
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
335 memcpy(&pes_header[6+ptslen],data,payload_size);
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
336 my_write(pes_header,6+ptslen+payload_size);
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
337
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
338 len-=payload_size; data+=payload_size;
4306
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
339 ptslen=1; // store PTS only once, at first packet!
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
340 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
341
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
342 // printf("PES: draw frame! pts=%d size=%d \n",timestamp,len);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
343
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
344 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
345
4299
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
346 void send_lpcm_packet(unsigned char* data,int len,int id,unsigned int timestamp,int freq_id){
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
347
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
348 int ptslen=timestamp?5:0;
2706
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
349
4306
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
350 // startcode:
2706
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
351 pes_header[0]=pes_header[1]=0;
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
352 pes_header[2]=1; pes_header[3]=0xBD;
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
353
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
354 while(len>=4){
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
355 int payload_size;
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
356
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
357 payload_size=PES_MAX_SIZE-6-20; // max possible data len
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
358 if(payload_size>len) payload_size=len;
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
359 payload_size&=(~3); // align!
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
360
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
361 //if(6+payload_size>PES_MAX_SIZE) payload_size=PES_MAX_SIZE-6;
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
362
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
363 // packetsize:
4299
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
364 pes_header[4]=(payload_size+3+ptslen+7)>>8;
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
365 pes_header[5]=(payload_size+3+ptslen+7)&255;
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
366
2706
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
367 // stuffing:
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
368 pes_header[6]=0x81;
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
369 pes_header[7]=0x80;
4299
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
370
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
371 // hdrlen:
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
372 pes_header[8]=ptslen;
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
373
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
374 if(ptslen){
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
375 int x;
2706
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
376 // presentation time stamp:
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
377 x=(0x02 << 4) | (((timestamp >> 30) & 0x07) << 1) | 1;
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
378 pes_header[9]=x;
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
379 x=((((timestamp >> 15) & 0x7fff) << 1) | 1);
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
380 pes_header[10]=x>>8; pes_header[11]=x&255;
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
381 x=((((timestamp) & 0x7fff) << 1) | 1);
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
382 pes_header[12]=x>>8; pes_header[13]=x&255;
4299
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
383 }
2706
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
384
4299
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
385 // ============ LPCM header: (7 bytes) =================
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
386 // Info by mocm@convergence.de
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
387
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
388 // ID:
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
389 pes_header[ptslen+9]=id;
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
390
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
391 // number of frames:
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
392 pes_header[ptslen+10]=0x07;
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
393
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
394 // first acces unit pointer, i.e. start of audio frame:
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
395 pes_header[ptslen+11]=0x00;
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
396 pes_header[ptslen+12]=0x04;
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
397
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
398 // audio emphasis on-off 1 bit
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
399 // audio mute on-off 1 bit
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
400 // reserved 1 bit
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
401 // audio frame number 5 bit
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
402 pes_header[ptslen+13]=0x0C;
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
403
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
404 // quantization word length 2 bit
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
405 // audio sampling frequency (48khz = 0, 96khz = 1) 2 bit
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
406 // reserved 1 bit
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
407 // number of audio channels - 1 (e.g. stereo = 1) 3 bit
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
408 pes_header[ptslen+14]=1|(freq_id<<4);
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
409
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
410 // dynamic range control (0x80 if off)
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
411 pes_header[ptslen+15]=0x80;
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
412
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
413 memcpy(&pes_header[6+3+ptslen+7],data,payload_size);
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
414 my_write(pes_header,6+3+ptslen+7+payload_size);
2706
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
415
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
416 len-=payload_size; data+=payload_size;
4306
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
417 ptslen=0; // store PTS only once, at first packet!
2706
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
418 }
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
419
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
420 // printf("PES: draw frame! pts=%d size=%d \n",timestamp,len);
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
421
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
422 }
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
423
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
424
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
425 static uint32_t draw_frame(uint8_t * src[])
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
426 {
1872
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
427 vo_mpegpes_t *p=(vo_mpegpes_t *)src[0];
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
428 unsigned char *data=p->data;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
429 // int tmp=-1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
430 send_pes_packet(p->data,p->size,p->id,p->timestamp); // video data
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
431 // send_pes_packet(&tmp,0,0x1C0,p->timestamp+30000); // fake audio data
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
432
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
433 return 0;
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
434 }
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
435
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
436 static void flip_page (void)
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
437 {
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
438 #ifdef USE_LIBFAME
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
439 if(picture_buf){ // YV12 only:
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
440 int out_size;
4330
41dbef7900d0 vo_pts fix (10l)
arpi
parents: 4306
diff changeset
441 // static int fno=0;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
442 /* encode the image */
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
443 out_size = fame_encode_frame(ctx, &yuv, NULL);
4330
41dbef7900d0 vo_pts fix (10l)
arpi
parents: 4306
diff changeset
444 // send_pes_packet(outbuf,out_size,0x1E0,fno*(90000/25));++fno;
41dbef7900d0 vo_pts fix (10l)
arpi
parents: 4306
diff changeset
445 send_pes_packet(outbuf,out_size,0x1E0,vo_pts);
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
446 // printf("frame size: %d \n",out_size);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
447 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
448 #endif
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
449 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
450
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
451 static uint32_t draw_slice(uint8_t *srcimg[], int stride[], int w,int h,int x0,int y0)
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
452 {
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
453 #ifdef USE_LIBFAME
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
454 int y;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
455 unsigned char* s;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
456 unsigned char* d;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
457
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
458 x0+=d_pos_x;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
459 y0+=d_pos_y;
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
460 if(x0+w>yuv.w) w=yuv.w-x0; // !!
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
461 if(y0+h>params.height) h=params.height-y0;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
462
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
463 // Y
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
464 s=srcimg[0]+s_pos_x+s_pos_y*stride[0];
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
465 d=yuv.y+x0+y0*yuv.w;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
466 for(y=0;y<h;y++){
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
467 memcpy(d,s,w);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
468 s+=stride[0];
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
469 d+=yuv.w;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
470 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
471
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
472 w/=2;h/=2;x0/=2;y0/=2;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
473
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
474 // U
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
475 s=srcimg[1]+(s_pos_x/2)+(s_pos_y/2)*stride[1];
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
476 d=yuv.u+x0+y0*(yuv.w>>1);
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
477 for(y=0;y<h;y++){
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
478 memcpy(d,s,w);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
479 s+=stride[1];
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
480 d+=(yuv.w>>1);
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
481 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
482
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
483 // V
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
484 s=srcimg[2]+(s_pos_x/2)+(s_pos_y/2)*stride[2];
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
485 d=yuv.v+x0+y0*(yuv.w>>1);
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
486 for(y=0;y<h;y++){
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
487 memcpy(d,s,w);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
488 s+=stride[2];
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
489 d+=(yuv.w>>1);
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
490 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
491 #endif
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
492 return 0;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
493 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
494
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
495
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
496 static uint32_t
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
497 query_format(uint32_t format)
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
498 {
2706
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
499 if(format==IMGFMT_MPEGPES) return 1|256;
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
500 #ifdef USE_LIBFAME
2706
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
501 if(format==IMGFMT_YV12) return 1|256;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
502 #endif
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
503 return 0;
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
504 }
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
505
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
506 static void
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
507 uninit(void)
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
508 {
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
509 #ifdef USE_LIBFAME
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
510 if(picture_buf){ // YV12 only:
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
511 free(outbuf);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
512 free(picture_buf);
5059
8914f0bb6f35 using libFAME...
arpi
parents: 4737
diff changeset
513 fame_close(ctx); ctx=NULL;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
514 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
515 #endif
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
516 if(vo_mpegpes_fd>=0){ close(vo_mpegpes_fd);vo_mpegpes_fd=-1;}
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
517 if(vo_mpegpes_fd2>=0){ close(vo_mpegpes_fd2);vo_mpegpes_fd2=-1;}
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
518 }
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
519
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
520
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
521 static void check_events(void)
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
522 {
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
523 }
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
524
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4341
diff changeset
525 static uint32_t preinit(const char *arg)
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4341
diff changeset
526 {
4737
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
527 if(arg)
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
528 {
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
529 printf("vo_mpegpes: Unknown subdevice: %s\n",arg);
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
530 return ENOSYS;
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
531 }
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
532 return 0;
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4341
diff changeset
533 }
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4341
diff changeset
534
4596
c35d7ce151b3 10000hl to Holm... control MUST BE static...
arpi
parents: 4592
diff changeset
535 static uint32_t control(uint32_t request, void *data, ...)
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4341
diff changeset
536 {
4592
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
537 switch (request) {
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
538 case VOCTRL_QUERY_FORMAT:
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
539 return query_format(*((uint32_t*)data));
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
540 }
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
541 return VO_NOTIMPL;
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4341
diff changeset
542 }