summaryrefslogtreecommitdiff
path: root/dxr3interface.h
blob: 68dcaedf8e0df4a11d66cd760f57b84bbed6ab56 (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
167
168
169
170
171
/*
 * dxr3interface.h
 *
 * Copyright (C) 2002-2004 Kai Möller
 * Copyright (C) 2004-2009 Christian Gmeiner
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 *
 */

#ifndef _DXR3_INTERFACE_H_
#define _DXR3_INTERFACE_H_

#include <linux/em8300.h>
#include <sys/ioctl.h>
#include <linux/limits.h>

#include <vdr/tools.h>
#include "settings.h"

// ==================================
class cFixedLengthFrame;
class cDxr3PesFrame;

class cDxr3Name {
public:
    cDxr3Name(const char *name, int n) {
        snprintf(buffer, sizeof(buffer), "%s%s-%d", "/dev/em8300", name, n);
    }
    const char *operator*() { return buffer; }

private:
    char buffer[PATH_MAX];
};

// ==================================
//! interafce to dxr3-card
/*!
  cDxr3Interface is the interface to the dxr3
  driver and so to the card,
  so this is the layer between plugin and driver.
*/
class cDxr3Interface : public Singleton<cDxr3Interface> {
public:
    cDxr3Interface();
    ~cDxr3Interface();

    static int Dxr3Open(const char *name, int mode, bool report_error = true) {
        const char *filename = *cDxr3Name(name, cSettings::instance()->card());
        int fd = open(filename, mode);

        if (report_error && (fd < 0)) {
            LOG_ERROR_STR(filename);
        }
        return fd;
    }

    // audio
    bool IsOssAudio();
    int OssSetPlayMode(uint32_t mode);

    // clock
    void SetSysClock(uint32_t scr);
    uint32_t GetSysClock();
    void SetPts(uint32_t pts);
    void SetSpuPts(uint32_t pts);
    int64_t GetPts();

    // state changes
    void EnableVideo()
    {
	m_VideoActive = true;
    }
    void DisableVideo()
    {
	m_VideoActive = false;
    }

    // set/get functions
    uint32_t GetAspectRatio() const;
    void SetAspectRatio(uint32_t ratio);
    uint32_t GetHorizontalSize() const    { return m_horizontal; }
    uint32_t GetVerticalSize() const      { return m_vertical; }

    void setDimension(uint32_t horizontal, uint32_t vertical);
    void dimension(uint32_t &horizontal, uint32_t &vertical);

    // play functions
    void SetPlayMode();
    void Pause();
    void PlayVideoFrame(cFixedLengthFrame* pFrame);
    void PlayVideoFrame(cDxr3PesFrame *frame);

    // device access
    void ClaimDevices();
    void ReleaseDevices();

    // tools
    void PlayBlackFrame();

    // osd/spu
    void WriteSpu(const uint8_t* pBuf, int length);
    void SetButton(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey,
		   uint32_t palette);
    void ClearButton();
    void SetPalette(unsigned int *pal);

    // helper functions for dxr3 main osd screen
    void ResetHardware();

    void updateBcsValues();
    // get brightness/contrast/saturation
    int GetBrightness();
    int GetContrast();
    int GetSaturation();

private:
    // file handles
    int m_fdControl;		///< filehandle for contol fifo of dxr3 card
    int m_fdVideo;		///< filehandle for video fifo of dxr3 card
    int m_fdSpu;		///< filehandle for spu fifo of dxr3 card
    uint32_t m_lastSeenPts;

    // clock
    uint32_t m_offset;

    uint32_t m_aspectRatio;	///< current used aspect ratio
    uint32_t m_horizontal;	///< horizontal size of current videostream
    uint32_t m_vertical;	///< vertical size of current videostream
    bool m_VideoActive;		///< is video active?

    // bcs
    em8300_bcs_t m_bcs;		///< BrightnessContrastSaturation values

    void UploadMicroCode();
    void ConfigureDevice();
    void Resuscitation();

    static cMutex* m_pMutex;	///< mutex for dxr3interface

    static void Lock()
    {
        cDxr3Interface::m_pMutex->Lock();
    }
    static void Unlock()
    {
        cDxr3Interface::m_pMutex->Unlock();
    }
};

#endif /*_DXR3_INTERFACE_H_*/

// Local variables:
// mode: c++
// c-file-style: "stroustrup"
// c-file-offsets: ((inline-open . 0))
// c-basic-offset: 4
// indent-tabs-mode: nil
// End: