164 lines
4.6 KiB
C++
164 lines
4.6 KiB
C++
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
|
|
*
|
|
* Description:
|
|
*
|
|
* Author: huangshuyi
|
|
*
|
|
* Create: 2024-8
|
|
*--------------------------------------------------------------------------*/
|
|
|
|
#include "TjdUiWFCustomVideoPage.h"
|
|
#include "TjdUiImageIds.h"
|
|
#include "TjdUiMemManage.h"
|
|
#include "common/image_cache_manager.h"
|
|
#include "sql_setting.h"
|
|
#include "sys_config.h"
|
|
#include "wearable_log.h"
|
|
#include <stdio.h>
|
|
|
|
using namespace OHOS;
|
|
using namespace OHOS::Media;
|
|
using OHOS::Media::Player;
|
|
|
|
namespace TJD {
|
|
|
|
#define ENABLE_PRINT_INFO 0
|
|
#if ENABLE_PRINT_INFO
|
|
#define static_print_info(...) sys_ui_log_i(__VA_ARGS__) //一般信息打印宏控制
|
|
#define static_print_warn(...) sys_ui_log_w(__VA_ARGS__) //警告信息打印一般常开
|
|
#define static_print_error(...) sys_ui_log_e(__VA_ARGS__) //错误信息打印一般常开
|
|
#define static_print_debug(...) sys_ui_log_d(__VA_ARGS__)
|
|
#else
|
|
#define static_print_info(...)
|
|
#define static_print_warn(...)
|
|
#define static_print_error(...)
|
|
#define static_print_debug(...)
|
|
#endif
|
|
|
|
static constexpr int16_t VIDEO_WIDTH = HORIZONTAL_RESOLUTION;
|
|
static constexpr int16_t VIDEO_HEIGHT = VERTICAL_RESOLUTION;
|
|
static constexpr int16_t STRIDE_ALIGNMENT_VALUE = 128;
|
|
static constexpr int16_t BUFFER_QUEUE_SIZE = 3;
|
|
static constexpr int16_t JPEG_HEIGHT_DIVISOR = 2;
|
|
static constexpr int16_t JPEG_WIDTH_BYTE_ALIGNMENT = 128;
|
|
static constexpr int16_t JPEG_HEIGHT_BYTE_ALIGNMENT = 16;
|
|
|
|
TjdUiWFCustomVideoPage::TjdUiWFCustomVideoPage(UIView *parent, std::string uri, std::string previewPath)
|
|
: Parent_(parent), uri_(uri), previewPath_(previewPath)
|
|
{
|
|
InitView();
|
|
}
|
|
|
|
TjdUiWFCustomVideoPage::~TjdUiWFCustomVideoPage()
|
|
{
|
|
if (videoPlay_ != nullptr) {
|
|
delete videoPlay_;
|
|
videoPlay_ = nullptr;
|
|
}
|
|
ImageCacheManager::GetInstance().UnloadSingleRes(previewPath_.c_str());
|
|
}
|
|
|
|
bool TjdUiWFCustomVideoPage::InitView(void)
|
|
{
|
|
static_print_debug("TjdUiWFCustomVideoPage::InitView");
|
|
surfaceView_ = new UILiteSurfaceView();
|
|
if (surfaceView_ == nullptr) {
|
|
GRAPHIC_LOGE("surfaceView is nullptr");
|
|
return false;
|
|
}
|
|
UIViewGroup *p = (UIViewGroup *)Parent_;
|
|
p->Add(surfaceView_);
|
|
ImageInfo *imgInfo;
|
|
imgInfo = ImageCacheManager::GetInstance().LoadSingleRes(previewPath_.c_str());
|
|
surfaceView_->SetPreview(imgInfo);
|
|
colorKey_.full = 0xff169aff;
|
|
surfaceView_->SetViewId("sur");
|
|
surfaceView_->SetPosition(0, 0, VIDEO_WIDTH, VIDEO_HEIGHT);
|
|
surfaceView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
|
|
surfaceView_->SetSurfaceColorkey(colorKey_);
|
|
|
|
Surface *surface = surfaceView_->GetSurface();
|
|
surface->SetStrideAlignment(STRIDE_ALIGNMENT_VALUE);
|
|
surface->SetWidthAndHeight(VIDEO_WIDTH, VIDEO_HEIGHT);
|
|
surface->SetQueueSize(BUFFER_QUEUE_SIZE);
|
|
surface->SetFormat(PIXEL_FMT_YCBCR_420_SP);
|
|
|
|
// jpeg decoder output buffer size calculation formula
|
|
int32_t ySize = ALIGN_BYTE(VIDEO_WIDTH, JPEG_WIDTH_BYTE_ALIGNMENT) * VIDEO_HEIGHT;
|
|
int32_t uvSize = ALIGN_BYTE(VIDEO_WIDTH, JPEG_WIDTH_BYTE_ALIGNMENT) *
|
|
ALIGN_BYTE(VIDEO_HEIGHT, JPEG_HEIGHT_BYTE_ALIGNMENT) / JPEG_HEIGHT_DIVISOR;
|
|
int32_t bufferSize = ySize + uvSize;
|
|
surface->SetSize(bufferSize);
|
|
if (videoPlay_ == nullptr) {
|
|
videoPlay_ = new TjdUiVideoCommon(surface, uri_, false);
|
|
videoPlay_->SetMute(true);
|
|
}
|
|
static_print_debug("TjdUiWFCustomVideoPage::InitView end");
|
|
return true;
|
|
}
|
|
|
|
bool TjdUiWFCustomVideoPage::StartPlay()
|
|
{
|
|
if (videoPlay_ == nullptr) {
|
|
return false;
|
|
}
|
|
videoPlay_->StartVideoPlay();
|
|
return true;
|
|
}
|
|
|
|
bool TjdUiWFCustomVideoPage::ResumePlay()
|
|
{
|
|
if (videoPlay_ == nullptr) {
|
|
return false;
|
|
}
|
|
videoPlay_->ResumeVideoPlay();
|
|
return true;
|
|
}
|
|
|
|
bool TjdUiWFCustomVideoPage::PausePlay()
|
|
{
|
|
if (videoPlay_ == nullptr) {
|
|
return false;
|
|
}
|
|
videoPlay_->PauseVideoPlay();
|
|
return true;
|
|
}
|
|
|
|
bool TjdUiWFCustomVideoPage::StopPlay()
|
|
{
|
|
if (videoPlay_ == nullptr) {
|
|
return false;
|
|
}
|
|
videoPlay_->StopVideoPlay();
|
|
return true;
|
|
}
|
|
|
|
bool TjdUiWFCustomVideoPage::IsPaused()
|
|
{
|
|
if (videoPlay_ == nullptr) {
|
|
return false;
|
|
}
|
|
return videoPlay_->isPause_;
|
|
}
|
|
|
|
bool TjdUiWFCustomVideoPage::IsPlayed()
|
|
{
|
|
if (videoPlay_ == nullptr) {
|
|
return false;
|
|
}
|
|
return videoPlay_->isPlayed_;
|
|
}
|
|
|
|
bool TjdUiWFCustomVideoPage::IsStopped()
|
|
{
|
|
if (videoPlay_ == nullptr) {
|
|
return false;
|
|
}
|
|
return videoPlay_->isExited_;
|
|
}
|
|
|
|
OHOS::MediaVideoPlay *TjdUiWFCustomVideoPage::GetVideoPlay() { return videoPlay_; }
|
|
|
|
} // namespace TJD
|