blob: b3ce6f49946936a81a797bbc409e1bf9b47ea830
1 | #ifndef ANDROID_FRONTEND_H |
2 | #define ANDROID_FRONTEND_H |
3 | #include <stdio.h> |
4 | #include <stdlib.h> |
5 | #include <unistd.h> |
6 | #include <string.h> |
7 | #include "CTvLog.h" |
8 | #include "CTvEv.h" |
9 | extern "C" { |
10 | #include "am_fend.h" |
11 | #include "am_vout.h" |
12 | #include "linux/dvb/frontend.h" |
13 | } |
14 | //for app |
15 | typedef enum atv_audo_std_s { |
16 | CC_ATV_AUDIO_STD_START = 0, |
17 | CC_ATV_AUDIO_STD_DK = 0, |
18 | CC_ATV_AUDIO_STD_I, |
19 | CC_ATV_AUDIO_STD_BG, |
20 | CC_ATV_AUDIO_STD_M, |
21 | CC_ATV_AUDIO_STD_L, |
22 | CC_ATV_AUDIO_STD_AUTO, |
23 | CC_ATV_AUDIO_STD_END = CC_ATV_AUDIO_STD_AUTO, |
24 | CC_ATV_AUDIO_STD_MUTE, |
25 | } atv_audio_std_t; |
26 | //for app |
27 | typedef enum atv_video_std_s { |
28 | CC_ATV_VIDEO_STD_START = 0, |
29 | CC_ATV_VIDEO_STD_AUTO = 0, |
30 | CC_ATV_VIDEO_STD_PAL, |
31 | CC_ATV_VIDEO_STD_NTSC, |
32 | CC_ATV_VIDEO_STD_SECAM, |
33 | CC_ATV_VIDEO_STD_END = CC_ATV_VIDEO_STD_SECAM, |
34 | } atv_video_std_t; |
35 | |
36 | |
37 | //from kernel |
38 | /*COLOR MODULATION TYPE*/ |
39 | static const v4l2_std_id V4L2_COLOR_STD_PAL = ((v4l2_std_id)0x04000000); |
40 | static const v4l2_std_id V4L2_COLOR_STD_NTSC = ((v4l2_std_id)0x08000000); |
41 | static const v4l2_std_id V4L2_COLOR_STD_SECAM = ((v4l2_std_id)0x10000000); |
42 | //virtual |
43 | static const v4l2_std_id V4L2_COLOR_STD_AUTO = ((v4l2_std_id)0x02000000); |
44 | |
45 | typedef struct frontend_para_set_s { |
46 | fe_type_t mode; |
47 | int freq; |
48 | atv_video_std_t videoStd; |
49 | atv_audio_std_t audioStd; |
50 | int para1; |
51 | int para2; |
52 | } frontend_para_set_t; |
53 | |
54 | typedef struct atv_channel_info_s { |
55 | int finefreq; |
56 | atv_video_std_t videoStd; |
57 | atv_audio_std_t audioStd; |
58 | int isAutoStd; |
59 | } atv_channel_info_t; |
60 | |
61 | typedef struct dtv_channel_info_s { |
62 | int strength; |
63 | int quality; |
64 | int ber; |
65 | } dtv_channel_info_t; |
66 | |
67 | typedef struct channel_info_s { |
68 | int freq; |
69 | union { |
70 | atv_channel_info_t atvChanInfo; |
71 | dtv_channel_info_t dtvChanInfo; |
72 | } uInfo; |
73 | } channel_info_t; |
74 | |
75 | class CFrontEnd { |
76 | public: |
77 | |
78 | static const int FE_DEV_ID = 0; |
79 | static const int AFC_RANGE = 1000000; |
80 | |
81 | CFrontEnd(); |
82 | ~CFrontEnd(); |
83 | |
84 | int Open(int mode); |
85 | int Close(); |
86 | int setMode(int mode); |
87 | int fineTune(int freq); |
88 | int formatATVFreq(int freq); |
89 | int GetTSSource(AM_DMX_Source_t *src); |
90 | int setPara(int frequency, int symbol_rate, int modulation, int bandwidth); |
91 | int ClearAnalogFrontEnd(); |
92 | int autoLoadFE(); |
93 | |
94 | static int stdAndColorToAudioEnum(int std); |
95 | static int stdAndColorToVideoEnum(int std); |
96 | static int printVideoStdStr(int videoStd, char strBuffer[], int buff_size); |
97 | static int printAudioStdStr(int audioStd, char strBuffer[], int buff_size); |
98 | static v4l2_std_id enumToStdAndColor(int videoStd, int audioStd); |
99 | static int stdEnumToCvbsFmt (int videoStd, int audioStd); |
100 | class FEEvent: public CTvEv { |
101 | public: |
102 | //static const int EVENT_FE_HAS_SIG = 0X01; /* found something above the noise level */ |
103 | //static const int EVENT_FE_HAS_CARRIER = 0x02; /* found a DVB signal */ |
104 | //static const int EVENT_FE_HAS_VITERBI = 0X04; /* FEC is stable */ |
105 | //static const int EVENT_FE_HAS_SYNC = 0X08; /* found sync bytes */ |
106 | // static const int EVENT_FE_HAS_LOCK = 0X10; /* everything's working... */ |
107 | //static const int EVENT_FE_HAS_TIMEOUT = 0X20; /* no lock within the last ~2 seconds */ |
108 | //static const int EVENT_FE_REINIT = 0X40; /* frontend was reinitialized, */ |
109 | static const int EVENT_FE_HAS_SIG = 0x01; |
110 | static const int EVENT_FE_NO_SIG = 0x02; |
111 | static const int EVENT_FE_INIT = 0x03; |
112 | |
113 | FEEvent(): CTvEv(CTvEv::TV_EVENT_SIGLE_DETECT) |
114 | { |
115 | } |
116 | ~FEEvent() |
117 | { |
118 | } |
119 | int mCurSigStaus; |
120 | int mCurFreq; |
121 | }; |
122 | |
123 | class IObserver { |
124 | public: |
125 | IObserver() {}; |
126 | virtual ~IObserver() {}; |
127 | virtual void onEvent(const FEEvent &ev) = 0; |
128 | }; |
129 | |
130 | int setObserver(IObserver *ob) |
131 | { |
132 | mpObserver = ob; |
133 | return 0; |
134 | } |
135 | |
136 | int getSNR(); |
137 | int getBER(); |
138 | int getInfo(); |
139 | int getStatus(); |
140 | int checkStatusOnce(); |
141 | int getStrength(); |
142 | int setCvbsAmpOut(int amp); |
143 | int setThreadDelay(int delay) ; |
144 | int getPara(frontend_para_set_t *fpara); |
145 | int lock(int frequency, int symbol_rate, int modulation, int bandwidth); |
146 | private: |
147 | int mFrontDevID; |
148 | int mDemuxDevID; |
149 | int mTvPlayDevID; |
150 | int mCurFineFreq; |
151 | IObserver *mpObserver; |
152 | FEEvent mCurSigEv; |
153 | int mCurMode; |
154 | static void dmd_fend_callback(long dev_no, int event_type, void *param, void *user_data); |
155 | }; |
156 | #endif // ANDROID_FRONTEND_H |
157 | |
158 |