File: VideoDeviceInput.cc

package info (click to toggle)
camstream 0.27%2Bdfsg-4
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 12,368 kB
  • ctags: 5,393
  • sloc: cpp: 17,031; sh: 8,154; asm: 455; ansic: 440; makefile: 343
file content (178 lines) | stat: -rw-r--r-- 4,080 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
  \class CVideoDeviceInput

  Every video device has one or more inputs (called channels in the
  Video4Linux API). Each input refers to one of the physical inputs
  on the card/chip, like Tuner, Composite, S-video, etc. This class represents
  such an input.

  In addition, each input can have 0 or more tuners attached to it (to keep
  matters simple...). A tuner does the actual frequency and norm setting,
  and is represented by a \ref CVideoDeviceTuner class.
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>

#include "VideoDeviceInput.h"
#include "VideoDeviceLinux.h"

/**
  \brief Constructor

  In the constructor the channel information is queried and stored. It
  will also create any Tuner objects that may be needed.
*/

CVideoDeviceInput::CVideoDeviceInput(CVideoDeviceLinux *video, int channel)
        : QObject(video, "video device input")
{
   char buf[33];
   CVideoDeviceTuner *tuner = 0;

   m_pVideo = video;

   memset(&m_VChan, 0, sizeof(m_VChan));
   m_CurrentTuner = -1;

   m_Tuners.setAutoDelete(TRUE);
   // Query data
   m_VChan.channel = channel;
   if (ioctl(m_pVideo->m_CamFD, VIDIOCGCHAN, &m_VChan) == 0) {
     strncpy(buf, m_VChan.name, 32);
     buf[32] = '\0';
     m_Name = buf;

     if (m_VChan.flags & VIDEO_VC_TUNER) {
       m_Tuners.resize(m_VChan.tuners);
qDebug("%s has %d tuners", buf, m_VChan.tuners);
       for (int i = 0; i < m_VChan.tuners; i++) {
          tuner = new CVideoDeviceTuner(m_pVideo, i);
          m_Tuners.insert(i, tuner);
          connect(tuner, SIGNAL(Selected(int)), this, SLOT(VideoTunerSwitched(int)));
       }
     }
     else
       m_Tuners.resize(0);
   }
   else
     qWarning("CVideoDeviceInput: Warning: no channel info available.");
}

// private slots

void CVideoDeviceInput::VideoTunerSwitched(int n)
{
   m_CurrentTuner = n;
}


// public

/**
  \brief Return channel number.
*/
int CVideoDeviceInput::GetNumber() const
{
   return m_VChan.channel;
}

/**
  \brief Return symbolic name for input.
*/
QString CVideoDeviceInput::GetName() const
{
   return m_Name;
}

/**
  \brief Return type for this input.

  Returns a value from the \ref InputTypes enum, either TV or Camera
*/
int CVideoDeviceInput::GetType() const
{
   int type = Unknown;

    switch(m_VChan.type) {
      case VIDEO_TYPE_TV:     type = TV;     break;
      case VIDEO_TYPE_CAMERA: type = Camera; break;
   }
   return type;
}

/**
  \brief Returns whether this input has audio settings associated with it.
*/
bool CVideoDeviceInput::HasAudio() const
{
   if (m_Flags & VIDEO_VC_AUDIO)
     return true;
   return false;
}


/**
  \brief Make this input the current one.

*/
bool CVideoDeviceInput::Select()
{
   if (ioctl(m_pVideo->GetDescriptor(), VIDIOCSCHAN, &m_VChan) < 0)
   {
     qDebug("CVideoDeviceInput::Select() failed.");
     return false;
   }
   else
     emit Selected(m_VChan.channel);
   return true;
}


/**
  \brief Return number of tuners.

  Most inputs don't have a tuner, or at most 1. Multiple tuners could
  be used for multi-norm cards (each norm having a separate tuner), but
  this hasn't happened sofar.
*/
int CVideoDeviceInput::GetNumberOfTuners() const
{
   return (int)m_Tuners.count();
}

/**
  \brief Get a Tuner object
  \param number The desired input (0 to GetTuners() - 1); -1 for default (current) one
  \return A pointer to a CVideoDeviceTuner object

  This function will return 0 if the current tuner is unknown or \b number is out of range.
*/
CVideoDeviceTuner *CVideoDeviceInput::GetTuner(int number) const
{
   if (number == -1) {
     number = m_CurrentTuner;
   }

   if (number < 0 || number >= (int)m_Tuners.count())
     return 0;
   return m_Tuners.at((uint) number);
}

/**
  \brief Return current tuner number
  \return Tuner number, or -1 if the current tuner is unknown

  Since there is no way to query the current selected tuner from the device,
  this function returns -1 until a tuner has been selected.
*/
int CVideoDeviceInput::GetCurrentTuner() const
{
   return m_CurrentTuner;
}