player

package
v0.11.10 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2020 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ChunkSize is a size of decrypted blob.
	ChunkSize = stream.MaxBlobSize - 1

	// DefaultPrefetchLen is how many blobs we should prefetch ahead.
	// 3 should be enough to deliver 2 x 4 = 8MB/s streams.
	DefaultPrefetchLen = 3

	// RetrieverSourceL2Cache is for labeling cache speed sourced from level 2 chunk cache (LFU)
	RetrieverSourceL2Cache = "l2_cache"

	// RetrieverSourceReflector is for labeling cache speed sourced from reflector
	RetrieverSourceReflector = "reflector"
)
View Source
const ParamDownload = "download"

Variables

View Source
var CacheLogger = localLogger{monitor.NewModuleLogger("player_cache")}

CacheLogger is for caching operations only.

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

Logger is a package-wide logger. Warning: will generate a lot of output if DEBUG loglevel is enabled. Logger variables here are made public so logging can be disabled on the spot when needed (in tests etc).

View Source
var RetLogger = localLogger{monitor.NewModuleLogger("player_retriever")}

RetLogger is for blob/chunk retrieval operations logging.

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 GetBlobStore added in v0.11.0

func GetBlobStore() *peer.Store

GetBlobStore returns default pre-configured blob store.

func InstallRoutes added in v0.11.0

func InstallRoutes(r *mux.Router)

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 ChunkCache added in v0.11.1

type ChunkCache interface {
	Has(string) bool
	Get(string) (ReadableChunk, bool)
	Set(string, []byte) (ReadableChunk, error)
	Remove(string)
	Size() uint64
}

ChunkCache can save and retrieve readable chunks.

func InitFSCache added in v0.11.1

func InitFSCache(opts *FSCacheOpts) (ChunkCache, error)

InitFSCache initializes disk cache for chunks. All chunk-sized files inside `dir` will be removed on initialization, if `dir` does not exist, it will be created. In other words, os.TempDir() should not be passed as a `dir`.

type ChunkCalculator added in v0.11.1

type ChunkCalculator struct {
	Offset           int64
	ReadLen          int
	FirstChunkIdx    int
	LastChunkIdx     int
	FirstChunkOffset int
	LastChunkReadLen int
	LastChunkOffset  int
}

ChunkCalculator provides handy blob calculations for a requested stream range.

func NewChunkCalculator added in v0.11.1

func NewChunkCalculator(size, offset int64, readLen int) ChunkCalculator

NewChunkCalculator initializes ChunkCalculator with provided stream size, start offset and reader buffer length.

func (ChunkCalculator) String added in v0.11.1

func (c ChunkCalculator) String() string

type FSCacheOpts added in v0.11.1

type FSCacheOpts struct {
	Path          string
	Size          int64
	SweepInterval time.Duration
}

FSCacheOpts contains options for filesystem cache. Size is max size in bytes

type Opts added in v0.11.1

type Opts struct {
	Lbrynet          *ljsonrpc.Client
	EnableLocalCache bool
	EnablePrefetch   bool
}

Opts are options to be set for Player instance.

type Player added in v0.7.0

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

Player is an entry-point object to the new player package.

func NewPlayer added in v0.11.0

func NewPlayer(opts *Opts) *Player

NewPlayer initializes an instance with optional BlobStore.

func (*Player) Play added in v0.11.0

func (p *Player) Play(s *Stream, w http.ResponseWriter, r *http.Request) error

Play delivers requested URI onto the supplied http.ResponseWriter.

func (*Player) ResolveStream added in v0.11.0

func (p *Player) ResolveStream(uri string) (*Stream, error)

ResolveStream resolves provided URI by calling the SDK.

func (*Player) RetrieveStream added in v0.11.0

func (p *Player) RetrieveStream(s *Stream) error

RetrieveStream downloads stream description from the reflector and tries to determine stream size using several methods, including legacy ones for streams that do not have metadata.

type ReadableChunk added in v0.11.1

type ReadableChunk interface {
	Read(offset, n int, dest []byte) (int, error)
	Size() int
}

ReadableChunk interface describes generic chunk object that Stream can Read() from.

type RequestHandler added in v0.11.0

type RequestHandler struct {
	// contains filtered or unexported fields
}

RequestHandler is a HTTP request handler for player package.

func NewRequestHandler added in v0.11.0

func NewRequestHandler(p *Player) *RequestHandler

NewRequestHandler initializes a HTTP request handler with the provided Player instance.

func (*RequestHandler) Handle added in v0.11.0

func (h *RequestHandler) Handle(w http.ResponseWriter, r *http.Request)

Handle is responsible for all HTTP media delivery via player module.

func (*RequestHandler) HandleHead added in v0.11.1

func (h *RequestHandler) HandleHead(w http.ResponseWriter, r *http.Request)

HandleHead handlers OPTIONS requests for media.

type Stream added in v0.11.0

type Stream struct {
	URI  string
	Hash string

	Size        int64
	ContentType string
	Claim       *ljsonrpc.Claim
	// contains filtered or unexported fields
}

Stream provides an io.ReadSeeker interface to a stream of blobs to be used by standard http library for range requests, as well as some stream metadata.

func (*Stream) Read added in v0.11.0

func (s *Stream) Read(dest []byte) (n int, err error)

Read implements io.ReadSeeker interface and is meant to be called by http.ServeContent. Actual chunk retrieval and delivery happens in s.readFromChunks().

func (*Stream) Seek added in v0.11.0

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

Seek implements io.ReadSeeker interface and is meant to be called by http.ServeContent.

func (*Stream) Timestamp added in v0.11.0

func (s *Stream) Timestamp() time.Time

Timestamp returns stream creation timestamp, used in HTTP response header.

Jump to

Keyboard shortcuts

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