streaming

Media streaming and broadcast systems in Go
Log | Files | Refs | README | LICENSE

codec_test.go (1935B)


      1 package scte35_test
      2 
      3 import (
      4 	"encoding/base64"
      5 	"fmt"
      6 
      7 	"github.com/untangledco/streaming/scte35"
      8 )
      9 
     10 func Example() {
     11 	msg := "/DA0AAAAAAAA///wBQb+cr0AUAAeAhxDVUVJSAAAjn/PAAGlmbAICAAAAAAsoKGKNAIAmsnRfg=="
     12 	b, err := base64.StdEncoding.DecodeString(msg)
     13 	if err != nil {
     14 		// handle error...
     15 	}
     16 	splice, err := scte35.Decode(b)
     17 	if err != nil {
     18 		// handle error...
     19 	}
     20 
     21 	dur := splice.Descriptors[0].(scte35.SegmentationDescriptor).Duration
     22 	fmt.Println(*dur)
     23 	*dur += 15 * 90000 // add 15 seconds as per 90KHz clock.
     24 	fmt.Println(*splice.Descriptors[0].(scte35.SegmentationDescriptor).Duration)
     25 
     26 	bb, err := scte35.Encode(splice)
     27 	if err != nil {
     28 		// handle error...
     29 	}
     30 	fmt.Println(base64.StdEncoding.EncodeToString(bb))
     31 
     32 	// Output: 27630000
     33 	// 28980000
     34 	// /DA0AAAAAAAA///wBQb+cr0AUAAeAhxDVUVJSAAAjn/PAAG6MyAICAAAAAAsoKGKNAIAQO/SuQ==
     35 }
     36 
     37 func ExampleEncode() {
     38 	when := uint64(12 * 60 * 60 * 90000) // 12 hours since midnight UTC as 90KHz ticks
     39 	duration := uint64(60 * 90000)       // 60 seconds as 90KHz ticks
     40 	splice := scte35.Splice{
     41 		SAPType: scte35.SAPNone,
     42 		Command: &scte35.Command{
     43 			Type:       scte35.TimeSignal,
     44 			TimeSignal: &when,
     45 		},
     46 		Descriptors: []scte35.SpliceDescriptor{
     47 			scte35.SegmentationDescriptor{
     48 				EventID:      1234,
     49 				Restrictions: scte35.NoRegionalBlackout | scte35.ArchiveAllowed | scte35.DeviceRestrictionsNone,
     50 				Duration:     &duration,
     51 				UPID: scte35.UPID{
     52 					Type:  scte35.UPIDTI,
     53 					Value: []byte{0x00, 0x00, 0x00, 0x00, 0x2c, 0xa0, 0xa1, 0x8a},
     54 				},
     55 				Type:     scte35.ProviderPlacementOppStart,
     56 				Number:   2,
     57 				Expected: 0,
     58 			},
     59 		},
     60 	}
     61 	b, err := scte35.Encode(&splice)
     62 	if err != nil {
     63 		// handle error...
     64 	}
     65 	// SCTE 35 time_signal() commands can be inserted into HLS playlists using the
     66 	// EXT-X-DATERANGE tag. See "Mapping SCTE-35 into EXT-X-DATERANGE"
     67 	// RFC 8216 section 4.3.2.7.1.
     68 	fmt.Printf("#EXT-X-DATERANGE:ID=\"example\",SCTE35-CMD=%#x\n", b)
     69 }