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_CLIENT_H
17 #define PLAYER_CLIENT_H
18 
19 #include <unistd.h>
20 #include <pthread.h>
21 #include <iunknown.h>
22 #include <iproxy_server.h>
23 #include <iproxy_client.h>
24 #include "format.h"
25 #include "media_log.h"
26 #include "player_type.h"
27 #include "ipc_skeleton.h"
28 #include "surface.h"
29 #include "source.h"
30 #include "player.h"
31 namespace OHOS {
32 namespace Media {
33 class Player::PlayerClient {
34 public:
GetInstance()35     static PlayerClient* GetInstance()
36     {
37         static PlayerClient client;
38         if (client.InitPlayerClient() == false) {
39             printf("InitPlayerClient failed\n");
40             return nullptr;
41         }
42         return &client;
43     }
44 
45     bool InitPlayerClient();
46     static int32_t PlayerCommonCallback(uint32_t code, IpcIo *data, IpcIo *reply, MessageOption option);
47 
48     static int Callback(void* owner, int code, IpcIo *reply);
49     int32_t SetSource(const Source &source);
50     int32_t Prepare();
51     int32_t Play();
52     bool IsPlaying();
53     int32_t Pause();
54     int32_t Stop();
55     int32_t Rewind(int64_t mSeconds, int32_t mode);
56     int32_t SetVolume(float leftVolume, float rightVolume);
57     int32_t SetSurface(Surface *surface);
58     int32_t SetLoop(bool loop);
59     bool IsSingleLooping();
60     int32_t GetCurrentPosition(int64_t &time) const;
61     int32_t GetDuration(int64_t &duration) const;
62     int32_t GetVideoWidth(int32_t &videoWidth);
63     int32_t GetVideoHeight(int32_t &videoHeight);
64     int32_t Reset();
65     int32_t Release();
66     void SetPlayerCallback(const std::shared_ptr<PlayerCallback> &cb);
67     int32_t GetPlayerState(int32_t &state) const;
68     int32_t SetPlaybackSpeed(float speed);
69     int32_t GetPlaybackSpeed(float &speed);
70     int32_t SetParameter(const Format &params);
71     int32_t SetAudioStreamType(int32_t type);
72     void GetAudioStreamType(int32_t &type);
73 
74 private:
PlayerClient()75     PlayerClient() : proxy_(nullptr), sid_(nullptr) {}
~PlayerClient()76     ~PlayerClient() {}
77     IClientProxy *proxy_;
78     SvcIdentity *sid_;
79     IpcObjectStub objectStub_;
80 };
81 }
82 }
83 #endif