package com.yfd.monitor.service;

import com.alibaba.fastjson2.JSONObject;
import com.yfd.monitor.common.StreamInfo;
import com.yfd.monitor.conf.exception.ServiceException;
import com.yfd.monitor.gdw2019.bean.Device;
import com.yfd.monitor.gdw2019.bean.InviteStreamCallback;
import com.yfd.monitor.gdw2019.bean.InviteStreamInfo;
import com.yfd.monitor.gdw2019.event.SipSubscribe;
import com.yfd.monitor.media.bean.MediaInfo;
import com.yfd.monitor.media.zlm.ZlmHttpHookSubscribe;
import com.yfd.monitor.media.zlm.dto.MediaServerItem;
import com.yfd.monitor.service.bean.ErrorCallback;
import com.yfd.monitor.service.bean.InviteTimeOutCallback;
import com.yfd.monitor.service.bean.PlayBackCallback;
import com.yfd.monitor.service.bean.SSRCInfo;
import com.yfd.monitor.vmanager.bean.AudioBroadcastResult;
import com.yfd.monitor.vmanager.bean.StreamContent;
import com.yfd.monitor.vmanager.bean.WVPResult;
import com.yfd.monitor.vmanager.gdw2019.play.bean.AudioBroadcastEvent;
import org.springframework.web.context.request.async.DeferredResult;

import javax.sip.InvalidArgumentException;
import javax.sip.SipException;
import java.text.ParseException;

/**
 * 点播处理
 */
public interface IPlayService {
    StreamInfo onPublishHandlerForPlay(MediaServerItem mediaServerItem, MediaInfo mediaInfo, String deviceId, String channelId);
    void onPublishHandlerForPlay(MediaServerItem mediaServerItem, JSONObject resonse, String deviceId, String channelId);

    void play(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,
              ZlmHttpHookSubscribe.Event hookEvent, SipSubscribe.Event errorEvent,
              InviteTimeOutCallback timeoutCallback);
    void play(MediaServerItem mediaServerItem, String deviceId, String channelId, ZlmHttpHookSubscribe.Event event, SipSubscribe.Event errorEvent, Runnable timeoutCallback);
//    SSRCInfo play(MediaServerItem mediaServerItem, String deviceId, String channelId, String ssrc, ErrorCallback<Object> callback);

    DeferredResult<WVPResult<StreamContent>> play_subStream(MediaServerItem mediaServerItem, String deviceId, String channelId);
    MediaServerItem getNewMediaServerItem(Device device);

    /**
     * 获取包含assist服务的节点
     */
    MediaServerItem getNewMediaServerItemHasAssist(Device device);

    void onPublishHandlerForDownload(InviteStreamInfo inviteStreamInfo, String deviceId, String channelId, String toString);

    void playBack(String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback playBackCallback);
    void playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);

    void zlmServerOffline(String mediaServerId);

    void download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback playBackCallback);
    void download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteStreamCallback infoCallBack, PlayBackCallback hookCallBack);

    StreamInfo getDownLoadInfo(String deviceId, String channelId, String stream);

    void zlmServerOnline(String mediaServerId);

    void pauseRtp(String streamId) throws ServiceException, InvalidArgumentException, ParseException, SipException;

    void resumeRtp(String streamId) throws ServiceException, InvalidArgumentException, ParseException, SipException;
    AudioBroadcastResult audioBroadcast(Device device, String channelId, Boolean broadcastMode);

    void stopAudioBroadcast(String deviceId, String channelId);
    boolean audioBroadcastCmd(Device device, String channelId, MediaServerItem mediaServerItem, String app, String stream, int timeout, boolean isFromPlatform, AudioBroadcastEvent event) throws InvalidArgumentException, ParseException, SipException;
    void talkCmd(Device device, String channelId, MediaServerItem mediaServerItem, String stream, AudioBroadcastEvent event);
    void stopTalk(Device device, String channelId, Boolean streamIsReady);
}
