aix
2024-08-14 3434b7f03df4be419875bc7cc52f93be796e154d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package com.dji.sample.manage.controller;
 
import com.dji.sample.common.model.ResponseResult;
import com.dji.sample.component.mqtt.model.ChannelName;
import com.dji.sample.manage.model.dto.CapacityCameraDTO;
import com.dji.sample.manage.model.dto.CapacityDeviceDTO;
import com.dji.sample.manage.model.dto.LiveTypeDTO;
import com.dji.sample.manage.model.receiver.LiveCapacityReceiver;
import com.dji.sample.manage.service.ILiveStreamService;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.messaging.MessageHeaders;
import org.springframework.web.bind.annotation.*;
 
import java.io.IOException;
import java.util.List;
 
/**
 * @author sean.zhou
 * @version 0.1
 * @date 2021/11/19
 */
 
@RestController
@Slf4j
@RequestMapping("${url.manage.prefix}${url.manage.version}/live")
public class LiveStreamController {
 
    @Autowired
    private ILiveStreamService liveStreamService;
 
    @Autowired
    private ObjectMapper mapper;
 
    /**
     * Analyze the live streaming capabilities of drones.
     * This data is necessary if drones are required for live streaming.
     * @param liveCapacity    the capacity of drone and dock
     */
    @ServiceActivator(inputChannel = ChannelName.INBOUND_STATE_CAPACITY)
    public void stateCapacity(LiveCapacityReceiver liveCapacity, MessageHeaders headers) {
        liveStreamService.saveLiveCapacity(liveCapacity, headers.getTimestamp());
    }
 
 
    /**
     * 获取直播地址
     * @param workspaceId 项目id
     * @param sn 设备号
     * @return
     */
    @GetMapping("/getLiveUrl/{workspace_id}")
    public ResponseResult getLiveUrl(@PathVariable("workspace_id") String workspaceId, String sn) {
        List<CapacityDeviceDTO> liveCapacity = liveStreamService.getLiveCapacity(workspaceId,sn);
 
        if (null == liveCapacity || liveCapacity.isEmpty()) {
            return ResponseResult.error(-1,"暂无直播或者设备未开机");
        }
        CapacityDeviceDTO deviceDTO = liveCapacity.get(0);
 
        if (null == deviceDTO.getCamerasList() || deviceDTO.getCamerasList().isEmpty()) {
            return ResponseResult.error(-1,"暂无直播地址");
        }
 
        List<CapacityCameraDTO> camerasList = deviceDTO.getCamerasList();
        if (null == camerasList || camerasList.isEmpty()) {
            return ResponseResult.error(-1,"获取相机信息失败");
        }
 
        CapacityCameraDTO cameraDTO = camerasList.get(0);
 
        String videoIndex = cameraDTO.getVideosList().get(0).getIndex();
 
        LiveTypeDTO liveParam = new LiveTypeDTO();
        String videoId = deviceDTO.getSn() + "-" + cameraDTO.getIndex() + "-" + videoIndex;
        liveParam.setUrl("rtmp://www.ainfo.top:735/uav/" + videoId);
        liveParam.setUrlType(1);
        liveParam.setVideoId(deviceDTO.getSn() + "/" + cameraDTO.getIndex() + "/" + videoIndex);
        liveParam.setVideoQuality(0);
        return liveStreamService.liveStart(liveParam);
    }
 
    /**
     * Get live capability data of all drones in the current user's workspace from the database.
     * 从数据库中获取当前工作区中所有无人机的实时性能数据。
     * @param workspaceId
     * @return  live capability
     */
    @GetMapping("/capacity/{workspace_id}")
    public ResponseResult<List<CapacityDeviceDTO>> getLiveCapacity(@PathVariable("workspace_id") String workspaceId,String sn) {
        // Get information about the current user. 获取当前登录用户的信息
//        CustomClaim customClaim = (CustomClaim)request.getAttribute(TOKEN_CLAIM);
 
        List<CapacityDeviceDTO> liveCapacity = liveStreamService.getLiveCapacity(workspaceId,sn);
        return ResponseResult.success(liveCapacity);
    }
 
    /**
     * Live streaming according to the parameters passed in from the web side.
     * 根据从web端传入的参数进行直播。
     * @param liveParam Live streaming parameters.
     * @return
     */
    @PostMapping("/streams/start")
    public ResponseResult liveStart(@RequestBody LiveTypeDTO liveParam) {
        return liveStreamService.liveStart(liveParam);
    }
 
    @PostMapping("/streams/address")
    public ResponseResult liveAddress(@RequestParam String deviceSn,@RequestParam String deviceName) throws IOException {
        return liveStreamService.liveAddress(deviceSn,deviceName);
    }
 
    /**
     * Stop live streaming according to the parameters passed in from the web side.
     * 根据从web端传入的参数停止直播。
     * @param liveParam Live streaming parameters.
     * @return
     */
    @PostMapping("/streams/stop")
    public ResponseResult liveStop(@RequestBody LiveTypeDTO liveParam) {
        return liveStreamService.liveStop(liveParam.getVideoId());
    }
 
    /**
     * 根据从web端传入的参数设置直播的质量。
     * @param liveParam 直播参数
     * @return
     */
    @PostMapping("/streams/update")
    public ResponseResult liveSetQuality(@RequestBody LiveTypeDTO liveParam) {
        return liveStreamService.liveSetQuality(liveParam);
    }
 
    @PostMapping("/streams/switch")
    public ResponseResult liveLensChange(@RequestBody LiveTypeDTO liveParam) {
        return liveStreamService.liveLensChange(liveParam);
    }
 
}