in camera-sdk/iotccsdk/camera.py [0:0]
def configure_preview(self, resolution=None, encode=None,
bitrate=None, framerate=None, display_out=None):
"""
This method is for setting preview params.
Parameters
----------
resolution : str
A value from `resolutions` attribute
encode : str
A value from `encodetype` attribute
bitrate : str
A value from `bitrates` attribute
framerate : int
A value from `framerates` attribute
display_out : {0, 1}
For enabling or disabling HDMI output
Returns
-------
bool
True if the request is successful.
False on failure.
Raises
------
Exception
Any exception raised by ipc provider post
"""
if resolution and self.resolutions and resolution in self.resolutions:
res = self.resolutions.index(resolution)
else:
res = self.resolutions.index(self.cur_resolution)
if encode and self.encodetype and encode in self.encodetype:
enc = self.encodetype.index(encode)
else:
enc = self.encodetype.index(self.cur_codec)
if bitrate and self.bitrates and bitrate in self.bitrates:
bit = self.bitrates.index(bitrate)
else:
bit = self.bitrates.index(self.cur_bitrate)
if framerate and self.framerates and framerate in self.framerates:
fps = self.framerates.index(framerate)
else:
fps = self.framerates.index(self.cur_framerate)
if display_out not in [0, 1]:
self.logger.error(
"Invalid value: display_out should 0/1 got: %s" % display_out)
display_out = self.display_out
path = "/video"
payload = {
"resolutionSelectVal": res,
"encodeModeSelectVal": enc,
"bitRateSelectVal": bit,
"fpsSelectVal": fps,
"displayOut": display_out
}
response = self.ipc_provider.post(path, payload)
if response["status"]:
if self.cur_resolution != self.resolutions[res]:
self.cur_resolution = self.resolutions[res]
self.logger.info("resolution now: %s" % self.cur_resolution)
if self.cur_codec != self.encodetype[enc]:
self.cur_codec = self.encodetype[enc]
self.logger.info("encodetype now: %s" % self.cur_codec)
if self.cur_bitrate != self.bitrates[bit]:
self.cur_bitrate = self.bitrates[bit]
self.logger.info("bitrate now : %s" % self.cur_bitrate)
if self.cur_framerate != self.framerates[fps]:
self.cur_framerate = self.framerates[fps]
self.logger.info("framerate now: %s" % self.cur_framerate)
if self.display_out != display_out:
self.display_out = display_out
self.logger.info("display_out now: %s" % self.display_out)
return response["status"]