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