blob: 4f2f714de8c4595f43b8883991f617a5b2094370
1 | #define LOG_TAG "TvPlay" |
2 | |
3 | #include <utils/Log.h> |
4 | #include <string.h> |
5 | #include "TvPlay.h" |
6 | #include "tvcmd.h" |
7 | #include <math.h> |
8 | |
9 | TvPlay::TvPlay() |
10 | { |
11 | mpObserver = NULL; |
12 | tvSession = TvClient::connect(); |
13 | tvSession->setListener(this); |
14 | mHdmiPorts = getHdmiPorts(); |
15 | |
16 | if ( mHdmiPorts >= pow(10, (max_port_num-1))) |
17 | hdmi_port[3] = mHdmiPorts/pow(10, (max_port_num-1)); |
18 | else |
19 | hdmi_port[3] = 0;//in this case,there is only 3 hdmi_in ports |
20 | hdmi_port[2] = (mHdmiPorts -hdmi_port[3]*1000)/100; |
21 | hdmi_port[1] = (mHdmiPorts -hdmi_port[3]*1000-hdmi_port[2]*100)/10; |
22 | hdmi_port[0] = mHdmiPorts -hdmi_port[3]*1000-hdmi_port[2]*100-hdmi_port[1]*10; |
23 | } |
24 | |
25 | TvPlay::~TvPlay() |
26 | { |
27 | tvSession.clear(); |
28 | } |
29 | |
30 | int TvPlay::setTvObserver ( TvPlayObserver *ob ) |
31 | { |
32 | mpObserver = ob; |
33 | return 0; |
34 | } |
35 | |
36 | void TvPlay::notify(int32_t msgType, const Parcel &p) |
37 | { |
38 | ALOGD("TvPlay-------notify-------"); |
39 | if (mpObserver != NULL) |
40 | mpObserver->onTvEvent(msgType, p); |
41 | } |
42 | |
43 | int TvPlay::StartTv() |
44 | { |
45 | Parcel p, r; |
46 | p.writeInt32(START_TV); |
47 | tvSession->processCmd(p, &r); |
48 | return r.readInt32(); |
49 | } |
50 | |
51 | int TvPlay::StopTv() |
52 | { |
53 | Parcel p, r; |
54 | p.writeInt32(STOP_TV); |
55 | tvSession->processCmd(p, &r); |
56 | return r.readInt32(); |
57 | } |
58 | |
59 | int TvPlay::SwitchSourceInput(tv_source_input_t source_input) |
60 | { |
61 | Parcel p, r; |
62 | p.writeInt32(SET_SOURCE_INPUT); |
63 | p.writeInt32(source_input); |
64 | tvSession->processCmd(p, &r); |
65 | return r.readInt32(); |
66 | } |
67 | |
68 | int TvPlay::DoSuspend(int type) |
69 | { |
70 | Parcel p, r; |
71 | p.writeInt32(DO_SUSPEND); |
72 | p.writeInt32(type); |
73 | tvSession->processCmd(p, &r); |
74 | return r.readInt32(); |
75 | } |
76 | |
77 | int TvPlay::DoResume(int type) |
78 | { |
79 | Parcel p, r; |
80 | p.writeInt32(DO_RESUME); |
81 | p.writeInt32(type); |
82 | tvSession->processCmd(p, &r); |
83 | return r.readInt32(); |
84 | } |
85 | |
86 | int TvPlay::GetSourceConnectStatus(tv_source_input_t source_input) |
87 | { |
88 | Parcel p, r; |
89 | p.writeInt32(GET_SOURCE_CONNECT_STATUS); |
90 | p.writeInt32(source_input); |
91 | tvSession->processCmd(p, &r); |
92 | return r.readInt32(); |
93 | } |
94 | |
95 | int TvPlay::GetCurrentSourceInput() |
96 | { |
97 | Parcel p, r; |
98 | p.writeInt32(GET_CURRENT_SOURCE_INPUT_VIRTUAL); |
99 | tvSession->processCmd(p, &r); |
100 | return r.readInt32(); |
101 | } |
102 | |
103 | int TvPlay::GetHdmiAvHotplugDetectOnoff() |
104 | { |
105 | Parcel p, r; |
106 | p.writeInt32(HDMIAV_HOTPLUGDETECT_ONOFF); |
107 | tvSession->processCmd(p, &r); |
108 | return r.readInt32(); |
109 | } |
110 | |
111 | int TvPlay::getAllTvDevices(int *devices, int *count) |
112 | { |
113 | Parcel p, r; |
114 | p.writeInt32(GET_ALL_TV_DEVICES); |
115 | tvSession->processCmd(p, &r); |
116 | const char *input_list = r.readCString(); |
117 | ALOGD("input_list = %s", input_list); |
118 | |
119 | int len = 0; |
120 | const char *seg = ","; |
121 | char *pT = strtok((char*)input_list, seg); |
122 | while (pT) { |
123 | len ++; |
124 | *devices = atoi(pT); |
125 | ALOGD("devices: %d: %d", len , *devices); |
126 | devices ++; |
127 | pT = strtok(NULL, seg); |
128 | } |
129 | *count = len; |
130 | return 0; |
131 | } |
132 | |
133 | int TvPlay::getHdmiPorts() |
134 | { |
135 | Parcel p, r; |
136 | p.writeInt32(GET_HDMI_PORTS); |
137 | tvSession->processCmd(p, &r); |
138 | |
139 | return r.readInt32(); |
140 | } |
141 | |
142 | int TvPlay::getHdmiPort(tv_source_input_t source_input) { |
143 | return mHdmiPorts == 0 ? 0 : hdmi_port[source_input - SOURCE_HDMI1]; |
144 | } |
145 | |
146 |