annotate libmpdemux/tv.c @ 2937:4307478ad922

added support for setting color values
author alex
date Fri, 16 Nov 2001 22:59:07 +0000
parents fa3224774679
children 60c1b7c0ea21
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
2931
bce9c945b29c tv interface update
alex
parents: 2842
diff changeset
6 UNDER HEAVY DEVELOPEMENT, NO FEATURE REQUESTS PLEASE! :)
2790
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>
2932
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
12 #include <string.h>
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
13
98769cea155c added tv subsystem
alex
parents:
diff changeset
14 #include "config.h"
98769cea155c added tv subsystem
alex
parents:
diff changeset
15
2819
2e58962dc9fe cleaned up some warnings, and tv_param_on moved out from #ifdef USE_TV
alex
parents: 2818
diff changeset
16 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
17
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
18 #ifdef USE_TV
98769cea155c added tv subsystem
alex
parents:
diff changeset
19 #include "mp_msg.h"
98769cea155c added tv subsystem
alex
parents:
diff changeset
20 #include "help_mp.h"
98769cea155c added tv subsystem
alex
parents:
diff changeset
21
98769cea155c added tv subsystem
alex
parents:
diff changeset
22 #include "stream.h"
98769cea155c added tv subsystem
alex
parents:
diff changeset
23 #include "demuxer.h"
98769cea155c added tv subsystem
alex
parents:
diff changeset
24 #include "stheader.h"
2830
596a6ba3520f never include files from public headers...
arpi
parents: 2819
diff changeset
25
596a6ba3520f never include files from public headers...
arpi
parents: 2819
diff changeset
26 #include "../libao2/afmt.h"
596a6ba3520f never include files from public headers...
arpi
parents: 2819
diff changeset
27 #include "../libvo/img_format.h"
596a6ba3520f never include files from public headers...
arpi
parents: 2819
diff changeset
28 #include "../libvo/fastmemcpy.h"
596a6ba3520f never include files from public headers...
arpi
parents: 2819
diff changeset
29
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
30 #include "tv.h"
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
31
98769cea155c added tv subsystem
alex
parents:
diff changeset
32 /* some default values */
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
33 char *tv_param_freq = NULL;
2932
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
34 char *tv_param_channel = "26"; /* hungarian national tv channel 1 */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
35 char *tv_param_norm = "pal";
98769cea155c added tv subsystem
alex
parents:
diff changeset
36 char *tv_param_device = NULL;
98769cea155c added tv subsystem
alex
parents:
diff changeset
37 char *tv_param_driver = "dummy";
98769cea155c added tv subsystem
alex
parents:
diff changeset
38 int tv_param_width = -1;
98769cea155c added tv subsystem
alex
parents:
diff changeset
39 int tv_param_height = -1;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
40 int tv_param_input = 0; /* used in v4l and bttv */
2817
cc93d9786954 added support for -tv outfmt
alex
parents: 2813
diff changeset
41 char *tv_param_outfmt = "yv12";
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
42
98769cea155c added tv subsystem
alex
parents:
diff changeset
43
98769cea155c added tv subsystem
alex
parents:
diff changeset
44 /* ================== DEMUX_TV ===================== */
98769cea155c added tv subsystem
alex
parents:
diff changeset
45 /*
98769cea155c added tv subsystem
alex
parents:
diff changeset
46 Return value:
98769cea155c added tv subsystem
alex
parents:
diff changeset
47 0 = EOF(?) or no stream
98769cea155c added tv subsystem
alex
parents:
diff changeset
48 1 = successfully read a packet
98769cea155c added tv subsystem
alex
parents:
diff changeset
49 */
98769cea155c added tv subsystem
alex
parents:
diff changeset
50 /* fill demux->video and demux->audio */
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
51 int demux_tv_fill_buffer(demuxer_t *demux, tvi_handle_t *tvh)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
52 {
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
53 int seq = tvh->seq++;
2813
d6d88771f5ef demuxer fixed
arpi
parents: 2810
diff changeset
54 demux_packet_t* dp;
d6d88771f5ef demuxer fixed
arpi
parents: 2810
diff changeset
55 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
56 sh_video_t *sh_video = demux->video->sh;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
57
2931
bce9c945b29c tv interface update
alex
parents: 2842
diff changeset
58 mp_dbg(MSGT_DEMUX, MSGL_DBG2, "demux_tv_fill_buffer(sequence:%d) called!\n", seq);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
59
2813
d6d88771f5ef demuxer fixed
arpi
parents: 2810
diff changeset
60 // demux->filepos = -1;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
61
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
62 // seq++;
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
63 // tvh->seq++;
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
64
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
65 /* ================== ADD VIDEO PACKET =================== */
2813
d6d88771f5ef demuxer fixed
arpi
parents: 2810
diff changeset
66 len = tvh->functions->get_video_framesize(tvh->priv);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
67
2813
d6d88771f5ef demuxer fixed
arpi
parents: 2810
diff changeset
68 dp=new_demux_packet(len);
d6d88771f5ef demuxer fixed
arpi
parents: 2810
diff changeset
69 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
70 dp->pts=seq/sh_video->fps; //(float)pts/90000.0f;
2813
d6d88771f5ef demuxer fixed
arpi
parents: 2810
diff changeset
71 //dp->pos=pos;
d6d88771f5ef demuxer fixed
arpi
parents: 2810
diff changeset
72 //dp->flags=flags;
d6d88771f5ef demuxer fixed
arpi
parents: 2810
diff changeset
73 // append packet to DS stream:
d6d88771f5ef demuxer fixed
arpi
parents: 2810
diff changeset
74 ds_add_packet(demux->video,dp);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
75
98769cea155c added tv subsystem
alex
parents:
diff changeset
76 /* ================== ADD AUDIO PACKET =================== */
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
77 if (tvh->functions->control(tvh->priv, TVI_CONTROL_IS_AUDIO, 0) != TVI_CONTROL_TRUE)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
78 return 1; /* no audio, only video */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
79
2813
d6d88771f5ef demuxer fixed
arpi
parents: 2810
diff changeset
80 len = tvh->functions->get_audio_framesize(tvh->priv);
d6d88771f5ef demuxer fixed
arpi
parents: 2810
diff changeset
81
d6d88771f5ef demuxer fixed
arpi
parents: 2810
diff changeset
82 dp=new_demux_packet(len);
d6d88771f5ef demuxer fixed
arpi
parents: 2810
diff changeset
83 tvh->functions->grab_audio_frame(tvh->priv, dp->buffer, len);
d6d88771f5ef demuxer fixed
arpi
parents: 2810
diff changeset
84 //dp->pts=pts; //(float)pts/90000.0f;
d6d88771f5ef demuxer fixed
arpi
parents: 2810
diff changeset
85 //dp->pos=pos;
d6d88771f5ef demuxer fixed
arpi
parents: 2810
diff changeset
86 //dp->flags=flags;
d6d88771f5ef demuxer fixed
arpi
parents: 2810
diff changeset
87 // append packet to DS stream:
d6d88771f5ef demuxer fixed
arpi
parents: 2810
diff changeset
88 ds_add_packet(demux->audio,dp);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
89
98769cea155c added tv subsystem
alex
parents:
diff changeset
90 return 1;
98769cea155c added tv subsystem
alex
parents:
diff changeset
91 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
92
2931
bce9c945b29c tv interface update
alex
parents: 2842
diff changeset
93 int stream_open_tv(stream_t *stream, tvi_handle_t *tvh)
bce9c945b29c tv interface update
alex
parents: 2842
diff changeset
94 {
2932
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
95 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
96 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
97
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
98 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
99 {
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
100 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
101 return;
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
102 }
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 (!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
105 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
106 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
107 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
108 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
109 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
110 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
111 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
112 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
113 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
114 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
115 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
116 else
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
117 {
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
118 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
119 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
120 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
121 }
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
122 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
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 /* 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
125 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
126 {
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
127 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
128 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
129 else
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
130 {
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
131 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
132 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
133 }
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
134 }
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
135
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
136 /* 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
137 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
138 {
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
139 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
140 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
141 else
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
142 {
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
143 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
144 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
145 }
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
146 }
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
147
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
148 /* 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
149 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
150
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
151 /* we need to set frequency */
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
152 if (tv_param_freq && (funcs->control(tvh->priv, TVI_CONTROL_IS_TUNER, 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
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 unsigned long freq = atof(tv_param_freq)*16;
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
155
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
156 /* set freq in MHz */
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
157 funcs->control(tvh->priv, TVI_CONTROL_TUN_SET_FREQ, &freq);
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
158
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
159 funcs->control(tvh->priv, TVI_CONTROL_TUN_GET_FREQ, &freq);
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
160 mp_msg(MSGT_TV, MSGL_INFO, "Current frequency: %lu (%.3f)\n",
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
161 freq, (float)freq/16);
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
162 }
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
163
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
164 /* 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
165 return(funcs->start(tvh->priv));
2931
bce9c945b29c tv interface update
alex
parents: 2842
diff changeset
166 }
bce9c945b29c tv interface update
alex
parents: 2842
diff changeset
167
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
168 int demux_open_tv(demuxer_t *demuxer, tvi_handle_t *tvh)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
169 {
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
170 sh_video_t *sh_video = NULL;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
171 sh_audio_t *sh_audio = NULL;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
172 tvi_functions_t *funcs = tvh->functions;
98769cea155c added tv subsystem
alex
parents:
diff changeset
173
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
174 sh_video = new_sh_video(demuxer, 0);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
175
2932
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
176 /* get IMAGE FORMAT */
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
177 funcs->control(tvh->priv, TVI_CONTROL_VID_GET_FORMAT, &sh_video->format);
2810
1f0bcdb49910 tv update
alex
parents: 2802
diff changeset
178 // if (IMGFMT_IS_RGB(sh_video->format) || IMGFMT_IS_BGR(sh_video->format))
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
179 sh_video->format = 0x0;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
180
09d5c9834580 tv update
alex
parents: 2790
diff changeset
181 /* set FPS and FRAMETIME */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
182 if(!sh_video->fps)
98769cea155c added tv subsystem
alex
parents:
diff changeset
183 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
184 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
185 sh_video->fps = 25.0f; /* on PAL */
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
186 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
187 sh_video->frametime = 1.0f/sh_video->fps;
98769cea155c added tv subsystem
alex
parents:
diff changeset
188
98769cea155c added tv subsystem
alex
parents:
diff changeset
189 /* 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
190 funcs->control(tvh->priv, TVI_CONTROL_VID_GET_WIDTH, &sh_video->disp_w);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
191
98769cea155c added tv subsystem
alex
parents:
diff changeset
192 /* 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
193 funcs->control(tvh->priv, TVI_CONTROL_VID_GET_HEIGHT, &sh_video->disp_h);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
194
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2817
diff changeset
195 mp_msg(MSGT_TV, MSGL_INFO, "Output size: %dx%d\n", sh_video->disp_w, sh_video->disp_h);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
196
98769cea155c added tv subsystem
alex
parents:
diff changeset
197 demuxer->video->sh = sh_video;
98769cea155c added tv subsystem
alex
parents:
diff changeset
198 sh_video->ds = demuxer->video;
98769cea155c added tv subsystem
alex
parents:
diff changeset
199 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
200
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
201 // demuxer->seekable = 0;
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
202
98769cea155c added tv subsystem
alex
parents:
diff changeset
203 /* here comes audio init */
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
204 if (funcs->control(tvh->priv, TVI_CONTROL_IS_AUDIO, 0) == TVI_CONTROL_TRUE)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
205 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
206 int audio_format;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
207
09d5c9834580 tv update
alex
parents: 2790
diff changeset
208 sh_audio = new_sh_audio(demuxer, 0);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
209
09d5c9834580 tv update
alex
parents: 2790
diff changeset
210 sh_audio->wf = malloc(sizeof(WAVEFORMATEX));
09d5c9834580 tv update
alex
parents: 2790
diff changeset
211 memset(sh_audio->wf, 0, sizeof(WAVEFORMATEX));
09d5c9834580 tv update
alex
parents: 2790
diff changeset
212
09d5c9834580 tv update
alex
parents: 2790
diff changeset
213 /* yeah, audio is present */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
214 if (funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_FORMAT, &audio_format) != TVI_CONTROL_TRUE)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
215 goto no_audio;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
216 switch(audio_format)
09d5c9834580 tv update
alex
parents: 2790
diff changeset
217 {
09d5c9834580 tv update
alex
parents: 2790
diff changeset
218 case AFMT_U8:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
219 case AFMT_S8:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
220 case AFMT_U16_LE:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
221 case AFMT_U16_BE:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
222 case AFMT_S16_LE:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
223 case AFMT_S16_BE:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
224 case AFMT_S32_LE:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
225 case AFMT_S32_BE:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
226 sh_audio->format = 0x1; /* PCM */
09d5c9834580 tv update
alex
parents: 2790
diff changeset
227 break;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
228 case AFMT_IMA_ADPCM:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
229 case AFMT_MU_LAW:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
230 case AFMT_A_LAW:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
231 case AFMT_MPEG:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
232 case AFMT_AC3:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
233 default:
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2817
diff changeset
234 mp_msg(MSGT_TV, MSGL_ERR, "Audio type '%s' unsupported!\n", audio_out_format_name(audio_format));
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
235 goto no_audio;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
236 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
237
09d5c9834580 tv update
alex
parents: 2790
diff changeset
238 funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_CHANNELS, &sh_audio->wf->nChannels);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
239 funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_SAMPLERATE, &sh_audio->wf->nSamplesPerSec);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
240 funcs->control(tvh->priv, TVI_CONTROL_AUD_GET_SAMPLESIZE, &sh_audio->wf->nAvgBytesPerSec);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
241
09d5c9834580 tv update
alex
parents: 2790
diff changeset
242 demuxer->audio->sh = sh_audio;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
243 sh_audio->ds = demuxer->audio;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
244 demuxer->audio->id = 0;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
245 }
09d5c9834580 tv update
alex
parents: 2790
diff changeset
246 no_audio:
09d5c9834580 tv update
alex
parents: 2790
diff changeset
247
2932
fa3224774679 splitted demux_open_tv into two parts: stream_open_tv and demux_open_tv to support caching
alex
parents: 2931
diff changeset
248 return(1);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
249 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
250
98769cea155c added tv subsystem
alex
parents:
diff changeset
251 /* ================== STREAM_TV ===================== */
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
252 tvi_handle_t *tv_begin(void)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
253 {
98769cea155c added tv subsystem
alex
parents:
diff changeset
254 if (!strcmp(tv_param_driver, "dummy"))
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
255 return (tvi_handle_t *)tvi_init_dummy(tv_param_device);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
256 if (!strcmp(tv_param_driver, "v4l"))
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
257 return (tvi_handle_t *)tvi_init_v4l(tv_param_device);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
258
98769cea155c added tv subsystem
alex
parents:
diff changeset
259 mp_msg(MSGT_TV, MSGL_ERR, "No such driver: %s\n", tv_param_driver);
98769cea155c added tv subsystem
alex
parents:
diff changeset
260 return(NULL);
98769cea155c added tv subsystem
alex
parents:
diff changeset
261 }
98769cea155c added tv subsystem
alex
parents:
diff changeset
262
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
263 int tv_init(tvi_handle_t *tvh)
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
264 {
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
265 tvi_param_t *params;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
266
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2817
diff changeset
267 mp_msg(MSGT_TV, MSGL_INFO, "Selected driver: %s\n", tvh->info->short_name);
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2817
diff changeset
268 mp_msg(MSGT_TV, MSGL_INFO, " name: %s\n", tvh->info->name);
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2817
diff changeset
269 mp_msg(MSGT_TV, MSGL_INFO, " author: %s\n", tvh->info->author);
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
270 if (tvh->info->comment)
2818
9f68d309f8cb printf's changed into mp_msg
alex
parents: 2817
diff changeset
271 mp_msg(MSGT_TV, MSGL_INFO, " comment: %s\n", tvh->info->comment);
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
272
2802
09d5c9834580 tv update
alex
parents: 2790
diff changeset
273 params = malloc(sizeof(tvi_param_t)*2);
09d5c9834580 tv update
alex
parents: 2790
diff changeset
274 params[0].opt = malloc(strlen("input"));
09d5c9834580 tv update
alex
parents: 2790
diff changeset
275 sprintf((char *)params[0].opt, "input");
09d5c9834580 tv update
alex
parents: 2790
diff changeset
276 params[0].value = malloc(sizeof(int));
09d5c9834580 tv update
alex
parents: 2790
diff changeset
277 (int)*(void **)params[0].value = tv_param_input;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
278 params[1].opt = params[1].value = NULL;
09d5c9834580 tv update
alex
parents: 2790
diff changeset
279
2837
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
280 return(tvh->functions->init(tvh->priv, params));
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
281 }
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
282
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
283 int tv_uninit(tvi_handle_t *tvh)
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
284 {
c63562f5f56f tuning worx (can set frequency)
alex
parents: 2830
diff changeset
285 return(tvh->functions->uninit(tvh->priv));
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
286 }
2937
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
287
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
288 /* utilities for mplayer (not mencoder!!) */
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
289 int tv_set_color_options(tvi_handle_t *tvh, int opt, int value)
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
290 {
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
291 tvi_functions_t *funcs = tvh->functions;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
292
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
293 switch(opt)
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
294 {
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
295 case TV_COLOR_BRIGHTNESS:
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
296 if (value == 50)
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
297 value = 32768;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
298 if (value > 50)
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
299 {
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
300 value *= 100;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
301 value += 32768;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
302 }
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
303 if (value < 50)
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
304 {
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
305 int i;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
306 value *= 100;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
307 i = value;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
308 value = 32768 - i;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
309 }
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
310 funcs->control(tvh->priv, TVI_CONTROL_VID_SET_BRIGHTNESS, &value);
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
311 break;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
312 case TV_COLOR_HUE:
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
313 if (value == 50)
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
314 value = 32768;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
315 if (value > 50)
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
316 {
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
317 value *= 100;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
318 value += 32768;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
319 }
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
320 if (value < 50)
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
321 {
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
322 int i;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
323 value *= 100;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
324 i = value;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
325 value = 32768 - i;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
326 }
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
327 funcs->control(tvh->priv, TVI_CONTROL_VID_SET_HUE, &value);
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
328 break;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
329 case TV_COLOR_SATURATION:
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
330 if (value == 50)
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
331 value = 32512;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
332 if (value > 50)
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
333 {
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
334 value *= 100;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
335 value += 32512;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
336 }
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
337 if (value < 50)
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
338 {
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
339 int i;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
340 value *= 100;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
341 i = value;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
342 value = 32512 - i;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
343 }
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
344 funcs->control(tvh->priv, TVI_CONTROL_VID_SET_SATURATION, &value);
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
345 break;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
346 case TV_COLOR_CONTRAST:
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
347 if (value == 50)
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
348 value = 27648;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
349 if (value > 50)
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
350 {
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
351 value *= 100;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
352 value += 27648;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
353 }
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
354 if (value < 50)
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
355 {
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
356 int i;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
357 value *= 100;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
358 i = value;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
359 value = 27648 - i;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
360 }
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
361 funcs->control(tvh->priv, TVI_CONTROL_VID_SET_CONTRAST, &value);
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
362 break;
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
363 default:
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
364 mp_msg(MSGT_TV, MSGL_WARN, "Unknown color option (%d) specified!\n", opt);
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
365 }
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
366
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
367 return(1);
4307478ad922 added support for setting color values
alex
parents: 2932
diff changeset
368 }
2790
98769cea155c added tv subsystem
alex
parents:
diff changeset
369 #endif /* USE_TV */