• 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 STREAM_OPERATOR_ISTREAM_H
17 #define STREAM_OPERATOR_ISTREAM_H
18 
19 #include "camera.h"
20 #include "capture_message.h"
21 #include "ibuffer.h"
22 #include "ipipeline_core.h"
23 #include "object_factory.h"
24 #include "stream_tunnel.h"
25 #include <memory>
26 #include <string>
27 #include <map>
28 
29 #define STREAM_INTENT_TO_STRING(m) #m
30 
31 namespace OHOS::Camera {
32 class CaptureRequest;
33 class OfflineStream;
34 
35 static std::map<VdiStreamIntent, std::string> g_availableStreamType;
36 
37 class IStream {
38 public:
39     virtual ~IStream() = default;
40     virtual RetCode ConfigStream(StreamConfiguration& config) = 0;
41     virtual RetCode CommitStream() = 0;
42     virtual RetCode StartStream() = 0;
43     virtual RetCode StopStream() = 0;
44     virtual RetCode AddRequest(std::shared_ptr<CaptureRequest>& request) = 0;
45     virtual RetCode CancelRequest(const std::shared_ptr<CaptureRequest>& request) = 0;
46     virtual RetCode AttachStreamTunnel(std::shared_ptr<StreamTunnel>& tunnel) = 0;
47     virtual RetCode DetachStreamTunnel() = 0;
48     virtual RetCode ChangeToOfflineStream(std::shared_ptr<OfflineStream> offlineStream) = 0;
49     virtual bool GetTunnelMode() const = 0;
50     virtual StreamConfiguration GetStreamAttribute() const = 0;
51     virtual int32_t GetStreamId() const = 0;
52     virtual RetCode Capture(const std::shared_ptr<CaptureRequest>& request) = 0;
53     virtual RetCode OnFrame(const std::shared_ptr<CaptureRequest>& request) = 0;
54     virtual bool IsRunning() const = 0;
55     virtual void DumpStatsInfo() const = 0;
56     virtual void ReleaseStreamBufferPool() = 0;
57 
58 public:
59     static std::map<VdiStreamIntent, std::string> g_availableStreamType;
60 };
61 
62 using StreamFactory = RegisterFactoty<IStream,
63                                       const int32_t,
64                                       const VdiStreamIntent,
65                                       std::shared_ptr<IPipelineCore>&,
66                                       std::shared_ptr<CaptureMessageOperator>&>;
67 #define REGISTERSTREAM(cls, ...)                                                                           \
68     namespace {                                                                                            \
69     static std::string g_##cls = StreamFactory::Instance().DoRegister<cls>(                                \
70         __VA_ARGS__,                                                                                       \
71         [](const int32_t id,                                                                               \
72            const VdiStreamIntent type,                                                                        \
73            std::shared_ptr<IPipelineCore>& p,                                                              \
74            std::shared_ptr<CaptureMessageOperator>& m) { return std::make_shared<cls>(id, type, p, m); }); \
75     }
76 } // namespace OHOS::Camera
77 #endif // STREAM_OPERATOR_ISTREAM_H
78