diff --git a/config.gni b/config.gni index 190c9e536456590f91c06be51e49c276924f505f..1a92777148c9e0bd915736aef61b4a02ce93d66a 100644 --- a/config.gni +++ b/config.gni @@ -165,6 +165,7 @@ MEDIA_PLAYER_HISTREAMER = "//foundation/multimedia/media_foundation" MEDIA_PLAYER_C_UTILS = "//commonlibrary/c_utils" MEDIA_PLAYER_GRAPHIC = "//foundation/graphic/graphic_2d" +MEDIA_PLAYER_GRAPHIC_SURFACE = "//foundation/graphic/graphic_surface" # Fuzz test output path MODULE_OUTPUT_PATH = "player_framework/player_framework" diff --git a/frameworks/native/capi/screencapture/native_avscreen_capture.cpp b/frameworks/native/capi/screencapture/native_avscreen_capture.cpp index 5679709995b0704781f7d330515b9e31670d8bc9..3a2f24acd1f4d5b860c2240b14af92ad3cdd028b 100644 --- a/frameworks/native/capi/screencapture/native_avscreen_capture.cpp +++ b/frameworks/native/capi/screencapture/native_avscreen_capture.cpp @@ -19,12 +19,15 @@ #include "native_player_magic.h" #include "surface_buffer_impl.h" #include "native_avscreen_capture.h" +#include "native_window.h" namespace { constexpr int MAX_WINDOWS_LEN = 1000; constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN, "NativeScreenCapture"}; } +typedef struct NativeWindow OHNativeWindow; + using namespace OHOS::Media; class NativeScreenCaptureCallback; @@ -173,6 +176,24 @@ OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StartScreenCapture(struct OH_AVSc return AV_SCREEN_CAPTURE_ERR_OK; } +OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StartScreenCaptureWithSurface(struct OH_AVScreenCapture *capture, + OHNativeWindow* window) +{ + CHECK_AND_RETURN_RET_LOG(capture != nullptr, AV_SCREEN_CAPTURE_ERR_INVALID_VAL, "input capture is nullptr!"); + CHECK_AND_RETURN_RET_LOG(window != nullptr, AV_SCREEN_CAPTURE_ERR_INVALID_VAL, "input window is nullptr!"); + CHECK_AND_RETURN_RET_LOG(window->surface != nullptr, AV_SCREEN_CAPTURE_ERR_INVALID_VAL, + "Input window surface is nullptr!"); + + struct ScreenCaptureObject *screenCaptureObj = reinterpret_cast(capture); + CHECK_AND_RETURN_RET_LOG(screenCaptureObj->screenCapture_ != nullptr, + AV_SCREEN_CAPTURE_ERR_INVALID_VAL, "screenCapture_ is null"); + + int32_t ret = screenCaptureObj->screenCapture_->StartScreenCaptureWithSurface(window->surface); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, AV_SCREEN_CAPTURE_ERR_OPERATE_NOT_PERMIT, "StartScreenCapture failed!"); + + return AV_SCREEN_CAPTURE_ERR_OK; +} + OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StopScreenCapture(struct OH_AVScreenCapture *capture) { CHECK_AND_RETURN_RET_LOG(capture != nullptr, AV_SCREEN_CAPTURE_ERR_INVALID_VAL, "input capture is nullptr!"); diff --git a/frameworks/native/screen_capture/screen_capture_impl.cpp b/frameworks/native/screen_capture/screen_capture_impl.cpp index fdbdfcacc7830f256e5d7dc09879947cab420d07..7c329d738ab326e96cdaa1a1f0f8fb7040892776 100644 --- a/frameworks/native/screen_capture/screen_capture_impl.cpp +++ b/frameworks/native/screen_capture/screen_capture_impl.cpp @@ -201,6 +201,20 @@ int32_t ScreenCaptureImpl::StartScreenCapture() } } +int32_t ScreenCaptureImpl::StartScreenCaptureWithSurface(sptr surface) +{ + MEDIA_LOGD("ScreenCaptureImpl:0x%{public}06" PRIXPTR " StartScreenCapture in", FAKE_POINTER(this)); + CHECK_AND_RETURN_RET_LOG(screenCaptureService_ != nullptr, MSERR_UNKNOWN, + "screen capture service does not exist.."); + CHECK_AND_RETURN_RET_LOG(surface != nullptr, MSERR_UNKNOWN, "surface is nullptr"); + if (dataType_ == ORIGINAL_STREAM) { + return screenCaptureService_->StartScreenCaptureWithSurface(surface); + } else { + MEDIA_LOGE("ScreenCaptureImpl::StartScreenCapture error , dataType_ : %{public}d", dataType_); + return MSERR_INVALID_VAL; + } +} + int32_t ScreenCaptureImpl::StopScreenCapture() { MEDIA_LOGD("ScreenCaptureImpl:0x%{public}06" PRIXPTR " StopScreenCapture in", FAKE_POINTER(this)); diff --git a/frameworks/native/screen_capture/screen_capture_impl.h b/frameworks/native/screen_capture/screen_capture_impl.h index 19c854082a6f0e85b80365149165ce5b1e9fe025..0b97a7bc5b9b10ef21517ac11a9a50564260ad42 100644 --- a/frameworks/native/screen_capture/screen_capture_impl.h +++ b/frameworks/native/screen_capture/screen_capture_impl.h @@ -31,6 +31,7 @@ public: int32_t Init(AVScreenCaptureConfig config) override; int32_t SetMicrophoneEnabled(bool isMicrophone) override; int32_t StartScreenCapture() override; + int32_t StartScreenCaptureWithSurface(sptr surface) override; int32_t StopScreenCapture() override; int32_t StartScreenRecording() override; int32_t StopScreenRecording() override; diff --git a/interfaces/inner_api/native/screen_capture.h b/interfaces/inner_api/native/screen_capture.h index 23257a1f73dc0967f1ec79223919c3777496e3c0..23cff65221ed1f3c9771bfb5d718413723cc07c7 100644 --- a/interfaces/inner_api/native/screen_capture.h +++ b/interfaces/inner_api/native/screen_capture.h @@ -166,6 +166,7 @@ public: virtual int32_t Init(AVScreenCaptureConfig config) = 0; virtual int32_t SetMicrophoneEnabled(bool isMicrophone) = 0; virtual int32_t StartScreenCapture() = 0; + virtual int32_t StartScreenCaptureWithSurface(sptr surface) = 0; virtual int32_t StopScreenCapture() = 0; virtual int32_t StartScreenRecording() = 0; virtual int32_t StopScreenRecording() = 0; diff --git a/interfaces/kits/c/avscreen_capture/libnative_avscreen_capture.ndk.json b/interfaces/kits/c/avscreen_capture/libnative_avscreen_capture.ndk.json index f00ca3838ad49102f2e6af120cc9cf8f277304a3..13b7cbbf84e8d748f8bdab1980f0cd048b400f8a 100644 --- a/interfaces/kits/c/avscreen_capture/libnative_avscreen_capture.ndk.json +++ b/interfaces/kits/c/avscreen_capture/libnative_avscreen_capture.ndk.json @@ -2,6 +2,7 @@ { "name": "OH_AVScreenCapture_Create" }, { "name": "OH_AVScreenCapture_Init" }, { "name": "OH_AVScreenCapture_StartScreenCapture" }, + { "name": "OH_AVScreenCapture_StartScreenCaptureWithSurface" }, { "name": "OH_AVScreenCapture_StopScreenCapture" }, { "name": "OH_AVScreenCapture_StartScreenRecording" }, { "name": "OH_AVScreenCapture_StopScreenRecording" }, diff --git a/interfaces/kits/c/native_avscreen_capture.h b/interfaces/kits/c/native_avscreen_capture.h index 22837a29dac5448236f11f5a47ce624914e94396..77db8205cb43631692d5bde96cef132be003edec 100644 --- a/interfaces/kits/c/native_avscreen_capture.h +++ b/interfaces/kits/c/native_avscreen_capture.h @@ -20,6 +20,7 @@ #include #include "native_avscreen_capture_errors.h" #include "native_avscreen_capture_base.h" +#include "external_window.h" #ifdef __cplusplus extern "C" { @@ -61,6 +62,19 @@ OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_Init(struct OH_AVScreenCapture *c */ OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StartScreenCapture(struct OH_AVScreenCapture *capture); +/** + * @brief Start the av screen capture + * @syscap SystemCapability.Multimedia.Media.AVScreenCapture + * @param capture Pointer to an OH_AVScreenCapture instance + * @param window Pointer to an OHNativeWindow instance + * @return Returns AVSCREEN_CAPTURE_ERR_OK if the execution is successful, + * otherwise returns a specific error code, refer to {@link OH_AVSCREEN_CAPTURE_ErrCode} + * @since 12 + * @version 1.0 + */ +OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_StartScreenCaptureWithSurface(struct OH_AVScreenCapture *capture, + OHNativeWindow* window); + /** * @brief Stop the av screen capture * @syscap SystemCapability.Multimedia.Media.AVScreenCapture diff --git a/services/include/i_screen_capture_service.h b/services/include/i_screen_capture_service.h index e4c9b3e4a0f1d8662134eae105109ccaac169c8d..760fabfca73af103ae4bee8406da8f866ae5bad5 100644 --- a/services/include/i_screen_capture_service.h +++ b/services/include/i_screen_capture_service.h @@ -38,6 +38,7 @@ public: virtual int32_t InitVideoEncInfo(VideoEncInfo videoEncInfo) = 0; virtual int32_t InitVideoCap(VideoCaptureInfo videoInfo) = 0; virtual int32_t StartScreenCapture() = 0; + virtual int32_t StartScreenCaptureWithSurface(sptr surface) = 0; virtual int32_t StopScreenCapture() = 0; virtual int32_t AcquireAudioBuffer(std::shared_ptr &audioBuffer, AudioCaptureSourceType type) = 0; virtual int32_t AcquireVideoBuffer(sptr &surfacebuffer, int32_t &fence, diff --git a/services/services/screen_capture/client/screen_capture_client.cpp b/services/services/screen_capture/client/screen_capture_client.cpp index 6925da00362a43367f4ca2a7c48de563c76b7051..8fd8a3a86ed00ab31044a702820b394bc0c6fe30 100644 --- a/services/services/screen_capture/client/screen_capture_client.cpp +++ b/services/services/screen_capture/client/screen_capture_client.cpp @@ -163,6 +163,14 @@ int32_t ScreenCaptureClient::StartScreenCapture() return screenCaptureProxy_->StartScreenCapture(); } +int32_t ScreenCaptureClient::StartScreenCaptureWithSurface(sptr surface) +{ + std::lock_guard lock(mutex_); + CHECK_AND_RETURN_RET_LOG(screenCaptureProxy_ != nullptr, MSERR_NO_MEMORY, "screenCapture service does not exist."); + return screenCaptureProxy_->StartScreenCaptureWithSurface(surface); +} + + int32_t ScreenCaptureClient::StopScreenCapture() { std::lock_guard lock(mutex_); diff --git a/services/services/screen_capture/client/screen_capture_client.h b/services/services/screen_capture/client/screen_capture_client.h index cf2a55fbb143466151e074b6fe7679ac0716fc59..31c9b336dbf37c9e2bd75ca0f4ef3f6192e05704 100644 --- a/services/services/screen_capture/client/screen_capture_client.h +++ b/services/services/screen_capture/client/screen_capture_client.h @@ -40,6 +40,7 @@ public: int32_t InitVideoEncInfo(VideoEncInfo videoEncInfo) override; int32_t InitVideoCap(VideoCaptureInfo videoInfo) override; int32_t StartScreenCapture() override; + int32_t StartScreenCaptureWithSurface(sptr surface) override; int32_t StopScreenCapture() override; int32_t AcquireAudioBuffer(std::shared_ptr &audioBuffer, AudioCaptureSourceType type) override; int32_t AcquireVideoBuffer(sptr &surfaceBuffer, int32_t &fence, diff --git a/services/services/screen_capture/ipc/i_standard_screen_capture_service.h b/services/services/screen_capture/ipc/i_standard_screen_capture_service.h index b65a74a03b6148ed2f75355fa2034bb722c8e78a..fa18ae6a61383759b191bf95fd2cb5760e6d3821 100644 --- a/services/services/screen_capture/ipc/i_standard_screen_capture_service.h +++ b/services/services/screen_capture/ipc/i_standard_screen_capture_service.h @@ -41,6 +41,7 @@ public: virtual int32_t InitVideoEncInfo(VideoEncInfo videoEncInfo) = 0; virtual int32_t InitVideoCap(VideoCaptureInfo videoInfo) = 0; virtual int32_t StartScreenCapture() = 0; + virtual int32_t StartScreenCaptureWithSurface(sptr surface) = 0; virtual int32_t StopScreenCapture() = 0; virtual int32_t SetMicrophoneEnabled(bool isMicrophone) = 0; virtual int32_t SetListenerObject(const sptr &object) = 0; @@ -71,6 +72,7 @@ public: RELEASE_VIDEO_BUF, SET_MIC_ENABLE, START_SCREEN_CAPTURE, + START_SCREEN_CAPTURE_WITH_SURFACE, STOP_SCREEN_CAPTURE, }; diff --git a/services/services/screen_capture/ipc/screen_capture_service_proxy.cpp b/services/services/screen_capture/ipc/screen_capture_service_proxy.cpp index 75caed6ffa5e524d1d2a09f29679b8e5c99ca7be..da1866fb95e942cefe417b64b4011d28a956cea1 100644 --- a/services/services/screen_capture/ipc/screen_capture_service_proxy.cpp +++ b/services/services/screen_capture/ipc/screen_capture_service_proxy.cpp @@ -263,6 +263,34 @@ int32_t ScreenCaptureServiceProxy::StartScreenCapture() return reply.ReadInt32(); } +int32_t ScreenCaptureServiceProxy::StartScreenCaptureWithSurface(sptr surface) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + + bool token = data.WriteInterfaceToken(ScreenCaptureServiceProxy::GetDescriptor()); + CHECK_AND_RETURN_RET_LOG(token, MSERR_INVALID_OPERATION, "Failed to write descriptor!"); + + CHECK_AND_RETURN_RET_LOG(surface != nullptr, MSERR_NO_MEMORY, "surface is nullptr"); + sptr producer = surface->GetProducer(); + CHECK_AND_RETURN_RET_LOG(producer != nullptr, MSERR_NO_MEMORY, "producer is nullptr"); + + sptr object = producer->AsObject(); + if (data.WriteRemoteObject(object)) { + MEDIA_LOGI("ScreenCaptureServiceProxy StartScreenCaptureWithSurface WriteRemoteObject successfully"); + } else { + MEDIA_LOGI("ScreenCaptureServiceProxy StartScreenCaptureWithSurface WriteRemoteObject failed"); + return MSERR_INVALID_OPERATION; + } + + int error = Remote()->SendRequest(START_SCREEN_CAPTURE_WITH_SURFACE, data, reply, option); + CHECK_AND_RETURN_RET_LOG(error == MSERR_OK, MSERR_INVALID_OPERATION, + "StartScreenCapture failed, error: %{public}d", error); + + return reply.ReadInt32(); +} + int32_t ScreenCaptureServiceProxy::StopScreenCapture() { MessageParcel data; diff --git a/services/services/screen_capture/ipc/screen_capture_service_proxy.h b/services/services/screen_capture/ipc/screen_capture_service_proxy.h index a93948bfaf7b43789a4ddb30f63b092b63ab978b..a63a76725407441cde521d8b4b9b733a5b2d609b 100644 --- a/services/services/screen_capture/ipc/screen_capture_service_proxy.h +++ b/services/services/screen_capture/ipc/screen_capture_service_proxy.h @@ -36,6 +36,7 @@ public: int32_t InitVideoEncInfo(VideoEncInfo videoEncInfo) override; int32_t InitVideoCap(VideoCaptureInfo videoInfo) override; int32_t StartScreenCapture() override; + int32_t StartScreenCaptureWithSurface(sptr surface) override; int32_t StopScreenCapture() override; int32_t AcquireAudioBuffer(std::shared_ptr &audioBuffer, AudioCaptureSourceType type) override; int32_t AcquireVideoBuffer(sptr &surfaceBuffer, int32_t &fence, diff --git a/services/services/screen_capture/ipc/screen_capture_service_stub.cpp b/services/services/screen_capture/ipc/screen_capture_service_stub.cpp index c68b04b3ad952d17a86f27ac5aa58453242296f3..2bf746b50d7845c2fd268b4701ce4446897479dd 100644 --- a/services/services/screen_capture/ipc/screen_capture_service_stub.cpp +++ b/services/services/screen_capture/ipc/screen_capture_service_stub.cpp @@ -64,6 +64,8 @@ int32_t ScreenCaptureServiceStub::Init() screenCaptureStubFuncs_[INIT_VIDEO_ENC_INFO] = &ScreenCaptureServiceStub::InitVideoEncInfo; screenCaptureStubFuncs_[INIT_VIDEO_CAP] = &ScreenCaptureServiceStub::InitVideoCap; screenCaptureStubFuncs_[START_SCREEN_CAPTURE] = &ScreenCaptureServiceStub::StartScreenCapture; + screenCaptureStubFuncs_[START_SCREEN_CAPTURE_WITH_SURFACE] = + &ScreenCaptureServiceStub::StartScreenCaptureWithSurface; screenCaptureStubFuncs_[STOP_SCREEN_CAPTURE] = &ScreenCaptureServiceStub::StopScreenCapture; screenCaptureStubFuncs_[ACQUIRE_AUDIO_BUF] = &ScreenCaptureServiceStub::AcquireAudioBuffer; screenCaptureStubFuncs_[ACQUIRE_VIDEO_BUF] = &ScreenCaptureServiceStub::AcquireVideoBuffer; @@ -171,6 +173,14 @@ int32_t ScreenCaptureServiceStub::StartScreenCapture() return screenCaptureServer_->StartScreenCapture(); } +int32_t ScreenCaptureServiceStub::StartScreenCaptureWithSurface(sptr surface) +{ + CHECK_AND_RETURN_RET_LOG(screenCaptureServer_ != nullptr, false, + "screen capture server is nullptr"); + + return screenCaptureServer_->StartScreenCaptureWithSurface(surface); +} + int32_t ScreenCaptureServiceStub::StopScreenCapture() { CHECK_AND_RETURN_RET_LOG(screenCaptureServer_ != nullptr, false, @@ -359,6 +369,26 @@ int32_t ScreenCaptureServiceStub::StartScreenCapture(MessageParcel &data, Messag return MSERR_OK; } +int32_t ScreenCaptureServiceStub::StartScreenCaptureWithSurface(MessageParcel &data, MessageParcel &reply) +{ + CHECK_AND_RETURN_RET_LOG(screenCaptureServer_ != nullptr, MSERR_INVALID_STATE, + "screen capture server is nullptr"); + + sptr object = data.ReadRemoteObject(); + CHECK_AND_RETURN_RET_LOG(object != nullptr, MSERR_NO_MEMORY, + "ScreenCaptureServiceProxy StartScreenCaptureWithSurface object is nullptr"); + + sptr producer = iface_cast(object); + CHECK_AND_RETURN_RET_LOG(producer != nullptr, MSERR_NO_MEMORY, "failed to convert object to producer"); + + sptr surface = Surface::CreateSurfaceAsProducer(producer); + CHECK_AND_RETURN_RET_LOG(surface != nullptr, MSERR_NO_MEMORY, "failed to create surface"); + + int32_t ret = StartScreenCaptureWithSurface(surface); + reply.WriteInt32(ret); + return MSERR_OK; +} + int32_t ScreenCaptureServiceStub::StopScreenCapture(MessageParcel &data, MessageParcel &reply) { CHECK_AND_RETURN_RET_LOG(screenCaptureServer_ != nullptr, MSERR_INVALID_STATE, diff --git a/services/services/screen_capture/ipc/screen_capture_service_stub.h b/services/services/screen_capture/ipc/screen_capture_service_stub.h index ac55badae577b56ce5cfe3798451b240cec7dba8..902d3386c5a6a1a196890ac9db4fbb0af4914d39 100644 --- a/services/services/screen_capture/ipc/screen_capture_service_stub.h +++ b/services/services/screen_capture/ipc/screen_capture_service_stub.h @@ -38,6 +38,7 @@ public: int32_t InitVideoEncInfo(VideoEncInfo videoEncInfo) override; int32_t InitVideoCap(VideoCaptureInfo videoInfo) override; int32_t StartScreenCapture() override; + int32_t StartScreenCaptureWithSurface(sptr surface) override; int32_t StopScreenCapture() override; int32_t AcquireAudioBuffer(std::shared_ptr &audioBuffer, AudioCaptureSourceType type) override; int32_t AcquireVideoBuffer(sptr &surfaceBuffer, int32_t &fence, @@ -60,6 +61,7 @@ private: int32_t InitVideoEncInfo(MessageParcel &data, MessageParcel &reply); int32_t InitVideoCap(MessageParcel &data, MessageParcel &reply); int32_t StartScreenCapture(MessageParcel &data, MessageParcel &reply); + int32_t StartScreenCaptureWithSurface(MessageParcel &data, MessageParcel &reply); int32_t StopScreenCapture(MessageParcel &data, MessageParcel &reply); int32_t SetListenerObject(MessageParcel &data, MessageParcel &reply); int32_t AcquireAudioBuffer(MessageParcel &data, MessageParcel &reply); diff --git a/services/services/screen_capture/server/screen_capture_server.cpp b/services/services/screen_capture/server/screen_capture_server.cpp index 4c8a0e36016424ea043a122b9fb0c72b1152fba4..8d861ef9830a70ca7edc68ff961e472ccc257f9d 100644 --- a/services/services/screen_capture/server/screen_capture_server.cpp +++ b/services/services/screen_capture/server/screen_capture_server.cpp @@ -468,6 +468,54 @@ int32_t ScreenCaptureServer::StartScreenCapture() readInnerAudioLoop_ = std::make_unique(&ScreenCaptureServer::StartAudioInnerCapture, this); } } + isSurfaceMode_ = false; + int32_t ret = StartVideoCapture(); + if (ret == MSERR_OK) { + BehaviorEventWriteForScreenCapture("start", "AVScreenCapture", appinfo_.appUid, appinfo_.appPid); + } + return ret; +} + +int32_t ScreenCaptureServer::StartScreenCaptureWithSurface(sptr surface) +{ + std::lock_guard lock(mutex_); + MediaTrace trace("ScreenCaptureServer::StartScreenCaptureWithSurface"); + MEDIA_LOGI("ScreenCaptureServer::StartScreenCaptureWithSurface start"); + isAudioStart_ = true; + if (audioMicCapturer_ != nullptr) { + if (!audioMicCapturer_->Start()) { + MEDIA_LOGE("Start mic audio stream failed"); + audioMicCapturer_->Release(); + audioMicCapturer_ = nullptr; + isAudioStart_ = false; + } + if (isAudioStart_) { + MEDIA_LOGE("Capturing started"); + isRunning_.store(true); + readAudioLoop_ = std::make_unique(&ScreenCaptureServer::StartAudioCapture, this); + } + } + isAudioInnerStart_ = true; + if (audioInnerCapturer_ != nullptr) { + if (!audioInnerCapturer_->Start()) { + MEDIA_LOGE("Start inner audio stream failed"); + audioInnerCapturer_->Release(); + audioInnerCapturer_ = nullptr; + isAudioInnerStart_ = false; + } + if (isAudioInnerStart_) { + MEDIA_LOGE("Capturing started"); + isInnerRunning_.store(true); + readInnerAudioLoop_ = std::make_unique(&ScreenCaptureServer::StartAudioInnerCapture, this); + } + } + + if (surface == nullptr) { + MEDIA_LOGE("surface is nullptr"); + return MSERR_INVALID_OPERATION; + } + surface_ = surface; + isSurfaceMode_ = true; int32_t ret = StartVideoCapture(); if (ret == MSERR_OK) { BehaviorEventWriteForScreenCapture("start", "AVScreenCapture", appinfo_.appUid, appinfo_.appPid); @@ -507,8 +555,13 @@ int32_t ScreenCaptureServer::StartHomeVideoCapture() CHECK_AND_RETURN_RET_LOG(psurface != nullptr, MSERR_UNKNOWN, "CreateSurfaceAsProducer failed"); std::string virtualScreenName = "screen_capture"; - int32_t ret = CreateVirtualScreen(virtualScreenName, psurface); - CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, MSERR_UNKNOWN, "create virtual screen failed"); + if (isSurfaceMode_ == false) { + int32_t ret = CreateVirtualScreen(virtualScreenName, psurface); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, MSERR_UNKNOWN, "create virtual screen failed"); + } else { + int32_t ret = CreateVirtualScreen(virtualScreenName, surface_); + CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, MSERR_UNKNOWN, "create virtual screen with surface failed"); + } return MSERR_OK; } diff --git a/services/services/screen_capture/server/screen_capture_server.h b/services/services/screen_capture/server/screen_capture_server.h index 3c54b92d87027cfb09ed15e5e5c19f9431c17818..c6d9325d269975927b5475c93c4af2877fcc9eac 100644 --- a/services/services/screen_capture/server/screen_capture_server.h +++ b/services/services/screen_capture/server/screen_capture_server.h @@ -123,6 +123,7 @@ public: int32_t InitVideoEncInfo(VideoEncInfo videoEncInfo) override; int32_t InitVideoCap(VideoCaptureInfo videoInfo) override; int32_t StartScreenCapture() override; + int32_t StartScreenCaptureWithSurface(sptr surface) override; int32_t StopScreenCapture() override; int32_t SetScreenCaptureCallback(const std::shared_ptr &callback) override; int32_t AcquireAudioBuffer(std::shared_ptr &audioBuffer, AudioCaptureSourceType type) override; @@ -144,7 +145,9 @@ private: int32_t StartAudioCapture(); int32_t StartAudioInnerCapture(); int32_t StartVideoCapture(); + int32_t StartVideoCaptureWithSurface(sptr surface); int32_t StartHomeVideoCapture(); + int32_t StartHomeVideoCaptureWithSurface(sptr surface); int32_t StartHomeVideoCaptureFile(); int32_t CreateVirtualScreen(const std::string &name, sptr consumer); VirtualScreenOption InitVirtualScreenOption(const std::string &name, sptr consumer); @@ -205,6 +208,8 @@ private: const std::string MP4 = "mp4"; const std::string M4A = "m4a"; OHOS::AudioStandard::AppInfo appinfo_; + sptr surface_ = nullptr; + bool isSurfaceMode_ = false; static constexpr uint32_t MAX_AUDIO_BUFFER_SIZE = 128; static constexpr uint64_t SEC_TO_NANOSECOND = 1000000000; diff --git a/test/unittest/resources/ohos_test.xml b/test/unittest/resources/ohos_test.xml index 87866f95bb040ea40c5e4ea74df28da7f51f5d05..0d59f6204deb7ba27d3bc8d443a677886fde507c 100644 --- a/test/unittest/resources/ohos_test.xml +++ b/test/unittest/resources/ohos_test.xml @@ -108,6 +108,8 @@