• 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_ENGINE_GST_IMPL
17 #define PLAYER_ENGINE_GST_IMPL
18 
19 #include <mutex>
20 #include <cstdint>
21 #include <thread>
22 #include <map>
23 
24 #include "i_player_engine.h"
25 #include "gst_player_build.h"
26 #include "gst_player_ctrl.h"
27 #include "gst_appsrc_warp.h"
28 
29 namespace OHOS {
30 namespace Media {
31 class PlayerEngineGstImpl : public IPlayerEngine, public NoCopyable {
32 public:
33     PlayerEngineGstImpl();
34     ~PlayerEngineGstImpl();
35 
36     int32_t SetSource(const std::string &url) override;
37     int32_t SetSource(const std::shared_ptr<IMediaDataSource> &dataSrc) override;
38     int32_t SetObs(const std::weak_ptr<IPlayerEngineObs> &obs) override;
39     int32_t SetVideoSurface(sptr<Surface> surface) override;
40     int32_t Prepare() override;
41     int32_t PrepareAsync() override;
42     int32_t Play() override;
43     int32_t Pause() override;
44     int32_t Stop() override;
45     int32_t Reset() override;
46     int32_t SetVolume(float leftVolume, float rightVolume) override;
47     int32_t Seek(int32_t mSeconds, PlayerSeekMode mode) override;
48     int32_t GetCurrentTime(int32_t &currentTime) override;
49     int32_t GetVideoTrackInfo(std::vector<Format> &videoTrack) override;
50     int32_t GetAudioTrackInfo(std::vector<Format> &audioTrack) override;
51     int32_t GetVideoWidth() override;
52     int32_t GetVideoHeight() override;
53     int32_t GetDuration(int32_t &duration) override;
54     int32_t SetPlaybackSpeed(PlaybackRateMode mode) override;
55     int32_t GetPlaybackSpeed(PlaybackRateMode &mode) override;
56     int32_t SetParameter(const Format &param) override;
57     int32_t SetLooping(bool loop) override;
58 
59 private:
60     double ChangeModeToSpeed(const PlaybackRateMode &mode) const;
61     PlaybackRateMode ChangeSpeedToMode(double rate) const;
62     int32_t GstPlayerInit();
63     int32_t GstPlayerPrepare() const;
64     void PlayerLoop();
65     void GstPlayerDeInit();
66     int32_t GetRealPath(const std::string &url, std::string &realUrlPath) const;
67     bool IsFileUrl(const std::string &url) const;
68     std::mutex mutex_;
69     std::mutex mutexSync_;
70     std::unique_ptr<GstPlayerBuild> playerBuild_ = nullptr;
71     std::shared_ptr<GstPlayerCtrl> playerCtrl_ = nullptr;
72     std::shared_ptr<GstPlayerVideoRendererCtrl> rendererCtrl_ = nullptr;
73     std::weak_ptr<IPlayerEngineObs> obs_;
74     sptr<Surface> producerSurface_ = nullptr;
75     std::string url_ = "";
76     std::condition_variable condVarSync_;
77     bool gstPlayerInit_ = false;
78     std::unique_ptr<std::thread> playerThread_;
79     std::shared_ptr<GstAppsrcWarp> appsrcWarp_ = nullptr;
80 };
81 } // namespace Media
82 } // namespace OHOS
83 #endif // PLAYER_ENGINE_GST_IMPL
84