1 /*
2  * Copyright (c) 2020 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_SERVER_H
17 #define PLAYER_SERVER_H
18 
19 #include "ipc_skeleton.h"
20 #include "player_interface.h"
21 
22 namespace OHOS {
23 namespace Media {
24 class PalyerCallbackImpl : public PlayerCallback {
25 public:
PalyerCallbackImpl(SvcIdentity & sid)26     PalyerCallbackImpl(SvcIdentity &sid) : sid_(sid) {}
~PalyerCallbackImpl()27     ~PalyerCallbackImpl() {}
28     void OnPlaybackComplete();
29     void OnError(int32_t errorType, int32_t errorCode);
30     void OnInfo(int type, int extra);
31     void OnVideoSizeChanged(int width, int height);
32     void OnRewindToComplete();
33 private:
34     SvcIdentity sid_;
35 };
36 
37 class PlayerServer {
38 public:
GetInstance()39     static PlayerServer* GetInstance()
40     {
41         static PlayerServer server;
42         return &server;
43     }
44 
45     static void PlayerServerRequestHandle(int funcId, void *origin, IpcIo *req, IpcIo *reply);
46     int32_t PlayerServerInit();
47 private:
48     std::shared_ptr<PlayerInterface> player_;
49     std::shared_ptr<StreamSource> stream_;
50     std::shared_ptr<PlayerCallback> playerCallback_;
51     SvcIdentity *sid_;
52     IpcObjectStub objectStub_;
PlayerServer()53     PlayerServer() : player_(nullptr), stream_(nullptr), sid_(nullptr) {}
~PlayerServer()54     ~PlayerServer() {}
55 
56     void SetSource(IpcIo *req, IpcIo *reply);
57     void Prepare(IpcIo *req, IpcIo *reply);
58     void Play(IpcIo *req, IpcIo *reply);
59     void IsPlaying(IpcIo *req, IpcIo *reply);
60     void Pause(IpcIo *req, IpcIo *reply);
61     void Stop(IpcIo *req, IpcIo *reply);
62     void Rewind(IpcIo *req, IpcIo *reply);
63     void SetVolume(IpcIo *req, IpcIo *reply);
64     void SetSurface(IpcIo *req, IpcIo *reply);
65     void SetLoop(IpcIo *req, IpcIo *reply);
66     void IsSingleLooping(IpcIo *req, IpcIo *reply);
67     void GetCurrentPosition(IpcIo *req, IpcIo *reply);
68     void GetDuration(IpcIo *req, IpcIo *reply);
69     void GetVideoWidth(IpcIo *req, IpcIo *reply);
70     void GetVideoHeight(IpcIo *req, IpcIo *reply);
71     void Reset(IpcIo *req, IpcIo *reply);
72     void Release(IpcIo *req, IpcIo *reply);
73     void SetPlayerCallback(IpcIo *req, IpcIo *reply);
74     void GetPlayerState(IpcIo *req, IpcIo *reply);
75     void SetPlaybackSpeed(IpcIo *req, IpcIo *reply);
76     void GetPlaybackSpeed(IpcIo *req, IpcIo *reply);
77     void SetParameter(IpcIo *req, IpcIo *reply);
78     void SetAudioStreamType(IpcIo *req, IpcIo *reply);
79     void GetAudioStreamType(IpcIo *req, IpcIo *reply);
80     void SetStreamSource(IpcIo *reply);
81 };
82 }
83 }
84 #endif
85