• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 TEST_SCREEN_CAPTURE_H
17 #define TEST_SCREEN_CAPTURE_H
18 
19 #include <fcntl.h>
20 #include <thread>
21 #include <cstdio>
22 #include <iostream>
23 #include "nativetoken_kit.h"
24 #include "accesstoken_kit.h"
25 #include "token_setproc.h"
26 #include "screen_capture.h"
27 #include "aw_common.h"
28 #include "media_errors.h"
29 
30 namespace OHOS {
31 namespace Media {
32 #define RETURN_IF(cond, ret, ...)        \
33 do {                                     \
34     if (!(cond)) {                       \
35         return ret;                      \
36     }                                    \
37 } while (0)
38 
39 class TestScreenCapture : public NoCopyable {
40 public:
41     TestScreenCapture();
42     ~TestScreenCapture();
43     std::shared_ptr<ScreenCapture> screenCapture = nullptr;
44     bool CreateScreenCapture();
45     bool CreateScreenCapture(OHOS::AudioStandard::AppInfo& appInfo);
46     int32_t SetScreenCaptureCallback(const std::shared_ptr<ScreenCaptureCallBack>& callback);
47     int32_t Init(AVScreenCaptureConfig config);
48     int32_t StartScreenCapture();
49     int32_t StopScreenCapture();
50     int32_t Release();
51     int32_t SetMicrophoneEnabled(bool isMicrophone);
52     int32_t SetCanvasRotation(bool canvasRotation);
53     int32_t ShowCursor(bool showCursor);
54     int32_t ResizeCanvas(int32_t width, int32_t height);
55     int32_t SkipPrivacyMode(std::vector<uint64_t> &windowIDsVec);
56     int32_t SetMaxFrameRate(int32_t frameRate);
57     int32_t AcquireAudioBuffer(std::shared_ptr<AudioBuffer> &audioBuffer, AudioCaptureSourceType type);
58     sptr<OHOS::SurfaceBuffer> AcquireVideoBuffer(int32_t &fence, int64_t &timestamp, Rect &damage);
59     int32_t ReleaseAudioBuffer(AudioCaptureSourceType type);
60     int32_t ReleaseVideoBuffer();
61     int32_t UpdateSurface(sptr<Surface> surface);
62 };
63 
64 class TestScreenCaptureCallbackTest : public ScreenCaptureCallBack, public NoCopyable {
65 public:
TestScreenCaptureCallbackTest()66     TestScreenCaptureCallbackTest() {}
67     ~TestScreenCaptureCallbackTest() = default;
68     std::shared_ptr<TestScreenCapture> screenCapture;
69     void OnError(ScreenCaptureErrorType errorType, int32_t errorCode) override;
70     void OnAudioBufferAvailable(bool isReady, AudioCaptureSourceType type) override;
71     void OnVideoBufferAvailable(bool isReady) override;
72 };
73 } // namespace Media
74 } // namespace OHOS
75 #endif
76