You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
244 lines
10 KiB
244 lines
10 KiB
/*
|
|
* Copyright (c) Hisilicon Technologies Co., Ltd. 2019-2020. All rights reserved.
|
|
* Description: NxMediaPlayerManager class implement
|
|
* Author: NxPlayer software group
|
|
* Create: 2019-11-21
|
|
*/
|
|
|
|
#ifndef ANDROID_MEDIAPLAYER_MANAGE_H
|
|
#define ANDROID_MEDIAPLAYER_MANAGE_H
|
|
|
|
#include "NxMediaDefine.h"
|
|
#include "NxMediaMsg.h"
|
|
|
|
#include <utils/RefBase.h>
|
|
#include <utils/threads.h>
|
|
#include <utils/KeyedVector.h>
|
|
#include <android/hidl/memory/1.0/IMemory.h>
|
|
#include <hidlmemory/mapping.h>
|
|
#include <securec.h>
|
|
#include <vendor/hardware/hwnxmediaplayerhal/1.0/INxMediaPlayerStore.h>
|
|
#include <vendor/hardware/hwnxmediaplayerhal/1.0/INxMediaPlayer.h>
|
|
#include <vendor/hardware/hwnxmediaplayerhal/1.0/IMediaCallBack.h>
|
|
#include <vendor/hardware/hwnxmediaplayerhal/1.0/types.h>
|
|
#include <vendor/hardware/hwnxmediaplayerhal/1.1/INxMediaPlayerStore.h>
|
|
#include "NxMediaPlayerInterface.h"
|
|
|
|
namespace android {
|
|
using ::android::sp;
|
|
using android::status_t;
|
|
|
|
using ::android::hardware::hidl_string;
|
|
using ::android::hardware::hidl_vec;
|
|
using ::android::hardware::Return;
|
|
using ::android::hardware::Void;
|
|
using ::android::hardware::hidl_array;
|
|
|
|
using ::vendor::hardware::hwnxmediaplayerhal::V1_0::INxMediaPlayerStore;
|
|
using INxMediaPlayerStore_V1_1 = ::vendor::hardware::hwnxmediaplayerhal::V1_1::INxMediaPlayerStore;
|
|
using ::vendor::hardware::hwnxmediaplayerhal::V1_0::INxMediaPlayer;
|
|
using ::vendor::hardware::hwnxmediaplayerhal::V1_0::IMediaCallBack;
|
|
using ::vendor::hardware::hwnxmediaplayerhal::V1_0::MediaBuffer;
|
|
using ::vendor::hardware::hwnxmediaplayerhal::V1_0::Header;
|
|
using HMemory = ::android::hidl::memory::V1_0::IMemory;
|
|
using ::android::hardware::hidl_memory;
|
|
|
|
class NxMediaPlayerManage;
|
|
|
|
class NxMediaPlayerListener : virtual public RefBase {
|
|
public:
|
|
virtual void notify(int msg, int ext1, int ext2, const Parcel *obj) = 0;
|
|
};
|
|
|
|
class MediaCallBack : public IMediaCallBack {
|
|
public:
|
|
explicit MediaCallBack(NxMediaPlayerManage *p, int instIdx) : m_mediaPlayerManage(p), m_instIdx(instIdx)
|
|
{
|
|
HLOGD("new %s", __FUNCTION__);
|
|
}
|
|
|
|
~MediaCallBack() override
|
|
{
|
|
HLOGD("release %s", __FUNCTION__);
|
|
}
|
|
|
|
Return<void> Notify(int32_t msg, int32_t ext1, int32_t ext2, const hidl_string &obj) override;
|
|
void SetMediaCallBack(NxMediaPlayerManage *p);
|
|
|
|
private:
|
|
NxMediaPlayerManage *m_mediaPlayerManage;
|
|
Mutex m_notifyLock;
|
|
int m_instIdx;
|
|
};
|
|
|
|
class NxMediaPlayerManage : public NxMediaPlayerInterface {
|
|
public:
|
|
explicit NxMediaPlayerManage(int idx);
|
|
~NxMediaPlayerManage() override;
|
|
|
|
status_t initCheck() override;
|
|
status_t setUID(uid_t uid) const;
|
|
status_t setDataSource(const char *url, const KeyedVector<String8, String8> *headers) override;
|
|
status_t setDataSource(int fd, int64_t offset, int64_t length) override;
|
|
status_t setVideoSurfaceTexture(const sp<HGraphicBufferProducer> &bufferProducer,
|
|
sp<ANativeWindow> &nativeWindow, int isSurfaceView) override;
|
|
status_t prepare();
|
|
status_t prepareAsync() override;
|
|
status_t start() override;
|
|
status_t stop() override;
|
|
status_t pause() override;
|
|
bool isPlaying() override;
|
|
status_t getPlaybackSettings(NxPlayerRate *rate) override;
|
|
status_t setPlaybackSettings(const NxPlayerRate &rate) override;
|
|
status_t getDefaultBufferingSettings(NxPlayerBufferingSettings *buffering) override;
|
|
status_t getBufferingSettings(NxPlayerBufferingSettings *buffering) override;
|
|
status_t setBufferingSettings(const NxPlayerBufferingSettings &buffering) override;
|
|
status_t seekTo(int msec, NxPlayerSeekMode mode = NxPlayerSeekMode::NX_PLAYER_SEEK_PRE_KEY) override;
|
|
status_t getCurrentPosition(int *millisecond) override;
|
|
status_t getDuration(int *msec) override;
|
|
status_t reset() override;
|
|
status_t setLooping(int loop) override;
|
|
status_t setVolume(float leftVolume, float rightVolume) override;
|
|
status_t invoke(const Parcel &request, Parcel *reply) override;
|
|
status_t setParameter(int key, const Parcel &request) override;
|
|
status_t getParameter(int key, Parcel *reply) override;
|
|
|
|
status_t getMetadata(Parcel *records) override;
|
|
|
|
status_t dump(int fd, const Vector<String16> &args) override;
|
|
status_t getTrackInfo(Parcel *reply) override;
|
|
status_t setAudioStreamType(int streamType) override;
|
|
status_t setUID(int uid) override;
|
|
status_t notifyAt(int64_t mediaTimeUs) override;
|
|
/* 16: uuid length */
|
|
status_t prepareDrm(const uint8_t uuid[16], const Vector<uint8_t>& drmSessionId) override;
|
|
status_t releaseDrm() override;
|
|
|
|
/* NxMedia extend */
|
|
status_t AddTimeTextSource(const char *filepath, const char *mimeType);
|
|
int SetTimeTextFlag(int flags);
|
|
status_t setSubSurface(const sp<HGraphicBufferProducer> &bufferProducer) override;
|
|
status_t CreateNxMediaMsg();
|
|
bool UseAsycModeNotifyMsg() const;
|
|
void PostMsg(int msg, int ext1 = 0, int ext2 = 0, const Parcel &obj = Parcel()) const;
|
|
void notifyFunc(int msg, int ext1, int ext2, const Parcel *obj = nullptr) override;
|
|
static void notify(NxMediaPlayerManage *cookie, int msg, int ext1, int ext2, const Parcel *obj = nullptr);
|
|
bool isLooping() override;
|
|
|
|
private:
|
|
status_t AttachNewPlayer(const sp <INxMediaPlayer> &player);
|
|
sp<INxMediaPlayer> CreatePlayer();
|
|
void NotifyResourceManage();
|
|
void NotifyMediaPrepared();
|
|
void NotifyPlayBackComplete();
|
|
void NotifyMediaError(const int &ext1, const int &ext2);
|
|
void NotifyMediaInfo(int &ext1, const int &ext2);
|
|
void NotifySeekComplete();
|
|
void NotifySetVidSize(const int &ext1, const int &ext2);
|
|
void NotifyFastForwordComplete();
|
|
void NotifyFastBackwordComplete();
|
|
status_t InvokeGetTrackInfo(const Parcel &request __unused, Parcel *reply);
|
|
status_t AddSubtitle(int fd, int subFd, int64_t offset, int64_t length, const hidl_string &mime) const;
|
|
status_t InvokeAddExternalSource(const Parcel &request __unused, Parcel *reply __unused) const;
|
|
status_t InvokeAddExternalSourceFd(const Parcel &request, Parcel *reply __unused) const;
|
|
status_t InvokeSelectTrack(const Parcel &request, Parcel *reply __unused) const;
|
|
status_t InvokeUnSelectTrack(const Parcel &request, Parcel *reply __unused) const;
|
|
status_t InvokeSetVidScalMode(const Parcel &request, Parcel *reply __unused) const;
|
|
status_t InvokeGetSelectedTrack(const Parcel &request, Parcel *reply) const;
|
|
status_t InvokeSetExtSubtitleFile(const Parcel &request, Parcel *reply) const;
|
|
status_t TransInvoke(const Parcel &request, Parcel *reply, uint32_t currentPos) const;
|
|
void Clear();
|
|
status_t CallGetDuration();
|
|
status_t SeekToL(int msec);
|
|
status_t PrepareAsyncL();
|
|
status_t GetDurationL(int *msec);
|
|
status_t ResetL();
|
|
|
|
status_t GetUrlFromFd(int fd, char *url, int urlLen) const;
|
|
status_t FindExtSubTitleFromUrl(const char *url, int len __unused);
|
|
status_t ScanExtSubFile(const char *path, unsigned int pathLenMax,
|
|
const char *prefixName, unsigned int nameLenMax);
|
|
void ScanExtSubPath(const char *path, struct dirent **fileList,
|
|
const char *prefixName, int fileNum);
|
|
status_t AddTimedTextSource(const char *subUrl) const;
|
|
bool IsSubSuffixName(const char *name) const;
|
|
status_t ProcessScreenOrient() const;
|
|
status_t SetUserID() const;
|
|
bool CheckIdxSub(String8 idxFileUrl, int &subFd) const;
|
|
status_t SetSubScreenDisplay();
|
|
bool IsUseSidebandMode() const;
|
|
bool SwitchModeIsBlack();
|
|
int SetSidebandHandle(const sp<ANativeWindow> &native);
|
|
void InitDeathRecipient();
|
|
void DeInitDeathRecipient() const;
|
|
void SetSurfaceUniqueId(const sp<ANativeWindow> &nativeWindow);
|
|
class DeathRecipient : public android::hardware::hidl_death_recipient {
|
|
public:
|
|
explicit DeathRecipient(NxMediaPlayerManage *playerManage, int idx)
|
|
:m_nxMediaPlayerManager(playerManage), m_instIdx(idx){ }
|
|
~DeathRecipient() override;
|
|
void serviceDied(uint64_t cookie, const wp< ::android::hidl::base::V1_0::IBase> &) override;
|
|
|
|
private:
|
|
NxMediaPlayerManage *m_nxMediaPlayerManager;
|
|
int m_instIdx;
|
|
};
|
|
sp<DeathRecipient> m_deathRecipient;
|
|
sp<INxMediaPlayerStore> m_playerStore;
|
|
sp<INxMediaPlayer> m_player;
|
|
sp<MediaCallBack> m_callback;
|
|
sp<NxMediaMsg> m_nxMsg { nullptr };
|
|
sp<NxMediaMsgHandle> m_nxMsgHandle { nullptr };
|
|
int m_isSurfaceView;
|
|
int m_isSeeking;
|
|
int m_isStarting;
|
|
Mutex m_lock;
|
|
Mutex m_notifyLock;
|
|
Condition m_signal;
|
|
sp<NxMediaPlayerListener> m_listener;
|
|
void *m_cookie;
|
|
uint32_t m_currentState;
|
|
int m_duration;
|
|
int m_currentPosition;
|
|
int m_seekPosition;
|
|
NxPlayerSeekMode m_seekMode;
|
|
bool m_prepareSync;
|
|
status_t m_prepareStatus;
|
|
bool m_loop;
|
|
float m_leftVolume;
|
|
float m_rightVolume;
|
|
int m_videoWidth;
|
|
int m_videoHeight;
|
|
float m_sendLevel;
|
|
|
|
int m_videoSurfaceX;
|
|
int m_videoSurfaceY;
|
|
int m_videoSurfaceWidth;
|
|
int m_videoSurfaceHeight;
|
|
Vector<String8> m_extSubUrl;
|
|
sp<ANativeWindow> m_nativeWindow;
|
|
static std::vector<std::string> g_extSubSuffixName;
|
|
int m_instIdx;
|
|
static const int NUM_INTS = 2; /* apply 2 ints spaces for this handle */
|
|
static const int NX_FAILURE = -1;
|
|
static const int MAX_TRACK_NUM = 128; /* max number of track */
|
|
static const int INVALID_FD = -1; /* -1 is invalid fd */
|
|
static const int SUB_SUFFIX_LEN = 4;
|
|
static const int IDXSUB_EXTS_LEN = 9;
|
|
static constexpr const char IDXSUB_EXTS[IDXSUB_EXTS_LEN][SUB_SUFFIX_LEN] = {
|
|
"sub",
|
|
"SUB",
|
|
"Sub",
|
|
"SUb",
|
|
"SuB",
|
|
"sUB",
|
|
"sUb",
|
|
"suB",
|
|
""
|
|
};
|
|
static const int SIDEBAND_NXPLAY_MAGIC_NUM = ('NXPY'); /* 0x48495059 */
|
|
static const int SIDEBAND_NXPLAY_MAGIC_NUM_BLACK = ('BLAK');
|
|
};
|
|
};
|
|
#endif
|