美文网首页
2020-07-02

2020-07-02

作者: 海_63ea | 来源:发表于2020-07-02 14:19 被阅读0次
    camera_module_t HAL_MODULE_INFO_SYM __attribute__((visibility("default"))) = {
        .common =
            {
                .tag = HARDWARE_MODULE_TAG,
                .module_api_version = CAMERA_MODULE_API_VERSION_2_3,
                .hal_api_version = HARDWARE_HAL_API_VERSION,
                .id = CAMERA_HARDWARE_MODULE_ID,
                .name = "V4L2 Camera HAL v3",
                .author = "The Android Open Source Project",
                .methods = &v4l2_module_methods,
                .dso = nullptr,
                .reserved = {0},
            },
        .get_number_of_cameras = v4l2_camera_hal::get_number_of_cameras,
        .get_camera_info = v4l2_camera_hal::get_camera_info,
        .set_callbacks = v4l2_camera_hal::set_callbacks,
        .get_vendor_tag_ops = v4l2_camera_hal::get_vendor_tag_ops,
        .open_legacy = v4l2_camera_hal::open_legacy,
        //.set_torch_mode = v4l2_camera_hal::set_torch_mode,
        //.init = nullptr,
        //.get_physical_camera_info = nullptr,
        .reserved = {0},
    };
    
    const camera3_device_ops_t Camera::sOps = {
        .initialize = default_camera_hal::initialize,
        .configure_streams = default_camera_hal::configure_streams,
        .register_stream_buffers = nullptr,
        .construct_default_request_settings
            = default_camera_hal::construct_default_request_settings,
        .process_capture_request = default_camera_hal::process_capture_request,
        .get_metadata_vendor_tag_ops = nullptr,
        .dump = default_camera_hal::dump,
        .flush = default_camera_hal::flush,
        .reserved = {0},
    };
    
    int Camera::openDevice(const hw_module_t *module, hw_device_t **device)
    {
        ALOGI("%s:%d: Opening camera device", __func__, mId);
        ATRACE_CALL();
        android::Mutex::Autolock dl(mDeviceLock);
    
        if (mBusy) {
            ALOGE("%s:%d: Error! Camera device already opened", __func__, mId);
            return -EBUSY;
        }
    
        int connectResult = connect();
        if (connectResult != 0) {
          return connectResult;
        }
        mBusy = true;
        mDevice.common.module = const_cast<hw_module_t*>(module);
        *device = &mDevice.common;
        return 0;
    }
    
    Camera::Camera(int id)
      : mId(id),
        mSettingsSet(false),
        mBusy(false),
        mCallbackOps(NULL),
        mInFlightTracker(new RequestTracker)
    {
        memset(&mTemplates, 0, sizeof(mTemplates));
        memset(&mDevice, 0, sizeof(mDevice));
        mDevice.common.tag    = HARDWARE_DEVICE_TAG;
        mDevice.common.version = CAMERA_DEVICE_API_VERSION_3_2;
        mDevice.common.close  = close_device;
        mDevice.ops           = const_cast<camera3_device_ops_t*>(&sOps);
        mDevice.priv          = this;
    }
    
    int Camera::initialize(const camera3_callback_ops_t *callback_ops)
    {
        int res;
    
        mCallbackOps = callback_ops;
        // per-device specific initialization
        res = initDevice();
        if (res != 0) {
            ALOGE("%s:%d: Failed to initialize device!", __func__, mId);
            return res;
        }
        return 0;
    }
    
    int V4L2Camera::initDevice() {
      HAL_LOG_ENTER();
    
      // Start the buffer enqueue/dequeue threads if they're not already running.
      if (!buffer_enqueuer_->isRunning()) {
        android::status_t res = buffer_enqueuer_->run("Enqueue buffers");
        if (res != android::OK) {
          HAL_LOGE("Failed to start buffer enqueue thread: %d", res);
          return -ENODEV;
        }
      }
      if (!buffer_dequeuer_->isRunning()) {
        android::status_t res = buffer_dequeuer_->run("Dequeue buffers");
        if (res != android::OK) {
          HAL_LOGE("Failed to start buffer dequeue thread: %d", res);
          return -ENODEV;
        }
      }
    
      return 0;
    }
    
    int Camera::configureStreams(camera3_stream_configuration_t *stream_config)
    {
        android::Mutex::Autolock dl(mDeviceLock);
        android::Mutex::Autolock tl(mInFlightTrackerLock);
    
        ALOGV("%s:%d: stream_config=%p", __func__, mId, stream_config);
        ATRACE_CALL();
    
        // Check that there are no in-flight requests.
        if (!mInFlightTracker->Empty()) {
            ALOGE("%s:%d: Can't configure streams while frames are in flight.",
                  __func__, mId);
            return -EINVAL;
        }
    
        // Verify the set of streams in aggregate, and perform configuration if valid.
        int res = validateStreamConfiguration(stream_config);
        if (res) {
            ALOGE("%s:%d: Failed to validate stream set", __func__, mId);
        } else {
            // Set up all streams. Since they've been validated,
            // this should only result in fatal (-ENODEV) errors.
            // This occurs after validation to ensure that if there
            // is a non-fatal error, the stream configuration doesn't change states.
            res = setupStreams(stream_config);
            if (res) {
                ALOGE("%s:%d: Failed to setup stream set", __func__, mId);
            }
        }
    
        // Set trackers based on result.
        if (!res) {
            // Success, set up the in-flight trackers for the new streams.
            mInFlightTracker->SetStreamConfiguration(*stream_config);
            // Must provide new settings for the new configuration.
            mSettingsSet = false;
        } else if (res != -EINVAL) {
            // Fatal error, the old configuration is invalid.
            mInFlightTracker->ClearStreamConfiguration();
        }
        // On a non-fatal error the old configuration, if any, remains valid.
        return res;
    }
    

    相关文章

      网友评论

          本文标题:2020-07-02

          本文链接:https://www.haomeiwen.com/subject/hqwlqktx.html