1 /* 2 * Copyright (c) 2022 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 FRAMEWORKS_BOOTANIMATION_INCLUDE_BOOT_VIDEOPLAYER_H 17 #define FRAMEWORKS_BOOTANIMATION_INCLUDE_BOOT_VIDEOPLAYER_H 18 19 #ifdef PLAYER_FRAMEWORK_ENABLE 20 #include <media_errors.h> 21 #endif 22 #include <parameters.h> 23 24 #include "event_handler.h" 25 #ifdef PLAYER_FRAMEWORK_ENABLE 26 #include "player.h" 27 #endif 28 29 namespace OHOS { 30 using VSyncCallback = std::function<void(void*)>; 31 struct FrameCallback { 32 void *userData_; 33 VSyncCallback callback_; 34 }; 35 class BootVideoPlayer : public std::enable_shared_from_this<BootVideoPlayer> { 36 public: 37 void SetVideoPath(const std::string& path); 38 #ifdef PLAYER_FRAMEWORK_ENABLE 39 void SetPlayerSurface(const OHOS::sptr<OHOS::Surface>& surface); 40 #endif SetCallback(const FrameCallback * cb)41 void SetCallback(const FrameCallback* cb) 42 { 43 std::lock_guard<std::mutex> locker(mtx_); 44 vsyncCallbacks_ = cb->callback_; 45 userData_ = cb->userData_; 46 } 47 bool PlayVideo(); 48 void StopVideo(); 49 void SetVideoSound(); 50 private: 51 #ifdef PLAYER_FRAMEWORK_ENABLE 52 std::shared_ptr<Media::Player> mediaPlayer_; 53 OHOS::sptr<OHOS::Surface> surface_; 54 #endif 55 std::string videopath_; 56 VSyncCallback vsyncCallbacks_; 57 void *userData_; 58 std::mutex mtx_; 59 60 #ifdef PLAYER_FRAMEWORK_ENABLE 61 friend class VideoPlayerCallback; 62 #endif 63 }; 64 65 #ifdef PLAYER_FRAMEWORK_ENABLE 66 class VideoPlayerCallback : public Media::PlayerCallback, public NoCopyable { 67 public: VideoPlayerCallback(std::shared_ptr<BootVideoPlayer> boot)68 VideoPlayerCallback(std::shared_ptr<BootVideoPlayer> boot) 69 { 70 boot_ = boot; 71 }; 72 virtual ~VideoPlayerCallback() = default; 73 74 void OnError(int32_t errorCode, const std::string &errorMsg) override; 75 void OnInfo(Media::PlayerOnInfoType type, int32_t extra, const Media::Format &infoBody) override; 76 private: 77 std::shared_ptr<BootVideoPlayer> boot_; 78 }; 79 #endif 80 } // namespace OHOS 81 82 #endif // FRAMEWORKS_BOOTANIMATION_INCLUDE_BOOT_VIDEOPLAYER_H 83