Mercurial > mplayer.hg
annotate libmpdemux/tv.c @ 3573:1b2ee529e7b7
*** empty log message ***
author | gabucino |
---|---|
date | Tue, 18 Dec 2001 00:19:28 +0000 |
parents | a73b02e35e70 |
children | a1522fa7728a |
rev | line source |
---|---|
2790 | 1 /* |
3284 | 2 TV Interface for MPlayer |
2790 | 3 |
3284 | 4 (C) Alex Beregszaszi <alex@naxine.org> |
5 | |
6 API idea based on libvo2 | |
2790 | 7 |
2931 | 8 UNDER HEAVY DEVELOPEMENT, NO FEATURE REQUESTS PLEASE! :) |
2790 | 9 */ |
10 | |
11 #include <stdio.h> | |
12 #include <stdlib.h> | |
13 #include <unistd.h> | |
2932
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
14 #include <string.h> |
2790 | 15 |
16 #include "config.h" | |
17 | |
2819
2e58962dc9fe
cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents:
2818
diff
changeset
|
18 int tv_param_on = 0; |
2e58962dc9fe
cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents:
2818
diff
changeset
|
19 |
2790 | 20 #ifdef USE_TV |
21 #include "mp_msg.h" | |
22 #include "help_mp.h" | |
23 | |
24 #include "stream.h" | |
25 #include "demuxer.h" | |
26 #include "stheader.h" | |
2830 | 27 |
28 #include "../libao2/afmt.h" | |
29 #include "../libvo/img_format.h" | |
30 #include "../libvo/fastmemcpy.h" | |
31 | |
2802 | 32 #include "tv.h" |
2790 | 33 |
2941
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
34 #include "frequencies.h" |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
35 |
2790 | 36 /* some default values */ |
2837 | 37 char *tv_param_freq = NULL; |
3284 | 38 char *tv_param_channel = NULL; |
2790 | 39 char *tv_param_norm = "pal"; |
2941
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
40 char *tv_param_chanlist = "europe-east"; |
2790 | 41 char *tv_param_device = NULL; |
42 char *tv_param_driver = "dummy"; | |
43 int tv_param_width = -1; | |
44 int tv_param_height = -1; | |
2802 | 45 int tv_param_input = 0; /* used in v4l and bttv */ |
2817 | 46 char *tv_param_outfmt = "yv12"; |
3285 | 47 float tv_param_fps = -1.0; |
2790 | 48 |
49 /* ================== DEMUX_TV ===================== */ | |
50 /* | |
51 Return value: | |
52 0 = EOF(?) or no stream | |
53 1 = successfully read a packet | |
54 */ | |
55 /* fill demux->video and demux->audio */ | |
2802 | 56 int demux_tv_fill_buffer(demuxer_t *demux, tvi_handle_t *tvh) |
2790 | 57 { |
2810 | 58 int seq = tvh->seq++; |
2813 | 59 demux_packet_t* dp; |
60 int len; | |
2932
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
61 sh_video_t *sh_video = demux->video->sh; |
2790 | 62 |
2931 | 63 mp_dbg(MSGT_DEMUX, MSGL_DBG2, "demux_tv_fill_buffer(sequence:%d) called!\n", seq); |
2802 | 64 |
2813 | 65 // demux->filepos = -1; |
2790 | 66 |
2810 | 67 // seq++; |
68 // tvh->seq++; | |
2802 | 69 |
2790 | 70 /* ================== ADD VIDEO PACKET =================== */ |
2813 | 71 len = tvh->functions->get_video_framesize(tvh->priv); |
2790 | 72 |
2813 | 73 dp=new_demux_packet(len); |
74 tvh->functions->grab_video_frame(tvh->priv, dp->buffer, len); | |
2932
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
75 dp->pts=seq/sh_video->fps; //(float)pts/90000.0f; |
2813 | 76 //dp->pos=pos; |
77 //dp->flags=flags; | |
78 // append packet to DS stream: | |
79 ds_add_packet(demux->video,dp); | |
2790 | 80 |
81 /* ================== ADD AUDIO PACKET =================== */ | |
2802 | 82 if (tvh->functions->control(tvh->priv, TVI_CONTROL_IS_AUDIO, 0) != TVI_CONTROL_TRUE) |
83 return 1; /* no audio, only video */ | |
84 | |
2813 | 85 len = tvh->functions->get_audio_framesize(tvh->priv); |
86 | |
87 dp=new_demux_packet(len); | |
88 tvh->functions->grab_audio_frame(tvh->priv, dp->buffer, len); | |
89 //dp->pts=pts; //(float)pts/90000.0f; | |
90 //dp->pos=pos; | |
91 //dp->flags=flags; | |
92 // append packet to DS stream: | |
93 ds_add_packet(demux->audio,dp); | |
2790 | 94 |
95 return 1; | |
96 } | |
97 | |
2931 | 98 int stream_open_tv(stream_t *stream, tvi_handle_t *tvh) |
99 { | |
2941
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
100 int i; |
2932
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
101 tvi_functions_t *funcs = tvh->functions; |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
102 int picture_format = 0; |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
103 |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
104 if (funcs->control(tvh->priv, TVI_CONTROL_IS_VIDEO, 0) != TVI_CONTROL_TRUE) |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
105 { |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
106 mp_msg(MSGT_TV, MSGL_ERR, "Error: no video input present!\n"); |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
107 return; |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
108 } |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
109 |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
110 if (!strcasecmp(tv_param_outfmt, "yv12")) |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
111 picture_format = IMGFMT_YV12; |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
112 else if (!strcasecmp(tv_param_outfmt, "uyvy")) |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
113 picture_format = IMGFMT_UYVY; |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
114 else if (!strcasecmp(tv_param_outfmt, "rgb32")) |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
115 picture_format = IMGFMT_RGB32; |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
116 else if (!strcasecmp(tv_param_outfmt, "rgb24")) |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
117 picture_format = IMGFMT_RGB24; |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
118 else if (!strcasecmp(tv_param_outfmt, "rgb16")) |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
119 picture_format = IMGFMT_RGB16; |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
120 else if (!strcasecmp(tv_param_outfmt, "rgb15")) |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
121 picture_format = IMGFMT_RGB15; |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
122 else |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
123 { |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
124 mp_msg(MSGT_TV, MSGL_ERR, "Unknown format given: %s\n", tv_param_outfmt); |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
125 mp_msg(MSGT_TV, MSGL_INFO, "Using default: Planar YV12\n"); |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
126 picture_format = IMGFMT_YV12; |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
127 } |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
128 funcs->control(tvh->priv, TVI_CONTROL_VID_SET_FORMAT, &picture_format); |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
129 |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
130 /* set width */ |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
131 if (tv_param_width != -1) |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
132 { |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
133 if (funcs->control(tvh->priv, TVI_CONTROL_VID_CHK_WIDTH, &tv_param_width) == TVI_CONTROL_TRUE) |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
134 funcs->control(tvh->priv, TVI_CONTROL_VID_SET_WIDTH, &tv_param_width); |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
135 else |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
136 { |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
137 mp_msg(MSGT_TV, MSGL_ERR, "Unable set requested width: %d\n", tv_param_width); |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
138 funcs->control(tvh->priv, TVI_CONTROL_VID_GET_WIDTH, &tv_param_width); |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
139 } |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
140 } |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
141 |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
142 /* set height */ |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
143 if (tv_param_height != -1) |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
144 { |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
145 if (funcs->control(tvh->priv, TVI_CONTROL_VID_CHK_HEIGHT, &tv_param_height) == TVI_CONTROL_TRUE) |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
146 funcs->control(tvh->priv, TVI_CONTROL_VID_SET_HEIGHT, &tv_param_height); |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
147 else |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
148 { |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
149 mp_msg(MSGT_TV, MSGL_ERR, "Unable set requested height: %d\n", tv_param_height); |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
150 funcs->control(tvh->priv, TVI_CONTROL_VID_GET_HEIGHT, &tv_param_height); |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
151 } |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
152 } |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
153 |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
154 /* set some params got from cmdline */ |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
155 funcs->control(tvh->priv, TVI_CONTROL_SPC_SET_INPUT, &tv_param_input); |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
156 |
2941
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
157 /* select video norm */ |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
158 if (!strcasecmp(tv_param_norm, "pal")) |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
159 tvh->norm = TV_NORM_PAL; |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
160 else if (!strcasecmp(tv_param_norm, "ntsc")) |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
161 tvh->norm = TV_NORM_NTSC; |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
162 else if (!strcasecmp(tv_param_norm, "secam")) |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
163 tvh->norm = TV_NORM_SECAM; |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
164 |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
165 mp_msg(MSGT_TV, MSGL_INFO, "Selected norm: %s\n", tv_param_norm); |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
166 |
3284 | 167 if (funcs->control(tvh->priv, TVI_CONTROL_IS_TUNER, 0) != TVI_CONTROL_TRUE) |
168 { | |
169 mp_msg(MSGT_TV, MSGL_WARN, "Selected input hasn't got a tuner!\n"); | |
170 goto start_device; | |
171 } | |
172 | |
2941
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
173 /* select channel list */ |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
174 for (i = 0; chanlists[i].name != NULL; i++) |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
175 { |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
176 if (!strcasecmp(chanlists[i].name, tv_param_chanlist)) |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
177 { |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
178 tvh->chanlist = i; |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
179 tvh->chanlist_s = chanlists[i].list; |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
180 break; |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
181 } |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
182 } |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
183 |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
184 if (tvh->chanlist == -1) |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
185 mp_msg(MSGT_TV, MSGL_WARN, "Unable to find selected channel list! (%s)\n", |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
186 tv_param_chanlist); |
3284 | 187 else |
188 mp_msg(MSGT_TV, MSGL_INFO, "Selected channel list: %s (including %d channels)\n", | |
189 chanlists[tvh->chanlist].name, chanlists[tvh->chanlist].count); | |
2941
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
190 |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
191 if (tv_param_freq && tv_param_channel) |
3284 | 192 { |
193 mp_msg(MSGT_TV, MSGL_WARN, "You can't set frequency and channel simultanly!\n"); | |
194 goto start_device; | |
195 } | |
196 | |
197 /* we need to set frequency */ | |
198 if (tv_param_freq) | |
199 { | |
200 unsigned long freq = atof(tv_param_freq)*16; | |
2941
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
201 |
3284 | 202 /* set freq in MHz */ |
203 funcs->control(tvh->priv, TVI_CONTROL_TUN_SET_FREQ, &freq); | |
204 | |
205 funcs->control(tvh->priv, TVI_CONTROL_TUN_GET_FREQ, &freq); | |
206 mp_msg(MSGT_TV, MSGL_INFO, "Selected frequency: %lu (%.3f)\n", | |
207 freq, (float)freq/16); | |
208 } | |
209 | |
210 if (tv_param_channel) | |
2941
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
211 { |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
212 struct CHANLIST cl; |
3284 | 213 |
214 mp_msg(MSGT_TV, MSGL_V, "Requested channel: %s\n", tv_param_channel); | |
2941
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
215 for (i = 0; i < chanlists[tvh->chanlist].count; i++) |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
216 { |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
217 cl = tvh->chanlist_s[i]; |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
218 // printf("count%d: name: %s, freq: %d\n", |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
219 // i, cl.name, cl.freq); |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
220 if (!strcasecmp(cl.name, tv_param_channel)) |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
221 { |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
222 tvh->channel = i; |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
223 mp_msg(MSGT_TV, MSGL_INFO, "Selected channel: %s (freq: %.3f)\n", |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
224 cl.name, (float)cl.freq/1000); |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
225 tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16)); |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
226 break; |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
227 } |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
228 } |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
229 } |
3284 | 230 |
231 start_device: | |
2932
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
232 /* also start device! */ |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
233 return(funcs->start(tvh->priv)); |
2931 | 234 } |
235 | |
2802 | 236 int demux_open_tv(demuxer_t *demuxer, tvi_handle_t *tvh) |
2790 | 237 { |
2802 | 238 sh_video_t *sh_video = NULL; |
239 sh_audio_t *sh_audio = NULL; | |
2790 | 240 tvi_functions_t *funcs = tvh->functions; |
241 | |
2802 | 242 sh_video = new_sh_video(demuxer, 0); |
2790 | 243 |
2932
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
244 /* get IMAGE FORMAT */ |
2802 | 245 funcs->control(tvh->priv, TVI_CONTROL_VID_GET_FORMAT, &sh_video->format); |
2810 | 246 // if (IMGFMT_IS_RGB(sh_video->format) || IMGFMT_IS_BGR(sh_video->format)) |
3398 | 247 // sh_video->format = 0x0; |
2802 | 248 |
249 /* set FPS and FRAMETIME */ | |
2790 | 250 if(!sh_video->fps) |
251 { | |
252 if (funcs->control(tvh->priv, TVI_CONTROL_VID_GET_FPS, &sh_video->fps) != TVI_CONTROL_TRUE) | |
2932
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
253 sh_video->fps = 25.0f; /* on PAL */ |
3285 | 254 } |
255 if (tv_param_fps != -1.0f) | |
256 sh_video->fps = tv_param_fps; | |
2790 | 257 sh_video->frametime = 1.0f/sh_video->fps; |
258 | |
259 /* set width */ | |
2932
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
260 funcs->control(tvh->priv, TVI_CONTROL_VID_GET_WIDTH, &sh_video->disp_w); |
2790 | 261 |
262 /* set height */ | |
2932
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
263 funcs->control(tvh->priv, TVI_CONTROL_VID_GET_HEIGHT, &sh_video->disp_h); |
2802 | 264 |
2818 | 265 mp_msg(MSGT_TV, MSGL_INFO, "Output size: %dx%d\n", sh_video->disp_w, sh_video->disp_h); |
2790 | 266 |
267 demuxer->video->sh = sh_video; | |
268 sh_video->ds = demuxer->video; | |
269 demuxer->video->id = 0; | |
2932
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
270 |
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
271 // demuxer->seekable = 0; |
2790 | 272 |
273 /* here comes audio init */ | |
2802 | 274 if (funcs->control(tvh->priv, TVI_CONTROL_IS_AUDIO, 0) == TVI_CONTROL_TRUE) |
275 { | |
276 int audio_format; | |
277 | |
278 sh_audio = new_sh_audio(demuxer, 0); | |
279 | |
280 sh_audio->wf = malloc(sizeof(WAVEFORMATEX)); | |
281 memset(sh_audio->wf, 0, sizeof(WAVEFORMATEX)); | |
282 | |
283 /* yeah, audio is present */ | |
284 if (funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_FORMAT, &audio_format) != TVI_CONTROL_TRUE) | |
285 goto no_audio; | |
286 switch(audio_format) | |
287 { | |
288 case AFMT_U8: | |
289 case AFMT_S8: | |
290 case AFMT_U16_LE: | |
291 case AFMT_U16_BE: | |
292 case AFMT_S16_LE: | |
293 case AFMT_S16_BE: | |
294 case AFMT_S32_LE: | |
295 case AFMT_S32_BE: | |
296 sh_audio->format = 0x1; /* PCM */ | |
297 break; | |
298 case AFMT_IMA_ADPCM: | |
299 case AFMT_MU_LAW: | |
300 case AFMT_A_LAW: | |
301 case AFMT_MPEG: | |
302 case AFMT_AC3: | |
303 default: | |
2818 | 304 mp_msg(MSGT_TV, MSGL_ERR, "Audio type '%s' unsupported!\n", audio_out_format_name(audio_format)); |
2802 | 305 goto no_audio; |
306 } | |
307 | |
308 funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_CHANNELS, &sh_audio->wf->nChannels); | |
309 funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_SAMPLERATE, &sh_audio->wf->nSamplesPerSec); | |
310 funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_SAMPLESIZE, &sh_audio->wf->nAvgBytesPerSec); | |
311 | |
312 demuxer->audio->sh = sh_audio; | |
313 sh_audio->ds = demuxer->audio; | |
314 demuxer->audio->id = 0; | |
315 } | |
316 no_audio: | |
317 | |
2932
fa3224774679
splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents:
2931
diff
changeset
|
318 return(1); |
2790 | 319 } |
320 | |
321 /* ================== STREAM_TV ===================== */ | |
2802 | 322 tvi_handle_t *tv_begin(void) |
2790 | 323 { |
324 if (!strcmp(tv_param_driver, "dummy")) | |
2802 | 325 return (tvi_handle_t *)tvi_init_dummy(tv_param_device); |
3249 | 326 #ifdef HAVE_TV_V4L |
2790 | 327 if (!strcmp(tv_param_driver, "v4l")) |
2802 | 328 return (tvi_handle_t *)tvi_init_v4l(tv_param_device); |
3249 | 329 #endif |
2790 | 330 |
331 mp_msg(MSGT_TV, MSGL_ERR, "No such driver: %s\n", tv_param_driver); | |
332 return(NULL); | |
333 } | |
334 | |
2802 | 335 int tv_init(tvi_handle_t *tvh) |
2790 | 336 { |
2802 | 337 tvi_param_t *params; |
338 | |
2818 | 339 mp_msg(MSGT_TV, MSGL_INFO, "Selected driver: %s\n", tvh->info->short_name); |
340 mp_msg(MSGT_TV, MSGL_INFO, " name: %s\n", tvh->info->name); | |
341 mp_msg(MSGT_TV, MSGL_INFO, " author: %s\n", tvh->info->author); | |
2802 | 342 if (tvh->info->comment) |
2818 | 343 mp_msg(MSGT_TV, MSGL_INFO, " comment: %s\n", tvh->info->comment); |
2790 | 344 |
2802 | 345 params = malloc(sizeof(tvi_param_t)*2); |
346 params[0].opt = malloc(strlen("input")); | |
347 sprintf((char *)params[0].opt, "input"); | |
348 params[0].value = malloc(sizeof(int)); | |
349 (int)*(void **)params[0].value = tv_param_input; | |
350 params[1].opt = params[1].value = NULL; | |
351 | |
2837 | 352 return(tvh->functions->init(tvh->priv, params)); |
353 } | |
354 | |
355 int tv_uninit(tvi_handle_t *tvh) | |
356 { | |
357 return(tvh->functions->uninit(tvh->priv)); | |
2790 | 358 } |
2937 | 359 |
360 /* utilities for mplayer (not mencoder!!) */ | |
361 int tv_set_color_options(tvi_handle_t *tvh, int opt, int value) | |
362 { | |
363 tvi_functions_t *funcs = tvh->functions; | |
364 | |
365 switch(opt) | |
366 { | |
367 case TV_COLOR_BRIGHTNESS: | |
368 if (value == 50) | |
369 value = 32768; | |
370 if (value > 50) | |
371 { | |
372 value *= 100; | |
373 value += 32768; | |
374 } | |
375 if (value < 50) | |
376 { | |
377 int i; | |
378 value *= 100; | |
379 i = value; | |
380 value = 32768 - i; | |
381 } | |
382 funcs->control(tvh->priv, TVI_CONTROL_VID_SET_BRIGHTNESS, &value); | |
383 break; | |
384 case TV_COLOR_HUE: | |
385 if (value == 50) | |
386 value = 32768; | |
387 if (value > 50) | |
388 { | |
389 value *= 100; | |
390 value += 32768; | |
391 } | |
392 if (value < 50) | |
393 { | |
394 int i; | |
395 value *= 100; | |
396 i = value; | |
397 value = 32768 - i; | |
398 } | |
399 funcs->control(tvh->priv, TVI_CONTROL_VID_SET_HUE, &value); | |
400 break; | |
401 case TV_COLOR_SATURATION: | |
402 if (value == 50) | |
403 value = 32512; | |
404 if (value > 50) | |
405 { | |
406 value *= 100; | |
407 value += 32512; | |
408 } | |
409 if (value < 50) | |
410 { | |
411 int i; | |
412 value *= 100; | |
413 i = value; | |
414 value = 32512 - i; | |
415 } | |
416 funcs->control(tvh->priv, TVI_CONTROL_VID_SET_SATURATION, &value); | |
417 break; | |
418 case TV_COLOR_CONTRAST: | |
419 if (value == 50) | |
420 value = 27648; | |
421 if (value > 50) | |
422 { | |
423 value *= 100; | |
424 value += 27648; | |
425 } | |
426 if (value < 50) | |
427 { | |
428 int i; | |
429 value *= 100; | |
430 i = value; | |
431 value = 27648 - i; | |
432 } | |
433 funcs->control(tvh->priv, TVI_CONTROL_VID_SET_CONTRAST, &value); | |
434 break; | |
435 default: | |
436 mp_msg(MSGT_TV, MSGL_WARN, "Unknown color option (%d) specified!\n", opt); | |
437 } | |
438 | |
439 return(1); | |
440 } | |
2941
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
441 |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
442 int tv_set_freq(tvi_handle_t *tvh, unsigned long freq) |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
443 { |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
444 if (tvh->functions->control(tvh->priv, TVI_CONTROL_IS_TUNER, 0) == TVI_CONTROL_TRUE) |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
445 { |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
446 // unsigned long freq = atof(tv_param_freq)*16; |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
447 |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
448 /* set freq in MHz */ |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
449 tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_SET_FREQ, &freq); |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
450 |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
451 tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_GET_FREQ, &freq); |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
452 mp_msg(MSGT_TV, MSGL_INFO, "Current frequency: %lu (%.3f)\n", |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
453 freq, (float)freq/16); |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
454 } |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
455 } |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
456 |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
457 int tv_step_channel(tvi_handle_t *tvh, int direction) |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
458 { |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
459 struct CHANLIST cl; |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
460 |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
461 if (direction == TV_CHANNEL_LOWER) |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
462 { |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
463 if (tvh->channel-1 >= 0) |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
464 { |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
465 cl = tvh->chanlist_s[tvh->channel--]; |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
466 mp_msg(MSGT_TV, MSGL_INFO, "Selected channel: %s (freq: %.3f)\n", |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
467 cl.name, (float)cl.freq/1000); |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
468 tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16)); |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
469 } |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
470 } |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
471 |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
472 if (direction == TV_CHANNEL_HIGHER) |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
473 { |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
474 if (tvh->channel+1 <= chanlists[tvh->chanlist].count) |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
475 { |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
476 cl = tvh->chanlist_s[tvh->channel++]; |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
477 mp_msg(MSGT_TV, MSGL_INFO, "Selected channel: %s (freq: %.3f)\n", |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
478 cl.name, (float)cl.freq/1000); |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
479 tv_set_freq(tvh, (unsigned long)(((float)cl.freq/1000)*16)); |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
480 } |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
481 } |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
482 } |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
483 |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
484 int tv_step_norm(tvi_handle_t *tvh) |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
485 { |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
486 } |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
487 |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
488 int tv_step_chanlist(tvi_handle_t *tvh) |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
489 { |
60c1b7c0ea21
added support for norm=,chanlist=,channel= and also on-the-fly channel chaning with keys
alex
parents:
2937
diff
changeset
|
490 } |
2790 | 491 #endif /* USE_TV */ |