/* * Copyright (c) 2020 Amlogic, Inc. All rights reserved. * * This source code is subject to the terms and conditions defined in the * file 'LICENSE' which is part of this source code package. * * Description: */ #define LOG_NDEBUG 0 #define LOG_TAG "AmlMpPlayer" #include #ifdef CONFIG_AMP_SERVER #include #include "Aml_MP_PlayerClient.h" #endif #include "Aml_MP_PlayerImpl.h" #include "utils/AmlMpUtils.h" #include "utils/AmlMpHandle.h" static const char* mName = LOG_TAG; using namespace aml_mp; int Aml_MP_Player_Create(Aml_MP_PlayerCreateParams* createParams, AML_MP_PLAYER* handle) { AML_MP_TRACE(10); RETURN_IF(-1, createParams == nullptr); sptr client = nullptr; #ifdef CONFIG_AMP_SERVER bool useRemotePlayer = false; if (createParams->reserved[0] == 'u' && createParams->reserved[1] == 'r' && createParams->reserved[2] == 'p') { useRemotePlayer = true; MLOGI("will create remote player by createParams"); } else if (createParams->reserved[0] == 'n' && createParams->reserved[1] == 'u' && createParams->reserved[2] == 'r' && createParams->reserved[3] == 'p') { useRemotePlayer = false; MLOGI("will create normal player by createParams"); } else { #ifdef HAVE_TUNER_HAL if (createParams->options & AML_MP_OPTION_PREFER_TUNER_HAL || AmlMpConfig::instance().mPreferTunerHal == 1) { useRemotePlayer = false; MLOGI("build amp server, but need tuner hal, so disable remote player."); } else #endif { useRemotePlayer = property_get_bool("vendor.media.aml_mp.remote_player", true); } MLOGI("will create remote player by prop? %s", useRemotePlayer ? "Yes" : "No"); } if (useRemotePlayer) { client = new Aml_MP_PlayerClient(createParams); } else #endif { client = new AmlMpPlayerImpl(createParams); } client->incStrong(client.get()); *handle = aml_handle_cast(client); return 0; } int Aml_MP_Player_Destroy(AML_MP_PLAYER handle) { AML_MP_TRACE(10); sptr client = aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); client->decStrong(handle); return 0; } int Aml_MP_Player_RegisterEventCallBack(AML_MP_PLAYER handle, Aml_MP_PlayerEventCallback cb, void* userData) { sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); RETURN_IF(-1, cb == nullptr); return client->registerEventCallback(cb, userData); } int Aml_MP_Player_SetVideoParams(AML_MP_PLAYER handle, Aml_MP_VideoParams* params) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); RETURN_IF(-1, params == nullptr); return client->setVideoParams(params); } int Aml_MP_Player_SetAudioParams(AML_MP_PLAYER handle, Aml_MP_AudioParams* params) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); RETURN_IF(-1, params == nullptr); return client->setAudioParams(params); } int Aml_MP_Player_SetSubtitleParams(AML_MP_PLAYER handle, Aml_MP_SubtitleParams* params) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); RETURN_IF(-1, params == nullptr); return client->setSubtitleParams(params); } int Aml_MP_Player_SetCasSession(AML_MP_PLAYER handle, AML_MP_CASSESSION casSession) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->setCasSession(casSession); } int Aml_MP_Player_SetCASParams(AML_MP_PLAYER handle, Aml_MP_CASParams* params) { AML_MP_TRACE(10); sptr player = aml_handle_cast(handle); RETURN_IF(-1, player == nullptr); Aml_MP_CASServiceType serviceType{AML_MP_CAS_SERVICE_TYPE_INVALID}; Aml_MP_IptvCASParams iptvCasParam{}; if (params->type == AML_MP_CAS_VERIMATRIX_IPTV) { //coverity[value_overwrite] serviceType = AML_MP_CAS_SERVICE_VERIMATRIX_IPTV; } else if (params->type == AML_MP_CAS_WIDEVINE) { //coverity[value_overwrite] serviceType = AML_MP_CAS_SERVICE_WIDEVINE; } else { MLOGE("unsupported cas type! %s", mpCASType2Str(params->type)); return -1; } iptvCasParam.videoCodec = params->u.iptvCasParam.videoCodec; iptvCasParam.audioCodec = params->u.iptvCasParam.audioCodec; iptvCasParam.videoPid = params->u.iptvCasParam.videoPid; iptvCasParam.audioPid = params->u.iptvCasParam.audioPid; iptvCasParam.ecmPid[0] = params->u.iptvCasParam.ecmPid;//audio ecm pid iptvCasParam.ecmPid[1] = params->u.iptvCasParam.ecmPid;// video ecm pid iptvCasParam.demuxId = params->u.iptvCasParam.demuxId; strncpy(iptvCasParam.serverAddress, params->u.iptvCasParam.serverAddress, sizeof(params->u.iptvCasParam.serverAddress)); iptvCasParam.serverPort = params->u.iptvCasParam.serverPort; strncpy(iptvCasParam.keyPath, params->u.iptvCasParam.keyPath, sizeof(params->u.iptvCasParam.keyPath)); return player->setIptvCASParams(serviceType, &iptvCasParam); } int Aml_MP_Player_Start(AML_MP_PLAYER handle) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->start(); } int Aml_MP_Player_Stop(AML_MP_PLAYER handle) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->stop(); } int Aml_MP_Player_Pause(AML_MP_PLAYER handle) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->pause(); } int Aml_MP_Player_Resume(AML_MP_PLAYER handle) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->resume(); } int Aml_MP_Player_Flush(AML_MP_PLAYER handle) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->flush(); } int Aml_MP_Player_SetPlaybackRate(AML_MP_PLAYER handle, float rate) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->setPlaybackRate(rate); } int Aml_MP_Player_SetPlaybackRate2(AML_MP_PLAYER handle, float rate, Aml_MP_VideoDecodeMode decodeMode) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->setPlaybackRate2(rate, decodeMode); } int Aml_MP_Player_GetPlaybackRate(AML_MP_PLAYER handle, float* rate) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); RETURN_IF(-1, rate == nullptr); return client->getPlaybackRate(rate); } int Aml_MP_Player_SwitchAudioTrack(AML_MP_PLAYER handle, Aml_MP_AudioParams* params) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); RETURN_IF(-1, params == nullptr); return client->switchAudioTrack(params); } int Aml_MP_Player_SwitchSubtitleTrack(AML_MP_PLAYER handle, Aml_MP_SubtitleParams* params) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); RETURN_IF(-1, params == nullptr); return client->switchSubtitleTrack(params); } int Aml_MP_Player_WriteData(AML_MP_PLAYER handle, const uint8_t* buffer, size_t size) { sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); RETURN_IF(-1, buffer == nullptr); return client->writeData(buffer, size); } int Aml_MP_Player_WriteEsData(AML_MP_PLAYER handle, Aml_MP_StreamType streamType, const uint8_t* buffer, size_t size, int64_t pts) { sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); RETURN_IF(-1, buffer == nullptr || size == 0); return client->writeEsData(streamType, buffer, size, pts); } int Aml_MP_Player_GetCurrentPts(AML_MP_PLAYER handle, Aml_MP_StreamType streamType, int64_t* pts) { sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); RETURN_IF(-1, pts == nullptr); return client->getCurrentPts(streamType, pts); } int Aml_MP_Player_GetFirstPts(AML_MP_PLAYER handle, Aml_MP_StreamType streamType, int64_t* pts) { sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); RETURN_IF(-1, pts == nullptr); return client->getFirstPts(streamType, pts); } int Aml_MP_Player_GetBufferStat(AML_MP_PLAYER handle, Aml_MP_BufferStat* bufferStat) { sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); RETURN_IF(-1, bufferStat == nullptr); return client->getBufferStat(bufferStat); } int Aml_MP_Player_SetANativeWindow(AML_MP_PLAYER handle, ANativeWindow* nativeWindow) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->setANativeWindow(nativeWindow); } int Aml_MP_Player_SetVideoWindow(AML_MP_PLAYER handle, int32_t x, int32_t y, int32_t width, int32_t height) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->setVideoWindow(x, y, width, height); } int Aml_MP_Player_SetVolume(AML_MP_PLAYER handle, float volume) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->setVolume(volume); } int Aml_MP_Player_GetVolume(AML_MP_PLAYER handle, float* volume) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); RETURN_IF(-1, volume == nullptr); return client->getVolume(volume); } int Aml_MP_Player_ShowVideo(AML_MP_PLAYER handle) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->showVideo(); } int Aml_MP_Player_HideVideo(AML_MP_PLAYER handle) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->hideVideo(); } //int Aml_MP_Player_MuteAudio(AML_MP_PLAYER handle) //{ //return 0; //} //int Aml_MP_Player_UnmuteAudio(AML_MP_PLAYER handle) //{ //return 0; //} int Aml_MP_Player_ShowSubtitle(AML_MP_PLAYER handle) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->showSubtitle(); } int Aml_MP_Player_HideSubtitle(AML_MP_PLAYER handle) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->hideSubtitle(); } int Aml_MP_Player_SetParameter(AML_MP_PLAYER handle, Aml_MP_PlayerParameterKey key, void* parameter) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->setParameter(key, parameter); } int Aml_MP_Player_GetParameter(AML_MP_PLAYER handle, Aml_MP_PlayerParameterKey key, void* parameter) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); RETURN_IF(-1, parameter == nullptr); return client->getParameter(key, parameter); } int Aml_MP_Player_SetSubtitleWindow(AML_MP_PLAYER handle, int x, int y, int width, int height) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->setSubtitleWindow(x, y, width, height); } //********************* BASIC INTERFACES END **************************/ int Aml_MP_Player_SetAVSyncSource(AML_MP_PLAYER handle, Aml_MP_AVSyncSource syncSource) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->setAVSyncSource(syncSource); } int Aml_MP_Player_SetPcrPid(AML_MP_PLAYER handle, int pid) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->setPcrPid(pid); } int Aml_MP_Player_StartVideoDecoding(AML_MP_PLAYER handle) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->startVideoDecoding(); } int Aml_MP_Player_StopVideoDecoding(AML_MP_PLAYER handle) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->stopVideoDecoding(); } int Aml_MP_Player_StartAudioDecoding(AML_MP_PLAYER handle) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->startAudioDecoding(); } int Aml_MP_Player_StopAudioDecoding(AML_MP_PLAYER handle) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->stopAudioDecoding(); } int Aml_MP_Player_StartSubtitleDecoding(AML_MP_PLAYER handle) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->startSubtitleDecoding(); } int Aml_MP_Player_StopSubtitleDecoding(AML_MP_PLAYER handle) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->stopSubtitleDecoding(); } int Aml_MP_Player_SetADParams(AML_MP_PLAYER handle, Aml_MP_AudioParams* params) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); RETURN_IF(-1, params == nullptr); return client->setADParams(params); } int Aml_MP_Player_StartADDecoding(AML_MP_PLAYER handle) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->startADDecoding(); } int Aml_MP_Player_StopADDecoding(AML_MP_PLAYER handle) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->stopADDecoding(); } int Aml_MP_Player_GetDecodingState(AML_MP_PLAYER handle, Aml_MP_StreamType streamType, AML_MP_DecodingState* decodingState) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); RETURN_IF(-1, decodingState == nullptr); return client->getDecodingState(streamType, decodingState); } int Aml_MP_Player_SetADVolume(AML_MP_PLAYER handle, float volume) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); return client->setADVolume(volume); } int Aml_MP_Player_GetADVolume(AML_MP_PLAYER handle, float* volume) { AML_MP_TRACE(10); sptr client =aml_handle_cast(handle); RETURN_IF(-1, client == nullptr); RETURN_IF(-1, volume == nullptr); return client->getADVolume(volume); }