• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_ICAMERA_SOURCE_DATA_PROCESS_PRODUCER_H
17 #define OHOS_ICAMERA_SOURCE_DATA_PROCESS_PRODUCER_H
18 
19 #include <condition_variable>
20 #include <mutex>
21 #include <queue>
22 #include <thread>
23 
24 #include "data_buffer.h"
25 #include "event_handler.h"
26 #include "v1_0/id_camera_provider.h"
27 
28 namespace OHOS {
29 namespace DistributedHardware {
30 using namespace OHOS::HDI::DistributedCamera::V1_0;
31 class DCameraStreamDataProcessProducer {
32 public:
33     typedef enum {
34         DCAMERA_PRODUCER_STATE_STOP = 0,
35         DCAMERA_PRODUCER_STATE_START = 1,
36     } DCameraProducerState;
37 
38     DCameraStreamDataProcessProducer(std::string devId, std::string dhId, int32_t streamId, DCStreamType streamType);
39     ~DCameraStreamDataProcessProducer();
40     void Start();
41     void Stop();
42     void FeedStream(const std::shared_ptr<DataBuffer>& buffer);
43     void UpdateInterval(uint32_t fps);
44 
45 private:
46     void StartEvent();
47     void LooperContinue();
48     void LooperSnapShot();
49     int32_t FeedStreamToDriver(const DHBase& dhBase, const std::shared_ptr<DataBuffer>& buffer);
50     int32_t CheckSharedMemory(const DCameraBuffer& sharedMemory, const std::shared_ptr<DataBuffer>& buffer);
51 
52     const uint32_t DCAMERA_PRODUCER_MAX_BUFFER_SIZE = 30;
53     const uint32_t DCAMERA_PRODUCER_RETRY_SLEEP_MS = 500;
54 
55 private:
56     std::string devId_;
57     std::string dhId_;
58 
59     std::thread eventThread_;
60     std::thread producerThread_;
61     std::condition_variable eventCon_;
62     std::condition_variable producerCon_;
63     std::mutex bufferMutex_;
64     std::mutex eventMutex_;
65     std::queue<std::shared_ptr<DataBuffer>> buffers_;
66     DCameraProducerState state_;
67     uint32_t interval_;
68     int32_t streamId_;
69     DCStreamType streamType_;
70     std::shared_ptr<AppExecFwk::EventHandler> eventHandler_;
71 
72     sptr<IDCameraProvider> camHdiProvider_;
73 };
74 } // namespace DistributedHardware
75 } // namespace OHOS
76 #endif // OHOS_ICAMERA_SOURCE_DATA_PROCESS_PRODUCER_H
77