summaryrefslogtreecommitdiff
path: root/dxr3device.h
blob: 0df1053899a25eceecbe38915395f92d89d3daa6 (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
/*
 *           _                 _             _                 _          _____
 * __   ____| |_ __      _ __ | |_   _  __ _(_)_ __         __| |_  ___ _|___ /
 * \ \ / / _` | '__|____| '_ \| | | | |/ _` | | '_ \ _____ / _` \ \/ / '__||_ \
 *  \ V / (_| | | |_____| |_) | | |_| | (_| | | | | |_____| (_| |>  <| |  ___) |
 *   \_/ \__,_|_|       | .__/|_|\__,_|\__, |_|_| |_|      \__,_/_/\_\_| |____/
 *                      |_|            |___/
 *
 * Copyright (C) 2002-2004 Kai Möller
 * Copyright (C) 2004-2010 Christian Gmeiner
 *
 * This file is part of vdr-plugin-dxr3.
 *
 * vdr-plugin-dxr3 is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation version 2.
 *
 * vdr-plugin-dxr3 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with dxr3-plugin.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef _DXR3_DEVICE_H_
#define _DXR3_DEVICE_H_

//#include <string>
#include <vdr/device.h>

#include <linux/em8300.h>
#include "decoder.h"
#include "dxr3spudecoder.h"
#include "dxr3audio.h"
#include "settings.h"
#include "uncopyable.h"

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];
};

/*!
  cDxr3Device is the interface for VDR devices.
  Is is the part, which VDR "talks" with our plugin.
*/
class cDxr3Device : public cDevice, public Uncopyable, public iSettingsObserver {
public:
    static cDxr3Device *instance();

    static int Dxr3Open(const char *name, int mode, bool report_error = true);
    virtual void MakePrimaryDevice(bool On);

    // replaying
    virtual bool HasDecoder() const;
    virtual bool CanReplay() const;
    virtual bool SetPlayMode(ePlayMode PlayMode);
    virtual int64_t GetSTC();
    virtual void TrickSpeed(int Speed);
    virtual void Clear();
    virtual void Play();
    virtual void Freeze();
    virtual void Mute();
    virtual void StillPicture(const uchar *Data, int Length);
    virtual bool Poll(cPoller &Poller, int TimeoutMs = 0);
    virtual int PlayVideo(const uchar *Data, int Length);
    virtual int PlayAudio(const uchar *Data, int Length, uchar Id);

#if VDRVERSNUM >= 10710
    virtual void GetVideoSize(int &Width, int &Height, double &VideoAspect);
#endif

    // additional functions
    virtual void SetVideoFormat(bool VideoFormat16_9);
    virtual void SetVolumeDevice(int Volume);
    virtual void SetAudioChannelDevice(int AudioChannel);
    virtual int GetAudioChannelDevice();
    virtual void SetDigitalAudioDevice(bool on);

    // osd
    virtual cSpuDecoder *GetSpuDecoder();
    iAudio *getAudioOutput() const      { return audio; }

    void turnPlugin(bool on);

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

    void setPalette(uint8_t *pal);
    void writeSpu(const uint8_t* data, int length);
    void setButton(uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey, uint32_t palette);
    void clearButton();

    // observer
    virtual void settingsChange(SettingsChange change);

private:
    cDxr3Device();
    ~cDxr3Device();

    void claimDevices();
    void releaseDevices();
    void uploadFirmware();
    void setPlayMode();
    void playVideoFrame(cDxr3PesFrame *frame, uint32_t pts);
    void playBlackFrame(uint32_t pts);
    void writeRegister(int reg, int value);
    void setScr(uint32_t val);
    uint32_t getScr();

    int offset;
    cMutex mutex;
    cDecoder *decoder;
    cDxr3SpuDecoder* spuDecoder;
    iAudio *audio;
    bool pluginOn;

    em8300_bcs_t bcs;

    int fdControl;
    int fdVideo;
    int fdSpu;

    uint32_t vPts;
    uint32_t aPts;
    bool scrSet;

    uint32_t horizontal;
    uint32_t vertical;
    uint32_t aspectRatio;

    static cDxr3Device *inst;
};

#endif /*_DXR3_DEVICE_H_*/

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