File: v4l.h

package info (click to toggle)
dvr 3.2-8
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 896 kB
  • ctags: 394
  • sloc: cpp: 3,192; makefile: 134; sh: 100; yacc: 39
file content (111 lines) | stat: -rw-r--r-- 3,136 bytes parent folder | download
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
#ifndef V4L_H
#define V4L_H

#include "linux/videodev.h"

#define DEBUG_OUTPUT(res, text) if(res==-1) { cerr<<__FILE__<<":"<<__LINE__<<" : "; if(text) { cerr<<text<<" : "<<strerror(errno)<<endl; } else { cerr<<strerror(errno)<<endl;}  }

#include <string>
#include <vector>

using namespace std;

class V4LDevice {
public:
  string file_name;
  string name;
};

class V4L {
public:
  enum PixelFormat { PX_RGB565, PX_RGB24, PX_YUV420P };

protected:

  int v4lfd;
  int sem_id;
  int current_frame;
  
  string v4l_file_name;
  struct video_capability vcap; // capabilities of the video device
  vector<video_channel> vchan;  // list of video channels
  vector<video_audio> achan;  // list of audio channels
  
  struct video_mmap *vgrab;   // description of each frame (dimension and format)
  struct video_buffer vbuf;     // description of the video buffer (address, dimension, depth, ...)
  struct video_mbuf vmbuf;      // description of video buffers mapping (total size, frame offsets, ...)
  struct video_window vwind;    // description of the overlay video window (location, dimension)
  struct video_picture vpic;    // description of the video picture (palette, hue, brightness, ...)

  unsigned char *capture_memory; // base address of frame data
  int capture_memory_size; // base address of frame data

  PixelFormat pixel_format;
  unsigned int current_video_channel;
  unsigned int current_audio_channel;
  bool video_preview_enabled;


private:
  // these functions are not thread safe
  void _setCaptureSize(unsigned int width, unsigned int height);
  void _setCurrentAudioChannel(unsigned int);
  bool _setPixelFormat(PixelFormat pixel_format);
  void _enableAudio(bool on);
  void _enableVideoPreview(bool on);
  void _close();

public:
  // these functions are thread safe
  V4L();
  ~V4L();

  vector<V4LDevice> availableDevicesList();
  
  void open(const char *file_name);
  void close();

  void lock();
  void unlock();

  string deviceFileName();
  string deviceName();

  bool isGood();

  vector<video_channel> &videoChannels();
  unsigned int currentVideoChannel();
  void setCurrentVideoChannel(unsigned int);
  
  vector<video_audio> &audioChannels();
  unsigned int currentAudioChannel();
  void setCurrentAudioChannel(unsigned int);
  
  bool hasVideoPreview();
  void enableVideoPreview(bool on);
  bool isVideoPreviewEnabled();

  void getMinSize(int &width, int &height);
  void getMaxSize(int &width, int &height);

  void getWindowPosition(unsigned int &x, unsigned int &y);
  void getWindowSize(unsigned int &width, unsigned int &height);
  void setWindowPositionSize(unsigned int x, unsigned int y, unsigned int width, unsigned int height);

  unsigned char *captureFrame();
  void setCaptureSize(unsigned int width, unsigned int height);
  void getCaptureSize(unsigned int &width, unsigned int &height, int frame=0);

  bool setPixelFormat(PixelFormat pixel_format);
  PixelFormat pixelFormat();

  bool hasAudio();
  void enableAudio(bool on);
  bool isAudioEnabled();

  bool hasTuner();
  void setTunerFrequency(unsigned long frequency);
  unsigned long tunerFrequency();
};

#endif //V4L_H