12e147c35Sopenharmony_ci/* 22e147c35Sopenharmony_ci * Copyright (C) 2023-2023 Huawei Device Co., Ltd. 32e147c35Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 42e147c35Sopenharmony_ci * you may not use this file except in compliance with the License. 52e147c35Sopenharmony_ci * You may obtain a copy of the License at 62e147c35Sopenharmony_ci * 72e147c35Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 82e147c35Sopenharmony_ci * 92e147c35Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 102e147c35Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 112e147c35Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 122e147c35Sopenharmony_ci * See the License for the specific language governing permissions and 132e147c35Sopenharmony_ci * limitations under the License. 142e147c35Sopenharmony_ci * Description: Stream Player function realization. 152e147c35Sopenharmony_ci * Author: huangchanggui 162e147c35Sopenharmony_ci * Create: 2023-01-12 172e147c35Sopenharmony_ci */ 182e147c35Sopenharmony_ci 192e147c35Sopenharmony_ci#include "stream_player.h" 202e147c35Sopenharmony_ci#include "cast_engine_errors.h" 212e147c35Sopenharmony_ci#include "cast_engine_log.h" 222e147c35Sopenharmony_ci#include "stream_player_listener_impl_stub.h" 232e147c35Sopenharmony_ci 242e147c35Sopenharmony_cinamespace OHOS { 252e147c35Sopenharmony_cinamespace CastEngine { 262e147c35Sopenharmony_cinamespace CastEngineClient { 272e147c35Sopenharmony_ciDEFINE_CAST_ENGINE_LABEL("Cast-Client-StreamPlayer"); 282e147c35Sopenharmony_ci 292e147c35Sopenharmony_ciStreamPlayer::~StreamPlayer() 302e147c35Sopenharmony_ci{ 312e147c35Sopenharmony_ci CLOGD("destructor in"); 322e147c35Sopenharmony_ci} 332e147c35Sopenharmony_ci 342e147c35Sopenharmony_ciint32_t StreamPlayer::RegisterListener(std::shared_ptr<IStreamPlayerListener> listener) 352e147c35Sopenharmony_ci{ 362e147c35Sopenharmony_ci if (listener == nullptr) { 372e147c35Sopenharmony_ci CLOGE("listener is null"); 382e147c35Sopenharmony_ci return ERR_INVALID_PARAM; 392e147c35Sopenharmony_ci } 402e147c35Sopenharmony_ci sptr<IStreamPlayerListenerImpl> listenerStub = new (std::nothrow) StreamPlayerListenerImplStub(listener); 412e147c35Sopenharmony_ci if (listenerStub == nullptr) { 422e147c35Sopenharmony_ci CLOGE("Failed to new a stream player listener"); 432e147c35Sopenharmony_ci return CAST_ENGINE_ERROR; 442e147c35Sopenharmony_ci } 452e147c35Sopenharmony_ci 462e147c35Sopenharmony_ci return proxy_ ? proxy_->RegisterListener(listenerStub) : CAST_ENGINE_ERROR; 472e147c35Sopenharmony_ci} 482e147c35Sopenharmony_ci 492e147c35Sopenharmony_ciint32_t StreamPlayer::UnregisterListener() 502e147c35Sopenharmony_ci{ 512e147c35Sopenharmony_ci return proxy_ ? proxy_->UnregisterListener() : CAST_ENGINE_ERROR; 522e147c35Sopenharmony_ci} 532e147c35Sopenharmony_ci 542e147c35Sopenharmony_ciint32_t StreamPlayer::SetSurface(const std::string &surfaceId) 552e147c35Sopenharmony_ci{ 562e147c35Sopenharmony_ci errno = 0; 572e147c35Sopenharmony_ci uint64_t surfaceUniqueId = static_cast<uint64_t>(std::strtoll(surfaceId.c_str(), nullptr, 10)); 582e147c35Sopenharmony_ci if (errno == ERANGE) { 592e147c35Sopenharmony_ci return ERR_INVALID_PARAM; 602e147c35Sopenharmony_ci } 612e147c35Sopenharmony_ci 622e147c35Sopenharmony_ci sptr<Surface> surface = SurfaceUtils::GetInstance()->GetSurface(surfaceUniqueId); 632e147c35Sopenharmony_ci if (!surface) { 642e147c35Sopenharmony_ci return CAST_ENGINE_ERROR; 652e147c35Sopenharmony_ci } 662e147c35Sopenharmony_ci sptr<IBufferProducer> producer = surface->GetProducer(); 672e147c35Sopenharmony_ci if (!producer) { 682e147c35Sopenharmony_ci CLOGE("producer is null"); 692e147c35Sopenharmony_ci return CAST_ENGINE_ERROR; 702e147c35Sopenharmony_ci } 712e147c35Sopenharmony_ci return proxy_ ? proxy_->SetSurface(producer) : CAST_ENGINE_ERROR; 722e147c35Sopenharmony_ci} 732e147c35Sopenharmony_ci 742e147c35Sopenharmony_ciint32_t StreamPlayer::Load(const MediaInfo &mediaInfo) 752e147c35Sopenharmony_ci{ 762e147c35Sopenharmony_ci return proxy_ ? proxy_->Load(mediaInfo) : CAST_ENGINE_ERROR; 772e147c35Sopenharmony_ci} 782e147c35Sopenharmony_ci 792e147c35Sopenharmony_ciint32_t StreamPlayer::Play(const MediaInfo &mediaInfo) 802e147c35Sopenharmony_ci{ 812e147c35Sopenharmony_ci return proxy_ ? proxy_->Play(mediaInfo) : CAST_ENGINE_ERROR; 822e147c35Sopenharmony_ci} 832e147c35Sopenharmony_ci 842e147c35Sopenharmony_ciint32_t StreamPlayer::Play(int index) 852e147c35Sopenharmony_ci{ 862e147c35Sopenharmony_ci return proxy_ ? proxy_->Play(index) : CAST_ENGINE_ERROR; 872e147c35Sopenharmony_ci} 882e147c35Sopenharmony_ci 892e147c35Sopenharmony_ciint32_t StreamPlayer::Play() 902e147c35Sopenharmony_ci{ 912e147c35Sopenharmony_ci return proxy_ ? proxy_->Play() : CAST_ENGINE_ERROR; 922e147c35Sopenharmony_ci} 932e147c35Sopenharmony_ci 942e147c35Sopenharmony_ciint32_t StreamPlayer::Pause() 952e147c35Sopenharmony_ci{ 962e147c35Sopenharmony_ci return proxy_ ? proxy_->Pause() : CAST_ENGINE_ERROR; 972e147c35Sopenharmony_ci} 982e147c35Sopenharmony_ci 992e147c35Sopenharmony_ciint32_t StreamPlayer::Stop() 1002e147c35Sopenharmony_ci{ 1012e147c35Sopenharmony_ci return proxy_ ? proxy_->Stop() : CAST_ENGINE_ERROR; 1022e147c35Sopenharmony_ci} 1032e147c35Sopenharmony_ci 1042e147c35Sopenharmony_ciint32_t StreamPlayer::Next() 1052e147c35Sopenharmony_ci{ 1062e147c35Sopenharmony_ci return proxy_ ? proxy_->Next() : CAST_ENGINE_ERROR; 1072e147c35Sopenharmony_ci} 1082e147c35Sopenharmony_ci 1092e147c35Sopenharmony_ciint32_t StreamPlayer::Previous() 1102e147c35Sopenharmony_ci{ 1112e147c35Sopenharmony_ci return proxy_ ? proxy_->Previous() : CAST_ENGINE_ERROR; 1122e147c35Sopenharmony_ci} 1132e147c35Sopenharmony_ci 1142e147c35Sopenharmony_ciint32_t StreamPlayer::Seek(int position) 1152e147c35Sopenharmony_ci{ 1162e147c35Sopenharmony_ci return proxy_ ? proxy_->Seek(position) : CAST_ENGINE_ERROR; 1172e147c35Sopenharmony_ci} 1182e147c35Sopenharmony_ci 1192e147c35Sopenharmony_ciint32_t StreamPlayer::FastForward(int delta) 1202e147c35Sopenharmony_ci{ 1212e147c35Sopenharmony_ci return proxy_ ? proxy_->FastForward(delta) : CAST_ENGINE_ERROR; 1222e147c35Sopenharmony_ci} 1232e147c35Sopenharmony_ci 1242e147c35Sopenharmony_ciint32_t StreamPlayer::FastRewind(int delta) 1252e147c35Sopenharmony_ci{ 1262e147c35Sopenharmony_ci return proxy_ ? proxy_->FastRewind(delta) : CAST_ENGINE_ERROR; 1272e147c35Sopenharmony_ci} 1282e147c35Sopenharmony_ci 1292e147c35Sopenharmony_ciint32_t StreamPlayer::SetVolume(int volume) 1302e147c35Sopenharmony_ci{ 1312e147c35Sopenharmony_ci return proxy_ ? proxy_->SetVolume(volume) : CAST_ENGINE_ERROR; 1322e147c35Sopenharmony_ci} 1332e147c35Sopenharmony_ci 1342e147c35Sopenharmony_ciint32_t StreamPlayer::SetMute(bool mute) 1352e147c35Sopenharmony_ci{ 1362e147c35Sopenharmony_ci return proxy_ ? proxy_->SetMute(mute) : CAST_ENGINE_ERROR; 1372e147c35Sopenharmony_ci} 1382e147c35Sopenharmony_ci 1392e147c35Sopenharmony_ciint32_t StreamPlayer::SetLoopMode(const LoopMode mode) 1402e147c35Sopenharmony_ci{ 1412e147c35Sopenharmony_ci return proxy_ ? proxy_->SetLoopMode(mode) : CAST_ENGINE_ERROR; 1422e147c35Sopenharmony_ci} 1432e147c35Sopenharmony_ci 1442e147c35Sopenharmony_ciint32_t StreamPlayer::SetSpeed(const PlaybackSpeed speed) 1452e147c35Sopenharmony_ci{ 1462e147c35Sopenharmony_ci return proxy_ ? proxy_->SetSpeed(speed) : CAST_ENGINE_ERROR; 1472e147c35Sopenharmony_ci} 1482e147c35Sopenharmony_ci 1492e147c35Sopenharmony_ciint32_t StreamPlayer::GetPlayerStatus(PlayerStates &playerStates) 1502e147c35Sopenharmony_ci{ 1512e147c35Sopenharmony_ci return proxy_ ? proxy_->GetPlayerStatus(playerStates) : CAST_ENGINE_ERROR; 1522e147c35Sopenharmony_ci} 1532e147c35Sopenharmony_ci 1542e147c35Sopenharmony_ciint32_t StreamPlayer::GetPosition(int &position) 1552e147c35Sopenharmony_ci{ 1562e147c35Sopenharmony_ci return proxy_ ? proxy_->GetPosition(position) : CAST_ENGINE_ERROR; 1572e147c35Sopenharmony_ci} 1582e147c35Sopenharmony_ci 1592e147c35Sopenharmony_ciint32_t StreamPlayer::GetDuration(int &duration) 1602e147c35Sopenharmony_ci{ 1612e147c35Sopenharmony_ci return proxy_ ? proxy_->GetDuration(duration) : CAST_ENGINE_ERROR; 1622e147c35Sopenharmony_ci} 1632e147c35Sopenharmony_ci 1642e147c35Sopenharmony_ciint32_t StreamPlayer::GetVolume(int &volume, int &maxVolume) 1652e147c35Sopenharmony_ci{ 1662e147c35Sopenharmony_ci return proxy_ ? proxy_->GetVolume(volume, maxVolume) : CAST_ENGINE_ERROR; 1672e147c35Sopenharmony_ci} 1682e147c35Sopenharmony_ci 1692e147c35Sopenharmony_ciint32_t StreamPlayer::GetMute(bool &mute) 1702e147c35Sopenharmony_ci{ 1712e147c35Sopenharmony_ci return proxy_ ? proxy_->GetMute(mute) : CAST_ENGINE_ERROR; 1722e147c35Sopenharmony_ci} 1732e147c35Sopenharmony_ci 1742e147c35Sopenharmony_ciint32_t StreamPlayer::GetLoopMode(LoopMode &loopMode) 1752e147c35Sopenharmony_ci{ 1762e147c35Sopenharmony_ci return proxy_ ? proxy_->GetLoopMode(loopMode) : CAST_ENGINE_ERROR; 1772e147c35Sopenharmony_ci} 1782e147c35Sopenharmony_ci 1792e147c35Sopenharmony_ciint32_t StreamPlayer::GetPlaySpeed(PlaybackSpeed &playbackSpeed) 1802e147c35Sopenharmony_ci{ 1812e147c35Sopenharmony_ci return proxy_ ? proxy_->GetPlaySpeed(playbackSpeed) : CAST_ENGINE_ERROR; 1822e147c35Sopenharmony_ci} 1832e147c35Sopenharmony_ci 1842e147c35Sopenharmony_ciint32_t StreamPlayer::GetMediaInfoHolder(MediaInfoHolder &mediaInfoHolder) 1852e147c35Sopenharmony_ci{ 1862e147c35Sopenharmony_ci return proxy_ ? proxy_->GetMediaInfoHolder(mediaInfoHolder) : CAST_ENGINE_ERROR; 1872e147c35Sopenharmony_ci} 1882e147c35Sopenharmony_ci 1892e147c35Sopenharmony_ciint32_t StreamPlayer::Release() 1902e147c35Sopenharmony_ci{ 1912e147c35Sopenharmony_ci return proxy_ ? proxy_->Release() : CAST_ENGINE_ERROR; 1922e147c35Sopenharmony_ci} 1932e147c35Sopenharmony_ci} // namespace CastEngineClient 1942e147c35Sopenharmony_ci} // namespace CastEngine 1952e147c35Sopenharmony_ci} // namespace OHOS