Skip to content

Instantly share code, notes, and snippets.

@why404
Created September 29, 2015 06:37
Show Gist options
  • Save why404/28083751fe174dc5da68 to your computer and use it in GitHub Desktop.
Save why404/28083751fe174dc5da68 to your computer and use it in GitHub Desktop.

Server-Side SDK Interface Specification

Content

Model

[Stream Object] : {
    "id"                : [String],
    "createdAt"         : [String: Time ISO 8601],
    "updatedAt"         : [String: Time ISO 8601],
    "title"             : [String: Length[4-200]],
    "hub"               : [String],
    "publishKey"        : [String],
    "publishSecurity"   : [String: "static" or "dynamic"],
    "disabled"          : [Boolean],
    "profiles"          : [Array: String],
    "hosts": {
        "publish": {
            "rtmp"   : [String: URL]
        },
        "live": {
            "rtmp"   : [String: URL],
            "hls"    : [String: URL],
            "hdl"    : [String: URL]
        },
        "playback": {
            "hls"   : [String: URL]
        }
    }
}

Server-Side SDK

Features

  • Minimize API exposure
  • Maximum language features

Notes

  • All time parameters is in second

Interface

// Replace Dictionary to Struct below in some languages

type Stream struct {
	auth            *Transport // authed transport
	Id              string    `json:"id"`
	CreatedAt       time.Time `json:"createdAt"`
	UpdatedAt       time.Time `json:"updatedAt"`
	Title           string    `json:"title"`
	Hub             string    `json:"hub"`
	Disabled        bool      `json:"disabled"`
	PublishKey      string    `json:"publishKey"`
	PublishSecurity string    `json:"publishSecurity"`
	Profiles        []string  `json:"profiles,omitempty"`
	Hosts           struct {
		Publish  map[string]string `json:"publish,omitempty"`
		Live     map[string]string `json:"live,omitempty"`
		Playback map[string]string `json:"playback,omitempty"`
	} `json:"hosts,omitempty"`
}

type StreamList struct {
	Marker string    `json:"marker"`
	Items  []*Stream `json:"items"`
}

type StreamSegment struct {
	Start int64 `json:"start"`
	End   int64 `json:"end"`
}

type StreamSegmentList struct {
	Segments []*StreamSegment `json:"segments"`
}

type StreamStatus struct {
	Addr            string  `json:"addr"`
	StartFrom       string  `json:startFrom`
	Status          string  `json:"status"`
	BytesPerSecond  float64 `json:"bytesPerSecond"`
	FramesPerSecond struct {
		Audio float64 `json:"audio"`
		video float64 `json:"video"`
		Data  float64 `json:"data"`
	} `json:"framesPerSecond"`
}

type StreamSaveAsResponse struct {
	Url          string `json:"url"`
	TargetUrl    string `json:"targetUrl"`
	PersistentId string `json:"persistentId"`
}

type StreamSnapshotResponse struct {
	TargetUrl    string `json:"targetUrl"`
	PersistentId string `json:"persistentId"`
}
// Set const value
const (
    ORIGIN              = "ORIGIN"
    SDK_VERSION         = "{major}.{feature}.{patch}"
    SDK_USER_AGENT      = "pili-sdk-{language_name}"
    DEFAULT_API_HOST    = "pili.qiniuapi.com"
    DEFAULT_API_VERSION = "v1"
)

// Set global variables
var (
    API_HOST  string
    USE_HTTPS bool
)

// Instantiate a Pili Hub object
credentials = new Credentials(QINIU_ACCESS_KEY, QINIU_SECRET_KEY)     => Credentials Object
hub = new Pili.Hub(credentials, PILI_HUB_NAME)                        => Hub Object

// Stream Create,Get,List
hub.CreateStream(options = {title, publishKey, publishSecrity})       => Stream Object
hub.GetStream(streamId)                                               => Stream Object
hub.ListStreams(options = {marker, limit, title})                     => Struct StreamList // or Dictionary

// Instantiate a Pili Stream object
auth = new Transport($credentials);                                    => Transport Object
stream = new Pili.Stream(&auth, streamJsonOrDictionary)                => Stream Object

// Stream operations else
stream.ToJSONString()                                                 => String "{...}"
stream.Update(options = {publishKey, publishSecrity, disabled})       => Stream Object
stream.Disable()                                                      => Stream Object
stream.Enable()                                                       => Stream Object
stream.Status()                                                       => Struct StreamStatus  // or Dictionary
stream.RtmpPublishUrl()                                               => String "rtmp://host/hub/title?args"
stream.RtmpLiveUrls()                                                 => Dictionary {ORIGIN, profile1, ...}
stream.HttpFlvLiveUrls()                                              => Dictionary {ORIGIN, profile1, ...}
stream.HlsLiveUrls()                                                  => Dictionary {ORIGIN, profile1, ...}
stream.Segments(options = {start, end, limit})                        => Array [Struct StreamSegment, ...]
stream.HlsPlaybackUrls(start, end)                                    => Dictionary {ORIGIN, profile1, ...}
stream.SaveAs(name, format, start, end, options = {notifyUrl})        => Struct SaveAsResponse   // or Dictionary
stream.Snapshot(name, format, options = {time, notifyUrl})            => Struct SnapshotResponse // or Dictionary
stream.Delete()                                                       => NULL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment