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