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