<commit_before>'use strict'

const gstreamer = require('gstreamer-superficial')

module.exports = class PNGEncoder {
  /**
   * @return {module.PNGEncoder}
   */
  static create (width, height, gstBufferFormat) {
    const pipeline = new gstreamer.Pipeline(
      `appsrc name=source caps=video/x-raw,format=${gstBufferFormat},width=${width},height=${height},framerate=0/1 ! ` +
      `videoconvert ! videoscale  ! capsfilter name=scale caps=video/x-raw,format=RGBA,width=${width},height=${height},framerate=0/1 !` +
      'pngenc !' +
      'appsink name=sink'
    )
    const sink = pipeline.findChild('sink')
    const src = pipeline.findChild('source')
    const scale = pipeline.findChild('scale')
    pipeline.pollBus((event) => {
      switch (event.type) {
        case 'error':
          console.error(event)
          break
        case 'warning':
          console.warn(event)
          break
      }
    })
    pipeline.play()

    return new PNGEncoder(pipeline, sink, src, scale, width, height, gstBufferFormat)
  }

  constructor (pipeline, sink, src, scale, width, height, gstBufferFormat) {
    this.pipeline = pipeline
    this.sink = sink
    this.src = src
    this.scale = scale
    this.width = width
    this.height = height
    this.format = gstBufferFormat
  }

  /**
   * @param {number}width
   * @param {number}height
   * @param {string}gstBufferFormat
   */
  configure (width, height, gstBufferFormat) {
    // source caps describe what goes in<commit_msg>don't poll for gst pipeline events, the bindings implementation is bugged...<commit_after>'use strict'

const gstreamer = require('gstreamer-superficial')

module.exports = class PNGEncoder {
  /**
   * @return {module.PNGEncoder}
   */
  static create (width, height, gstBufferFormat) {
    const pipeline = new gstreamer.Pipeline(
      `appsrc name=source caps=video/x-raw,format=${gstBufferFormat},width=${width},height=${height},framerate=0/1 ! ` +
      `videoconvert ! videoscale  ! capsfilter name=scale caps=video/x-raw,format=RGBA,width=${width},height=${height},framerate=0/1 !` +
      'pngenc !' +
      'appsink name=sink'
    )
    const sink = pipeline.findChild('sink')
    const src = pipeline.findChild('source')
    const scale = pipeline.findChild('scale')
    pipeline.play()

    return new PNGEncoder(pipeline, sink, src, scale, width, height, gstBufferFormat)
  }

  constructor (pipeline, sink, src, scale, width, height, gstBufferFormat) {
    this.pipeline = pipeline
    this.sink = sink
    this.src = src
    this.scale = scale
    this.width = width
    this.height = height
    this.format = gstBufferFormat
  }

  /**
   * @param {number}width
   * @param {number}height
   * @param {string}gstBufferFormat
   */
  configure (width, height, gstBufferFormat) {
    // source caps describe what goes in
{'fraction_non_alphanumeric': 0.13080467919177596, 'fraction_numerical': 0.002835873803615739, 'mean_word_length': 3.301829268292683, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2607627', 'n_tokens_mistral': 890, 'n_tokens_neox': 886, 'n_words': 194}