annotate libmpdemux/tv.c @ 2790:98769cea155c

added tv subsystem
author alex
date Fri, 09 Nov 2001 23:46:06 +0000
parents
children 09d5c9834580
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
1 /*
98769cea155c added tv subsystem
alex
parents:
diff changeset
2 TV subsystem for libMPDemux by Alex
98769cea155c added tv subsystem
alex
parents:
diff changeset
3
98769cea155c added tv subsystem
alex
parents:
diff changeset
4 API idea based on libvo2's
98769cea155c added tv subsystem
alex
parents:
diff changeset
5
98769cea155c added tv subsystem
alex
parents:
diff changeset
6 UNDER HEAVY DEVELOPEMENT, DO NOT USE! :)
98769cea155c added tv subsystem
alex
parents:
diff changeset
7 */
98769cea155c added tv subsystem
alex
parents:
diff changeset
8
98769cea155c added tv subsystem
alex
parents:
diff changeset
9 #include <stdio.h>
98769cea155c added tv subsystem
alex
parents:
diff changeset
10 #include <stdlib.h>
98769cea155c added tv subsystem
alex
parents:
diff changeset
11 #include <unistd.h>
98769cea155c added tv subsystem
alex
parents:
diff changeset
12
98769cea155c added tv subsystem
alex
parents:
diff changeset
13 #include "config.h"
98769cea155c added tv subsystem
alex
parents:
diff changeset
14
98769cea155c added tv subsystem
alex
parents:
diff changeset
15 #ifdef USE_TV
98769cea155c added tv subsystem
alex
parents:
diff changeset
16 #include "tv.h"
98769cea155c added tv subsystem
alex
parents:
diff changeset
17 #include "mp_msg.h"
98769cea155c added tv subsystem
alex
parents:
diff changeset
18 #include "help_mp.h"
98769cea155c added tv subsystem
alex
parents:
diff changeset
19
98769cea155c added tv subsystem
alex
parents:
diff changeset
20 #include "stream.h"
98769cea155c added tv subsystem
alex
parents:
diff changeset
21 #include "demuxer.h"
98769cea155c added tv subsystem
alex
parents:
diff changeset
22 #include "stheader.h"
98769cea155c added tv subsystem
alex
parents:
diff changeset
23
98769cea155c added tv subsystem
alex
parents:
diff changeset
24 /* global! */
98769cea155c added tv subsystem
alex
parents:
diff changeset
25 tvi_handle_t *tv_handler;
98769cea155c added tv subsystem
alex
parents:
diff changeset
26
98769cea155c added tv subsystem
alex
parents:
diff changeset
27 /* some default values */
98769cea155c added tv subsystem
alex
parents:
diff changeset
28 float tv_param_freq = 0.0;
98769cea155c added tv subsystem
alex
parents:
diff changeset
29 char *tv_param_channel = "0";
98769cea155c added tv subsystem
alex
parents:
diff changeset
30 char *tv_param_norm = "pal";
98769cea155c added tv subsystem
alex
parents:
diff changeset
31 int tv_param_on = 0;
98769cea155c added tv subsystem
alex
parents:
diff changeset
32 char *tv_param_device = NULL;
98769cea155c added tv subsystem
alex
parents:
diff changeset
33 char *tv_param_driver = "dummy";
98769cea155c added tv subsystem
alex
parents:
diff changeset
34 int tv_param_width = -1;
98769cea155c added tv subsystem
alex
parents:
diff changeset
35 int tv_param_height = -1;
98769cea155c added tv subsystem
alex
parents:
diff changeset
36
98769cea155c added tv subsystem
alex
parents:
diff changeset
37
98769cea155c added tv subsystem
alex
parents:
diff changeset
38 /* ================== DEMUX_TV ===================== */
98769cea155c added tv subsystem
alex
parents:
diff changeset
39 /*
98769cea155c added tv subsystem
alex
parents:
diff changeset
40 Return value:
98769cea155c added tv subsystem
alex
parents:
diff changeset
41 0 = EOF(?) or no stream
98769cea155c added tv subsystem
alex
parents:
diff changeset
42 1 = successfully read a packet
98769cea155c added tv subsystem
alex
parents:
diff changeset
43 */
98769cea155c added tv subsystem
alex
parents:
diff changeset
44 /* fill demux->video and demux->audio */
98769cea155c added tv subsystem
alex
parents:
diff changeset
45 int demux_tv_fill_buffer(demuxer_t *demux)
98769cea155c added tv subsystem
alex
parents:
diff changeset
46 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
47 int seq;
98769cea155c added tv subsystem
alex
parents:
diff changeset
48 demux_stream_t *ds_video = NULL;
98769cea155c added tv subsystem
alex
parents:
diff changeset
49 demux_packet_t *dp_video = NULL;
98769cea155c added tv subsystem
alex
parents:
diff changeset
50 demux_stream_t *ds_audio = NULL;
98769cea155c added tv subsystem
alex
parents:
diff changeset
51 demux_packet_t *dp_audio = NULL;
98769cea155c added tv subsystem
alex
parents:
diff changeset
52 int len_video, len_audio;
98769cea155c added tv subsystem
alex
parents:
diff changeset
53
98769cea155c added tv subsystem
alex
parents:
diff changeset
54 demux->filepos = -1;
98769cea155c added tv subsystem
alex
parents:
diff changeset
55
98769cea155c added tv subsystem
alex
parents:
diff changeset
56 /* ================== ADD VIDEO PACKET =================== */
98769cea155c added tv subsystem
alex
parents:
diff changeset
57 len_video = tv_handler->functions->get_video_framesize(tv_handler->priv);
98769cea155c added tv subsystem
alex
parents:
diff changeset
58 ds_video = demux->video;
98769cea155c added tv subsystem
alex
parents:
diff changeset
59
98769cea155c added tv subsystem
alex
parents:
diff changeset
60 if (!ds_video)
98769cea155c added tv subsystem
alex
parents:
diff changeset
61 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
62 dp_video = new_demux_packet(len_video);
98769cea155c added tv subsystem
alex
parents:
diff changeset
63 tv_handler->functions->grab_video_frame(tv_handler->priv, dp_video->buffer, len_video);
98769cea155c added tv subsystem
alex
parents:
diff changeset
64 dp_video->pos = demux->filepos;
98769cea155c added tv subsystem
alex
parents:
diff changeset
65 ds_video->asf_packet = dp_video;
98769cea155c added tv subsystem
alex
parents:
diff changeset
66 ds_video->asf_seq = seq;
98769cea155c added tv subsystem
alex
parents:
diff changeset
67 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
68 else if (ds_video->asf_packet)
98769cea155c added tv subsystem
alex
parents:
diff changeset
69 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
70 if (ds_video->asf_seq != seq)
98769cea155c added tv subsystem
alex
parents:
diff changeset
71 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
72 ds_add_packet(ds_video, ds_video->asf_packet);
98769cea155c added tv subsystem
alex
parents:
diff changeset
73 ds_video->asf_packet = NULL;
98769cea155c added tv subsystem
alex
parents:
diff changeset
74 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
75 else
98769cea155c added tv subsystem
alex
parents:
diff changeset
76 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
77 dp_video = ds_video->asf_packet;
98769cea155c added tv subsystem
alex
parents:
diff changeset
78 dp_video->buffer = realloc(dp_video->buffer, dp_video->len+len_video);
98769cea155c added tv subsystem
alex
parents:
diff changeset
79 tv_handler->functions->grab_video_frame(tv_handler->priv, dp_video->buffer+dp_video->len, len_video);
98769cea155c added tv subsystem
alex
parents:
diff changeset
80 mp_dbg(MSGT_DEMUX,MSGL_DBG4, "video data appended %d+%d\n", dp_video->len, len_video);
98769cea155c added tv subsystem
alex
parents:
diff changeset
81 dp_video->len += len_video;
98769cea155c added tv subsystem
alex
parents:
diff changeset
82 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
83 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
84
98769cea155c added tv subsystem
alex
parents:
diff changeset
85
98769cea155c added tv subsystem
alex
parents:
diff changeset
86 /* ================== ADD AUDIO PACKET =================== */
98769cea155c added tv subsystem
alex
parents:
diff changeset
87 len_audio = tv_handler->functions->get_audio_framesize(tv_handler->priv);
98769cea155c added tv subsystem
alex
parents:
diff changeset
88 ds_audio = demux->audio;
98769cea155c added tv subsystem
alex
parents:
diff changeset
89
98769cea155c added tv subsystem
alex
parents:
diff changeset
90 if (!ds_audio)
98769cea155c added tv subsystem
alex
parents:
diff changeset
91 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
92 dp_audio = new_demux_packet(len_audio);
98769cea155c added tv subsystem
alex
parents:
diff changeset
93 tv_handler->functions->grab_audio_frame(tv_handler->priv, dp_audio->buffer, len_audio);
98769cea155c added tv subsystem
alex
parents:
diff changeset
94 dp_audio->pos = demux->filepos;
98769cea155c added tv subsystem
alex
parents:
diff changeset
95 ds_audio->asf_packet = dp_audio;
98769cea155c added tv subsystem
alex
parents:
diff changeset
96 ds_audio->asf_seq = seq;
98769cea155c added tv subsystem
alex
parents:
diff changeset
97 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
98 else if (ds_audio->asf_packet)
98769cea155c added tv subsystem
alex
parents:
diff changeset
99 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
100 if (ds_audio->asf_seq != seq)
98769cea155c added tv subsystem
alex
parents:
diff changeset
101 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
102 ds_add_packet(ds_audio, ds_audio->asf_packet);
98769cea155c added tv subsystem
alex
parents:
diff changeset
103 ds_audio->asf_packet = NULL;
98769cea155c added tv subsystem
alex
parents:
diff changeset
104 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
105 else
98769cea155c added tv subsystem
alex
parents:
diff changeset
106 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
107 dp_audio = ds_audio->asf_packet;
98769cea155c added tv subsystem
alex
parents:
diff changeset
108 dp_audio->buffer = realloc(dp_audio->buffer, dp_audio->len+len_audio);
98769cea155c added tv subsystem
alex
parents:
diff changeset
109 tv_handler->functions->grab_audio_frame(tv_handler->priv, dp_audio->buffer+dp_audio->len, len_audio);
98769cea155c added tv subsystem
alex
parents:
diff changeset
110 mp_dbg(MSGT_DEMUX,MSGL_DBG4, "audio data appended %d+%d\n", dp_audio->len, len_audio);
98769cea155c added tv subsystem
alex
parents:
diff changeset
111 dp_audio->len += len_audio;
98769cea155c added tv subsystem
alex
parents:
diff changeset
112 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
113 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
114
98769cea155c added tv subsystem
alex
parents:
diff changeset
115 return 1;
98769cea155c added tv subsystem
alex
parents:
diff changeset
116 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
117
98769cea155c added tv subsystem
alex
parents:
diff changeset
118 int demux_open_tv(demuxer_t *demuxer)
98769cea155c added tv subsystem
alex
parents:
diff changeset
119 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
120 sh_video_t *sh_video;
98769cea155c added tv subsystem
alex
parents:
diff changeset
121 tvi_handle_t *tvh = tv_handler;
98769cea155c added tv subsystem
alex
parents:
diff changeset
122 tvi_functions_t *funcs = tvh->functions;
98769cea155c added tv subsystem
alex
parents:
diff changeset
123
98769cea155c added tv subsystem
alex
parents:
diff changeset
124 sh_video = new_sh_video(demuxer,0);
98769cea155c added tv subsystem
alex
parents:
diff changeset
125
98769cea155c added tv subsystem
alex
parents:
diff changeset
126 // sh->format=0x7476696e; /* "tvin" */
98769cea155c added tv subsystem
alex
parents:
diff changeset
127 if (funcs->control(tvh->priv, TVI_CONTROL_VID_GET_FORMAT, &sh_video->format) != TVI_CONTROL_TRUE)
98769cea155c added tv subsystem
alex
parents:
diff changeset
128 sh_video->format = 0x00000000;
98769cea155c added tv subsystem
alex
parents:
diff changeset
129
98769cea155c added tv subsystem
alex
parents:
diff changeset
130 if(!sh_video->fps)
98769cea155c added tv subsystem
alex
parents:
diff changeset
131 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
132 if (funcs->control(tvh->priv, TVI_CONTROL_VID_GET_FPS, &sh_video->fps) != TVI_CONTROL_TRUE)
98769cea155c added tv subsystem
alex
parents:
diff changeset
133 sh_video->fps = 24.0f;
98769cea155c added tv subsystem
alex
parents:
diff changeset
134 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
135 sh_video->frametime = 1.0f/sh_video->fps;
98769cea155c added tv subsystem
alex
parents:
diff changeset
136
98769cea155c added tv subsystem
alex
parents:
diff changeset
137 /* set width */
98769cea155c added tv subsystem
alex
parents:
diff changeset
138 if (tv_param_width != -1)
98769cea155c added tv subsystem
alex
parents:
diff changeset
139 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
140 if (funcs->control(tvh->priv, TVI_CONTROL_VID_CHK_WIDTH, &tv_param_width) == TVI_CONTROL_TRUE)
98769cea155c added tv subsystem
alex
parents:
diff changeset
141 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
142 funcs->control(tvh->priv, TVI_CONTROL_VID_SET_WIDTH, &tv_param_width);
98769cea155c added tv subsystem
alex
parents:
diff changeset
143 sh_video->disp_w = tv_param_width;
98769cea155c added tv subsystem
alex
parents:
diff changeset
144 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
145 else
98769cea155c added tv subsystem
alex
parents:
diff changeset
146 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
147 printf("Unable set requested width: %d\n", tv_param_width);
98769cea155c added tv subsystem
alex
parents:
diff changeset
148 funcs->control(tvh->priv, TVI_CONTROL_VID_GET_WIDTH, &sh_video->disp_w);
98769cea155c added tv subsystem
alex
parents:
diff changeset
149 tv_param_width = sh_video->disp_w;
98769cea155c added tv subsystem
alex
parents:
diff changeset
150 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
151 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
152 else
98769cea155c added tv subsystem
alex
parents:
diff changeset
153 funcs->control(tvh->priv, TVI_CONTROL_VID_GET_WIDTH, &sh_video->disp_w);
98769cea155c added tv subsystem
alex
parents:
diff changeset
154
98769cea155c added tv subsystem
alex
parents:
diff changeset
155 /* set height */
98769cea155c added tv subsystem
alex
parents:
diff changeset
156 if (tv_param_height != -1)
98769cea155c added tv subsystem
alex
parents:
diff changeset
157 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
158 if (funcs->control(tvh->priv, TVI_CONTROL_VID_CHK_HEIGHT, &tv_param_height) == TVI_CONTROL_TRUE)
98769cea155c added tv subsystem
alex
parents:
diff changeset
159 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
160 funcs->control(tvh->priv, TVI_CONTROL_VID_SET_HEIGHT, &tv_param_height);
98769cea155c added tv subsystem
alex
parents:
diff changeset
161 sh_video->disp_h = tv_param_height;
98769cea155c added tv subsystem
alex
parents:
diff changeset
162 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
163 else
98769cea155c added tv subsystem
alex
parents:
diff changeset
164 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
165 printf("Unable set requested height: %d\n", tv_param_height);
98769cea155c added tv subsystem
alex
parents:
diff changeset
166 funcs->control(tvh->priv, TVI_CONTROL_VID_GET_HEIGHT, &sh_video->disp_h);
98769cea155c added tv subsystem
alex
parents:
diff changeset
167 tv_param_height = sh_video->disp_h;
98769cea155c added tv subsystem
alex
parents:
diff changeset
168 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
169 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
170 else
98769cea155c added tv subsystem
alex
parents:
diff changeset
171 funcs->control(tvh->priv, TVI_CONTROL_VID_GET_HEIGHT, &sh_video->disp_h);
98769cea155c added tv subsystem
alex
parents:
diff changeset
172
98769cea155c added tv subsystem
alex
parents:
diff changeset
173 /* emulate BITMAPINFOHEADER */
98769cea155c added tv subsystem
alex
parents:
diff changeset
174 sh_video->bih = malloc(sizeof(BITMAPINFOHEADER));
98769cea155c added tv subsystem
alex
parents:
diff changeset
175 memset(sh_video->bih, 0, sizeof(BITMAPINFOHEADER));
98769cea155c added tv subsystem
alex
parents:
diff changeset
176 sh_video->bih->biSize = 40;
98769cea155c added tv subsystem
alex
parents:
diff changeset
177 sh_video->bih->biWidth = sh_video->disp_w;
98769cea155c added tv subsystem
alex
parents:
diff changeset
178 sh_video->bih->biHeight = sh_video->disp_h;
98769cea155c added tv subsystem
alex
parents:
diff changeset
179 if (funcs->control(tvh->priv, TVI_CONTROL_VID_GET_PLANES, &sh_video->bih->biPlanes) != TVI_CONTROL_TRUE)
98769cea155c added tv subsystem
alex
parents:
diff changeset
180 sh_video->bih->biPlanes = 1;
98769cea155c added tv subsystem
alex
parents:
diff changeset
181 if (funcs->control(tvh->priv, TVI_CONTROL_VID_GET_BITS, &sh_video->bih->biBitCount) != TVI_CONTROL_TRUE)
98769cea155c added tv subsystem
alex
parents:
diff changeset
182 sh_video->bih->biBitCount = 12;
98769cea155c added tv subsystem
alex
parents:
diff changeset
183 sh_video->bih->biCompression = sh_video->format;
98769cea155c added tv subsystem
alex
parents:
diff changeset
184 sh_video->bih->biSizeImage = sh_video->bih->biWidth * sh_video->bih->biHeight * 3;
98769cea155c added tv subsystem
alex
parents:
diff changeset
185
98769cea155c added tv subsystem
alex
parents:
diff changeset
186 demuxer->video->sh = sh_video;
98769cea155c added tv subsystem
alex
parents:
diff changeset
187 sh_video->ds = demuxer->video;
98769cea155c added tv subsystem
alex
parents:
diff changeset
188 demuxer->video->id = 0;
98769cea155c added tv subsystem
alex
parents:
diff changeset
189
98769cea155c added tv subsystem
alex
parents:
diff changeset
190 /* here comes audio init */
98769cea155c added tv subsystem
alex
parents:
diff changeset
191 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
192
98769cea155c added tv subsystem
alex
parents:
diff changeset
193 /* ================== STREAM_TV ===================== */
98769cea155c added tv subsystem
alex
parents:
diff changeset
194 tvi_handle_t *tv_begin()
98769cea155c added tv subsystem
alex
parents:
diff changeset
195 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
196 if (!strcmp(tv_param_driver, "dummy"))
98769cea155c added tv subsystem
alex
parents:
diff changeset
197 return tvi_init_dummy(tv_param_device);
98769cea155c added tv subsystem
alex
parents:
diff changeset
198 if (!strcmp(tv_param_driver, "v4l"))
98769cea155c added tv subsystem
alex
parents:
diff changeset
199 return tvi_init_v4l(tv_param_device);
98769cea155c added tv subsystem
alex
parents:
diff changeset
200
98769cea155c added tv subsystem
alex
parents:
diff changeset
201 mp_msg(MSGT_TV, MSGL_ERR, "No such driver: %s\n", tv_param_driver);
98769cea155c added tv subsystem
alex
parents:
diff changeset
202 return(NULL);
98769cea155c added tv subsystem
alex
parents:
diff changeset
203 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
204
98769cea155c added tv subsystem
alex
parents:
diff changeset
205 void tv_init(tvi_handle_t *tvi)
98769cea155c added tv subsystem
alex
parents:
diff changeset
206 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
207 printf("Using driver: %s\n", tvi->info->short_name);
98769cea155c added tv subsystem
alex
parents:
diff changeset
208 printf(" name: %s\n", tvi->info->name);
98769cea155c added tv subsystem
alex
parents:
diff changeset
209 printf(" author: %s\n", tvi->info->author);
98769cea155c added tv subsystem
alex
parents:
diff changeset
210 if (tvi->info->comment)
98769cea155c added tv subsystem
alex
parents:
diff changeset
211 printf(" comment: %s\n", tvi->info->comment);
98769cea155c added tv subsystem
alex
parents:
diff changeset
212
98769cea155c added tv subsystem
alex
parents:
diff changeset
213 return tvi->functions->init(tvi->priv);
98769cea155c added tv subsystem
alex
parents:
diff changeset
214 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
215 #endif /* USE_TV */