• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <media_errors.h>
20 #include <parameters.h>
21 #include <window_scene.h>
22 #include <foundation/window/window_manager/interfaces/innerkits/wm/window_manager.h>
23 
24 #include "event_handler.h"
25 #include "player.h"
26 
27 namespace OHOS {
28 using VSyncCallback = std::function<void(void*)>;
29 struct FrameCallback {
30     void *userData_;
31     VSyncCallback callback_;
32 };
33 class BootVideoPlayer : public std::enable_shared_from_this<BootVideoPlayer> {
34 public:
35     void SetVideoPath(const std::string& path);
36     void SetPlayerWindow(const OHOS::sptr<OHOS::Rosen::Window>& window);
37     void SetPlayerSurface(const OHOS::sptr<OHOS::Surface>& surface);
SetCallback(const FrameCallback * cb)38     void SetCallback(const FrameCallback* cb)
39     {
40         std::lock_guard<std::mutex> locker(mtx_);
41         vsyncCallbacks_ = cb->callback_;
42         userData_ = cb->userData_;
43     }
44     bool PlayVideo();
45     void StopVideo();
46 private:
47     std::shared_ptr<Media::Player> mediaPlayer_;
48     OHOS::sptr<OHOS::Rosen::Window> window_;
49     OHOS::sptr<OHOS::Surface> surface_;
50     std::string videopath_;
51     VSyncCallback vsyncCallbacks_;
52     void *userData_;
53     std::mutex mtx_;
54 
55     friend class VideoPlayerCallback;
56 };
57 
58 class VideoPlayerCallback : public Media::PlayerCallback, public NoCopyable {
59 public:
VideoPlayerCallback(std::shared_ptr<BootVideoPlayer> boot)60     VideoPlayerCallback(std::shared_ptr<BootVideoPlayer> boot)
61     {
62         boot_ = boot;
63     };
64     virtual ~VideoPlayerCallback() = default;
65 
66     void OnError(int32_t errorCode, const std::string &errorMsg) override;
67     void OnInfo(Media::PlayerOnInfoType type, int32_t extra, const Media::Format &infoBody) override;
68 private:
69     std::shared_ptr<BootVideoPlayer> boot_;
70 };
71 } // namespace OHOS
72 
73 #endif // FRAMEWORKS_BOOTANIMATION_INCLUDE_BOOT_VIDEOPLAYER_H
74