• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023-2023 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  * Description: Stream Player interface.
15  * Author: huangchanggui
16  * Create: 2023-01-11
17  */
18 
19 #ifndef I_STREAM_PLAYER_H
20 #define I_STREAM_PLAYER_H
21 
22 #include "cast_engine_common.h"
23 #include "pixel_map.h"
24 
25 namespace OHOS {
26 namespace CastEngine {
27 class EXPORT IStreamPlayerListener {
28 public:
29     IStreamPlayerListener() = default;
30     IStreamPlayerListener(const IStreamPlayerListener &) = delete;
31     IStreamPlayerListener &operator=(const IStreamPlayerListener &) = delete;
32     IStreamPlayerListener(IStreamPlayerListener &&) = delete;
33     IStreamPlayerListener &operator=(IStreamPlayerListener &&) = delete;
34     virtual ~IStreamPlayerListener() = default;
35 
36     virtual void OnStateChanged(const PlayerStates playbackState, bool isPlayWhenReady) = 0;
37     virtual void OnPositionChanged(int position, int bufferPosition, int duration) = 0;
38     virtual void OnMediaItemChanged(const MediaInfo &mediaInfo) = 0;
39     virtual void OnVolumeChanged(int volume, int maxVolume) = 0;
40     virtual void OnLoopModeChanged(const LoopMode loopMode) = 0;
41     virtual void OnPlaySpeedChanged(const PlaybackSpeed speed) = 0;
42     virtual void OnPlayerError(int errorCode, const std::string &errorMsg) = 0;
43     virtual void OnVideoSizeChanged(int width, int height) = 0;
44     virtual void OnNextRequest() = 0;
45     virtual void OnPreviousRequest() = 0;
46     virtual void OnSeekDone(int position) = 0;
47     virtual void OnEndOfStream(int isLooping) = 0;
48     virtual void OnPlayRequest(const MediaInfo &mediaInfo) = 0;
49     virtual void OnImageChanged(std::shared_ptr<Media::PixelMap> pixelMap) = 0;
50     virtual void OnAlbumCoverChanged(std::shared_ptr<Media::PixelMap> pixelMap) = 0;
51     virtual void OnKeyRequest(const std::string &mediaId, const std::vector<uint8_t> &keyRequestData) = 0;
52     virtual void OnAvailableCapabilityChanged(const StreamCapability &streamCapability) = 0;
53     virtual void OnData(const DataType dataType, const std::string &dataStr) = 0;
54 };
55 
56 class EXPORT IStreamPlayer {
57 public:
58     IStreamPlayer() = default;
59     IStreamPlayer(const IStreamPlayer &) = delete;
60     IStreamPlayer &operator=(const IStreamPlayer &) = delete;
61     IStreamPlayer(IStreamPlayer &&) = delete;
62     IStreamPlayer &operator=(IStreamPlayer &&) = delete;
63     virtual ~IStreamPlayer() = default;
64 
65     virtual int32_t RegisterListener(std::shared_ptr<IStreamPlayerListener> listener) = 0;
66     virtual int32_t UnregisterListener() = 0;
67     virtual int32_t SetSurface(const std::string &surfaceId) = 0;
68     virtual int32_t Load(const MediaInfo &mediaInfo) = 0;
69     virtual int32_t Play(const MediaInfo &mediaInfo) = 0;
70     virtual int32_t Play(int index) = 0;
71     virtual int32_t Play() = 0;
72     virtual int32_t Pause() = 0;
73     virtual int32_t Stop() = 0;
74     virtual int32_t Next() = 0;
75     virtual int32_t Previous() = 0;
76     virtual int32_t Seek(int position) = 0;
77     virtual int32_t FastForward(int delta) = 0;
78     virtual int32_t FastRewind(int delta) = 0;
79     virtual int32_t SetVolume(int volume) = 0;
80     virtual int32_t SetMute(bool mute) = 0;
81     virtual int32_t SetLoopMode(const LoopMode mode) = 0;
82     virtual int32_t SetAvailableCapability(const StreamCapability &streamCapability) = 0;
83     virtual int32_t SetSpeed(const PlaybackSpeed speed) = 0;
84     virtual int32_t SendData(const DataType dataType, const std::string &dataStr) = 0;
85     virtual int32_t GetPlayerStatus(PlayerStates &playerStates) = 0;
86     virtual int32_t GetPosition(int &position) = 0;
87     virtual int32_t GetDuration(int &duration) = 0;
88     virtual int32_t GetVolume(int &volume, int &maxVolume) = 0;
89     virtual int32_t GetMute(bool &mute) = 0;
90     virtual int32_t GetLoopMode(LoopMode &loopMode) = 0;
91     virtual int32_t GetAvailableCapability(StreamCapability &streamCapability) = 0;
92     virtual int32_t GetPlaySpeed(PlaybackSpeed &playbackSpeed) = 0;
93     virtual int32_t GetMediaInfoHolder(MediaInfoHolder &mediaInfoHolder) = 0;
94     virtual int32_t ProvideKeyResponse(const std::string &mediaId, const std::vector<uint8_t> &response) = 0;
95     virtual int32_t Release() = 0;
96     virtual int32_t GetMediaCapabilities(std::string &jsonCapabilities) = 0;
97 };
98 } // namespace CastEngine
99 } // namespace OHOS
100 
101 #endif
102