annotate libvo/vo_mpegpes.c @ 2575:37da7219ebaf

c optimizations
author michael
date Tue, 30 Oct 2001 22:03:25 +0000
parents b2ce5d6d7d4f
children 3066369adb32
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1939
d8dc5e438965 10l cola Arpi =)
atmos4
parents: 1935
diff changeset
1 #undef HAVE_DVB
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
2 #define PES_MAX_SIZE 2048
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
3 /*
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
4 * Based on:
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
5 *
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
6 * test_av.c - Test program for new API
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
7 *
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
8 * Copyright (C) 2000 Ralph Metzler <ralph@convergence.de>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
9 * & Marcus Metzler <marcus@convergence.de>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
10 * for convergence integrated media GmbH
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
11 *
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
12 * libav - MPEG-PS multiplexer, part of ffmpeg
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
13 * Copyright Gerard Lantau (see http://ffmpeg.sf.net)
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
14 *
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
15 */
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
16
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
17 #include <stdio.h>
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
18 #include <stdlib.h>
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
19 #include <string.h>
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
20
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
21 #include <sys/types.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
22 #include <sys/stat.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
23 #include <fcntl.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
24
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
25 #ifdef HAVE_DVB
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
26
2066
2b14cad013b7 using poll() only for DVB card - not required for file write
arpi
parents: 1986
diff changeset
27 #include <sys/poll.h>
2b14cad013b7 using poll() only for DVB card - not required for file write
arpi
parents: 1986
diff changeset
28
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
29 #include <sys/ioctl.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
30 #include <stdio.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
31 #include <time.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
32 #include <unistd.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
33
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
34 #include <ost/dmx.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
35 #include <ost/frontend.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
36 #include <ost/sec.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
37 #include <ost/video.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
38 #include <ost/audio.h>
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
39
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
40 #endif
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
41
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
42 #include "config.h"
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
43 #include "video_out.h"
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
44 #include "video_out_internal.h"
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
45
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
46 LIBVO_EXTERN (mpegpes)
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
47
1872
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
48 int vo_mpegpes_fd=-1;
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
49 int vo_mpegpes_fd2=-1;
1872
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
50
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
51 #ifdef USE_LIBAVCODEC
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
52
2496
b2ce5d6d7d4f libffmpeg.so support
nick
parents: 2066
diff changeset
53 #ifdef USE_LIBAVCODEC_SO
b2ce5d6d7d4f libffmpeg.so support
nick
parents: 2066
diff changeset
54 #include <libffmpeg/avcodec.h>
b2ce5d6d7d4f libffmpeg.so support
nick
parents: 2066
diff changeset
55 #else
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
56 #include "../libavcodec/avcodec.h"
2496
b2ce5d6d7d4f libffmpeg.so support
nick
parents: 2066
diff changeset
57 #endif
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
58 static unsigned char *picture_buf=NULL;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
59 static unsigned char *outbuf=NULL;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
60 static int outbuf_size = 100000;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
61
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
62 static int s_pos_x,s_pos_y;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
63 static int d_pos_x,d_pos_y;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
64
1943
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
65 static int osd_w,osd_h;
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
66
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
67 static AVPicture picture;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
68 static AVCodec *codec=NULL;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
69 static AVCodecContext codec_context;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
70 extern int avcodec_inited;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
71
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
72 #endif
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
73
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
74 static vo_info_t vo_info =
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
75 {
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
76 #ifdef HAVE_DVB
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
77 "Mpeg-PES to DVB card",
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
78 #else
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
79 "Mpeg-PES file",
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
80 #endif
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
81 "mpegpes",
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
82 "A'rpi",
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
83 ""
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
84 };
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
85
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
86 static uint32_t
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
87 init(uint32_t s_width, uint32_t s_height, uint32_t width, uint32_t height, uint32_t fullscreen, char *title, uint32_t format)
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
88 {
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
89 #ifdef HAVE_DVB
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
90 //|O_NONBLOCK
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
91 if((vo_mpegpes_fd = open("/dev/ost/video",O_RDWR)) < 0){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
92 perror("DVB VIDEO DEVICE: ");
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
93 return -1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
94 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
95 if((vo_mpegpes_fd2 = open("/dev/ost/audio",O_RDWR|O_NONBLOCK)) < 0){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
96 perror("DVB AUDIO DEVICE: ");
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
97 return -1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
98 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
99 if ( (ioctl(vo_mpegpes_fd,VIDEO_SET_BLANK, false) < 0)){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
100 perror("DVB VIDEO SET BLANK: ");
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
101 return -1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
102 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
103 if ( (ioctl(vo_mpegpes_fd,VIDEO_SELECT_SOURCE, VIDEO_SOURCE_MEMORY) < 0)){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
104 perror("DVB VIDEO SELECT SOURCE: ");
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
105 return -1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
106 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
107 #if 1
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
108 if ( (ioctl(vo_mpegpes_fd2,AUDIO_SELECT_SOURCE, AUDIO_SOURCE_MEMORY) < 0)){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
109 perror("DVB AUDIO 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 ( (ioctl(vo_mpegpes_fd2,AUDIO_PLAY) < 0)){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
113 perror("DVB AUDIO PLAY: ");
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
114 return -1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
115 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
116 #else
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
117 if ( (ioctl(vo_mpegpes_fd2,AUDIO_STOP,0) < 0)){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
118 perror("DVB AUDIO STOP: ");
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 #endif
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
122 if ( (ioctl(vo_mpegpes_fd,VIDEO_PLAY) < 0)){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
123 perror("DVB VIDEO PLAY: ");
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 if ( (ioctl(vo_mpegpes_fd2,AUDIO_SET_AV_SYNC, false) < 0)){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
127 perror("DVB AUDIO SET AV SYNC: ");
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
128 return -1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
129 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
130 if ( (ioctl(vo_mpegpes_fd2,AUDIO_SET_MUTE, false) < 0)){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
131 perror("DVB AUDIO SET MUTE: ");
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
132 return -1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
133 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
134
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
135 #else
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
136 vo_mpegpes_fd=open("grab.mpg",O_WRONLY|O_CREAT);
1872
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
137 if(vo_mpegpes_fd<0){
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
138 perror("vo_mpegpes");
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
139 return -1;
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
140 }
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
141 #endif
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
142
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
143 #ifdef USE_LIBAVCODEC
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
144 picture_buf=NULL;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
145 if(format==IMGFMT_YV12){
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
146 int size;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
147
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
148 if(!avcodec_inited){
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
149 avcodec_init();
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
150 avcodec_register_all();
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
151 avcodec_inited=1;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
152 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
153
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
154 /* find the mpeg1 video encoder */
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
155 codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
156 if (!codec) {
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
157 fprintf(stderr, "mpeg1 codec not found\n");
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
158 return -1;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
159 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
160 memset(&codec_context,0,sizeof(codec_context));
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
161 codec_context.bit_rate=100000; // not used
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
162 codec_context.frame_rate=25*FRAME_RATE_BASE; // !!!!!
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
163 codec_context.gop_size=0; // I frames only
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
164 codec_context.flags=CODEC_FLAG_QSCALE;
1986
b1d663f54725 Y clipping fixed
arpi
parents: 1943
diff changeset
165 codec_context.quality=1; // quality! 1..31 (1=best,slowest)
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
166
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
167 #if 0
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
168 codec_context.width=width;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
169 codec_context.height=height;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
170 #else
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
171 if(width<=352 && height<=288){
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
172 codec_context.width=352;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
173 codec_context.height=288;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
174 } else
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
175 if(width<=352 && height<=576){
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
176 codec_context.width=352;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
177 codec_context.height=576;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
178 } else
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
179 if(width<=480 && height<=576){
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
180 codec_context.width=480;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
181 codec_context.height=576;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
182 } else
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
183 if(width<=544 && height<=576){
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
184 codec_context.width=544;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
185 codec_context.height=576;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
186 } else {
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
187 codec_context.width=704;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
188 codec_context.height=576;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
189 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
190 #endif
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
191
1943
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
192 osd_w=s_width;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
193 d_pos_x=(codec_context.width-(int)s_width)/2;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
194 if(d_pos_x<0){
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
195 s_pos_x=-d_pos_x;d_pos_x=0;
1943
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
196 osd_w=codec_context.width;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
197 } else s_pos_x=0;
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_h=s_height;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
200 d_pos_y=(codec_context.height-(int)s_height)/2;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
201 if(d_pos_y<0){
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
202 s_pos_y=-d_pos_y;d_pos_y=0;
1943
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
203 osd_h=codec_context.height;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
204 } else s_pos_y=0;
1943
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
205
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
206 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
207
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
208 /* open it */
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
209 if (avcodec_open(&codec_context, codec) < 0) {
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
210 fprintf(stderr, "could not open codec\n");
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
211 return -1;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
212 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
213
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
214 outbuf_size=10000+width*height; // must be enough!
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
215 outbuf = malloc(outbuf_size);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
216
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
217 size = codec_context.width*codec_context.height;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
218 picture_buf = malloc((size * 3) / 2); /* size for YUV 420 */
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
219
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
220 memset(picture_buf,0,size); // clear Y
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
221 memset(picture_buf+size,128,size/2); // clear UV
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
222
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
223 picture.data[0] = picture_buf;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
224 picture.data[1] = picture.data[0] + size;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
225 picture.data[2] = picture.data[1] + size / 4;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
226 picture.linesize[0] = codec_context.width;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
227 picture.linesize[1] = codec_context.width / 2;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
228 picture.linesize[2] = codec_context.width / 2;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
229
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
230 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
231 #endif
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
232 return 0;
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
233 }
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
234
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
235 static const vo_info_t*
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
236 get_info(void)
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
237 {
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
238 return &vo_info;
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
239 }
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
240
1943
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
241 #ifdef USE_LIBAVCODEC
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
242 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
243 int x,y;
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
244 vo_draw_alpha_yv12(w,h,src,srca,stride,
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
245 picture.data[0]+(x0+d_pos_x)+(y0+d_pos_y)*picture.linesize[0],picture.linesize[0]);
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
246 }
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
247 #endif
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
248
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
249 static void draw_osd(void)
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
250 {
1943
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
251 #ifdef USE_LIBAVCODEC
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
252 if(picture_buf){ // YV12 only:
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
253 vo_draw_text(osd_w,osd_h,draw_alpha);
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
254 }
24c248fbdb0f software OSD support
arpi
parents: 1939
diff changeset
255 #endif
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
256 }
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
257
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
258
1872
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
259 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
260 #ifdef HAVE_DVB
2b14cad013b7 using poll() only for DVB card - not required for file write
arpi
parents: 1986
diff changeset
261 #define NFD 2
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
262 struct pollfd pfd[NFD];
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
263
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
264 // printf("write %d bytes \n",len);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
265
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
266 pfd[0].fd = vo_mpegpes_fd;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
267 pfd[0].events = POLLOUT;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
268
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
269 pfd[1].fd = vo_mpegpes_fd2;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
270 pfd[1].events = POLLOUT;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
271
1872
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
272 while(len>0){
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
273 if (poll(pfd,NFD,1)){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
274 if (pfd[0].revents & POLLOUT){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
275 int ret=write(vo_mpegpes_fd,data,len);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
276 // printf("ret=%d \n",ret);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
277 if(ret<=0){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
278 perror("write");
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
279 usleep(0);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
280 } else {
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
281 len-=ret; data+=ret;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
282 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
283 } else usleep(1000);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
284 }
1872
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
285 }
2066
2b14cad013b7 using poll() only for DVB card - not required for file write
arpi
parents: 1986
diff changeset
286
2b14cad013b7 using poll() only for DVB card - not required for file write
arpi
parents: 1986
diff changeset
287 #else
2b14cad013b7 using poll() only for DVB card - not required for file write
arpi
parents: 1986
diff changeset
288 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
289 #endif
1872
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
290 }
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
291
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
292 static unsigned char pes_header[PES_MAX_SIZE];
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
293
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
294 static void send_pes_packet(unsigned char* data,int len,int id,int timestamp){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
295 int x;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
296
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
297 pes_header[0]=pes_header[1]=0;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
298 pes_header[2]=id>>8; pes_header[3]=id&255;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
299
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
300 while(1){
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
301 int payload_size=len+5; // data + PTS
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
302 if(6+payload_size>PES_MAX_SIZE) payload_size=PES_MAX_SIZE-6;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
303
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
304 // construct PES header: (code from ffmpeg's libav)
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
305 // startcode:
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
306 // packetsize:
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
307 pes_header[4]=(payload_size)>>8;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
308 pes_header[5]=(payload_size)&255;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
309 // stuffing:
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
310 // presentation time stamp:
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
311 x=(0x02 << 4) | (((timestamp >> 30) & 0x07) << 1) | 1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
312 pes_header[6]=x;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
313 x=((((timestamp >> 15) & 0x7fff) << 1) | 1);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
314 pes_header[7]=x>>8; pes_header[8]=x&255;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
315 x=((((timestamp) & 0x7fff) << 1) | 1);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
316 pes_header[9]=x>>8; pes_header[10]=x&255;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
317
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
318 payload_size-=5;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
319 memcpy(&pes_header[6+5],data,payload_size);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
320 my_write(pes_header,6+5+payload_size);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
321
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
322 len-=payload_size; data+=payload_size;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
323 if(len<=0) break;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
324 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
325
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
326 // printf("PES: draw frame! pts=%d size=%d \n",timestamp,len);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
327
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
328 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
329
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
330 static uint32_t draw_frame(uint8_t * src[])
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
331 {
1872
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
332 vo_mpegpes_t *p=(vo_mpegpes_t *)src[0];
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
333 unsigned char *data=p->data;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
334 // int tmp=-1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
335 send_pes_packet(p->data,p->size,p->id,p->timestamp); // video data
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
336 // send_pes_packet(&tmp,0,0x1C0,p->timestamp+30000); // fake audio data
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
337
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
338 return 0;
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
339 }
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
340
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
341 static void flip_page (void)
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
342 {
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
343 #ifdef USE_LIBAVCODEC
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
344 if(picture_buf){ // YV12 only:
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
345 int out_size;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
346 static int fno=0;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
347 /* encode the image */
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
348 out_size = avcodec_encode_video(&codec_context, outbuf, outbuf_size, &picture);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
349 send_pes_packet(outbuf,out_size,0x1E0,fno*(90000/25));++fno;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
350 // printf("frame size: %d \n",out_size);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
351 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
352 #endif
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
353 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
354
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
355 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
356 {
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
357 #ifdef USE_LIBAVCODEC
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
358 int y;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
359 unsigned char* s;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
360 unsigned char* d;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
361
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
362 x0+=d_pos_x;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
363 y0+=d_pos_y;
1986
b1d663f54725 Y clipping fixed
arpi
parents: 1943
diff changeset
364 if(x0+w>picture.linesize[0]) w=picture.linesize[0]-x0; // !!
b1d663f54725 Y clipping fixed
arpi
parents: 1943
diff changeset
365 if(y0+h>codec_context.height) h=codec_context.height-y0;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
366
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
367 // Y
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
368 s=srcimg[0]+s_pos_x+s_pos_y*stride[0];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
369 d=picture.data[0]+x0+y0*picture.linesize[0];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
370 for(y=0;y<h;y++){
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
371 memcpy(d,s,w);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
372 s+=stride[0];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
373 d+=picture.linesize[0];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
374 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
375
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
376 w/=2;h/=2;x0/=2;y0/=2;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
377
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
378 // U
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
379 s=srcimg[1]+(s_pos_x/2)+(s_pos_y/2)*stride[1];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
380 d=picture.data[1]+x0+y0*picture.linesize[1];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
381 for(y=0;y<h;y++){
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
382 memcpy(d,s,w);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
383 s+=stride[1];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
384 d+=picture.linesize[1];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
385 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
386
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
387 // V
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
388 s=srcimg[2]+(s_pos_x/2)+(s_pos_y/2)*stride[2];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
389 d=picture.data[2]+x0+y0*picture.linesize[2];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
390 for(y=0;y<h;y++){
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
391 memcpy(d,s,w);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
392 s+=stride[2];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
393 d+=picture.linesize[2];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
394 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
395 #endif
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
396 return 0;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
397 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
398
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
399
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
400 static uint32_t
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
401 query_format(uint32_t format)
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
402 {
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
403 if(format==IMGFMT_MPEGPES) return 1;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
404 #ifdef USE_LIBAVCODEC
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
405 if(format==IMGFMT_YV12) return 1;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
406 #endif
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
407 return 0;
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
408 }
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
409
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
410 static void
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
411 uninit(void)
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
412 {
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
413 #ifdef USE_LIBAVCODEC
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
414 if(picture_buf){ // YV12 only:
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
415 free(outbuf);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
416 free(picture_buf);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
417 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
418 #endif
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
419 if(vo_mpegpes_fd>=0){ close(vo_mpegpes_fd);vo_mpegpes_fd=-1;}
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
420 if(vo_mpegpes_fd2>=0){ close(vo_mpegpes_fd2);vo_mpegpes_fd2=-1;}
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
421 }
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
422
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
423
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
424 static void check_events(void)
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
425 {
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
426 }
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
427