package com.yfd.monitor.media.service;



import com.yfd.monitor.common.CommonCallback;
import com.yfd.monitor.common.StreamInfo;
import com.yfd.monitor.gdw2019.bean.ParentPlatform;
import com.yfd.monitor.gdw2019.bean.SendRtpItem;
import com.yfd.monitor.media.bean.MediaInfo;
import com.yfd.monitor.media.zlm.dto.MediaServerItem;
import com.yfd.monitor.service.bean.MediaServerLoad;
import com.yfd.monitor.service.bean.SSRCInfo;
import com.yfd.monitor.vmanager.bean.WVPResult;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * 媒体服务节点
 */
public interface IMediaServerService {

    List<MediaServerItem> getAllOnlineList();

    List<MediaServerItem> getAll();

    List<MediaServerItem> getAllFromDatabase();

    List<MediaServerItem> getAllOnline();

    MediaServerItem getOne(String generalMediaServerId);

    void syncCatchFromDatabase();

    MediaServerItem getMediaServerForMinimumLoad(Boolean hasAssist);

    void updateVmServer(List<MediaServerItem> mediaServerItemList);

    SSRCInfo openRTPServer(MediaServerItem mediaServerItem, String streamId, String presetSsrc, boolean ssrcCheck,
                           boolean isPlayback, Integer port, Boolean onlyAuto, Boolean disableAudio,
                           Boolean reUsePort, Integer tcpMode);

    void closeRTPServer(MediaServerItem mediaServerItem, String streamId);

    void closeRTPServer(MediaServerItem mediaServerItem, String streamId, CommonCallback<Boolean> callback);
    Boolean updateRtpServerSSRC(MediaServerItem mediaServerItem, String streamId, String ssrc);

    void closeRTPServer(String mediaServerId, String streamId);

    void clearRTPServer(MediaServerItem mediaServerItem);

    void update(MediaServerItem mediaSerItem);

    void addCount(String mediaServerId);

    void removeCount(String mediaServerId);

    void releaseSsrc(String mediaServerItemId, String ssrc);

    void clearMediaServerForOnline();

    void add(MediaServerItem mediaSerItem);

    void resetOnlineServerItem(MediaServerItem serverItem);

    MediaServerItem checkMediaServer(String ip, int port, String secret, String type);

    boolean checkMediaRecordServer(String ip, int port);

    void delete(String id);

    MediaServerItem getDefaultMediaServer();

    MediaServerLoad getLoad(MediaServerItem mediaServerItem);

    List<MediaServerItem> getAllWithAssistPort();

    MediaServerItem getOneFromDatabase(String id);

    boolean stopSendRtp(MediaServerItem mediaInfo, String app, String stream, String ssrc);

    boolean initStopSendRtp(MediaServerItem mediaInfo, String app, String stream, String ssrc);

    boolean deleteRecordDirectory(MediaServerItem mediaServerItem, String app, String stream, String date, String fileName);

    List<StreamInfo> getMediaList(MediaServerItem mediaInfo, String app, String stream, String callId);

    Boolean connectRtpServer(MediaServerItem mediaServerItem, String address, int port, String stream);

    void getSnap(MediaServerItem mediaServerItemInuse, String streamUrl, int timeoutSec, int expireSec, String path, String fileName) throws IOException;

    MediaInfo getMediaInfo(MediaServerItem mediaServerItem, String app, String stream);

    Boolean pauseRtpCheck(MediaServerItem mediaServerItem, String streamKey);

    boolean resumeRtpCheck(MediaServerItem mediaServerItem, String streamKey);

    String getFfmpegCmd(MediaServerItem mediaServer, String cmdKey);

    void closeStreams(MediaServerItem mediaServerItem, String app, String stream);

    WVPResult<String> addFFmpegSource(MediaServerItem mediaServerItem, String srcUrl, String dstUrl, int timeoutMs,
                                      boolean enableAudio, boolean enableMp4, String ffmpegCmdKey);

    WVPResult<String> addStreamProxy(MediaServerItem mediaServerItem, String app, String stream, String url, boolean enableAudio, boolean enableMp4, String rtpType);

    Boolean delFFmpegSource(MediaServerItem mediaServerItem, String streamKey);

    Boolean delStreamProxy(MediaServerItem mediaServerItem, String streamKey);

    Map<String, String> getFFmpegCMDs(MediaServerItem mediaServer);

    /**
     * 根据应用名和流ID获取播放地址, 通过zlm接口检查是否存在
     * @param app
     * @param stream
     * @return
     */
    StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String mediaServerId, String addr, boolean authority);


    /**
     * 根据应用名和流ID获取播放地址, 通过zlm接口检查是否存在, 返回的ip使用远程访问ip，适用与zlm与wvp在一台主机的情况
     * @param app
     * @param stream
     * @return
     */
    StreamInfo getStreamInfoByAppAndStreamWithCheck(String app, String stream, String mediaServerId, boolean authority);

    /**
     * 根据应用名和流ID获取播放地址, 只是地址拼接
     * @param app
     * @param stream
     * @return
     */
    StreamInfo getStreamInfoByAppAndStream(MediaServerItem mediaServerItem, String app, String stream, MediaInfo mediaInfo, String callId);

    /**
     * 根据应用名和流ID获取播放地址, 只是地址拼接，返回的ip使用远程访问ip，适用与zlm与wvp在一台主机的情况
     * @param app
     * @param stream
     * @return
     */
    StreamInfo getStreamInfoByAppAndStream(MediaServerItem mediaServer, String app, String stream, MediaInfo mediaInfo, String addr, String callId, boolean isPlay);

    Boolean isStreamReady(MediaServerItem mediaServer, String rtp, String streamId);

    void startSendRtpPassive(MediaServerItem mediaServer, ParentPlatform platform, SendRtpItem sendRtpItem,
                             Integer timeout);

    void startSendRtp(MediaServerItem mediaServer, ParentPlatform platform, SendRtpItem sendRtpItem);

    SendRtpItem createSendRtpItem(MediaServerItem mediaServerItem, String addressStr, int port, String ssrc, String requesterId, String deviceId, String channelId, boolean mediaTransmissionTCP, boolean rtcp);

    SendRtpItem createSendRtpItem(MediaServerItem serverItem, String ip, int port, String ssrc, String platformId,
                                  String app, String stream, String channelId, boolean tcp, boolean rtcp);

    MediaServerItem getMediaServerByAppAndStream(String app, String stream);
}
