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