Example #1
0
status_t BnCameraService::onTransact(
    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
    switch(code) {
        case GET_NUMBER_OF_CAMERAS: {
            CHECK_INTERFACE(ICameraService, data, reply);
            reply->writeInt32(getNumberOfCameras());
            return NO_ERROR;
        } break;
        case GET_CAMERA_INFO: {
            CHECK_INTERFACE(ICameraService, data, reply);
            CameraInfo cameraInfo;
            memset(&cameraInfo, 0, sizeof(cameraInfo));
            status_t result = getCameraInfo(data.readInt32(), &cameraInfo);
            reply->writeInt32(cameraInfo.facing);
            reply->writeInt32(cameraInfo.orientation);
            reply->writeInt32(result);
            return NO_ERROR;
        } break;
        case CONNECT: {
            CHECK_INTERFACE(ICameraService, data, reply);
            sp<ICameraClient> cameraClient = interface_cast<ICameraClient>(data.readStrongBinder());
            sp<ICamera> camera = connect(cameraClient, data.readInt32());
            reply->writeStrongBinder(camera->asBinder());
            return NO_ERROR;
        } break;
        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
}
CameraModule::CameraModule(camera_module_t *module) {
    if (module == NULL) {
        ALOGE("%s: camera hardware module must not be null", __FUNCTION__);
        assert(0);
    }

    mModule = module;
    mCameraInfoMap.setCapacity(getNumberOfCameras());
}
		extern "C" sp<CameraHardwareInterface> HAL_openCameraHardware(int cameraId)
		{
			LOGV("openCameraHardware: call createInstance");
			if (getNumberOfCameras() == 2) {
				htcCameraSwitch(cameraId);
#ifdef BOARD_USE_REVERSE_FFC
				if (cameraId == 1) {
					/* Change default parameters for the front camera */
					sp<CameraHardwareInterface> hardware = openCameraHardware(cameraId);
					if (hardware != NULL) {
						CameraParameters params(hardware->getParameters());
						params.set("front-camera-mode", "reverse"); // default is "mirror"
						hardware->setParameters(params);
					}
					return hardware;
				}
#endif
			}
			return openCameraHardware(cameraId);
		}
void SCameraConfigLauncher::onImportClicked()
{
    auto sdb = ::fwMedData::SeriesDB::New();
    ::fwServices::IService::sptr readerService = ::fwServices::add("::ioAtoms::SReader");
    readerService->registerInOut(sdb, ::fwIO::s_DATA_KEY);

    try
    {
        ::fwIO::IReader::sptr reader = ::fwIO::IReader::dynamicCast(readerService);
        reader->start();
        reader->configureWithIHM();
        reader->update();
        reader->stop();
    }
    catch(std::exception const& e)
    {
        ::fwGui::dialog::MessageDialog dlg;
        const auto msg = "Cannot read file: " + std::string(e.what());
        dlg.setTitle("Read error");
        dlg.setMessage(msg);
        dlg.setIcon(::fwGui::dialog::IMessageDialog::Icons::CRITICAL);
        SLM_ERROR(msg);

        throw;
    }
    ::fwServices::OSR::unregisterService(readerService);

    auto series       = sdb->getContainer();
    auto cameraSeries = std::vector< ::arData::CameraSeries::sptr>();

    for (auto& series_ : series)
    {
        auto cameraSeries_ = ::arData::CameraSeries::dynamicCast(series_);
        if (cameraSeries_ != nullptr)
        {
            cameraSeries.push_back(cameraSeries_);
        }
    }

    if (cameraSeries.size() == 0)
    {
        ::fwGui::dialog::MessageDialog::showMessageDialog(
            "No CameraSeries in SDB",
            "There are no CameraSeries present in the loaded SeriesDB",
            ::fwGui::dialog::IMessageDialog::CRITICAL);
    }
    else
    {
        QStringList cameras;
        std::map< std::string, ::arData::Camera::sptr> map;
        for (auto nSeries = 0; nSeries != cameraSeries.size(); ++nSeries)
        {
            auto cameraSeries_ = cameraSeries[nSeries];
            for (auto nCam = 0; nCam != cameraSeries_->getNumberOfCameras(); ++nCam)
            {
                auto cam      = cameraSeries_->getCamera(nCam);
                auto cameraID =
                    cam->getCameraID() + " [" + std::to_string(nSeries) + ", " +  std::to_string(nCam) + "]";
                map.insert(std::make_pair(cameraID, cam));
                cameras << QString(cameraID.data());
            }
        }

        if (cameras.size() == 0)
        {
            ::fwGui::dialog::MessageDialog::showMessageDialog(
                "No Cameras in SDB",
                "There are CameraSeries present in the loaded SeriesDB, but no Cameras were found",
                ::fwGui::dialog::IMessageDialog::CRITICAL);
        }
        else
        {
            auto qtContainer = ::fwGuiQt::container::QtContainer::dynamicCast(this->getContainer());
            bool ok          = false;
            auto selected    = QInputDialog::getItem(
                qtContainer->getQtContainer(), "Please select a camera", "Camera", cameras, 0, false, &ok);
            if (ok)
            {
                const auto selectedStd    = selected.toStdString();
                const auto selectedCamera = map[selectedStd];
                const auto camIdx         = m_cameraComboBox->currentIndex();
                auto camera               = m_cameraSeries->getCamera(camIdx);
                camera->deepCopy(selectedCamera);
                camera->signal< ::arData::Camera::IntrinsicCalibratedSignalType>(
                    ::arData::Camera::s_INTRINSIC_CALIBRATED_SIG)
                ->asyncEmit();
            }
        }
    }
}
		extern "C" int HAL_getNumberOfCameras()
		{
			return getNumberOfCameras();
		}
status_t BnCameraService::onTransact(
    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
    switch(code) {
        case GET_NUMBER_OF_CAMERAS: {
            CHECK_INTERFACE(ICameraService, data, reply);
            reply->writeNoException();
            reply->writeInt32(getNumberOfCameras());
            return NO_ERROR;
        } break;
        case GET_CAMERA_INFO: {
            CHECK_INTERFACE(ICameraService, data, reply);
            CameraInfo cameraInfo = CameraInfo();
            memset(&cameraInfo, 0, sizeof(cameraInfo));
            status_t result = getCameraInfo(data.readInt32(), &cameraInfo);
            reply->writeNoException();
            reply->writeInt32(result);

            // Fake a parcelable object here
            reply->writeInt32(1); // means the parcelable is included
            reply->writeInt32(cameraInfo.facing);
            reply->writeInt32(cameraInfo.orientation);
            return NO_ERROR;
        } break;
        case GET_CAMERA_CHARACTERISTICS: {
            CHECK_INTERFACE(ICameraService, data, reply);
            CameraMetadata info;
            status_t result = getCameraCharacteristics(data.readInt32(), &info);
            reply->writeNoException();
            reply->writeInt32(result);

            // out-variables are after exception and return value
            reply->writeInt32(1); // means the parcelable is included
            info.writeToParcel(reply);
            return NO_ERROR;
        } break;
        case CONNECT: {
            CHECK_INTERFACE(ICameraService, data, reply);
            sp<ICameraClient> cameraClient =
                    interface_cast<ICameraClient>(data.readStrongBinder());
            int32_t cameraId = data.readInt32();
            const String16 clientName = data.readString16();
            int32_t clientUid = data.readInt32();
            sp<ICamera> camera;
            status_t status = connect(cameraClient, cameraId,
                    clientName, clientUid, /*out*/ camera);
            reply->writeNoException();
            reply->writeInt32(status);
            if (camera != NULL) {
                reply->writeInt32(1);
                reply->writeStrongBinder(camera->asBinder());
            } else {
                reply->writeInt32(0);
            }
            return NO_ERROR;
        } break;
        case CONNECT_PRO: {
            CHECK_INTERFACE(ICameraService, data, reply);
            sp<IProCameraCallbacks> cameraClient =
                interface_cast<IProCameraCallbacks>(data.readStrongBinder());
            int32_t cameraId = data.readInt32();
            const String16 clientName = data.readString16();
            int32_t clientUid = data.readInt32();
            sp<IProCameraUser> camera;
            status_t status = connectPro(cameraClient, cameraId,
                    clientName, clientUid, /*out*/ camera);
            reply->writeNoException();
            reply->writeInt32(status);
            if (camera != NULL) {
                reply->writeInt32(1);
                reply->writeStrongBinder(camera->asBinder());
            } else {
                reply->writeInt32(0);
            }
            return NO_ERROR;
        } break;
        case CONNECT_DEVICE: {
            CHECK_INTERFACE(ICameraService, data, reply);
            sp<ICameraDeviceCallbacks> cameraClient =
                interface_cast<ICameraDeviceCallbacks>(data.readStrongBinder());
            int32_t cameraId = data.readInt32();
            const String16 clientName = data.readString16();
            int32_t clientUid = data.readInt32();
            sp<ICameraDeviceUser> camera;
            status_t status = connectDevice(cameraClient, cameraId,
                    clientName, clientUid, /*out*/ camera);
            reply->writeNoException();
            reply->writeInt32(status);
            if (camera != NULL) {
                reply->writeInt32(1);
                reply->writeStrongBinder(camera->asBinder());
            } else {
                reply->writeInt32(0);
            }
            return NO_ERROR;
        } break;
        case ADD_LISTENER: {
            CHECK_INTERFACE(ICameraService, data, reply);
            sp<ICameraServiceListener> listener =
                interface_cast<ICameraServiceListener>(data.readStrongBinder());
            reply->writeNoException();
            reply->writeInt32(addListener(listener));
            return NO_ERROR;
        } break;
        case REMOVE_LISTENER: {
            CHECK_INTERFACE(ICameraService, data, reply);
            sp<ICameraServiceListener> listener =
                interface_cast<ICameraServiceListener>(data.readStrongBinder());
            reply->writeNoException();
            reply->writeInt32(removeListener(listener));
            return NO_ERROR;
        } break;
        default:
            return BBinder::onTransact(code, data, reply, flags);
    }
}