github.com/cnotch/ipchub@v1.1.0/av/format/hls/segment.go (about) 1 // Copyright calabashdad. https://github.com/calabashdad/seal.git 2 // 3 // Copyright (c) 2019,CAOHONGJU All rights reserved. 4 // Use of this source code is governed by a MIT-style 5 // license that can be found in the LICENSE file. 6 7 package hls 8 9 // the wrapper of m3u8 segment from specification: 10 // 3.3.2. EXTINF 11 // The EXTINF tag specifies the duration of a media segment. 12 type segment struct { 13 // duration in seconds in m3u8. 14 duration float64 15 // sequence number in m3u8. 16 sequenceNo int 17 // ts uri in m3u8. 18 uri string 19 // ts full file to write. 20 // fullPath string 21 // the file to write ts. 22 file segmentFile 23 // current segment start pts for m3u8 24 segmentStartPts int64 25 // whether current segement is sequence header. 26 isSequenceHeader bool 27 } 28 29 func newSegment(memory bool) *segment { 30 seg := &segment{} 31 if memory { 32 seg.file = newMemorySegmentFile() 33 } else { 34 seg.file = newPersistentSegmentFile() 35 } 36 return seg 37 } 38 39 func (seg *segment) updateDuration(currentFramePts int64) { 40 41 // we use video/audio to update segment duration, 42 // so when reap segment, some previous audio frame will 43 // update the segment duration, which is nagetive, 44 // just ignore it. 45 if currentFramePts < seg.segmentStartPts { 46 return 47 } 48 49 seg.duration = float64(currentFramePts-seg.segmentStartPts) / 90000.0 50 }