 
 eventListeners = {}
 streams = {}
+streamGenerators = {}
 
 api =
   AVStream: AVStream
+  AVStreamGenerator: AVStreamGenerator
 
   emit: (name, data...) ->
     if eventListeners[name]?

  shasum = crypto.createHash 'sha512'
  shasum.update buf
  return shasum.digest('hex')[0..7]

class AVStream
  constructor: (id) ->

    return streams[streamId]?

  get: (streamId) ->
    if streamGenerators[streamId]?
      return streamGenerators[streamId].generate()
    else
      return streams[streamId]

  addGenerator: (streamId, generator) ->
    if streamGenerators[streamId]?
      logger.warn "warning: avstreams.addGenerator(): overwriting generator: #{streamId}"
    streamGenerators[streamId] = generator

  removeGenerator: (streamId) ->
    if streamGenerators[streamId]?
      streamGenerators[streamId].teardown()
    delete streamGenerators[streamId]

  createNewStreamId: ->
    retryCount = 0
