Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate adaptationfield #111

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
3 changes: 1 addition & 2 deletions cli/parsefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (

"github.com/Comcast/gots/ebp"
"github.com/Comcast/gots/packet"
"github.com/Comcast/gots/packet/adaptationfield"
"github.com/Comcast/gots/psi"
"github.com/Comcast/gots/scte35"
)
Expand Down Expand Up @@ -138,7 +137,7 @@ func main() {

}
if *showEbp {
ebpBytes, err := adaptationfield.EncoderBoundaryPoint(&pkt)
ebpBytes, err := packet.EncoderBoundaryPointBytes(&pkt)
if err != nil {
// Not an EBP
continue
Expand Down
3 changes: 2 additions & 1 deletion ebp/ebp.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ package ebp

import (
"encoding/binary"
"github.com/Comcast/gots"
"io"
"time"

"github.com/Comcast/gots"
)

// EBP tags
Expand Down
31 changes: 27 additions & 4 deletions packet/adaptationfield.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/Comcast/gots"
)

// NewPacket creates a new packet with a Null ID, sync byte, and with the adaptation field control set to payload only.
// NewAdaptationField creates a new *AdaptationField with the flag set for AdaptationField and no payload
// This function is error free.
func NewAdaptationField() *AdaptationField {
p := New()
Expand Down Expand Up @@ -305,8 +305,7 @@ func (af *AdaptationField) ElementaryStreamPriority() (bool, error) {
return af.getBit(5, 0x20), nil
}

// SetHasPCR sets HasPCR
// HasPCR determines if the packet has a PCR
// SetHasPCR sets HasPCR flag
func (af *AdaptationField) SetHasPCR(value bool) error {
if err := af.valid(); err != nil {
return err
Expand All @@ -320,7 +319,7 @@ func (af *AdaptationField) SetHasPCR(value bool) error {
return nil
}

// HasPCR returns if the packet has a PCR
// HasPCR returns true if the packet has a PCR
func (af *AdaptationField) HasPCR() (bool, error) {
if err := af.valid(); err != nil {
return false, err
Expand Down Expand Up @@ -564,3 +563,27 @@ func (af *AdaptationField) AdaptationFieldExtension() ([]byte, error) {
}
return af[af.adaptationExtensionStart():af.stuffingStart()], nil
}

// EncoderBoundaryPointBytes returns the byte array located in the optional TransportPrivateData of the (also optional)
// AdaptationField of the Packet. If either of these optional fields are missing an empty byte array is returned with an error
func EncoderBoundaryPointBytes(packet *Packet) ([]byte, error) {

af, err := packet.AdaptationField()
if err != nil {
return nil, err
}

hasTransPriv, err := af.HasTransportPrivateData()
if err != nil {
return nil, err
}

if af.Length() > 0 && hasTransPriv {
ebp, err := af.TransportPrivateData()
if err != nil {
return nil, err
}
return ebp, nil
}
return nil, gots.ErrNoEBP
}
136 changes: 0 additions & 136 deletions packet/adaptationfield/adaptationfield.go

This file was deleted.

26 changes: 0 additions & 26 deletions packet/adaptationfield/doc.go

This file was deleted.

4 changes: 2 additions & 2 deletions packet/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ const (
type AdaptationFieldControlOptions byte

const (
PayloadFlag AdaptationFieldControlOptions = 1 // 10
AdaptationFieldFlag AdaptationFieldControlOptions = 2 // 01
PayloadFlag AdaptationFieldControlOptions = 1 // 01
AdaptationFieldFlag AdaptationFieldControlOptions = 2 // 10
PayloadAndAdaptationFieldFlag AdaptationFieldControlOptions = 3 // 11
)

Expand Down
8 changes: 5 additions & 3 deletions packet/packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ SOFTWARE.

package packet

import "github.com/Comcast/gots"
import (
"github.com/Comcast/gots"
)

// PayloadUnitStartIndicator (PUSI) is a flag that indicates the start of PES data
// or PSI (Program-Specific Information) such as AT, CAT, PMT or NIT. The PUSI
Expand All @@ -36,7 +38,7 @@ func payloadUnitStartIndicator(packet *Packet) bool {
return packet[1]&0x040 != 0
}

// PID is the Packet Identifier. Each table or elementary stream in the
// Pid is the Packet Identifier. Each table or elementary stream in the
// transport stream is identified by a PID. The PID is contained in the 13
// bits that span the last 5 bits of second byte and all bits in the byte.
func Pid(packet *Packet) (uint16, error) {
Expand Down Expand Up @@ -148,7 +150,7 @@ func SetCC(packet *Packet, newCC uint8) (*Packet, error) {
return &newPacket, nil
}

// Returns a byte slice containing the PES header if the Packet contains one,
// PESHeader Returns a byte slice containing the PES header if the Packet contains one,
// otherwise returns an error
func PESHeader(packet *Packet) ([]byte, error) {
if containsPayload(packet) && payloadUnitStartIndicator(packet) {
Expand Down