Home | History | Annotate | Download | only in sound
      1 /*
      2  *  Copyright 2004 The WebRTC Project Authors. All rights reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #ifndef WEBRTC_SOUND_SOUNDOUTPUTSTREAMINTERFACE_H_
     12 #define WEBRTC_SOUND_SOUNDOUTPUTSTREAMINTERFACE_H_
     13 
     14 #include "webrtc/base/constructormagic.h"
     15 #include "webrtc/base/sigslot.h"
     16 
     17 namespace rtc {
     18 
     19 // Interface for outputting a stream to a playback device.
     20 // Semantics and thread-safety of EnableBufferMonitoring()/
     21 // DisableBufferMonitoring() are the same as for rtc::Worker.
     22 class SoundOutputStreamInterface {
     23  public:
     24   virtual ~SoundOutputStreamInterface() {}
     25 
     26   // Enables monitoring the available buffer space on the current thread.
     27   virtual bool EnableBufferMonitoring() = 0;
     28   // Disables the monitoring.
     29   virtual bool DisableBufferMonitoring() = 0;
     30 
     31   // Write the given samples to the devices. If currently monitoring then this
     32   // may only be called from the monitoring thread.
     33   virtual bool WriteSamples(const void *sample_data,
     34                             size_t size) = 0;
     35 
     36   // Retrieves the current output volume for this stream. Nominal range is
     37   // defined by SoundSystemInterface::k(Max|Min)Volume, but values exceeding the
     38   // max may be possible in some implementations. This call retrieves the actual
     39   // volume currently in use by the OS, not a cached value from a previous
     40   // (Get|Set)Volume() call.
     41   virtual bool GetVolume(int *volume) = 0;
     42 
     43   // Changes the output volume for this stream. Nominal range is defined by
     44   // SoundSystemInterface::k(Max|Min)Volume. The effect of exceeding kMaxVolume
     45   // is implementation-defined.
     46   virtual bool SetVolume(int volume) = 0;
     47 
     48   // Closes this stream object. If currently monitoring then this may only be
     49   // called from the monitoring thread.
     50   virtual bool Close() = 0;
     51 
     52   // Get the latency of the stream.
     53   virtual int LatencyUsecs() = 0;
     54 
     55   // Notifies the producer of the available buffer space for writes.
     56   // It fires continuously as long as the space is greater than zero.
     57   // The first parameter is the amount of buffer space available for data to
     58   // be written (i.e., the maximum amount of data that can be written right now
     59   // with WriteSamples() without blocking).
     60   // The 2nd parameter is the stream that is issuing the callback.
     61   sigslot::signal2<size_t, SoundOutputStreamInterface *> SignalBufferSpace;
     62 
     63  protected:
     64   SoundOutputStreamInterface() {}
     65 
     66  private:
     67   DISALLOW_COPY_AND_ASSIGN(SoundOutputStreamInterface);
     68 };
     69 
     70 }  // namespace rtc
     71 
     72 #endif  // WEBRTC_SOUND_SOUNDOUTPUTSTREAMINTERFACE_H_
     73