setTimestamp_(buffer, timestampMetadata, position) {
    // Wikipedia: "If only PTS is present, this is done by catenating 0010 ...
    // If both PTS and DTS are present, first 4 bits are 0011 and first 4 bits
    // for DTS are 0001."
    const ptsHeader = timestampMetadata.dts == null ? 0b0010 : 0b0011;
    const dtsHeader = 0b0001;

    const segmentTime = this.segmentDuration_ * position;

    if (timestampMetadata.pts != null) {
      const pts = timestampMetadata.pts - this.timestampOffset_ + segmentTime;
      this.writeTimestamp_(
          buffer, timestampMetadata.offset, ptsHeader, this.overflow_(pts));
    }
    if (timestampMetadata.dts != null) {
      const dts = timestampMetadata.dts - this.timestampOffset_ + segmentTime;
      this.writeTimestamp_(
          buffer, timestampMetadata.offset + 5, dtsHeader, this.overflow_(dts));
    }
  }
@param {!Uint8Array} buffer
@param {{offset: number, pts: ?number, dts: ?number}} timestampMetadata
@param {number} position
@private