All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scodec.protocols.mpeg.transport.TransportStreamHeader.scala Maven / Gradle / Ivy

The newest version!
package scodec.protocols.mpeg
package transport

import scodec.Codec
import scodec.codecs._

case class TransportStreamHeader(
  transportErrorIndicator: Boolean,
  payloadUnitStartIndicator: Boolean,
  transportPriority: Boolean,
  pid: Pid,
  scramblingControl: Int,
  adaptationFieldControl: Int,
  continuityCounter: ContinuityCounter
) {
  def adaptationFieldIncluded: Boolean = adaptationFieldControl >= 2
  def payloadIncluded: Boolean = adaptationFieldControl == 1 || adaptationFieldControl == 3
}

object TransportStreamHeader {
  implicit val codec: Codec[TransportStreamHeader] = "transport_stream_header" | fixedSizeBytes(4,
    ("syncByte"                  | constant(0x47)          ) :~>:
    ("transportErrorIndicator"   | bool                    ) ::
    ("payloadUnitStartIndicator" | bool                    ) ::
    ("transportPriority"         | bool                    ) ::
    ("pid"                       | Codec[Pid]              ) ::
    ("scramblingControl"         | uint2                   ) ::
    ("adaptationFieldControl"    | uint2                   ) ::
    ("continuityCounter"         | Codec[ContinuityCounter])
  ).as[TransportStreamHeader]
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy