mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-23 07:01:24 +00:00
commit
a2aa54d3e5
@ -16,6 +16,7 @@
|
||||
#include "core/common/ace_engine.h"
|
||||
|
||||
#include <thread>
|
||||
#include "unistd.h"
|
||||
|
||||
#include "base/log/log.h"
|
||||
#include "core/common/ace_page.h"
|
||||
@ -143,4 +144,16 @@ const std::string& AceEngine::GetProcessName() const
|
||||
return processName_;
|
||||
}
|
||||
|
||||
const std::string AceEngine::GetAssetAbsolutePath(const std::string& path) const
|
||||
{
|
||||
for (auto basePath: assetBasePathSet_) {
|
||||
std::string assetPath;
|
||||
assetPath.append(packagePath_).append(basePath).append(path);
|
||||
if (access(assetPath.c_str(), F_OK) == 0) {
|
||||
return "file://" + assetPath;
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
|
@ -53,6 +53,7 @@ public:
|
||||
int32_t GetUid() const;
|
||||
void SetProcessName(const std::string& processName);
|
||||
const std::string& GetProcessName() const;
|
||||
const std::string GetAssetAbsolutePath(const std::string& path) const;
|
||||
|
||||
private:
|
||||
AceEngine();
|
||||
|
@ -49,344 +49,6 @@ public:
|
||||
void TearDown() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @tc.name: RenderTextureTest001
|
||||
* @tc.desc: Verify the video display area with contain fit when the horizontal video is on the vertical screen,
|
||||
* and the video resolution is smaller than the screen resolution.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DAR0T
|
||||
* @tc.author: HeSu
|
||||
*/
|
||||
HWTEST_F(RenderTextureTest, RenderTextureTest001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. construct TextureComponent.
|
||||
* @tc.expected: step1. properties set correctly.
|
||||
*/
|
||||
RefPtr<TextureComponent> component = AceType::MakeRefPtr<TextureComponent>();
|
||||
component->SetTextureId(TEXTURE_ID_DEFAULT);
|
||||
component->SetSrcWidth(VIDEO_WIDTH_SMALL_PORTRAIT);
|
||||
component->SetSrcHeight(VIDEO_HEIGHT_SMALL_PORTRAIT);
|
||||
component->SetFit(ImageFit::CONTAIN);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. construct RenderTexture, update it with component.
|
||||
* @tc.expected: step2. properties is set correctly.
|
||||
*/
|
||||
RefPtr<MockRenderTexture> renderTexture = AceType::MakeRefPtr<MockRenderTexture>();
|
||||
renderTexture->Update(component);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Verify that the properties are calculated correctly.
|
||||
* @tc.expected: step3. Image offset and Size are calculated correctly.
|
||||
*/
|
||||
LayoutParam layoutParam;
|
||||
layoutParam.SetMaxSize(AREA_SMALL_PORTRAIT);
|
||||
renderTexture->SetLayoutParam(layoutParam);
|
||||
renderTexture->PerformLayout();
|
||||
|
||||
Offset imageOffset(0, 200);
|
||||
Size imageSize(720, 880);
|
||||
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageOffset(), imageOffset));
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageSize(), imageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RenderTextureTest002
|
||||
* @tc.desc: Verify the video display area with contain fit when the vertical video is on the vertical screen,
|
||||
* and the video resolution is smaller than the screen resolution.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DAR0T
|
||||
* @tc.author: HeSu
|
||||
*/
|
||||
HWTEST_F(RenderTextureTest, RenderTextureTest002, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. construct TextureComponent.
|
||||
* @tc.expected: step1. properties set correctly.
|
||||
*/
|
||||
RefPtr<TextureComponent> component = AceType::MakeRefPtr<TextureComponent>();
|
||||
component->SetTextureId(TEXTURE_ID_DEFAULT);
|
||||
component->SetSrcWidth(VIDEO_WIDTH_SMALL_LANDSCAPE);
|
||||
component->SetSrcHeight(VIDEO_HEIGHT_SMALL_LANDSCAPE);
|
||||
component->SetFit(ImageFit::CONTAIN);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. construct RenderTexture, update it with component.
|
||||
* @tc.expected: step2. properties is set correctly.
|
||||
*/
|
||||
RefPtr<MockRenderTexture> renderTexture = AceType::MakeRefPtr<MockRenderTexture>();
|
||||
renderTexture->Update(component);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Verify that the properties are calculated correctly.
|
||||
* @tc.expected: step3. Image offset and Size are calculated correctly.
|
||||
*/
|
||||
LayoutParam layoutParam;
|
||||
layoutParam.SetMaxSize(AREA_SMALL_PORTRAIT);
|
||||
renderTexture->SetLayoutParam(layoutParam);
|
||||
renderTexture->PerformLayout();
|
||||
|
||||
Offset imageOffset(0, 345.5);
|
||||
Size imageSize(720, 589);
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageOffset(), imageOffset));
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageSize(), imageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RenderTextureTest003
|
||||
* @tc.desc: Verify the video display area with contain fit when the horizontal video is on the vertical screen,
|
||||
* and the video resolution is greater than the screen resolution.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DAR0T
|
||||
* @tc.author: HeSu
|
||||
*/
|
||||
HWTEST_F(RenderTextureTest, RenderTextureTest003, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. construct TextureComponent.
|
||||
* @tc.expected: step1. properties set correctly.
|
||||
*/
|
||||
RefPtr<TextureComponent> component = AceType::MakeRefPtr<TextureComponent>();
|
||||
component->SetTextureId(TEXTURE_ID_DEFAULT);
|
||||
component->SetSrcWidth(VIDEO_WIDTH_LARGE_PORTRAIT);
|
||||
component->SetSrcHeight(VIDEO_HEIGHT_LARGE_PORTRAIT);
|
||||
component->SetFit(ImageFit::CONTAIN);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. construct RenderTexture, update it with component.
|
||||
* @tc.expected: step2. properties is set correctly.
|
||||
*/
|
||||
RefPtr<MockRenderTexture> renderTexture = AceType::MakeRefPtr<MockRenderTexture>();
|
||||
renderTexture->Update(component);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Verify that the properties are calculated correctly.
|
||||
* @tc.expected: step3. Image offset and Size are calculated correctly.
|
||||
*/
|
||||
LayoutParam layoutParam;
|
||||
layoutParam.SetMaxSize(AREA_SMALL_PORTRAIT);
|
||||
renderTexture->SetLayoutParam(layoutParam);
|
||||
renderTexture->PerformLayout();
|
||||
|
||||
Offset imageOffset(0, 0);
|
||||
Size imageSize(720, 1280);
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageOffset(), imageOffset));
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageSize(), imageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RenderTextureTest004
|
||||
* @tc.desc: Verify the video display area with contain fit when the vertical video is on the vertical screen,
|
||||
* and the video resolution is greater than the screen resolution.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DAR0T
|
||||
* @tc.author: HeSu
|
||||
*/
|
||||
HWTEST_F(RenderTextureTest, RenderTextureTest004, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. construct TextureComponent.
|
||||
* @tc.expected: step1. properties set correctly.
|
||||
*/
|
||||
RefPtr<TextureComponent> component = AceType::MakeRefPtr<TextureComponent>();
|
||||
component->SetTextureId(TEXTURE_ID_DEFAULT);
|
||||
component->SetSrcWidth(VIDEO_WIDTH_LARGE_LANDSCAPE);
|
||||
component->SetSrcHeight(VIDEO_HEIGHT_LARGE_LANDSCAPE);
|
||||
component->SetFit(ImageFit::CONTAIN);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. construct RenderTexture, update it with component.
|
||||
* @tc.expected: step2. properties is set correctly.
|
||||
*/
|
||||
RefPtr<MockRenderTexture> renderTexture = AceType::MakeRefPtr<MockRenderTexture>();
|
||||
renderTexture->Update(component);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Verify that the properties are calculated correctly.
|
||||
* @tc.expected: step3. Image offset and Size are calculated correctly.
|
||||
*/
|
||||
LayoutParam layoutParam;
|
||||
layoutParam.SetMaxSize(AREA_SMALL_PORTRAIT);
|
||||
renderTexture->SetLayoutParam(layoutParam);
|
||||
renderTexture->PerformLayout();
|
||||
|
||||
Offset imageOffset(0, 437);
|
||||
Size imageSize(720, 405);
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageOffset(), imageOffset));
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageSize(), imageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RenderTextureTest005
|
||||
* @tc.desc: Verify the video display area with cover fit when the horizontal video is on the vertical screen,
|
||||
* and the video resolution is smaller than the screen resolution.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DAR0T
|
||||
* @tc.author: HeSu
|
||||
*/
|
||||
HWTEST_F(RenderTextureTest, RenderTextureTest005, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. construct TextureComponent.
|
||||
* @tc.expected: step1. properties set correctly.
|
||||
*/
|
||||
RefPtr<TextureComponent> component = AceType::MakeRefPtr<TextureComponent>();
|
||||
component->SetTextureId(TEXTURE_ID_DEFAULT);
|
||||
component->SetSrcWidth(VIDEO_WIDTH_SMALL_PORTRAIT);
|
||||
component->SetSrcHeight(VIDEO_HEIGHT_SMALL_PORTRAIT);
|
||||
component->SetFit(ImageFit::COVER);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. construct RenderTexture, update it with component.
|
||||
* @tc.expected: step2. properties is set correctly.
|
||||
*/
|
||||
RefPtr<MockRenderTexture> renderTexture = AceType::MakeRefPtr<MockRenderTexture>();
|
||||
renderTexture->Update(component);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Verify that the properties are calculated correctly.
|
||||
* @tc.expected: step3. Image offset and Size are calculated correctly.
|
||||
*/
|
||||
LayoutParam layoutParam;
|
||||
layoutParam.SetMaxSize(AREA_SMALL_PORTRAIT);
|
||||
renderTexture->SetLayoutParam(layoutParam);
|
||||
renderTexture->PerformLayout();
|
||||
|
||||
Offset imageOffset(-163, 0);
|
||||
Size imageSize(1047, 1280);
|
||||
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageOffset(), imageOffset));
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageSize(), imageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RenderTextureTest006
|
||||
* @tc.desc: Verify the video display area with cover fit when the vertical video is on the vertical screen,
|
||||
* and the video resolution is smaller than the screen resolution.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DAR0T
|
||||
* @tc.author: HeSu
|
||||
*/
|
||||
HWTEST_F(RenderTextureTest, RenderTextureTest006, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. construct TextureComponent.
|
||||
* @tc.expected: step1. properties set correctly.
|
||||
*/
|
||||
RefPtr<TextureComponent> component = AceType::MakeRefPtr<TextureComponent>();
|
||||
component->SetTextureId(TEXTURE_ID_DEFAULT);
|
||||
component->SetSrcWidth(VIDEO_WIDTH_SMALL_LANDSCAPE);
|
||||
component->SetSrcHeight(VIDEO_HEIGHT_SMALL_LANDSCAPE);
|
||||
component->SetFit(ImageFit::COVER);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. construct RenderTexture, update it with component.
|
||||
* @tc.expected: step2. properties is set correctly.
|
||||
*/
|
||||
RefPtr<MockRenderTexture> renderTexture = AceType::MakeRefPtr<MockRenderTexture>();
|
||||
renderTexture->Update(component);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Verify that the properties are calculated correctly.
|
||||
* @tc.expected: step3. Image offset and Size are calculated correctly.
|
||||
*/
|
||||
LayoutParam layoutParam;
|
||||
layoutParam.SetMaxSize(AREA_SMALL_PORTRAIT);
|
||||
renderTexture->SetLayoutParam(layoutParam);
|
||||
renderTexture->PerformLayout();
|
||||
|
||||
Offset imageOffset(-422, 0);
|
||||
Size imageSize(1564, 1280);
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageOffset(), imageOffset));
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageSize(), imageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RenderTextureTest007
|
||||
* @tc.desc: Verify the video display area with cover fit when the horizontal video is on the vertical screen,
|
||||
* and the video resolution is greater than the screen resolution.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DAR0T
|
||||
* @tc.author: HeSu
|
||||
*/
|
||||
HWTEST_F(RenderTextureTest, RenderTextureTest007, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. construct TextureComponent.
|
||||
* @tc.expected: step1. properties set correctly.
|
||||
*/
|
||||
RefPtr<TextureComponent> component = AceType::MakeRefPtr<TextureComponent>();
|
||||
component->SetTextureId(TEXTURE_ID_DEFAULT);
|
||||
component->SetSrcWidth(VIDEO_WIDTH_LARGE_PORTRAIT);
|
||||
component->SetSrcHeight(VIDEO_HEIGHT_LARGE_PORTRAIT);
|
||||
component->SetFit(ImageFit::COVER);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. construct RenderTexture, update it with component.
|
||||
* @tc.expected: step2. properties is set correctly.
|
||||
*/
|
||||
RefPtr<MockRenderTexture> renderTexture = AceType::MakeRefPtr<MockRenderTexture>();
|
||||
renderTexture->Update(component);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Verify that the properties are calculated correctly.
|
||||
* @tc.expected: step3. Image offset and Size are calculated correctly.
|
||||
*/
|
||||
LayoutParam layoutParam;
|
||||
layoutParam.SetMaxSize(AREA_SMALL_PORTRAIT);
|
||||
renderTexture->SetLayoutParam(layoutParam);
|
||||
renderTexture->PerformLayout();
|
||||
|
||||
Offset imageOffset(0, 0);
|
||||
Size imageSize(720, 1280);
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageOffset(), imageOffset));
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageSize(), imageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RenderTextureTest008
|
||||
* @tc.desc: Verify the video display area with cover fit when the vertical video is on the vertical screen,
|
||||
* and the video resolution is greater than the screen resolution.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DAR0T
|
||||
* @tc.author: HeSu
|
||||
*/
|
||||
HWTEST_F(RenderTextureTest, RenderTextureTest008, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. construct TextureComponent.
|
||||
* @tc.expected: step1. properties set correctly.
|
||||
*/
|
||||
RefPtr<TextureComponent> component = AceType::MakeRefPtr<TextureComponent>();
|
||||
component->SetTextureId(TEXTURE_ID_DEFAULT);
|
||||
component->SetSrcWidth(VIDEO_WIDTH_LARGE_LANDSCAPE);
|
||||
component->SetSrcHeight(VIDEO_HEIGHT_LARGE_LANDSCAPE);
|
||||
component->SetFit(ImageFit::COVER);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. construct RenderTexture, update it with component.
|
||||
* @tc.expected: step2. properties is set correctly.
|
||||
*/
|
||||
RefPtr<MockRenderTexture> renderTexture = AceType::MakeRefPtr<MockRenderTexture>();
|
||||
renderTexture->Update(component);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Verify that the properties are calculated correctly.
|
||||
* @tc.expected: step3. Image offset and Size are calculated correctly.
|
||||
*/
|
||||
LayoutParam layoutParam;
|
||||
layoutParam.SetMaxSize(AREA_SMALL_PORTRAIT);
|
||||
renderTexture->SetLayoutParam(layoutParam);
|
||||
renderTexture->PerformLayout();
|
||||
|
||||
Offset imageOffset(-778, 0);
|
||||
Size imageSize(2275.56, 1280);
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageOffset(), imageOffset));
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageSize(), imageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RenderTextureTest009
|
||||
* @tc.desc: Verify the video display area with fill fit when the horizontal video is on the vertical screen,
|
||||
@ -559,342 +221,4 @@ HWTEST_F(RenderTextureTest, RenderTextureTest012, TestSize.Level1)
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageSize(), imageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RenderTextureTest013
|
||||
* @tc.desc: Verify the video display area with none fit when the horizontal video is on the vertical screen,
|
||||
* and the video resolution is smaller than the screen resolution.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DAR0T
|
||||
* @tc.author: HeSu
|
||||
*/
|
||||
HWTEST_F(RenderTextureTest, RenderTextureTest013, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. construct TextureComponent.
|
||||
* @tc.expected: step1. properties set correctly.
|
||||
*/
|
||||
RefPtr<TextureComponent> component = AceType::MakeRefPtr<TextureComponent>();
|
||||
component->SetTextureId(TEXTURE_ID_DEFAULT);
|
||||
component->SetSrcWidth(VIDEO_WIDTH_SMALL_PORTRAIT);
|
||||
component->SetSrcHeight(VIDEO_HEIGHT_SMALL_PORTRAIT);
|
||||
component->SetFit(ImageFit::NONE);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. construct RenderTexture, update it with component.
|
||||
* @tc.expected: step2. properties is set correctly.
|
||||
*/
|
||||
RefPtr<MockRenderTexture> renderTexture = AceType::MakeRefPtr<MockRenderTexture>();
|
||||
renderTexture->Update(component);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Verify that the properties are calculated correctly.
|
||||
* @tc.expected: step3. Image offset and Size are calculated correctly.
|
||||
*/
|
||||
LayoutParam layoutParam;
|
||||
layoutParam.SetMaxSize(AREA_SMALL_PORTRAIT);
|
||||
renderTexture->SetLayoutParam(layoutParam);
|
||||
renderTexture->PerformLayout();
|
||||
|
||||
Offset imageOffset(72, 288);
|
||||
Size imageSize(576, 704);
|
||||
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageOffset(), imageOffset));
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageSize(), imageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RenderTextureTest014
|
||||
* @tc.desc: Verify the video display area with none fit when the vertical video is on the vertical screen,
|
||||
* and the video resolution is smaller than the screen resolution.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DAR0T
|
||||
* @tc.author: HeSu
|
||||
*/
|
||||
HWTEST_F(RenderTextureTest, RenderTextureTest014, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. construct TextureComponent.
|
||||
* @tc.expected: step1. properties set correctly.
|
||||
*/
|
||||
RefPtr<TextureComponent> component = AceType::MakeRefPtr<TextureComponent>();
|
||||
component->SetTextureId(TEXTURE_ID_DEFAULT);
|
||||
component->SetSrcWidth(VIDEO_WIDTH_SMALL_LANDSCAPE);
|
||||
component->SetSrcHeight(VIDEO_HEIGHT_SMALL_LANDSCAPE);
|
||||
component->SetFit(ImageFit::NONE);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. construct RenderTexture, update it with component.
|
||||
* @tc.expected: step2. properties is set correctly.
|
||||
*/
|
||||
RefPtr<MockRenderTexture> renderTexture = AceType::MakeRefPtr<MockRenderTexture>();
|
||||
renderTexture->Update(component);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Verify that the properties are calculated correctly.
|
||||
* @tc.expected: step3. Image offset and Size are calculated correctly.
|
||||
*/
|
||||
LayoutParam layoutParam;
|
||||
layoutParam.SetMaxSize(AREA_SMALL_PORTRAIT);
|
||||
renderTexture->SetLayoutParam(layoutParam);
|
||||
renderTexture->PerformLayout();
|
||||
|
||||
Offset imageOffset(8, 352);
|
||||
Size imageSize(704, 576);
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageOffset(), imageOffset));
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageSize(), imageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RenderTextureTest015
|
||||
* @tc.desc: Verify the video display area with none fit when the horizontal video is on the vertical screen,
|
||||
* and the video resolution is greater than the screen resolution.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DAR0T
|
||||
* @tc.author: HeSu
|
||||
*/
|
||||
HWTEST_F(RenderTextureTest, RenderTextureTest015, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. construct TextureComponent.
|
||||
* @tc.expected: step1. properties set correctly.
|
||||
*/
|
||||
RefPtr<TextureComponent> component = AceType::MakeRefPtr<TextureComponent>();
|
||||
component->SetTextureId(TEXTURE_ID_DEFAULT);
|
||||
component->SetSrcWidth(VIDEO_WIDTH_LARGE_PORTRAIT);
|
||||
component->SetSrcHeight(VIDEO_HEIGHT_LARGE_PORTRAIT);
|
||||
component->SetFit(ImageFit::NONE);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. construct RenderTexture, update it with component.
|
||||
* @tc.expected: step2. properties is set correctly.
|
||||
*/
|
||||
RefPtr<MockRenderTexture> renderTexture = AceType::MakeRefPtr<MockRenderTexture>();
|
||||
renderTexture->Update(component);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Verify that the properties are calculated correctly.
|
||||
* @tc.expected: step3. Image offset and Size are calculated correctly.
|
||||
*/
|
||||
LayoutParam layoutParam;
|
||||
layoutParam.SetMaxSize(AREA_SMALL_PORTRAIT);
|
||||
renderTexture->SetLayoutParam(layoutParam);
|
||||
renderTexture->PerformLayout();
|
||||
|
||||
Offset imageOffset(-180, -320);
|
||||
Size imageSize(1080, 1920);
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageOffset(), imageOffset));
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageSize(), imageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RenderTextureTest016
|
||||
* @tc.desc: Verify the video display area with none fit when the vertical video is on the vertical screen,
|
||||
* and the video resolution is greater than the screen resolution.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DAR0T
|
||||
* @tc.author: HeSu
|
||||
*/
|
||||
HWTEST_F(RenderTextureTest, RenderTextureTest016, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. construct TextureComponent.
|
||||
* @tc.expected: step1. properties set correctly.
|
||||
*/
|
||||
RefPtr<TextureComponent> component = AceType::MakeRefPtr<TextureComponent>();
|
||||
component->SetTextureId(TEXTURE_ID_DEFAULT);
|
||||
component->SetSrcWidth(VIDEO_WIDTH_LARGE_LANDSCAPE);
|
||||
component->SetSrcHeight(VIDEO_HEIGHT_LARGE_LANDSCAPE);
|
||||
component->SetFit(ImageFit::NONE);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. construct RenderTexture, update it with component.
|
||||
* @tc.expected: step2. properties is set correctly.
|
||||
*/
|
||||
RefPtr<MockRenderTexture> renderTexture = AceType::MakeRefPtr<MockRenderTexture>();
|
||||
renderTexture->Update(component);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Verify that the properties are calculated correctly.
|
||||
* @tc.expected: step3. Image offset and Size are calculated correctly.
|
||||
*/
|
||||
LayoutParam layoutParam;
|
||||
layoutParam.SetMaxSize(AREA_SMALL_PORTRAIT);
|
||||
renderTexture->SetLayoutParam(layoutParam);
|
||||
renderTexture->PerformLayout();
|
||||
|
||||
Offset imageOffset(-600, 100);
|
||||
Size imageSize(1920, 1080);
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageOffset(), imageOffset));
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageSize(), imageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RenderTextureTest017
|
||||
* @tc.desc: Verify the video display area with scaledown fit when the horizontal video is on the vertical screen,
|
||||
* and the video resolution is smaller than the screen resolution.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DAR0T
|
||||
* @tc.author: HeSu
|
||||
*/
|
||||
HWTEST_F(RenderTextureTest, RenderTextureTest017, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. construct TextureComponent.
|
||||
* @tc.expected: step1. properties set correctly.
|
||||
*/
|
||||
RefPtr<TextureComponent> component = AceType::MakeRefPtr<TextureComponent>();
|
||||
component->SetTextureId(TEXTURE_ID_DEFAULT);
|
||||
component->SetSrcWidth(VIDEO_WIDTH_SMALL_PORTRAIT);
|
||||
component->SetSrcHeight(VIDEO_HEIGHT_SMALL_PORTRAIT);
|
||||
component->SetFit(ImageFit::SCALEDOWN);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. construct RenderTexture, update it with component.
|
||||
* @tc.expected: step2. properties is set correctly.
|
||||
*/
|
||||
RefPtr<MockRenderTexture> renderTexture = AceType::MakeRefPtr<MockRenderTexture>();
|
||||
renderTexture->Update(component);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Verify that the properties are calculated correctly.
|
||||
* @tc.expected: step3. Image offset and Size are calculated correctly.
|
||||
*/
|
||||
LayoutParam layoutParam;
|
||||
layoutParam.SetMaxSize(AREA_SMALL_PORTRAIT);
|
||||
renderTexture->SetLayoutParam(layoutParam);
|
||||
renderTexture->PerformLayout();
|
||||
|
||||
Offset imageOffset(72, 288);
|
||||
Size imageSize(576, 704);
|
||||
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageOffset(), imageOffset));
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageSize(), imageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RenderTextureTest018
|
||||
* @tc.desc: Verify the video display area with scaledown fit when the vertical video is on the vertical screen,
|
||||
* and the video resolution is smaller than the screen resolution.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DAR0T
|
||||
* @tc.author: HeSu
|
||||
*/
|
||||
HWTEST_F(RenderTextureTest, RenderTextureTest018, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. construct TextureComponent.
|
||||
* @tc.expected: step1. properties set correctly.
|
||||
*/
|
||||
RefPtr<TextureComponent> component = AceType::MakeRefPtr<TextureComponent>();
|
||||
component->SetTextureId(TEXTURE_ID_DEFAULT);
|
||||
component->SetSrcWidth(VIDEO_WIDTH_SMALL_LANDSCAPE);
|
||||
component->SetSrcHeight(VIDEO_HEIGHT_SMALL_LANDSCAPE);
|
||||
component->SetFit(ImageFit::SCALEDOWN);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. construct RenderTexture, update it with component.
|
||||
* @tc.expected: step2. properties is set correctly.
|
||||
*/
|
||||
RefPtr<MockRenderTexture> renderTexture = AceType::MakeRefPtr<MockRenderTexture>();
|
||||
renderTexture->Update(component);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Verify that the properties are calculated correctly.
|
||||
* @tc.expected: step3. Image offset and Size are calculated correctly.
|
||||
*/
|
||||
LayoutParam layoutParam;
|
||||
layoutParam.SetMaxSize(AREA_SMALL_PORTRAIT);
|
||||
renderTexture->SetLayoutParam(layoutParam);
|
||||
renderTexture->PerformLayout();
|
||||
|
||||
Offset imageOffset(8, 352);
|
||||
Size imageSize(704, 576);
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageOffset(), imageOffset));
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageSize(), imageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RenderTextureTest019
|
||||
* @tc.desc: Verify the video display area with scaledown fit when the horizontal video is on the vertical screen,
|
||||
* and the video resolution is greater than the screen resolution.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DAR0T
|
||||
* @tc.author: HeSu
|
||||
*/
|
||||
HWTEST_F(RenderTextureTest, RenderTextureTest019, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. construct TextureComponent.
|
||||
* @tc.expected: step1. properties set correctly.
|
||||
*/
|
||||
RefPtr<TextureComponent> component = AceType::MakeRefPtr<TextureComponent>();
|
||||
component->SetTextureId(TEXTURE_ID_DEFAULT);
|
||||
component->SetSrcWidth(VIDEO_WIDTH_LARGE_PORTRAIT);
|
||||
component->SetSrcHeight(VIDEO_HEIGHT_LARGE_PORTRAIT);
|
||||
component->SetFit(ImageFit::SCALEDOWN);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. construct RenderTexture, update it with component.
|
||||
* @tc.expected: step2. properties is set correctly.
|
||||
*/
|
||||
RefPtr<MockRenderTexture> renderTexture = AceType::MakeRefPtr<MockRenderTexture>();
|
||||
renderTexture->Update(component);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Verify that the properties are calculated correctly.
|
||||
* @tc.expected: step3. Image offset and Size are calculated correctly.
|
||||
*/
|
||||
LayoutParam layoutParam;
|
||||
layoutParam.SetMaxSize(AREA_SMALL_PORTRAIT);
|
||||
renderTexture->SetLayoutParam(layoutParam);
|
||||
renderTexture->PerformLayout();
|
||||
|
||||
Offset imageOffset(0, 0);
|
||||
Size imageSize(720, 1280);
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageOffset(), imageOffset));
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageSize(), imageSize));
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: RenderTextureTest020
|
||||
* @tc.desc: Verify the video display area with scaledown fit when the vertical video is on the vertical screen,
|
||||
* and the video resolution is greater than the screen resolution.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000DAR0T
|
||||
* @tc.author: HeSu
|
||||
*/
|
||||
HWTEST_F(RenderTextureTest, RenderTextureTest020, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. construct TextureComponent.
|
||||
* @tc.expected: step1. properties set correctly.
|
||||
*/
|
||||
RefPtr<TextureComponent> component = AceType::MakeRefPtr<TextureComponent>();
|
||||
component->SetTextureId(TEXTURE_ID_DEFAULT);
|
||||
component->SetSrcWidth(VIDEO_WIDTH_LARGE_LANDSCAPE);
|
||||
component->SetSrcHeight(VIDEO_HEIGHT_LARGE_LANDSCAPE);
|
||||
component->SetFit(ImageFit::SCALEDOWN);
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. construct RenderTexture, update it with component.
|
||||
* @tc.expected: step2. properties is set correctly.
|
||||
*/
|
||||
RefPtr<MockRenderTexture> renderTexture = AceType::MakeRefPtr<MockRenderTexture>();
|
||||
renderTexture->Update(component);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Verify that the properties are calculated correctly.
|
||||
* @tc.expected: step3. Image offset and Size are calculated correctly.
|
||||
*/
|
||||
LayoutParam layoutParam;
|
||||
layoutParam.SetMaxSize(AREA_SMALL_PORTRAIT);
|
||||
renderTexture->SetLayoutParam(layoutParam);
|
||||
renderTexture->PerformLayout();
|
||||
|
||||
Offset imageOffset(0, 437);
|
||||
Size imageSize(720, 405);
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageOffset(), imageOffset));
|
||||
ASSERT_TRUE(IsNearEqual(renderTexture->GetImageSize(), imageSize));
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace
|
@ -24,4 +24,17 @@ build_component("video") {
|
||||
"video_component.cpp",
|
||||
"video_element.cpp",
|
||||
]
|
||||
|
||||
if (is_standard_system && !use_mingw_win && !use_mac) {
|
||||
include_dirs = [
|
||||
"//drivers/peripheral/display/interfaces/include",
|
||||
"//foundation/multimedia/media_standard/interfaces/innerkits/native/include",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//foundation/graphic/standard:libwms_client",
|
||||
]
|
||||
|
||||
external_deps = [ "ipc:ipc_core" ]
|
||||
}
|
||||
}
|
||||
|
128
frameworks/core/components/video/media_player_callback.h
Normal file
128
frameworks/core/components/video/media_player_callback.h
Normal file
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MEDIA_PLAYER_CALLBACK_H
|
||||
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MEDIA_PLAYER_CALLBACK_H
|
||||
|
||||
#include "base/log/log.h"
|
||||
|
||||
#include "foundation/multimedia/media_standard/interfaces/innerkits/native/media/include/player.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
namespace {
|
||||
|
||||
constexpr int32_t MILLISECONDS_TO_SECONDS = 1000;
|
||||
|
||||
} // namespace
|
||||
|
||||
struct MediaPlayerCallback : public Media::PlayerCallback {
|
||||
|
||||
public:
|
||||
using PositionUpdatedEvent = std::function<void(uint32_t)>;
|
||||
using EndOfStreamEvent = std::function<void()>;
|
||||
using StateChangedEvent = std::function<void(bool)>;
|
||||
|
||||
MediaPlayerCallback() = default;
|
||||
~MediaPlayerCallback() = default;
|
||||
|
||||
void OnError(int32_t errorType, int32_t errorCode) override
|
||||
{
|
||||
LOGE("OnError callback, errorType: %{public}d, errorCode: %{public}d", errorType, errorCode);
|
||||
}
|
||||
|
||||
void OnEndOfStream(bool isLooping) override
|
||||
{
|
||||
(void)isLooping;
|
||||
LOGI("OnEndOfStream callback");
|
||||
if (endOfStreamEvent_ != nullptr) {
|
||||
endOfStreamEvent_();
|
||||
}
|
||||
}
|
||||
|
||||
void OnStateChanged(OHOS::Media::PlayerStates state) override
|
||||
{
|
||||
LOGI("OnStateChanged callback");
|
||||
PrintState(state);
|
||||
if (stateChangedEvent_ != nullptr) {
|
||||
stateChangedEvent_(state == OHOS::Media::PLAYER_STARTED);
|
||||
}
|
||||
}
|
||||
|
||||
void OnSeekDone(uint64_t currentPosition) override
|
||||
{
|
||||
LOGI("OnSeekDone callback");
|
||||
if (positionUpdatedEvent_ != nullptr && currentPosition != 0) {
|
||||
positionUpdatedEvent_(currentPosition / MILLISECONDS_TO_SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
void OnPositionUpdated(uint64_t position) override
|
||||
{
|
||||
if (positionUpdatedEvent_ != nullptr && position != 0) {
|
||||
positionUpdatedEvent_(position / MILLISECONDS_TO_SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
void OnMessage(int32_t type, int32_t extra) override
|
||||
{
|
||||
(void)extra;
|
||||
LOGI("OnMessage callback type: %{public}d", type);
|
||||
}
|
||||
|
||||
void PrintState(OHOS::Media::PlayerStates state) const
|
||||
{
|
||||
switch (state) {
|
||||
case OHOS::Media::PLAYER_STOPPED:
|
||||
LOGI("State: Stopped");
|
||||
break;
|
||||
case OHOS::Media::PLAYER_PREPARED:
|
||||
LOGI("State: Buffering");
|
||||
break;
|
||||
case OHOS::Media::PLAYER_PAUSED:
|
||||
LOGI("State: Paused");
|
||||
break;
|
||||
case OHOS::Media::PLAYER_STARTED:
|
||||
LOGI("State: Playing");
|
||||
break;
|
||||
default:
|
||||
LOGI("Invalid state");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void SetPositionUpdatedEvent(PositionUpdatedEvent&& positionUpdatedEvent)
|
||||
{
|
||||
positionUpdatedEvent_ = std::move(positionUpdatedEvent);
|
||||
}
|
||||
|
||||
void SetEndOfStreamEvent(EndOfStreamEvent&& endOfStreamEvent)
|
||||
{
|
||||
endOfStreamEvent_ = std::move(endOfStreamEvent);
|
||||
}
|
||||
|
||||
void SetStateChangedEvent(StateChangedEvent&& stateChangedEvent)
|
||||
{
|
||||
stateChangedEvent_ = std::move(stateChangedEvent);
|
||||
}
|
||||
|
||||
private:
|
||||
PositionUpdatedEvent positionUpdatedEvent_;
|
||||
EndOfStreamEvent endOfStreamEvent_;
|
||||
StateChangedEvent stateChangedEvent_;
|
||||
};
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
|
||||
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MEDIA_PLAYER_CALLBACK_H
|
@ -28,7 +28,6 @@ void RenderTexture::Update(const RefPtr<Component>& component)
|
||||
|
||||
textureId_ = texture->GetTextureId();
|
||||
sourceSize_ = Size(static_cast<double>(texture->GetSrcWidth()), static_cast<double>(texture->GetSrcHeight()));
|
||||
imageFit_ = texture->GetFit();
|
||||
|
||||
MarkNeedLayout();
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ protected:
|
||||
int64_t textureId_ = INVALID_TEXTURE;
|
||||
Size drawSize_; // size of draw area
|
||||
Size sourceSize_; // size of source
|
||||
ImageFit imageFit_ = ImageFit::CONTAIN;
|
||||
ImageFit imageFit_ = ImageFit::FILL;
|
||||
double alignmentX_ = 0.0;
|
||||
double alignmentY_ = 0.0;
|
||||
|
||||
|
@ -85,6 +85,9 @@ void Player::CreatePlayer(const std::function<void(int64_t)>& onCreate)
|
||||
return;
|
||||
}
|
||||
auto resRegister = context->GetPlatformResRegister();
|
||||
if (resRegister == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::stringstream paramStream;
|
||||
paramStream << PLAYER_PARAM_TEXTURE << PARAM_EQUALS << textureId_;
|
||||
std::string param = paramStream.str();
|
||||
@ -334,6 +337,9 @@ void Player::UnregisterEvent()
|
||||
return;
|
||||
}
|
||||
auto resRegister = context->GetPlatformResRegister();
|
||||
if (resRegister == nullptr) {
|
||||
return;
|
||||
}
|
||||
resRegister->UnregisterEvent(MakeEventHash(PLAYER_EVENT_PREPARED));
|
||||
resRegister->UnregisterEvent(MakeEventHash(PLAYER_EVENT_COMPLETION));
|
||||
resRegister->UnregisterEvent(MakeEventHash(PLAYER_EVENT_SEEKCOMPLETE));
|
||||
|
@ -45,6 +45,9 @@ void Resource::Release(const std::function<void(bool)>& onRelease)
|
||||
auto resRegister = context->GetPlatformResRegister();
|
||||
auto platformTaskExecutor = SingleTaskExecutor::Make(context->GetTaskExecutor(), TaskExecutor::TaskType::PLATFORM);
|
||||
auto releaseTask = [this, resRegister, onRelease] {
|
||||
if (resRegister == nullptr) {
|
||||
return;
|
||||
}
|
||||
bool ret = resRegister->ReleaseResource(hash_);
|
||||
if (ret) {
|
||||
id_ = INVALID_ID;
|
||||
@ -157,6 +160,9 @@ void Resource::CallResRegisterMethod(
|
||||
auto platformTaskExecutor = SingleTaskExecutor::Make(context->GetTaskExecutor(), TaskExecutor::TaskType::PLATFORM);
|
||||
|
||||
platformTaskExecutor.PostTask([method, param, resRegister, callback] {
|
||||
if (resRegister == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::string result;
|
||||
resRegister->OnMethodCall(method, param, result);
|
||||
if (callback) {
|
||||
|
@ -40,6 +40,9 @@ Texture::~Texture()
|
||||
}
|
||||
|
||||
auto resRegister = context->GetPlatformResRegister();
|
||||
if (resRegister == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto platformTaskExecutor = SingleTaskExecutor::Make(context->GetTaskExecutor(), TaskExecutor::TaskType::PLATFORM);
|
||||
if (platformTaskExecutor.IsRunOnCurrentThread()) {
|
||||
resRegister->UnregisterEvent(MakeEventHash(TEXTURE_METHOD_REFRESH));
|
||||
@ -72,6 +75,9 @@ void Texture::CreateTexture(const std::function<void(int64_t)>& onCreate)
|
||||
{
|
||||
auto context = context_.Upgrade();
|
||||
auto resRegister = context->GetPlatformResRegister();
|
||||
if (resRegister == nullptr) {
|
||||
return;
|
||||
}
|
||||
id_ = resRegister->CreateResource(type_, PARAM_NONE);
|
||||
if (id_ == INVALID_ID) {
|
||||
if (onError_) {
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
#include <securec.h>
|
||||
#include <sstream>
|
||||
|
||||
#include "base/i18n/localization.h"
|
||||
@ -25,6 +26,7 @@
|
||||
#include "base/log/log.h"
|
||||
#include "base/resource/internal_resource.h"
|
||||
#include "base/utils/utils.h"
|
||||
#include "core/common/ace_engine.h"
|
||||
#include "core/components/align/align_component.h"
|
||||
#include "core/components/box/box_component.h"
|
||||
#include "core/components/button/button_component.h"
|
||||
@ -42,6 +44,8 @@
|
||||
#include "core/event/back_end_event_manager.h"
|
||||
#include "core/pipeline/base/composed_component.h"
|
||||
#include "core/pipeline/pipeline_context.h"
|
||||
#include "display_type.h"
|
||||
#include "surface.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
namespace {
|
||||
@ -50,6 +54,10 @@ const char* PLAY_LABEL = "play";
|
||||
const char* PAUSE_LABEL = "pause";
|
||||
const char* FULLSCREEN_LABEL = "fullscreen";
|
||||
const char* EXIT_FULLSCREEN_LABEL = "exitFullscreen";
|
||||
const char* SURFACE_STRIDE_ALIGNMENT = "8";
|
||||
constexpr int32_t SURFACE_QUEUE_SIZE = 5;
|
||||
constexpr int32_t WINDOW_HEIGHT_DEFAULT = 1;
|
||||
constexpr int32_t WINDOW_WIDTH_DEFAULT = 1;
|
||||
|
||||
} // namespace
|
||||
|
||||
@ -86,6 +94,9 @@ VideoElement::~VideoElement()
|
||||
}
|
||||
}
|
||||
ReleasePlatformResource();
|
||||
if (mediaPlayer_ != nullptr) {
|
||||
mediaPlayer_->Release();
|
||||
}
|
||||
}
|
||||
|
||||
void VideoElement::PerformBuild()
|
||||
@ -108,6 +119,7 @@ void VideoElement::InitStatus(const RefPtr<VideoComponent>& videoComponent)
|
||||
src_ = videoComponent->GetSrc();
|
||||
poster_ = videoComponent->GetPoster();
|
||||
isFullScreen_ = videoComponent->IsFullscreen();
|
||||
PreparePlayer();
|
||||
|
||||
if (!videoComponent->GetPlayer().Invalid() && !videoComponent->GetTexture().Invalid()) {
|
||||
player_ = videoComponent->GetPlayer().Upgrade();
|
||||
@ -122,6 +134,151 @@ void VideoElement::InitStatus(const RefPtr<VideoComponent>& videoComponent)
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<OHOS::SubWindow> VideoElement::CreateSubWindow()
|
||||
{
|
||||
OHOS::WindowManager* windowManager = OHOS::WindowManager::GetInstance();
|
||||
if (windowManager == nullptr) {
|
||||
LOGE("Window manager get instance failed");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
auto context = context_.Upgrade();
|
||||
if (context == nullptr) {
|
||||
LOGE("context is nullptr");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int32_t windowId = context->GetWindowId();
|
||||
OHOS::WindowConfig windowConfig;
|
||||
memset_s(&windowConfig, sizeof(OHOS::WindowConfig), 0, sizeof(OHOS::WindowConfig));
|
||||
windowConfig.height = WINDOW_HEIGHT_DEFAULT;
|
||||
windowConfig.width = WINDOW_WIDTH_DEFAULT;
|
||||
windowConfig.pos_x = 0;
|
||||
windowConfig.pos_y = 0;
|
||||
windowConfig.type = WINDOW_TYPE_NORMAL;
|
||||
windowConfig.format = PIXEL_FMT_RGBA_8888;
|
||||
windowConfig.subwindow = true;
|
||||
return windowManager->CreateSubWindow(windowId, &windowConfig);
|
||||
}
|
||||
|
||||
void VideoElement::RegistMediaPlayerEvent()
|
||||
{
|
||||
auto context = context_.Upgrade();
|
||||
if (context == nullptr) {
|
||||
LOGE("context is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
auto uiTaskExecutor = SingleTaskExecutor::Make(context->GetTaskExecutor(), TaskExecutor::TaskType::UI);
|
||||
auto videoElement = WeakClaim(this);
|
||||
|
||||
auto&& positionUpdatedEvent = [videoElement, uiTaskExecutor](uint32_t currentPos) {
|
||||
uiTaskExecutor.PostSyncTask([&videoElement, currentPos] {
|
||||
auto video = videoElement.Upgrade();
|
||||
if (video != nullptr) {
|
||||
video->OnCurrentTimeChange(currentPos);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
auto&& stateChangedEvent = [videoElement, uiTaskExecutor](bool isPlaying) {
|
||||
uiTaskExecutor.PostSyncTask([&videoElement, isPlaying] {
|
||||
auto video = videoElement.Upgrade();
|
||||
if (video) {
|
||||
LOGD("OnPlayerStatus");
|
||||
video->OnPlayerStatus(isPlaying);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
auto&& endOfStreamEvent = [videoElement, uiTaskExecutor] {
|
||||
uiTaskExecutor.PostSyncTask([&videoElement] {
|
||||
auto video = videoElement.Upgrade();
|
||||
if (video) {
|
||||
LOGD("OnCompletion");
|
||||
video->OnCompletion();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
mediaPlayerCallback_ = std::make_shared<MediaPlayerCallback>();
|
||||
mediaPlayerCallback_->SetPositionUpdatedEvent(positionUpdatedEvent);
|
||||
mediaPlayerCallback_->SetStateChangedEvent(stateChangedEvent);
|
||||
mediaPlayerCallback_->SetEndOfStreamEvent(endOfStreamEvent);
|
||||
mediaPlayer_->SetPlayerCallback(mediaPlayerCallback_);
|
||||
}
|
||||
|
||||
void VideoElement::CreateMediaPlayer()
|
||||
{
|
||||
if (mediaPlayer_ != nullptr) {
|
||||
return;
|
||||
}
|
||||
subWindow_ = CreateSubWindow();
|
||||
if (subWindow_ == nullptr) {
|
||||
LOGE("Create subwindow failed");
|
||||
return;
|
||||
}
|
||||
|
||||
mediaPlayer_ = OHOS::Media::PlayerFactory::CreatePlayer();
|
||||
if (mediaPlayer_ == nullptr) {
|
||||
LOGE("Create player failed");
|
||||
return;
|
||||
}
|
||||
|
||||
PreparePlayer();
|
||||
}
|
||||
|
||||
void VideoElement::PreparePlayer()
|
||||
{
|
||||
if (mediaPlayer_ == nullptr) {
|
||||
LOGE("mediaPlayer_ is nullptr");
|
||||
return;
|
||||
}
|
||||
|
||||
if (mediaPlayer_->Reset() != 0) {
|
||||
LOGE("Player Reset failed");
|
||||
return;
|
||||
}
|
||||
const std::string filePath = AceEngine::Get().GetAssetAbsolutePath(src_);
|
||||
LOGI("filePath : %{private}s", filePath.c_str());
|
||||
if (mediaPlayer_->SetSource(filePath) != 0) {
|
||||
LOGE("Player SetSource failed");
|
||||
return;
|
||||
}
|
||||
RegistMediaPlayerEvent();
|
||||
sptr<Surface> producerSurface = subWindow_->GetSurface();
|
||||
if (producerSurface == nullptr) {
|
||||
LOGE("producerSurface is nullptr");
|
||||
return;
|
||||
}
|
||||
producerSurface->SetQueueSize(SURFACE_QUEUE_SIZE);
|
||||
producerSurface->SetUserData("SURFACE_STRIDE_ALIGNMENT", SURFACE_STRIDE_ALIGNMENT);
|
||||
producerSurface->SetUserData("SURFACE_FORMAT", std::to_string(PIXEL_FMT_RGBA_8888));
|
||||
if (mediaPlayer_->SetVideoSurface(producerSurface) != 0) {
|
||||
LOGE("Player SetVideoSurface failed");
|
||||
return;
|
||||
}
|
||||
if (mediaPlayer_->Prepare() != 0) {
|
||||
LOGE("Player prepare failed");
|
||||
return;
|
||||
}
|
||||
|
||||
auto context = context_.Upgrade();
|
||||
if (context == nullptr) {
|
||||
LOGE("context is nullptr");
|
||||
return;
|
||||
}
|
||||
auto uiTaskExecutor = SingleTaskExecutor::Make(context->GetTaskExecutor(), TaskExecutor::TaskType::UI);
|
||||
auto videoElement = WeakClaim(this);
|
||||
uiTaskExecutor.PostSyncTask([&videoElement] {
|
||||
auto video = videoElement.Upgrade();
|
||||
if (video) {
|
||||
video->OnPrepared(0.0, 0.0, false, 0, 0, true);
|
||||
LOGI("Video OnPrepared");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void VideoElement::ResetStatus()
|
||||
{
|
||||
needControls_ = true;
|
||||
@ -167,6 +324,7 @@ void VideoElement::Prepare(const WeakPtr<Element>& parent)
|
||||
|
||||
RenderElement::Prepare(parent);
|
||||
if (renderNode_) {
|
||||
CreateMediaPlayer();
|
||||
auto renderTexture = AceType::DynamicCast<RenderTexture>(renderNode_);
|
||||
if (renderTexture) {
|
||||
renderTexture->SetHiddenChangeEvent([weak = WeakClaim(this)](bool hidden) {
|
||||
@ -189,8 +347,30 @@ void VideoElement::Prepare(const WeakPtr<Element>& parent)
|
||||
|
||||
void VideoElement::OnTextureSize(int64_t textureId, int32_t textureWidth, int32_t textureHeight)
|
||||
{
|
||||
if (texture_) {
|
||||
texture_->OnSize(textureId, textureWidth, textureHeight);
|
||||
if (subWindow_ != nullptr) {
|
||||
auto context = context_.Upgrade();
|
||||
if (context == nullptr) {
|
||||
LOGE("context is nullptr");
|
||||
return;
|
||||
}
|
||||
int32_t height = textureHeight;
|
||||
if (needControls_) {
|
||||
height -= theme_->GetBtnSize().Height();
|
||||
height -= theme_->GetBtnEdge().Top().Value();
|
||||
height -= theme_->GetBtnEdge().Bottom().Value();
|
||||
}
|
||||
if (height <= 0) {
|
||||
height = textureHeight;
|
||||
}
|
||||
float viewScale = context->GetViewScale();
|
||||
subWindow_->SetSubWindowSize(textureWidth * viewScale, height * viewScale);
|
||||
LOGI("SetSubWindowSize width: %{public}f, height: %{public}f", textureWidth * viewScale, height * viewScale);
|
||||
|
||||
if (renderNode_ != nullptr) {
|
||||
Offset offset = renderNode_->GetGlobalOffset();
|
||||
subWindow_->Move(offset.GetX() * viewScale, offset.GetY() * viewScale);
|
||||
LOGI("SubWindow move X: %{public}f, Y: %{public}f", offset.GetX() * viewScale, offset.GetY() * viewScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -341,7 +521,6 @@ void VideoElement::SetNewComponent(const RefPtr<Component>& newComponent)
|
||||
CreatePlatformResource();
|
||||
}
|
||||
if (texture_) {
|
||||
videoComponent->SetTextureId(texture_->GetId());
|
||||
videoComponent->SetSrcWidth(videoWidth_);
|
||||
videoComponent->SetSrcHeight(videoHeight_);
|
||||
videoComponent->SetFit(imageFit_);
|
||||
@ -678,7 +857,6 @@ void VideoElement::OnPrepared(
|
||||
IntTimeToText(currentPos_, currentPosText_);
|
||||
|
||||
auto video = AceType::MakeRefPtr<VideoComponent>();
|
||||
video->SetTextureId(texture_->GetId());
|
||||
video->SetSrcWidth(videoWidth_);
|
||||
video->SetSrcHeight(videoHeight_);
|
||||
video->SetFit(imageFit_);
|
||||
@ -725,6 +903,17 @@ void VideoElement::OnPlayerStatus(bool isPlaying)
|
||||
|
||||
void VideoElement::OnCurrentTimeChange(uint32_t currentPos)
|
||||
{
|
||||
if (currentPos == currentPos_) {
|
||||
return;
|
||||
}
|
||||
if (duration_ == 0) {
|
||||
uint64_t duration = 0;
|
||||
if (mediaPlayer_->GetDuration(duration) == 0) {
|
||||
duration_ = duration / MILLISECONDS_TO_SECONDS;
|
||||
IntTimeToText(duration_, durationText_);
|
||||
}
|
||||
}
|
||||
|
||||
isInitialState_ = isInitialState_ ? currentPos == 0 : false;
|
||||
IntTimeToText(currentPos, currentPosText_);
|
||||
currentPos_ = currentPos;
|
||||
@ -863,8 +1052,6 @@ const RefPtr<Component> VideoElement::CreateControl()
|
||||
|
||||
rowChildren.emplace_back(SetPadding(CreateDurationText(), Edge(theme_->GetTextEdge())));
|
||||
|
||||
rowChildren.emplace_back(SetPadding(CreateFullScreenBtn(), Edge(theme_->GetBtnEdge())));
|
||||
|
||||
auto decoration = AceType::MakeRefPtr<Decoration>();
|
||||
decoration->SetBackgroundColor(theme_->GetBkgColor());
|
||||
auto box = AceType::MakeRefPtr<BoxComponent>();
|
||||
@ -901,8 +1088,6 @@ const RefPtr<Component> VideoElement::CreateChild()
|
||||
RefPtr<Component> child;
|
||||
if (isInitialState_ && !poster_.empty()) {
|
||||
std::list<RefPtr<Component>> columnChildren;
|
||||
columnChildren.emplace_back(AceType::MakeRefPtr<FlexItemComponent>(VIDEO_CHILD_COMMON_FLEX_GROW,
|
||||
VIDEO_CHILD_COMMON_FLEX_SHRINK, VIDEO_CHILD_COMMON_FLEX_BASIS, CreatePoster()));
|
||||
if (needControls_) {
|
||||
columnChildren.emplace_back(CreateControl());
|
||||
}
|
||||
@ -937,7 +1122,7 @@ const RefPtr<Component> VideoElement::CreateChild()
|
||||
|
||||
void VideoElement::OnStartBtnClick()
|
||||
{
|
||||
if (isPlaying_) {
|
||||
if (mediaPlayer_->IsPlaying()) {
|
||||
Pause();
|
||||
} else {
|
||||
Start();
|
||||
@ -1010,22 +1195,33 @@ void VideoElement::IntTimeToText(uint32_t time, std::string& timeText)
|
||||
|
||||
void VideoElement::Start()
|
||||
{
|
||||
if (!isPlaying_ && player_) {
|
||||
player_->Start();
|
||||
if (mediaPlayer_ != nullptr && !mediaPlayer_->IsPlaying()) {
|
||||
LOGI("Video Start");
|
||||
auto context = context_.Upgrade();
|
||||
if (context == nullptr) {
|
||||
LOGE("context is nullptr");
|
||||
return;
|
||||
}
|
||||
auto platformTask = SingleTaskExecutor::Make(context->GetTaskExecutor(), TaskExecutor::TaskType::BACKGROUND);
|
||||
platformTask.PostTask([mediaPlayer = mediaPlayer_] {
|
||||
mediaPlayer->Play();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void VideoElement::Pause()
|
||||
{
|
||||
if (isPlaying_ && player_) {
|
||||
player_->Pause();
|
||||
if (mediaPlayer_ != nullptr && mediaPlayer_->IsPlaying()) {
|
||||
LOGI("Video Pause");
|
||||
mediaPlayer_->Pause();
|
||||
}
|
||||
}
|
||||
|
||||
void VideoElement::SetCurrentTime(uint32_t currentPos)
|
||||
{
|
||||
if (currentPos >= 0 && currentPos < duration_ && player_) {
|
||||
player_->SeekTo(currentPos);
|
||||
if (mediaPlayer_ != nullptr && currentPos >= 0 && currentPos < duration_) {
|
||||
LOGI("Video Seek");
|
||||
mediaPlayer_->Seek(currentPos * MILLISECONDS_TO_SECONDS, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1093,8 +1289,8 @@ void VideoElement::ExitFullScreen()
|
||||
|
||||
void VideoElement::SetVolume(float volume)
|
||||
{
|
||||
if (player_) {
|
||||
player_->SetVolume(volume);
|
||||
if (mediaPlayer_ != nullptr) {
|
||||
mediaPlayer_->SetVolume(volume, volume);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "core/components/common/properties/edge.h"
|
||||
#include "core/components/multimodal/render_multimodal.h"
|
||||
#include "core/components/slider/slider_theme.h"
|
||||
#include "core/components/video/media_player_callback.h"
|
||||
#include "core/components/video/resource/player.h"
|
||||
#include "core/components/video/resource/texture.h"
|
||||
#include "core/components/video/video_component.h"
|
||||
@ -26,6 +27,9 @@
|
||||
#include "core/focus/focus_node.h"
|
||||
#include "core/pipeline/base/render_element.h"
|
||||
|
||||
#include "foundation/multimedia/media_standard/interfaces/innerkits/native/media/include/player.h"
|
||||
#include "window_manager.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
|
||||
constexpr double VIDEO_CHILD_COMMON_FLEX_GROW = 1.0;
|
||||
@ -114,8 +118,8 @@ private:
|
||||
bool isMute_ = false;
|
||||
std::string src_;
|
||||
std::string poster_;
|
||||
uint32_t duration_ = 0;
|
||||
uint32_t currentPos_ = 0;
|
||||
uint64_t duration_ = 0;
|
||||
uint64_t currentPos_ = 0;
|
||||
bool isPlaying_ = false;
|
||||
bool pastPlayingStatus_ = false; // Record the player status before dragging the progress bar.
|
||||
bool isReady_ = false;
|
||||
@ -156,6 +160,15 @@ private:
|
||||
VoiceEvent exitFullscreenVoiceEvent_;
|
||||
|
||||
FullscreenEvent fullscreenEvent_;
|
||||
|
||||
std::unique_ptr<OHOS::SubWindow> CreateSubWindow();
|
||||
void RegistMediaPlayerEvent();
|
||||
void CreateMediaPlayer();
|
||||
void PreparePlayer();
|
||||
|
||||
std::shared_ptr<OHOS::Media::Player> mediaPlayer_ = nullptr;
|
||||
std::unique_ptr<OHOS::SubWindow> subWindow_ = nullptr;
|
||||
std::shared_ptr<MediaPlayerCallback> mediaPlayerCallback_ = nullptr;
|
||||
};
|
||||
|
||||
} // namespace OHOS::Ace
|
||||
|
@ -92,6 +92,9 @@ void WebDelegate::UnregisterEvent()
|
||||
return;
|
||||
}
|
||||
auto resRegister = context->GetPlatformResRegister();
|
||||
if (resRegister == nullptr) {
|
||||
return;
|
||||
}
|
||||
resRegister->UnregisterEvent(MakeEventHash(WEB_EVENT_PAGESTART));
|
||||
resRegister->UnregisterEvent(MakeEventHash(WEB_EVENT_PAGEFINISH));
|
||||
resRegister->UnregisterEvent(MakeEventHash(WEB_EVENT_PAGEERROR));
|
||||
@ -150,6 +153,9 @@ void WebDelegate::CreatePluginResource(
|
||||
auto resRegister = pipelineContext->GetPlatformResRegister();
|
||||
|
||||
platformTaskExecutor.PostTask([this, resRegister, size, position] {
|
||||
if (resRegister == nullptr) {
|
||||
return;
|
||||
}
|
||||
auto webCom = this->webComponent_.Upgrade();
|
||||
if (!webCom) {
|
||||
OnError(NTC_ERROR, "fail to call WebDelegate::SetSrc PostTask");
|
||||
@ -224,6 +230,9 @@ void WebDelegate::RegisterWebEvent()
|
||||
return;
|
||||
}
|
||||
auto resRegister = context->GetPlatformResRegister();
|
||||
if (resRegister == nullptr) {
|
||||
return;
|
||||
}
|
||||
resRegister->RegisterEvent(MakeEventHash(WEB_EVENT_PAGESTART),
|
||||
[weak = WeakClaim(this)](const std::string& param) {
|
||||
auto delegate = weak.Upgrade();
|
||||
|
@ -43,6 +43,10 @@ void WebResource::Release(const std::function<void(bool)>& onRelease)
|
||||
}
|
||||
|
||||
auto resRegister = context->GetPlatformResRegister();
|
||||
if (resRegister == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto platformTaskExecutor = SingleTaskExecutor::Make(context->GetTaskExecutor(),
|
||||
TaskExecutor::TaskType::PLATFORM);
|
||||
auto releaseTask = [this, resRegister, onRelease] {
|
||||
@ -153,6 +157,9 @@ void WebResource::CallResRegisterMethod(const std::string& method,
|
||||
TaskExecutor::TaskType::PLATFORM);
|
||||
|
||||
platformTaskExecutor.PostTask([method, param, resRegister, callback] {
|
||||
if (resRegister == nullptr) {
|
||||
return;
|
||||
}
|
||||
std::string result;
|
||||
resRegister->OnMethodCall(method, param, result);
|
||||
if (callback) {
|
||||
|
@ -15,7 +15,8 @@
|
||||
<configuration ver="2.0">
|
||||
<target name="DomCardClockTest">
|
||||
<preparer>
|
||||
<option name="push" value="carddomclock -> /data/test/resource/" src="res"/>
|
||||
<option name="push" value="carddomclock/correct.json -> /data/test/resource/carddomclock/" src="res"/>
|
||||
<option name="push" value="carddomclock/error.json -> /data/test/resource/carddomclock/" src="res"/>
|
||||
</preparer>
|
||||
</target>
|
||||
</configuration>
|
||||
|
Loading…
Reference in New Issue
Block a user