player

package
v0.10.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2019 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger = monitor.NewModuleLogger("player")

Logger is a package-wide logger. Warning: will generate a lot of output if DEBUG loglevel is enabled.

Functions

func CopyN

func CopyN(dst io.Writer, src io.Reader, n int64) (written int64, err error)

CopyN copies n bytes (or until an error) from src to dst. It returns the number of bytes copied and the earliest error encountered while copying. On return, written == n if and only if err == nil.

If dst implements the ReaderFrom interface, the copy is implemented using it.

func Error

func Error(w http.ResponseWriter, error string, code int)

Error replies to the request with the specified error message and HTTP code. It does not otherwise end the request; the caller should ensure no further writes are done to w. The error message should be plain text.

func PlayURI

func PlayURI(uri string, w http.ResponseWriter, req *http.Request) error

PlayURI downloads and streams LBRY video content located at uri and delimited by rangeHeader (use rangeHeader := request.Header.Get("Range")). Streaming works like this: 1. Resolve stream hash through lbrynet daemon (see resolve) 2. Retrieve stream details (list of blob hashes and lengths, etc) by the SD hash from the reflector (see fetchData) 3. Implement io.ReadSeeker interface for http.ServeContent: - Seek simply implements io.Seeker - Read calculates boundaries and finds blobs that contain the requested stream range, then calls streamBlobs, which sequentially downloads and decrypts requested blobs

func ServeContent

func ServeContent(w http.ResponseWriter, req *http.Request, name string, modtime time.Time, content io.ReadSeeker)

ServeContent replies to the request using the content in the provided ReadSeeker. The main benefit of ServeContent over io.Copy is that it handles Range requests properly, sets the MIME type, and handles If-Match, If-Unmodified-Since, If-None-Match, If-Modified-Since, and If-Range requests.

If the response's Content-Type header is not set, ServeContent first tries to deduce the type from name's file extension and, if that fails, falls back to reading the first block of the content and passing it to DetectContentType. The name is otherwise unused; in particular it can be empty and is never sent in the response.

If modtime is not the zero time or Unix epoch, ServeContent includes it in a Last-Modified header in the response. If the request includes an If-Modified-Since header, ServeContent uses modtime to decide whether the content needs to be sent at all.

The content's Seek method must work: ServeContent uses a seek to the end of the content to determine its size.

If the caller has set w's ETag header formatted per RFC 7232, section 2.3, ServeContent uses it to handle requests using If-Match, If-None-Match, or If-Range.

Note that *os.File implements the io.ReadSeeker interface.

Types

type Metrics added in v0.7.0

type Metrics struct {
	ServingStreamsCount int
}

type Player added in v0.7.0

type Player struct {
	URI string
	// contains filtered or unexported fields
}

func (*Player) Read added in v0.7.0

func (s *Player) Read(p []byte) (n int, err error)

Read implements io.ReadSeeker interface

func (*Player) Seek added in v0.7.0

func (s *Player) Seek(offset int64, whence int) (int64, error)

Seek implements io.ReadSeeker interface

func (*Player) URL added in v0.7.0

func (s *Player) URL() string

type PlayerService added in v0.7.0

type PlayerService struct {
	Metrics *Metrics
}

func (*PlayerService) NewPlayer added in v0.7.0

func (ps *PlayerService) NewPlayer(uri string) *Player

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL