annotate libvo/vo_mpegpes.c @ 4973:544c1dae591c

video_out added to sh_video_t
author arpi
date Thu, 07 Mar 2002 02:49:46 +0000
parents 32e1f5042f65
children 8914f0bb6f35
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>
4737
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
19 #include <errno.h>
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
4433
df8e0f71cc3c new info for tuning
nick
parents: 4352
diff changeset
88 config(uint32_t s_width, uint32_t s_height, uint32_t width, uint32_t height, uint32_t fullscreen, char *title, uint32_t format,const vo_tune_info_t *info)
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
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;
4341
d407c8734ffe qscale 3->2 (Thank you Michael)
arpi
parents: 4330
diff changeset
166 codec_context.quality=2; // 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){
4306
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
296 int ptslen=timestamp?5:1;
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
297
4306
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
298 // startcode:
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
299 pes_header[0]=pes_header[1]=0;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
300 pes_header[2]=id>>8; pes_header[3]=id&255;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
301
4306
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
302 while(len>0){
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
303 int payload_size=len; // data + PTS
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
304 if(6+ptslen+payload_size>PES_MAX_SIZE) payload_size=PES_MAX_SIZE-(6+ptslen);
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
305
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
306 // construct PES header: (code from ffmpeg's libav)
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
307 // packetsize:
4306
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
308 pes_header[4]=(ptslen+payload_size)>>8;
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
309 pes_header[5]=(ptslen+payload_size)&255;
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
310
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
311 if(ptslen==5){
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
312 int x;
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
313 // presentation time stamp:
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
314 x=(0x02 << 4) | (((timestamp >> 30) & 0x07) << 1) | 1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
315 pes_header[6]=x;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
316 x=((((timestamp >> 15) & 0x7fff) << 1) | 1);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
317 pes_header[7]=x>>8; pes_header[8]=x&255;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
318 x=((((timestamp) & 0x7fff) << 1) | 1);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
319 pes_header[9]=x>>8; pes_header[10]=x&255;
4306
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
320 } else {
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
321 // stuffing and header bits:
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
322 pes_header[6]=0x0f;
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
323 }
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
324
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
325 memcpy(&pes_header[6+ptslen],data,payload_size);
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
326 my_write(pes_header,6+ptslen+payload_size);
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
327
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
328 len-=payload_size; data+=payload_size;
4306
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
329 ptslen=1; // store PTS only once, at first packet!
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
330 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
331
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
332 // printf("PES: draw frame! pts=%d size=%d \n",timestamp,len);
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
333
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
334 }
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
335
4299
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
336 void send_lpcm_packet(unsigned char* data,int len,int id,unsigned int timestamp,int freq_id){
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
337
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
338 int ptslen=timestamp?5:0;
2706
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
339
4306
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
340 // startcode:
2706
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
341 pes_header[0]=pes_header[1]=0;
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
342 pes_header[2]=1; pes_header[3]=0xBD;
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
343
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
344 while(len>=4){
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
345 int payload_size;
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
346
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
347 payload_size=PES_MAX_SIZE-6-20; // max possible data len
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
348 if(payload_size>len) payload_size=len;
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
349 payload_size&=(~3); // align!
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
350
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
351 //if(6+payload_size>PES_MAX_SIZE) payload_size=PES_MAX_SIZE-6;
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
352
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
353 // packetsize:
4299
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
354 pes_header[4]=(payload_size+3+ptslen+7)>>8;
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
355 pes_header[5]=(payload_size+3+ptslen+7)&255;
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
356
2706
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
357 // stuffing:
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
358 pes_header[6]=0x81;
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
359 pes_header[7]=0x80;
4299
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
360
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
361 // hdrlen:
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
362 pes_header[8]=ptslen;
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
363
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
364 if(ptslen){
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
365 int x;
2706
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
366 // presentation time stamp:
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
367 x=(0x02 << 4) | (((timestamp >> 30) & 0x07) << 1) | 1;
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
368 pes_header[9]=x;
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
369 x=((((timestamp >> 15) & 0x7fff) << 1) | 1);
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
370 pes_header[10]=x>>8; pes_header[11]=x&255;
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
371 x=((((timestamp) & 0x7fff) << 1) | 1);
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
372 pes_header[12]=x>>8; pes_header[13]=x&255;
4299
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
373 }
2706
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
374
4299
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
375 // ============ LPCM header: (7 bytes) =================
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
376 // Info by mocm@convergence.de
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
377
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
378 // ID:
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
379 pes_header[ptslen+9]=id;
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
380
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
381 // number of frames:
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
382 pes_header[ptslen+10]=0x07;
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
383
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
384 // first acces unit pointer, i.e. start of audio frame:
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
385 pes_header[ptslen+11]=0x00;
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
386 pes_header[ptslen+12]=0x04;
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
387
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
388 // audio emphasis on-off 1 bit
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
389 // audio mute on-off 1 bit
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
390 // reserved 1 bit
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
391 // audio frame number 5 bit
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
392 pes_header[ptslen+13]=0x0C;
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
393
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
394 // quantization word length 2 bit
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
395 // audio sampling frequency (48khz = 0, 96khz = 1) 2 bit
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
396 // reserved 1 bit
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
397 // number of audio channels - 1 (e.g. stereo = 1) 3 bit
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
398 pes_header[ptslen+14]=1|(freq_id<<4);
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
399
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
400 // dynamic range control (0x80 if off)
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
401 pes_header[ptslen+15]=0x80;
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
402
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
403 memcpy(&pes_header[6+3+ptslen+7],data,payload_size);
8e157167cee5 LPCM write code rewritten, thanks to Marcus at mocm@convergence.de
arpi
parents: 2727
diff changeset
404 my_write(pes_header,6+3+ptslen+7+payload_size);
2706
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
405
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
406 len-=payload_size; data+=payload_size;
4306
f11e25b77c1e cleanup of video packet writer, PTS sent only once
arpi
parents: 4299
diff changeset
407 ptslen=0; // store PTS only once, at first packet!
2706
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
408 }
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
409
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
410 // printf("PES: draw frame! pts=%d size=%d \n",timestamp,len);
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
411
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
412 }
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
413
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
414
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
415 static uint32_t draw_frame(uint8_t * src[])
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
416 {
1872
2fe0e11bab3c file writer implemented
arpi
parents: 1871
diff changeset
417 vo_mpegpes_t *p=(vo_mpegpes_t *)src[0];
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
418 unsigned char *data=p->data;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
419 // int tmp=-1;
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
420 send_pes_packet(p->data,p->size,p->id,p->timestamp); // video data
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
421 // send_pes_packet(&tmp,0,0x1C0,p->timestamp+30000); // fake audio data
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
422
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
423 return 0;
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
424 }
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
425
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
426 static void flip_page (void)
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
427 {
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
428 #ifdef USE_LIBAVCODEC
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
429 if(picture_buf){ // YV12 only:
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
430 int out_size;
4330
41dbef7900d0 vo_pts fix (10l)
arpi
parents: 4306
diff changeset
431 // static int fno=0;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
432 /* encode the image */
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
433 out_size = avcodec_encode_video(&codec_context, outbuf, outbuf_size, &picture);
4330
41dbef7900d0 vo_pts fix (10l)
arpi
parents: 4306
diff changeset
434 // send_pes_packet(outbuf,out_size,0x1E0,fno*(90000/25));++fno;
41dbef7900d0 vo_pts fix (10l)
arpi
parents: 4306
diff changeset
435 send_pes_packet(outbuf,out_size,0x1E0,vo_pts);
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
436 // printf("frame size: %d \n",out_size);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
437 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
438 #endif
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
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
441 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
442 {
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
443 #ifdef USE_LIBAVCODEC
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
444 int y;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
445 unsigned char* s;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
446 unsigned char* d;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
447
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
448 x0+=d_pos_x;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
449 y0+=d_pos_y;
1986
b1d663f54725 Y clipping fixed
arpi
parents: 1943
diff changeset
450 if(x0+w>picture.linesize[0]) w=picture.linesize[0]-x0; // !!
b1d663f54725 Y clipping fixed
arpi
parents: 1943
diff changeset
451 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
452
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
453 // Y
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
454 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
455 d=picture.data[0]+x0+y0*picture.linesize[0];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
456 for(y=0;y<h;y++){
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
457 memcpy(d,s,w);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
458 s+=stride[0];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
459 d+=picture.linesize[0];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
460 }
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 w/=2;h/=2;x0/=2;y0/=2;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
463
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
464 // U
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
465 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
466 d=picture.data[1]+x0+y0*picture.linesize[1];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
467 for(y=0;y<h;y++){
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
468 memcpy(d,s,w);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
469 s+=stride[1];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
470 d+=picture.linesize[1];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
471 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
472
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
473 // V
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
474 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
475 d=picture.data[2]+x0+y0*picture.linesize[2];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
476 for(y=0;y<h;y++){
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
477 memcpy(d,s,w);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
478 s+=stride[2];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
479 d+=picture.linesize[2];
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
480 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
481 #endif
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
482 return 0;
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
483 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
484
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
485
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
486 static uint32_t
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
487 query_format(uint32_t format)
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
488 {
2706
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
489 if(format==IMGFMT_MPEGPES) return 1|256;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
490 #ifdef USE_LIBAVCODEC
2706
3066369adb32 audio packet writting added
arpi
parents: 2496
diff changeset
491 if(format==IMGFMT_YV12) return 1|256;
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
492 #endif
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
493 return 0;
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
494 }
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
495
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
496 static void
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
497 uninit(void)
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
498 {
1935
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
499 #ifdef USE_LIBAVCODEC
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
500 if(picture_buf){ // YV12 only:
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
501 free(outbuf);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
502 free(picture_buf);
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
503 }
fcd39f3b13d4 YV12 support (using libavcodec for mpeg1-I encoding)
arpi
parents: 1876
diff changeset
504 #endif
1876
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
505 if(vo_mpegpes_fd>=0){ close(vo_mpegpes_fd);vo_mpegpes_fd=-1;}
220475b1676a PS multiplexing fixed
arpi
parents: 1872
diff changeset
506 if(vo_mpegpes_fd2>=0){ close(vo_mpegpes_fd2);vo_mpegpes_fd2=-1;}
1871
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
507 }
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
508
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
509
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
510 static void check_events(void)
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
511 {
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
512 }
cb5dde69354b Mpeg PES added
arpi
parents:
diff changeset
513
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4341
diff changeset
514 static uint32_t preinit(const char *arg)
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4341
diff changeset
515 {
4737
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
516 if(arg)
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
517 {
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
518 printf("vo_mpegpes: Unknown subdevice: %s\n",arg);
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
519 return ENOSYS;
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
520 }
32e1f5042f65 I don't like such reports: '-vo dga:vidix or -vo x11:vidix works fine for me'
nick
parents: 4596
diff changeset
521 return 0;
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4341
diff changeset
522 }
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4341
diff changeset
523
4596
c35d7ce151b3 10000hl to Holm... control MUST BE static...
arpi
parents: 4592
diff changeset
524 static uint32_t control(uint32_t request, void *data, ...)
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4341
diff changeset
525 {
4592
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
526 switch (request) {
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
527 case VOCTRL_QUERY_FORMAT:
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
528 return query_format(*((uint32_t*)data));
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
529 }
5fbfd8545c3b query_ stuff replaced by new control() - patch by David Holm
arpi
parents: 4433
diff changeset
530 return VO_NOTIMPL;
4352
ed5b85b713a3 Extensions for video accelerated architecture
nick
parents: 4341
diff changeset
531 }