15976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org/*
25976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * libjingle
35976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * Copyright 2004--2010, Google Inc.
45976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *
55976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * Redistribution and use in source and binary forms, with or without
65976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * modification, are permitted provided that the following conditions are met:
75976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *
85976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *  1. Redistributions of source code must retain the above copyright notice,
95976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     this list of conditions and the following disclaimer.
105976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *  2. Redistributions in binary form must reproduce the above copyright notice,
115976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     this list of conditions and the following disclaimer in the documentation
125976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     and/or other materials provided with the distribution.
135976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *  3. The name of the author may not be used to endorse or promote products
145976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *     derived from this software without specific prior written permission.
155976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org *
165976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
175976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
185976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
195976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
205976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
215976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
225976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
235976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
245976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
255976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
265976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org */
275976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
285976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#ifndef TALK_SOUND_SOUNDOUTPUTSTREAMINTERFACE_H_
295976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#define TALK_SOUND_SOUNDOUTPUTSTREAMINTERFACE_H_
305976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
315976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/base/constructormagic.h"
325976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#include "talk/base/sigslot.h"
335976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
345976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgnamespace cricket {
355976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
365976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Interface for outputting a stream to a playback device.
375976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// Semantics and thread-safety of EnableBufferMonitoring()/
385976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org// DisableBufferMonitoring() are the same as for talk_base::Worker.
395976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.orgclass SoundOutputStreamInterface {
405976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org public:
415976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual ~SoundOutputStreamInterface() {}
425976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
435976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // Enables monitoring the available buffer space on the current thread.
445976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool EnableBufferMonitoring() = 0;
455976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // Disables the monitoring.
465976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool DisableBufferMonitoring() = 0;
475976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
485976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // Write the given samples to the devices. If currently monitoring then this
495976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // may only be called from the monitoring thread.
505976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool WriteSamples(const void *sample_data,
515976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org                            size_t size) = 0;
525976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
535976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // Retrieves the current output volume for this stream. Nominal range is
545976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // defined by SoundSystemInterface::k(Max|Min)Volume, but values exceeding the
555976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // max may be possible in some implementations. This call retrieves the actual
565976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // volume currently in use by the OS, not a cached value from a previous
575976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // (Get|Set)Volume() call.
585976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool GetVolume(int *volume) = 0;
595976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
605976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // Changes the output volume for this stream. Nominal range is defined by
615976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // SoundSystemInterface::k(Max|Min)Volume. The effect of exceeding kMaxVolume
625976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // is implementation-defined.
635976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool SetVolume(int volume) = 0;
645976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
655976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // Closes this stream object. If currently monitoring then this may only be
665976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // called from the monitoring thread.
675976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual bool Close() = 0;
685976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
695976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // Get the latency of the stream.
705976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  virtual int LatencyUsecs() = 0;
715976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
725976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // Notifies the producer of the available buffer space for writes.
735976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // It fires continuously as long as the space is greater than zero.
745976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // The first parameter is the amount of buffer space available for data to
755976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // be written (i.e., the maximum amount of data that can be written right now
765976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // with WriteSamples() without blocking).
775976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  // The 2nd parameter is the stream that is issuing the callback.
785976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  sigslot::signal2<size_t, SoundOutputStreamInterface *> SignalBufferSpace;
795976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
805976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org protected:
815976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  SoundOutputStreamInterface() {}
825976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
835976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org private:
845976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org  DISALLOW_COPY_AND_ASSIGN(SoundOutputStreamInterface);
855976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org};
865976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
875976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org}  // namespace cricket
885976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org
895976650443d68ccfadf1dea24999ee459dd2819mflodman@webrtc.org#endif  // TALK_SOUND_SOUNDOUTPUTSTREAMINTERFACE_H_
90