• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 PLAYER_DEMO_H
17 #define PLAYER_DEMO_H
18 
19 #include "securec.h"
20 #include "player.h"
21 #include "surface.h"
22 #include "display_type.h"
23 #include "window_manager.h"
24 #include "nocopyable.h"
25 #include "media_data_source_demo.h"
26 #include "foundation/windowmanager/interfaces/innerkits/wm/window.h"
27 
28 namespace MediaDemo {
29     const int32_t POSITION_UPDATE_INTERVAL = 100;
30     const std::map<OHOS::Media::PlayerStates, std::string> STATE_MAP = {
31         {OHOS::Media::PlayerStates::PLAYER_STATE_ERROR, "Error"},
32         {OHOS::Media::PlayerStates::PLAYER_IDLE, "Idle"},
33         {OHOS::Media::PlayerStates::PLAYER_INITIALIZED, "Initialized"},
34         {OHOS::Media::PlayerStates::PLAYER_PREPARED, "Prepared"},
35         {OHOS::Media::PlayerStates::PLAYER_STARTED, "Started"},
36         {OHOS::Media::PlayerStates::PLAYER_PAUSED, "Paused"},
37         {OHOS::Media::PlayerStates::PLAYER_STOPPED, "Stopped"},
38         {OHOS::Media::PlayerStates::PLAYER_PLAYBACK_COMPLETE, "Complete"},
39     };
40 };
41 
42 namespace OHOS {
43 namespace Media {
44 class PlayerDemo : public NoCopyable {
45 public:
46     PlayerDemo();
47     ~PlayerDemo();
48     sptr<Surface> GetVideoSurface();
49     void RunCase(const std::string &path);
50 
51 private:
52     void DoNext();
53     void Seek(const std::string &cmd);
54     void SetLoop(const std::string &cmd);
55     void SetPlaybackSpeed(const std::string &cmd) const;
56     int32_t GetPlaying();
57     int32_t GetLooping();
58     void GetCurrentTime();
59     int32_t GetVideoTrackInfo();
60     int32_t GetAudioTrackInfo();
61     int32_t GetTrackInfo();
62     int32_t GetPlaybackSpeed() const;
63     int32_t SetDataSrc(const std::string &path, bool seekable);
64     int32_t SetFdSource(const std::string &path);
65     int32_t SelectSource(const std::string &path);
66     int32_t SetSurfaceSize();
67     int32_t SelectBufferingOut();
68     int32_t ChangeModeToSpeed(const PlaybackRateMode &mode, double &rate) const;
69     int32_t ChangeSpeedToMode(const double &rate, PlaybackRateMode &mode) const;
70     sptr<Surface> GetWindowSurface();
71     sptr<Surface> GetSubWindowSurface();
72     void RegisterTable();
73     sptr<Window> mwindow_ = nullptr;
74     sptr<Rosen::Window> previewWindow_ = nullptr;
75     std::map<std::string, std::function<int32_t()>> playerTable_;
76     std::shared_ptr<Player> player_ = nullptr;
77     std::shared_ptr<MediaDataSourceDemo> dataSrc_ = nullptr;
78     int32_t height_ = 0;
79     int32_t width_ = 0;
80 };
81 
82 class PlayerCallbackDemo : public PlayerCallback, public NoCopyable {
83 public:
84     PlayerCallbackDemo() = default;
85     virtual ~PlayerCallbackDemo() = default;
86 
87     void OnError(PlayerErrorType errorType, int32_t errorCode) override;
88     void OnInfo(PlayerOnInfoType type, int32_t extra, const Format &infoBody) override;
89     void SetBufferingOut(int32_t bufferingOut);
90 
91 private:
92     void PrintState(PlayerStates state) const;
93     void PrintResolution(const Format &infoBody) const;
94     void PrintBufferingUpdate(const Format &infoBody) const;
95     int32_t updateCount_ = 0;
96     int32_t bufferingOut_ = 0;
97     PlayerStates state_ = PLAYER_STATE_ERROR;
98 };
99 } // namespace Media
100 } // namespace OHOS
101 #endif // PLAYER_DEMO_H
102