通知回调

通知回调与认证回调一样,是正向接口,即由业务服务器提供接口,由直播云通过HTTP协议访问接口,将数据主动提供给业务服务器。

上图示意云主动发起HTTP请求至业务服务器,将数据提交给业务服务器,业务服务器将收到的数据保存到业务数据库中。

由此可见, 通知回调是由在业务服务器上实现的接口,由直播云调用

另外要注意的是,实现这些接口并不是要实现复杂的web service接口,而是提供一个地址,接收直播云发来的GET/POST请求即可。POST请求的处理和接收前端页面提交的表单数据一样处理,可以参考下面回调样例的抓包数据来理解这一点。

和认证回调一样,通知回调的接口地址也可以登录到直播云控制台进行修改。如果不配置某类型的通知回调地址,则直播云不会发生相应类型的通知回调。

当直播开始时,并且直播输出流可以播放时发生。当一个任务中有多个不同格式的输出时,每个格式都会有一个直播开始回调

直播开始中包含有以下字段

type=0, hashed_id, author, url, svod, size, created_at, duration, format, path, ctype, cversion, service_code, is_resume, tag, opaque, live_only

POST /notify HTTP/1.1
accept: */*
content-type: application/x-www-form-urlencoded
xvs-signature: 4be4f790dbc1aa79114dd86e70f9e6881414871e0db30047d4488d5c49256c5e
xvs-timestamp: 1444701447400
x-forwarded-for: 54.223.239.231
x-forwarded-port: 80
x-forwarded-proto: http
Content-Length: 504
connection: keep-alive
user-agent: ZhiboYun Cloud WoAn Ltd.
Host: 115.28.33.49:8000

type=0&hashed_id=aws-cn_north_1-5-a6eaff8eeef36a3b&author=001
&url=http://54.223.239.231:80/live/id/aws-cn_north_1-5-a6eaff8eeef36a3b.flv
&svod_url=http://54.223.239.231:80/TESTING/20151013/01/57/flv/aws-cn_north_1-5-a6eaff8eeef36a3b.flv?live=1
&size=480x800&created_at=1444701446&duration=0.00&format=flv/libx264/aac
&vs_id=aws-cn_north_1-5&path=TESTING/20151013/01/57/flv/&private_flag=0&ctype=10&cversion=448
&service_code=TESTING&is_resume=0&tag=tcp_output_flv_jpg&opaque=testing opaque string&live_only=0

直播结束包含以下字段

type=1, hashed_id, service_code, created_at, reach_end, is_resume, tag, http_output_bytes, input_bytes, duration, format, output_idx, opaque , live_only

POST /notify HTTP/1.1
accept: */*
content-type: application/x-www-form-urlencoded
xvs-signature: afdefb9e85571814e9c9ffa8c51aaf687e3f6778666f7ced904d81ac61e3952a
xvs-timestamp: 1444701464853
x-forwarded-for: 54.223.239.231
x-forwarded-port: 80
x-forwarded-proto: http
Content-Length: 295
connection: keep-alive
user-agent: ZhiboYun Cloud WoAn Ltd.
Host: 115.28.33.49:8000

type=1&hashed_id=aws-cn_north_1-5-a6eaff8eeef36a3b&vs_id=aws-cn_north_1-5&service_code=TESTING
&created_at=1444701446&reach_end=0&is_resume=0&tag=tcp_output_flv_jpg&http_output_bytes=0&input_bytes=1687675
&duration=16.54&format=flv/libx264/aac&output_idx=0&opaque=testing opaque string&live_only=0

type=2, hashed_id, author, size, created_at, duration, format, path, file_name, ctype, cversion, service_code, is_resume, tag, http_output_bytes, input_bytes, output_idx, opaquelive_only, url

POST /notify HTTP/1.1
accept: */*
content-type: application/x-www-form-urlencoded
xvs-signature: cecfd02ab4f1efbc9e6af74c13e89d0e7792a0f302a18ff02a92c7bdbd58f064
xvs-timestamp: 1444701465049
x-forwarded-for: 54.223.239.231
x-forwarded-port: 80
x-forwarded-proto: http
Content-Length: 540
connection: keep-alive
user-agent: ZhiboYun Cloud WoAn Ltd.
Host: 115.28.33.49:8000

type=2&hashed_id=aws-cn_north_1-5-a6eaff8eeef36a3b&author=001&size=480x800&created_at=1444701446&duration=16.54
&format=flv/libx264/aac&vs_id=aws-cn_north_1-5&path=TESTING/20151013/01/57/flv/
&file_name=aws-cn_north_1-5-a6eaff8eeef36a3b.flv&private_flag=0&ctype=10&cversion=448&service_code=TESTING&is_resume=0
&tag=tcp_output_flv_jpg&http_output_bytes=0&input_bytes=1687675&output_idx=0&opaque=testing opaque string&live_only=0
&url=http://s3.cn-north-1.amazonaws.com.cn/xvs/pub/TESTING/20151013/01/57/flv/aws-cn_north_1-5-a6eaff8eeef36a3b.flv

type=9, hashed_id, service_code, path, file_name, with, height, opaquelive_only, url

POST /notify HTTP/1.1
accept: */*
content-type: application/x-www-form-urlencoded
xvs-signature: e843d0f8185737f7afdca536aba0451d9252e4159ff4342bef982e937b7b4344
xvs-timestamp: 1444701454468
x-forwarded-for: 54.223.239.231
x-forwarded-port: 80
x-forwarded-proto: http
Content-Length: 243
connection: keep-alive
user-agent: ZhiboYun Cloud WoAn Ltd.
Host: 115.28.33.49:8000

type=9&hashed_id=aws-cn_north_1-5-a6eaff8eeef36a3b&vs_id=aws-cn_north_1-5&service_code=TESTING
&path=TESTING/20151013/01/57/flv/&file_name=aws-cn_north_1-5-a6eaff8eeef36a3b.flv.1.jpg
&width=480&height=800&opaque=testing opaque string&live_only=0
&url=http://s3.cn-north-1.amazonaws.com.cn/xvs/pub/TESTING/20151013/01/57/flv/aws-cn_north_1-5-a6eaff8eeef36a3b.flv.jpg

type=8, username, service_codesession_duration, disconnect_reason

POST /notify HTTP/1.1
accept: */*
xvs-signature: d4cd5c2d3332a9918d67c2138b0604edaed04d2a57c8f266d22394c2908672a2
xvs-timestamp: 1444699618716
Content-Length: 92
content-type: application/x-www-form-urlencoded
user-agent: ZhiboYun Cloud WoAn Ltd.
Host: localhost:8000
Connection: close

type=8&username=001&service_code=TESTING&session_duration=16&disconnect_reason=1&vs_id=Venus

type=15, username, service_codehashed_id, status

字段status在直播恢复回调中的含义:

status = 0 表示发现客户端异常断线,等待重连。 status = 1 表示客户端重连成功,直播恢复成功。

以下为各种通知类型中涉及到的所有字段的解释,以供参考。

发起直播的用户名

直播开始的unix时间戳|所谓的unix时间戳是指从1970-1-1 0:0:0开始的一个相对值,以秒为单位

客户端类型,以数字表示的直播采集客户端的类型。此字段只有在使用移动端SDK才有意义

客户端版本号。此字段只有在使用移动端SDK才有意义

视频时长

文件名, 点播通知为点播文件名,在切片通知中为此次切片文件名

视频格式描述,形式如 容器格式/视频编码格式/音频编码格式|例如: flv/libx264/libvo_aacenc

直播任务的唯一ID号

通过直播输出的字节数, 仅当输出格式为flv时有效,其他格式此值为0。

此次直播输入的字节数,

是否为续传。1:续传 0: 非续传

是否是仅直播,仅直播的视频最后不会被存档

通过直播云透传的业务文本数据。

一个直播输入可以生成多个输出格式,此字段标明当前通知所属输出格式的序号

视频保存的相对路径

是否是私有视频 此字段为了兼容老版本使用,在直播云中建议不要再使用

0或非0,在结束通知中标明此次停止是用户停止的还是异常停止的, reach_end=1表明是用户停止拍摄,=0表示异常原因引起服务器停止

m3u8切片序号,从0开始,仅在m3u8切片通知中使用,在直播云中不要使用此字段。

服务码

视频画面的大小 格式: 长x宽, 例如800x600

时移的播放地址, 时移播放地址和直播播放地址的比例,时移地址和直播地址一样在直播进行中未存档时就可以播放,区别在于,直播地址每次请求播放时总是从最新处播放,而时移地址总是从头开始播放。 并且只有flv输出格式才有时移地址。

播放地址, 在直播通知中为直播地址,在点播通知中为点播地址, 在缩略图通知中为缩略图的下载地址。

输出格式标签

通知类型

通过Xvs/云透传的业务数据

用户名,同author含义一样

用户在线时长,注意不是录制时长,用户在一个连续的网络连接中可能一个视频也不直播,也可能直播几段视频。此字段只有在使用移动端SDK才有意义

此字段只有在使用移动端SDK才有意义 断线原因:

  • disconnect_reason=0 网络超时
  • disconnect_reason=1 服务器读错误,一般为到客户端主动断开连接
  • disconnect_reason=2|协议错误,服务器主动断开连接
  • 字段status在直播恢复回调(type=15)中的含义:

    • status = 0 表示发现客户端异常断线,等待重连。
    • status = 1 表示客户端重连成功,直播恢复成功。