|
| 1 | +package com.qiniu.qvs; |
| 2 | + |
| 3 | +import com.qiniu.common.QiniuException; |
| 4 | +import com.qiniu.http.Client; |
| 5 | +import com.qiniu.http.Response; |
| 6 | +import com.qiniu.util.Auth; |
| 7 | +import com.qiniu.util.StringMap; |
| 8 | + |
| 9 | +public class RecordManager { |
| 10 | + private final String apiServer; |
| 11 | + private final Client client; |
| 12 | + private final Auth auth; |
| 13 | + |
| 14 | + public RecordManager(Auth auth) { |
| 15 | + this(auth, "http://qvs.qiniuapi.com"); |
| 16 | + } |
| 17 | + |
| 18 | + public RecordManager(Auth auth, String apiServer) { |
| 19 | + this(auth, apiServer, new Client()); |
| 20 | + } |
| 21 | + |
| 22 | + public RecordManager(Auth auth, String apiServer, Client client) { |
| 23 | + this.auth = auth; |
| 24 | + this.apiServer = apiServer; |
| 25 | + this.client = client; |
| 26 | + } |
| 27 | + |
| 28 | + /* |
| 29 | + * 启动按需录制 |
| 30 | + */ |
| 31 | + public Response startRecord(String namespaceId, String streamId) throws QiniuException { |
| 32 | + String url = String.format("%s/v1/namespaces/%s/streams/%s/record/start", apiServer, namespaceId, streamId); |
| 33 | + return QvsResponse.post(url, new StringMap(), client, auth); |
| 34 | + } |
| 35 | + |
| 36 | + /* |
| 37 | + * 停止按需录制 |
| 38 | + */ |
| 39 | + public Response stopRecord(String namespaceId, String streamId) throws QiniuException { |
| 40 | + String url = String.format("%s/v1/namespaces/%s/streams/%s/record/stop", apiServer, namespaceId, streamId); |
| 41 | + return QvsResponse.post(url, new StringMap(), client, auth); |
| 42 | + } |
| 43 | + |
| 44 | + /* |
| 45 | + * 删除录制片段 |
| 46 | + */ |
| 47 | + public Response deleteStreamRecordHistories(String namespaceId, String streamId, String[] files) throws QiniuException { |
| 48 | + String url = String.format("%s/v1/namespaces/%s/streams/%s/recordhistories", apiServer, namespaceId, streamId); |
| 49 | + StringMap params = new StringMap(); |
| 50 | + params.putNotNull("files", files); |
| 51 | + return QvsResponse.delete(url, params, client, auth); |
| 52 | + } |
| 53 | + |
| 54 | + /* |
| 55 | + * 录制视频片段合并 |
| 56 | + * 参数: |
| 57 | + * fname 保存的文件名(需要带上文件格式后缀),不指定系统会随机生成 |
| 58 | + * format 保存的文件格式,可以为m3u8, mp4或者flv |
| 59 | + * start 查询开始时间(unix时间戳,单位为秒) |
| 60 | + * end 查询结束时间(unix时间戳,单位为秒) |
| 61 | + * deleteTs 在不生成m3u8格式文件时是否删除对应的ts文件 |
| 62 | + * pipeline 数据处理的私有队列,不指定则使用公共队列 |
| 63 | + * notifyUrl 保存成功回调通知地址,不指定则不通知 |
| 64 | + * deleteAfterDays 文件过期时间,默认和录制模版中的设置保持一致 |
| 65 | + */ |
| 66 | + public Response recordClipsSaveas(String namespaceId, String streamId, String fname, String format, int start, int end, boolean deleteTs, String pipeline, String notifyUrl, int deleteAfterDays) throws QiniuException { |
| 67 | + String url = String.format("%s/v1/namespaces/%s/streams/%s/saveas", apiServer, namespaceId, streamId); |
| 68 | + StringMap params = new StringMap(); |
| 69 | + params.putNotNull("fname", fname); |
| 70 | + params.putNotNull("format", format); |
| 71 | + params.putNotNull("start", start); |
| 72 | + params.putNotNull("end", end); |
| 73 | + params.putNotNull("deleteTs", deleteTs); |
| 74 | + params.putNotNull("pipeline", pipeline); |
| 75 | + params.putNotNull("notifyUrl", notifyUrl); |
| 76 | + params.putNotNull("deleteAfterDays", deleteAfterDays); |
| 77 | + |
| 78 | + return QvsResponse.post(url, params, client, auth); |
| 79 | + } |
| 80 | + |
| 81 | + /* |
| 82 | + * 录制回放 |
| 83 | + */ |
| 84 | + public Response recordsPlayback(String namespaceId, String streamId, int start, int end) throws QiniuException { |
| 85 | + String url = String.format("%s/v1/namespaces/%s/streams/%s/records/playback.m3u8?start=%d&end=%d", apiServer, namespaceId, streamId, start, end); |
| 86 | + return QvsResponse.get(url, client, auth); |
| 87 | + } |
| 88 | +} |
0 commit comments