annotate libvo/vo_mpegpes.c @ 2916:5ecae3e4db37

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