nimsforestsmarttv

package module
v0.0.0-...-9549a31 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: MIT Imports: 17 Imported by: 0

README

nimsforestsmarttv

Go library for discovering and rendering to Smart TVs via DLNA/UPnP.

Installation

go get github.com/nimsforest/nimsforestsmarttv

Usage

As a library
package main

import (
    "context"
    "time"

    smarttv "github.com/nimsforest/nimsforestsmarttv"
)

func main() {
    ctx := context.Background()

    // Discover TVs on the network
    tvs, err := smarttv.Discover(ctx, 5*time.Second)
    if err != nil {
        panic(err)
    }

    if len(tvs) == 0 {
        println("No TVs found")
        return
    }

    // Create a renderer
    renderer, err := smarttv.NewRenderer()
    if err != nil {
        panic(err)
    }
    defer renderer.Close()

    // Display text on the first TV
    err = renderer.DisplayText(ctx, &tvs[0], "Hello World!")
    if err != nil {
        panic(err)
    }

    // Or stream HLS video
    hlsURL := "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8"
    err = renderer.DisplayHLS(ctx, &tvs[0], hlsURL, "My Stream")
    if err != nil {
        panic(err)
    }
}
Interactive CLI
go run ./cmd/smarttv

Commands:

  • Type any text to display it on the TV
  • /discover - Re-scan for TVs
  • /select - Choose a different TV
  • /stop - Stop displaying
  • /quit - Exit

Features

  • Zero external dependencies - Standard library only
  • SSDP discovery - Automatically find Smart TVs on your network
  • DLNA/UPnP transport - Send images and video streams via AVTransport
  • HLS streaming - Stream HLS video directly to your TV
  • Text rendering - Built-in text-to-image for simple messages
  • Thread-safe - Safe for concurrent use

HLS Streaming

The library supports streaming HLS (HTTP Live Streaming) content to your TV. The TV fetches and plays the stream directly.

// Stream HLS to TV
hlsURL := "https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8"
err := renderer.DisplayHLS(ctx, tv, hlsURL, "Big Buck Bunny")

// DisplayVideo is an alias that works the same way
err := renderer.DisplayVideo(ctx, tv, videoURL, "My Video")

Supported formats:

  • HLS streams (.m3u8) - Uses application/x-mpegURL content type
  • MPEG-TS streams - Uses video/mp2t content type
  • Other video URLs - Falls back to video/mp2t

The title parameter is displayed in the TV's UI during playback.

Supported TVs

Tested with:

  • JVC Smart TVs (VIDAA platform)
  • Other DLNA-compatible Smart TVs

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Black = color.RGBA{0, 0, 0, 255}
	White = color.RGBA{255, 255, 255, 255}
)

Predefined colors

Functions

func RenderText

func RenderText(text string, opts TextOptions) image.Image

RenderText renders text to an image using a simple bitmap font Note: This uses a basic pixel font. For better fonts, render your own image.

Types

type ImageServer

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

ImageServer serves images over HTTP for TVs to fetch

func NewImageServer

func NewImageServer() (*ImageServer, error)

NewImageServer creates a new image server on an available port

func (*ImageServer) Close

func (s *ImageServer) Close() error

Close shuts down the image server

func (*ImageServer) Store

func (s *ImageServer) Store(jpegData []byte) string

Store stores an image and returns its URL

func (*ImageServer) StreamURL

func (s *ImageServer) StreamURL() string

StreamURL returns the URL for the streaming endpoint

func (*ImageServer) URL

func (s *ImageServer) URL() string

URL returns the base URL of the image server

func (*ImageServer) UpdateLatestFrame

func (s *ImageServer) UpdateLatestFrame(jpegData []byte)

UpdateLatestFrame updates the latest frame for streaming mode

type Option

type Option func(*Renderer)

Option configures a Renderer

func WithTextOptions

func WithTextOptions(opts TextOptions) Option

WithTextOptions sets the default text rendering options

type Renderer

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

Renderer is the high-level API for displaying content on Smart TVs.

Two display modes are supported:

1. Static Image Mode (for most DLNA TVs like JVC, Samsung, LG):

  • Use DisplayImage() or DisplayImageJPEG() to show a static image
  • Each call triggers a full content switch (brief transition visible)
  • Designed for dashboards, info displays, infrequent updates
  • Image stays displayed until explicitly changed

2. Video Streaming Mode (requires TV video streaming support):

  • Use StreamVideo() to play HLS/video streams
  • TV handles continuous playback internally
  • Not supported by all TVs via DLNA

func NewRenderer

func NewRenderer(opts ...Option) (*Renderer, error)

NewRenderer creates a new Renderer with an embedded image server

func (*Renderer) Close

func (r *Renderer) Close() error

Close shuts down the renderer and its image server

func (*Renderer) Display

func (r *Renderer) Display(ctx context.Context, tv *TV, img image.Image) error

Display is deprecated. Use DisplayImage instead.

func (*Renderer) DisplayHLS

func (r *Renderer) DisplayHLS(ctx context.Context, tv *TV, hlsURL string, title string) error

DisplayHLS is deprecated. Use StreamVideo instead.

func (*Renderer) DisplayImage

func (r *Renderer) DisplayImage(ctx context.Context, tv *TV, img image.Image) error

DisplayImage shows a static image on the TV. The image remains displayed until another DisplayImage call or Stop. Each call triggers a content switch which may cause a brief transition.

Note: Go's standard JPEG encoder may not be compatible with all TVs. If you encounter "file not supported" errors, use DisplayImageJPEG with JPEG data generated by ffmpeg+imagemagick for proper JFIF headers.

func (*Renderer) DisplayImageJPEG

func (r *Renderer) DisplayImageJPEG(ctx context.Context, tv *TV, jpegData []byte) error

DisplayImageJPEG shows a static JPEG image on the TV. Use this when you have pre-encoded JPEG data (e.g., from ffmpeg). The image remains displayed until another call or Stop.

For JVC and similar TVs that require JFIF-compliant JPEGs, generate the JPEG using: ffmpeg -> imagemagick (magick convert)

func (*Renderer) DisplayJPEG

func (r *Renderer) DisplayJPEG(ctx context.Context, tv *TV, jpegData []byte) error

DisplayJPEG is deprecated. Use DisplayImageJPEG instead.

func (*Renderer) DisplayText

func (r *Renderer) DisplayText(ctx context.Context, tv *TV, text string) error

DisplayText renders text as an image and displays it on the TV

func (*Renderer) DisplayTextWithOptions

func (r *Renderer) DisplayTextWithOptions(ctx context.Context, tv *TV, text string, opts TextOptions) error

DisplayTextWithOptions renders text with custom options and displays it

func (*Renderer) DisplayVideo

func (r *Renderer) DisplayVideo(ctx context.Context, tv *TV, videoURL string, title string) error

DisplayVideo is deprecated. Use StreamVideo instead.

func (*Renderer) ServerURL

func (r *Renderer) ServerURL() string

ServerURL returns the URL of the embedded image server

func (*Renderer) Stop

func (r *Renderer) Stop(ctx context.Context, tv *TV) error

Stop stops playback on the TV

func (*Renderer) StreamVideo

func (r *Renderer) StreamVideo(ctx context.Context, tv *TV, videoURL string, title string) error

StreamVideo sends a video stream URL to the TV for continuous playback. Supports HLS (.m3u8), MPEG-TS, and other video formats depending on TV.

Note: Many consumer TVs (including JVC VIDAA) do not support video streaming via DLNA AVTransport. Use Static Image Mode for these TVs.

type TV

type TV struct {
	Name       string // Friendly name (e.g., "TV Salon")
	IP         string // IP address
	Port       int    // UPnP port
	ControlURL string // Full AVTransport control endpoint URL
	BaseURL    string // Base URL for the device
}

TV represents a discovered Smart TV

func Discover

func Discover(ctx context.Context, timeout time.Duration) ([]TV, error)

Discover finds Smart TVs on the local network using SSDP. It returns a list of discovered TVs within the given timeout.

func (*TV) String

func (tv *TV) String() string

String returns a string representation of the TV

type TextOptions

type TextOptions struct {
	FontSize   int         // Character height in pixels (default 100)
	Width      int         // Image width (default 1920)
	Height     int         // Image height (default 1080)
	Color      color.Color // Text color (default white)
	Background color.Color // Background color (default black)
}

TextOptions configures text rendering

Directories

Path Synopsis
cmd
smarttv command

Jump to

Keyboard shortcuts

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