summaryrefslogtreecommitdiff
path: root/dvbapi.c
blob: 5597fbd50b2697f7afc86512b554fc03e35443fc (plain)
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
/*
 * dvbapi.c: Interface to the DVB driver
 *
 * See the main source file 'osm.c' for copyright information and
 * how to reach the author.
 *
 * $Id: dvbapi.c 1.1 2000/02/19 13:36:48 kls Exp $
 */

// FIXME: these should be defined in ../DVB/driver/dvb.h!!!
typedef unsigned int u32;
typedef unsigned short u16;
typedef unsigned char u8;

#include "dvbapi.h"
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include "../DVB/driver/dvb.h"
#include "interface.h"
#include "tools.h"

#define VIDEODEVICE "/dev/video"

const char *DvbQuality = "LMH"; // Low, Medium, High

bool DvbSetChannel(int FrequencyMHz, char Polarization, int Diseqc, int Srate, int Vpid, int Apid)
{
  int v = open(VIDEODEVICE, O_RDWR);
  
  if (v >= 0) {
     struct frontend front;
     ioctl(v, VIDIOCGFRONTEND, &front);
     unsigned int freq = FrequencyMHz;
     front.ttk = (freq < 11800UL) ? 0 : 1;
     if (freq < 11800UL)
        freq -=  9750UL;
     else
        freq -= 10600UL;
     front.freq      = freq * 1000000UL;
     front.diseqc    = Diseqc;
     front.srate     = Srate * 1000;
     front.volt      = (Polarization == 'v') ? 0 : 1;
     front.video_pid = Vpid;
     front.audio_pid = Apid;
     front.AFC       = 1;
     ioctl(v, VIDIOCSFRONTEND, &front);
     close(v);
     if (front.sync & 0x1F == 0x1F)
        return true;
     esyslog(LOG_ERR, "channel not sync'ed (front.sync=%X)!", front.sync);
     }
  else
     Interface.Error("can't open VIDEODEVICE");//XXX
  return false;
}

// -- cDvbRecorder -----------------------------------------------------------

cDvbRecorder::cDvbRecorder(void)
{
}

cDvbRecorder::~cDvbRecorder()
{
  Stop();
}

bool cDvbRecorder::Record(const char *FileName, char Quality)
{
  isyslog(LOG_INFO, "record %s (%c)", FileName, Quality);
  return true;
  // TODO
  return false;
}

bool cDvbRecorder::Play(const char *FileName, int Frame)
{
  isyslog(LOG_INFO, "play %s (%d)", FileName, Frame);
  // TODO
  return false;
}

bool cDvbRecorder::FastForward(void)
{
  isyslog(LOG_INFO, "fast forward");
  // TODO
  return false;
}

bool cDvbRecorder::FastRewind(void)
{
  isyslog(LOG_INFO, "fast rewind");
  // TODO
  return false;
}

bool cDvbRecorder::Pause(void)
{
  isyslog(LOG_INFO, "pause");
  // TODO
  return false;
}

void cDvbRecorder::Stop(void)
{
  isyslog(LOG_INFO, "stop");
  // TODO
}

int cDvbRecorder::Frame(void)
{
  isyslog(LOG_INFO, "frame");
  // TODO
  return 0;
}

// ---------------------------------------------------------------------------

static void DvbOsdCmd(OSD_Command cmd, int color = 0, int x0 = 0, int y0 = 0, int x1 = 0, int y1 = 0, void *data = NULL)
{
  int v = open(VIDEODEVICE, O_RDWR);

  if (v >= 0) {
     struct drawcmd dc;
     dc.cmd   = cmd;
     dc.color = color;
     dc.x0    = x0;
     dc.y0    = y0;
     dc.x1    = x1;
     dc.y1    = y1;
     dc.data  = data;
     ioctl(v, VIDIOCSOSDCOMMAND, &dc);
     close(v);
     }
  else
     Interface.Error("can't open VIDEODEVICE");//XXX
}

void DvbOsdOpen(int x, int y, int w, int h)
{
  DvbOsdCmd(OSD_Open, 1, x, y, x + w - 1, y + h - 1);
  DvbOsdCmd(OSD_SetColor, 0,   0,   0,   0, 127); // background 50% gray
  DvbOsdCmd(OSD_SetColor, 1, 255, 255, 255, 255); // text white
}

void DvbOsdClose(void)
{
  DvbOsdCmd(OSD_Close);
}

void DvbOsdClear(void)
{
  DvbOsdCmd(OSD_Clear);
}

void DvbOsdClrEol(int x, int y)
{
  DvbOsdCmd(OSD_FillBlock, 0, x, y * DvbOsdLineHeight, x + 490, (y + 1) * DvbOsdLineHeight);//XXX
}

void DvbOsdText(int x, int y, char *s)
{
  DvbOsdCmd(OSD_Text, 1, x, y, 1, 0, s);
}