自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release 而非 aosp-main 建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
  
         
       
     
  
  
  
    
  
  
  
    
    
      
    
    
      
      透過集合功能整理內容
    
    
      
      你可以依據偏好儲存及分類內容。
    
  
  
    
  
  
  
  
    
  
  
    
    
    
  
  camera2_device_ops 結構體參考資料
 
  
   #include <
   
    camera2.h
   
   >
  
 
 
  
   |  | 
  
   | int(* | set_request_queue_src_ops
    
    )(const struct
    
     camera2_device
    
    *, const
    
     camera2_request_queue_src_ops_t
    
    *request_src_ops) | 
  
   |  | 
  
   | int(* | notify_request_queue_not_empty
    
    )(const struct
    
     camera2_device
    
    *) | 
  
   |  | 
  
   | int(* | set_frame_queue_dst_ops
    
    )(const struct
    
     camera2_device
    
    *, const
    
     camera2_frame_queue_dst_ops_t
    
    *frame_dst_ops) | 
  
   |  | 
  
   | int(* | get_in_progress_count
    
    )(const struct
    
     camera2_device
    
    *) | 
  
   |  | 
  
   | int(* | flush_captures_in_progress
    
    )(const struct
    
     camera2_device
    
    *) | 
  
   |  | 
  
   | int(* | construct_default_request
    
    )(const struct
    
     camera2_device
    
    *, int request_template,
    
     camera_metadata_t
    
    **request) | 
  
   |  | 
  
   | int(* | allocate_stream
    
    )(const struct
    
     camera2_device
    
    *, uint32_t width, uint32_t height, int format, const
    
     camera2_stream_ops_t
    
    *stream_ops, uint32_t *stream_id, uint32_t *format_actual, uint32_t *usage, uint32_t *max_buffers) | 
  
   |  | 
  
   | int(* | register_stream_buffers
    
    )(const struct
    
     camera2_device
    
    *, uint32_t stream_id, int num_buffers, buffer_handle_t *buffers) | 
  
   |  | 
  
   | int(* | release_stream
    
    )(const struct
    
     camera2_device
    
    *, uint32_t stream_id) | 
  
   |  | 
  
   | int(* | allocate_reprocess_stream
    
    )(const struct
    
     camera2_device
    
    *, uint32_t width, uint32_t height, uint32_t format, const
    
     camera2_stream_in_ops_t
    
    *reprocess_stream_ops, uint32_t *stream_id, uint32_t *consumer_usage, uint32_t *max_buffers) | 
  
   |  | 
  
   | int(* | allocate_reprocess_stream_from_stream
    
    )(const struct
    
     camera2_device
    
    *, uint32_t output_stream_id, const
    
     camera2_stream_in_ops_t
    
    *reprocess_stream_ops, uint32_t *stream_id) | 
  
   |  | 
  
   | int(* | release_reprocess_stream
    
    )(const struct
    
     camera2_device
    
    *, uint32_t stream_id) | 
  
   |  | 
  
   | int(* | trigger_action
    
    )(const struct
    
     camera2_device
    
    *, uint32_t trigger_id, int32_t ext1, int32_t ext2) | 
  
   |  | 
  
   | int(* | set_notify_callback
    
    )(const struct
    
     camera2_device
    
    *,
    
     camera2_notify_callback
    
    notify_cb, void *user) | 
  
   |  | 
  
   | int(* | get_metadata_vendor_tag_ops
    
    )(const struct
    
     camera2_device
    
    *, vendor_tag_query_ops_t **ops) | 
  
   |  | 
  
   | int(* | dump
    
    )(const struct
    
     camera2_device
    
    *, int fd) | 
  
   |  | 
  
   | int(* | get_instance_metadata
    
    )(const struct
    
     camera2_device
    
    *, camera_metadata **instance_metadata) | 
  
   |  | 
 
 
 
 
 
  
   定義位於檔案 
    camera2.h
    的第 
    527
    行。
  
 
 
 
 
  
   
    
     | int(* allocate_reprocess_stream)(const struct
      
       camera2_device
      
      *, uint32_t width, uint32_t height, uint32_t format, const
      
       camera2_stream_in_ops_t
      
      *reprocess_stream_ops,uint32_t *stream_id, uint32_t *consumer_usage, uint32_t *max_buffers) | 
   
   
  
   
    allocate_reprocess_stream:
   
    分配新的輸入串流供使用,並由輸出緩衝區寬度、高度和像素格式定義。成功時,會傳回新串流的 ID、gralloc 使用標記,以及所需的同時可取得緩衝區數量。錯誤狀況:
   
   
    - 
     要求的寬度/高度/格式組合並未列為感應器的靜態特性所支援
    
- 
     要求一次設定過多重新處理串流。
    輸入參數:
   
   
    - 
     width、height、format:透過此串流傳送緩衝區的規格。格式必須是 HAL_PIXEL_FORMAT_* 清單中的值。
- 
     reprocess_stream_ops:函式指標的結構,用於取得及釋放此串流的緩衝區。系統會根據用量和 max_buffers 輸出內容設定基礎串流。
    輸出參數:
   
   
    - 
     stream_id:用於識別此串流的無符號整數。這個值會用於識別串流的傳入請求,以及釋出串流。這些 ID 的編號與輸入串流 ID 分開。
- 
     consumer_usage:HAL 裝置用來使用要求的資料類型所需的 gralloc 用途遮罩。這可用於為串流緩衝區佇列分配新的 gralloc 緩衝區。
- 
     max_buffers:HAL 裝置可能需要同時取得的緩衝區數量上限。裝置可能不會同時取得比這個值更多的緩衝區。
    定義位於檔案 
     camera2.h
     的 
     708
     行。
   
  
 
 
 
  
  
   
    allocate_reprocess_stream_from_stream:
   
   
    分配新的輸入串流供使用,該串流會使用為現有輸出串流分配的緩衝區。也就是說,在 HAL 將緩衝區排入輸出串流後,可能會從這個輸入重新處理串流中看到相同的緩衝區。HAL 將緩衝區釋回至重新處理串流後,就會將其傳回至輸出佇列,以便重複使用。
   
    錯誤狀況:
   
   
    - 
     使用不合適的大小/格式輸出串流,做為重新處理串流的基礎。
- 
     嘗試一次分配太多重新處理串流。
    輸入參數:
   
   
    - 
     output_stream_id:現有輸出串流的 ID,其大小和格式適合重新處理。
- 
     reprocess_stream_ops:函式指標的結構,用於取得及釋放此串流的緩衝區。基礎串流會使用與輸出串流相同的圖形緩衝區句柄。
    輸出參數:
   
   
    - 
     stream_id:用於識別此串流的無符號整數。這個值會用於識別串流的傳入請求,以及釋出串流。這些 ID 的編號與輸入串流 ID 分開。
    HAL 用戶端必須先釋出重新處理串流,才能釋出所依據的輸出串流。
   
    定義位於檔案 
     camera2.h
     的 
     754
     行。
   
  
 
 
 
  
   
    
     | int(* allocate_stream)(const struct
      
       camera2_device
      
      *,uint32_t width, uint32_t height, int format, const
      
       camera2_stream_ops_t
      
      *stream_ops,uint32_t *stream_id, uint32_t *format_actual,uint32_t *usage, uint32_t *max_buffers) | 
   
   
  
   
    allocate_stream:
   
   
    分配新的輸出串流供使用,其定義由輸出緩衝區寬度、高度、目標和可能的像素格式決定。成功時,會傳回新串流的 ID、gralloc 使用旗標、佇列緩衝區的最小數量,以及可能的像素格式。錯誤狀況:
   
   
    - 
     要求的寬度/高度/格式組合並未列為感應器的靜態特性所支援
    
- 
     要求的串流格式類型過多 (例如 2 個 Bayer 原始串流)。
    
    輸入參數:
   
   
    - 
     width、height、format:透過此串流傳送緩衝區的規格。格式是 HAL_PIXEL_FORMAT_* 清單中的值。如果使用 HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,平台 gralloc 模組會根據相機 HAL 和串流使用者提供的用法標記,選取格式。相機 HAL 應檢查在 register_stream_buffers 呼叫中交給它的緩衝區,以便視需要取得特定實作格式。
- 
     stream_ops:函式指標的結構,用於取得此串流的緩衝區並排入佇列。系統會根據用量和 max_buffers 輸出內容設定基礎串流。只有在 allocate_stream 傳回後,才能呼叫這個結構體中的任何方法。
    輸出參數:
   
   
    - 
     stream_id:用於識別此串流的無符號整數。這個值會用於識別串流的傳入請求,以及釋出串流。
- 
     usage:HAL 裝置產生所要求的資料類型時所需的 gralloc 用途遮罩。這可用於為串流緩衝區佇列分配新的 gralloc 緩衝區。
- 
     max_buffers:HAL 裝置可能需要同時取消排隊的緩衝區數量上限。裝置可能不會同時從佇列中移除比這個值更多的緩衝區。
    定義位於檔案 
     camera2.h
     的 
     632
     行。
   
  
 
 
 
  
  
   
    為標準相機用途建立填入的預設要求。
   
    裝置必須傳回完整要求,且必須符合要求的用途而進行設定,該用途必須是 CAMERA2_TEMPLATE_* 列舉之一。除了 android.request.outputStreams 以外,請務必加入所有要求控制項欄位。
   
    傳回的中繼資料緩衝區必須使用 allocate_camera_metadata 進行分配。架構會取得緩衝區的擁有權。
   
    定義位於檔案 
     camera2.h
     的 
     580
     行。
   
  
 
 
 
 
 
 
  
  
   
    清除所有進行中的擷取作業。這包括所有已從佇列中移除的請求 (一般或重新處理),這些請求尚未將任何輸出內容放入串流或影格佇列。部分完成的擷取作業必須正常完成。在清除作業完成之前,請勿從要求佇列中移除任何新要求。
   
    定義位於檔案 
     camera2.h
     的 
     567
     行。
   
  
 
 
 
  
  
   
    裝置目前正在處理的攝影機要求數量 (已從佇列中移除要求的擷取/重新處理作業,但尚未排入輸出管道)。在進行中的數量為 0 之前,架構無法釋出任何串流。
   
    定義位於檔案 
     camera2.h
     的 
     558
     行。
   
  
 
 
 
  
   
    
     | int(* get_instance_metadata)(const struct
      
       camera2_device
      
      *, camera_metadata **instance_metadata) | 
   
   
  
   
    取得裝置執行個體專屬的中繼資料。對於相機裝置的單一例項,這項中繼資料必須是常數,但在 open() 呼叫之間可能不同。在呼叫裝置 close() 方法之前,傳回的 camera_metadata 指標必須有效。
   
    版本資訊:
   
   
    CAMERA_DEVICE_API_VERSION_2_0:
   
    不適用。架構可能無法存取這個函式指標。
   
    CAMERA_DEVICE_API_VERSION_2_1:
   
    有效。可由架構呼叫。
   
    定義位於檔案 
     camera2.h
     的 
     820
     行。
   
  
 
 
 
  
   
    
     | int(* get_metadata_vendor_tag_ops)(const struct
      
       camera2_device
      
      *, vendor_tag_query_ops_t **ops) | 
   
   
  
   
    取得查詢供應商擴充功能中繼資料標記資訊的方法。如果未定義供應商擴充功能代碼,可能會將 ops 設為 NULL。
   
    定義位於檔案 
     camera2.h
     的 
     795
     行。
   
  
 
 
 
  
  
   
    通知裝置要求佇列不再為空。只有在第一個緩衝區新增至新佇列,或來源在回應 dequeue 呼叫時已傳回 NULL 時,才能呼叫此方法。
   
    定義位於檔案 
     camera2.h
     的 
     544
     行。
   
  
 
 
 
  
   
    
     | int(* register_stream_buffers)(const struct
      
       camera2_device
      
      *, uint32_t stream_id, int num_buffers, buffer_handle_t *buffers) | 
   
   
  
   
    註冊指定串流的緩衝區。這個方法會在 allocate_stream 呼叫成功後,且在參照串流的第一個要求排入佇列之前呼叫。這個方法可讓 HAL 裝置對應或準備緩衝區,以供日後使用。num_buffers 保證至少為 max_buffers (來自 allocate_stream),但可能會更大。緩衝區已鎖定,可供使用。在呼叫結束時,所有緩衝區都必須準備好傳回佇列。如果串流格式已設為 HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED,相機 HAL 應在此檢查傳入的緩衝區,以判斷任何平台專屬的像素格式資訊。
   
    定義位於檔案 
     camera2.h
     的 
     657
     行。
   
  
 
 
 
  
   
    
     | int(* release_reprocess_stream)(const struct
      
       camera2_device
      
      *, uint32_t stream_id) | 
   
   
  
   
    釋出重新處理串流。如果在 get_in_progress_count 非零時呼叫,或串流 ID 無效,就會傳回錯誤。
   
    定義位於檔案 
     camera2.h
     的 
     765
     行。
   
  
 
 
 
  
   
    
     | int(* release_stream)(const struct
      
       camera2_device
      
      *, uint32_t stream_id) | 
   
   
  
   
    發布串流。如果在 get_in_progress_count 不為零時呼叫,或串流 ID 無效,就會傳回錯誤。
   
    定義位於檔案 
     camera2.h
     的 
     667
     行。
   
  
 
 
 
 
 
 
 
 
 
 
 
 
  
   
    
     | int(* trigger_action)(const struct
      
       camera2_device
      
      *, uint32_t trigger_id, int32_t ext1, int32_t ext2) | 
   
   
  
   
    觸發非同步活動。這可用於在使用相機 3A 例行程序時,觸發相機 3A 例行程序的特殊行為。如要進一步瞭解觸發 ID 及其引數,請參閱上方的 CAMERA2_TRIGGER_* 說明文件。
   
    定義位於檔案 
     camera2.h
     的 
     779
     行。
   
  
 
這個結構體的說明文件是由下列檔案產生:
 
  - 
   hardware/libhardware/include/hardware/
   
    camera2.h
   
  
 
 
  
  
  
 
  
    
    
      
    
    
  
       
    
    
  
  
  這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
  上次更新時間:2025-07-27 (世界標準時間)。
  
  
  
    
      [[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[]]