libcamera: media_device: Open and close media device inside populate()
Remove the need for the caller to open and close the media device when populating the MediaDevice. This is done as an effort to make the usage of the MediaDevice less error prone and the interface stricter. The rework also revealed and fixes a potential memory leak in MediaDevice::populate() where resources would not be deleted if the second MEDIA_IOC_G_TOPOLOGY would fail. Signed-off-by: Niklas Söderlund <niklas.soderlund@ragnatech.se> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
@@ -207,11 +207,7 @@ int DeviceEnumerator::addDevice(const std::string &deviceNode)
|
||||
{
|
||||
std::shared_ptr<MediaDevice> media = std::make_shared<MediaDevice>(deviceNode);
|
||||
|
||||
int ret = media->open();
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = media->populate();
|
||||
int ret = media->populate();
|
||||
if (ret < 0) {
|
||||
LOG(DeviceEnumerator, Info)
|
||||
<< "Unable to populate media device " << deviceNode
|
||||
@@ -238,8 +234,6 @@ int DeviceEnumerator::addDevice(const std::string &deviceNode)
|
||||
return ret;
|
||||
}
|
||||
|
||||
media->close();
|
||||
|
||||
LOG(DeviceEnumerator, Debug)
|
||||
<< "Added device " << deviceNode << ": " << media->driver();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user