• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2017 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""Meeting related operations"""
6
7from __future__ import print_function
8
9import logging
10import random
11
12MIN_VOL = 1
13MAX_VOL = 100
14
15def restart_chrome(handle, is_meeting, recovery):
16    """
17    Restart chrome and wait for telemetry commands to be ready.
18    @param handle: CfM telemetry remote facade,
19    @param is_meeting: True, None if CfM running MEET mode,
20                       False if CfM running hangout mode
21    @returns: True, None if success,
22              False otherwise.
23    """
24    try:
25        if recovery:
26            logging.info('+++Restart chrome')
27            handle.restart_chrome_for_cfm()
28            handle.wait_for_telemetry_commands()
29    except Exception as e:
30        errmsg = 'Fail to run telemetry api restart_chrome_for_cfm.'
31        logging.exception(errmsg)
32        return False, errmsg
33    return True, None
34
35def join_meeting(handle, is_meeting, meet_code):
36    """
37    Join meeting.
38    @param handle: CfM telemetry remote facade,
39    @param is_meeting: True, None if CfM running MEET mode,
40                       False if CfM running hangout mode
41    @param meeting_code: meeting code
42    @returns: True, None if CfM joins meeting successfully,
43              False otherwise.
44    """
45    try:
46        if is_meeting:
47            logging.info('+++Start meet meeting')
48            if meet_code:
49                handle.join_meeting_session(meet_code)
50            else:
51                handle.start_meeting_session()
52        else:
53            logging.info('+++start hangout meeting')
54            if meet_code:
55                handle.start_new_hangout_session(meet_code)
56            else:
57                errmsg = 'Meeting code is required for hangout meet.'
58                logging.exception(errmsg)
59                return False, errmsg
60        logging.info('+++Meeting %s joined.', meet_code)
61        return True, None
62    except Exception as e:
63        errmsg = 'Fail to run telemetry api to join meeting.'
64        logging.exception(errmsg)
65        return False, errmsg
66
67def leave_meeting(handle, is_meeting):
68    """
69    Leave meeting.
70    @param handle: CfM telemetry remote facade,
71    @param is_meeting: True, None if CfM running MEET mode,
72                       False if CfM running hangout mode
73    @returns: True, None if CfM leaves meeting successfully,
74              False otherwise.
75
76    """
77    try:
78        if is_meeting:
79            handle.end_meeting_session()
80        else:
81            handle.end_hangout_session()
82    except Exception as e:
83        errmsg = 'Fail to run telemetry api to leave meeting.'
84        logging.exception(errmsg)
85        return False, errmsg
86    logging.info('+++meet ended')
87    return True, None
88
89
90def mute_unmute_camera(handle, is_muted):
91    """
92    @param handle: CfM telemetry remote facade,
93    @param is_muted: True, None if camera is muted,
94                     False otherwise.
95    @returns: True, None if camera is muted/unmuted successfully,
96              False otherwise.
97    """
98    try:
99        if is_muted:
100            logging.info('+++unmute camera')
101            handle.unmute_camera()
102        else:
103            logging.info('+++mute camera')
104            handle.mute_camera()
105    except Exception as e:
106        errmsg = 'Fail to run telemetry api to mute/unmute camera.'
107        logging.exception(errmsg)
108        return False, errmsg
109    return True, None
110
111
112def mute_unmute_mic(handle, is_muted):
113    """
114    @param handle: CfM telemetry remote facade,
115    @param is_muted: True, None if mic is muted,
116                     False otherwise.
117    @returns: True, None if camera is muted/unmuted successfully,
118              False otherwise.
119    """
120    try:
121         if is_muted:
122             logging.info('+++unmute mic')
123             handle.unmute_mic()
124         else:
125             logging.info('+++mute mic')
126             handle.mute_mic()
127    except Exception as e:
128        errmsg = 'Fail to run telemetry api to mute/unmute mic.'
129        logging.exception(errmsg)
130        return False, errmsg
131    return True, None
132
133
134def set_speaker_volume(handle, volume):
135    """
136    Change speaker's volume.
137    @param handle: CfM telemetry remote facade
138    @param volume: volume for speaker
139    """
140    try:
141        handle.set_speaker_volume(volume)
142    except Exception as e:
143        errmsg = 'Fail to run telemetry api to set speaker volume.'
144        logging.exception(errmsg)
145        return False, errmsg
146    return True, str(volume)
147
148
149def speaker_volume_test(handle, step, mode, randommode):
150    """
151    Change speaker's volume.
152    @param handle: CfM telemetry remote facade,
153    @param step: volume to be increased or decreased in one call
154    @param mode: if it equal to 1, update volume directly to
155                 targeted value,
156                 else, update volume in multiple calls.
157    @param randommode: if True, None, the value of volume to be change in
158                 each call is randomly set,
159                 else, the value is fixed defined by step.
160    """
161    test_volume = random.randrange(MIN_VOL, MAX_VOL)
162    if mode == 1:
163        return set_speaker_volume(handle, test_volume)
164    step = max(2, step)
165    try:
166        current = int(handle.get_speaker_volume())
167    except Exception as e:
168        errmsg = 'Fail to run telemetry api to set speaker volume.'
169        logging.exception(errmsg)
170        return False, errmsg
171
172    if test_volume > current:
173        while test_volume > current:
174            if randommode:
175                transit_volume = current + random.randrange(1, step)
176            else:
177                transit_volume = current + step
178
179            if transit_volume > test_volume:
180                transit_volume = test_volume
181
182            handle.set_speaker_volume(transit_volume)
183            try:
184                current = int(handle.get_speaker_volume())
185            except Exception as e:
186                errmsg = 'Fail to run telemetry api to set speaker volume.'
187                logging.exception(errmsg)
188                return False, errmsg
189
190            logging.info('+++set vol %d, current %d, target %d',
191                         transit_volume, current, test_volume)
192    else:
193        while test_volume < current:
194            if randommode:
195                transit_volume = current - random.randrange(1, step)
196            else:
197                transit_volume = current - step
198            if transit_volume < test_volume:
199                transit_volume = test_volume
200            handle.set_speaker_volume(transit_volume)
201            try:
202                current = int(handle.get_speaker_volume())
203            except Exception as e:
204                errmsg = 'Fail to run telemetry api to set speaker volume.'
205                logging.exception(errmsg)
206                return False, errmsg
207
208            logging.info('+++set vol %d, current %d, target %d',
209                          transit_volume, current, test_volume)
210    return True, str(current)
211