Move webrtc/audio_*.h to webrtc/api/call

BUG=webrtc:5878
NOTRY=True

Review-Url: https://codereview.webrtc.org/2059703002
Cr-Commit-Position: refs/heads/master@{#13996}
diff --git a/webrtc/api/BUILD.gn b/webrtc/api/BUILD.gn
index f09c4e4..d14fe1f 100644
--- a/webrtc/api/BUILD.gn
+++ b/webrtc/api/BUILD.gn
@@ -19,6 +19,25 @@
   ]
 }
 
+source_set("call_api") {
+  sources = [
+    "call/audio_receive_stream.h",
+    "call/audio_send_stream.h",
+    "call/audio_sink.h",
+    "call/audio_state.h",
+  ]
+
+  configs += [ "..:common_config" ]
+  public_configs = [ "..:common_inherited_config" ]
+
+  deps = [
+    # TODO(kjellander): Add remaining dependencies when webrtc:4243 is done.
+    "..:webrtc_common",
+    "../base:rtc_base_approved",
+    "../modules/audio_coding:audio_encoder_interface",
+  ]
+}
+
 config("libjingle_peerconnection_warnings_config") {
   # GN orders flags on a target before flags from configs. The default config
   # adds these flags so to cancel them out they need to come from a config and
@@ -113,6 +132,7 @@
   }
 
   deps = [
+    ":call_api",
     "../call",
     "../media",
     "../pc",
diff --git a/webrtc/api/api.gyp b/webrtc/api/api.gyp
index 274b87c..5b14fdf 100644
--- a/webrtc/api/api.gyp
+++ b/webrtc/api/api.gyp
@@ -95,9 +95,26 @@
   ],  # conditions
   'targets': [
     {
+      'target_name': 'call_api',
+      'type': 'static_library',
+      'dependencies': [
+        # TODO(kjellander): Add remaining dependencies when webrtc:4243 is done.
+        '<(webrtc_root)/base/base.gyp:rtc_base_approved',
+        '<(webrtc_root)/common.gyp:webrtc_common',
+        '<(webrtc_root)/modules/modules.gyp:audio_encoder_interface',
+      ],
+      'sources': [
+        'call/audio_receive_stream.h',
+        'call/audio_send_stream.h',
+        'call/audio_sink.h',
+        'call/audio_state.h',
+      ],
+    },
+    {
       'target_name': 'libjingle_peerconnection',
       'type': 'static_library',
       'dependencies': [
+        ':call_api',
         '<(webrtc_root)/media/media.gyp:rtc_media',
         '<(webrtc_root)/pc/pc.gyp:rtc_pc',
       ],
diff --git a/webrtc/api/call/DEPS b/webrtc/api/call/DEPS
new file mode 100644
index 0000000..d1d4309
--- /dev/null
+++ b/webrtc/api/call/DEPS
@@ -0,0 +1,4 @@
+include_rules = [
+  "+webrtc/modules/audio_coding/codecs",
+]
+
diff --git a/webrtc/api/call/audio_receive_stream.h b/webrtc/api/call/audio_receive_stream.h
new file mode 100644
index 0000000..096cbc7
--- /dev/null
+++ b/webrtc/api/call/audio_receive_stream.h
@@ -0,0 +1,139 @@
+/*
+ *  Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_API_CALL_AUDIO_RECEIVE_STREAM_H_
+#define WEBRTC_API_CALL_AUDIO_RECEIVE_STREAM_H_
+
+#include <map>
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "webrtc/base/scoped_ref_ptr.h"
+#include "webrtc/modules/audio_coding/codecs/audio_decoder_factory.h"
+#include "webrtc/common_types.h"
+#include "webrtc/config.h"
+#include "webrtc/transport.h"
+#include "webrtc/typedefs.h"
+
+namespace webrtc {
+class AudioSinkInterface;
+
+// WORK IN PROGRESS
+// This class is under development and is not yet intended for for use outside
+// of WebRtc/Libjingle. Please use the VoiceEngine API instead.
+// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4690
+
+class AudioReceiveStream {
+ public:
+  struct Stats {
+    uint32_t remote_ssrc = 0;
+    int64_t bytes_rcvd = 0;
+    uint32_t packets_rcvd = 0;
+    uint32_t packets_lost = 0;
+    float fraction_lost = 0.0f;
+    std::string codec_name;
+    uint32_t ext_seqnum = 0;
+    uint32_t jitter_ms = 0;
+    uint32_t jitter_buffer_ms = 0;
+    uint32_t jitter_buffer_preferred_ms = 0;
+    uint32_t delay_estimate_ms = 0;
+    int32_t audio_level = -1;
+    float expand_rate = 0.0f;
+    float speech_expand_rate = 0.0f;
+    float secondary_decoded_rate = 0.0f;
+    float accelerate_rate = 0.0f;
+    float preemptive_expand_rate = 0.0f;
+    int32_t decoding_calls_to_silence_generator = 0;
+    int32_t decoding_calls_to_neteq = 0;
+    int32_t decoding_normal = 0;
+    int32_t decoding_plc = 0;
+    int32_t decoding_cng = 0;
+    int32_t decoding_plc_cng = 0;
+    int64_t capture_start_ntp_time_ms = 0;
+  };
+
+  struct Config {
+    std::string ToString() const;
+
+    // Receive-stream specific RTP settings.
+    struct Rtp {
+      std::string ToString() const;
+
+      // Synchronization source (stream identifier) to be received.
+      uint32_t remote_ssrc = 0;
+
+      // Sender SSRC used for sending RTCP (such as receiver reports).
+      uint32_t local_ssrc = 0;
+
+      // Enable feedback for send side bandwidth estimation.
+      // See
+      // https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions
+      // for details.
+      bool transport_cc = false;
+
+      // See NackConfig for description.
+      NackConfig nack;
+
+      // RTP header extensions used for the received stream.
+      std::vector<RtpExtension> extensions;
+    } rtp;
+
+    Transport* rtcp_send_transport = nullptr;
+
+    // Underlying VoiceEngine handle, used to map AudioReceiveStream to lower-
+    // level components.
+    // TODO(solenberg): Remove when VoiceEngine channels are created outside
+    // of Call.
+    int voe_channel_id = -1;
+
+    // Identifier for an A/V synchronization group. Empty string to disable.
+    // TODO(pbos): Synchronize streams in a sync group, not just one video
+    // stream to one audio stream. Tracked by issue webrtc:4762.
+    std::string sync_group;
+
+    // Decoders for every payload that we can receive. Call owns the
+    // AudioDecoder instances once the Config is submitted to
+    // Call::CreateReceiveStream().
+    // TODO(solenberg): Use unique_ptr<> once our std lib fully supports C++11.
+    std::map<uint8_t, AudioDecoder*> decoder_map;
+
+    rtc::scoped_refptr<AudioDecoderFactory> decoder_factory;
+  };
+
+  // Starts stream activity.
+  // When a stream is active, it can receive, process and deliver packets.
+  virtual void Start() = 0;
+  // Stops stream activity.
+  // When a stream is stopped, it can't receive, process or deliver packets.
+  virtual void Stop() = 0;
+
+  virtual Stats GetStats() const = 0;
+
+  // Sets an audio sink that receives unmixed audio from the receive stream.
+  // Ownership of the sink is passed to the stream and can be used by the
+  // caller to do lifetime management (i.e. when the sink's dtor is called).
+  // Only one sink can be set and passing a null sink clears an existing one.
+  // NOTE: Audio must still somehow be pulled through AudioTransport for audio
+  // to stream through this sink. In practice, this happens if mixed audio
+  // is being pulled+rendered and/or if audio is being pulled for the purposes
+  // of feeding to the AEC.
+  virtual void SetSink(std::unique_ptr<AudioSinkInterface> sink) = 0;
+
+  // Sets playback gain of the stream, applied when mixing, and thus after it
+  // is potentially forwarded to any attached AudioSinkInterface implementation.
+  virtual void SetGain(float gain) = 0;
+
+ protected:
+  virtual ~AudioReceiveStream() {}
+};
+}  // namespace webrtc
+
+#endif  // WEBRTC_API_CALL_AUDIO_RECEIVE_STREAM_H_
diff --git a/webrtc/api/call/audio_send_stream.h b/webrtc/api/call/audio_send_stream.h
new file mode 100644
index 0000000..b309f7a
--- /dev/null
+++ b/webrtc/api/call/audio_send_stream.h
@@ -0,0 +1,119 @@
+/*
+ *  Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_API_CALL_AUDIO_SEND_STREAM_H_
+#define WEBRTC_API_CALL_AUDIO_SEND_STREAM_H_
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "webrtc/config.h"
+#include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
+#include "webrtc/transport.h"
+#include "webrtc/typedefs.h"
+
+namespace webrtc {
+
+// WORK IN PROGRESS
+// This class is under development and is not yet intended for for use outside
+// of WebRtc/Libjingle. Please use the VoiceEngine API instead.
+// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4690
+
+class AudioSendStream {
+ public:
+  struct Stats {
+    // TODO(solenberg): Harmonize naming and defaults with receive stream stats.
+    uint32_t local_ssrc = 0;
+    int64_t bytes_sent = 0;
+    int32_t packets_sent = 0;
+    int32_t packets_lost = -1;
+    float fraction_lost = -1.0f;
+    std::string codec_name;
+    int32_t ext_seqnum = -1;
+    int32_t jitter_ms = -1;
+    int64_t rtt_ms = -1;
+    int32_t audio_level = -1;
+    float aec_quality_min = -1.0f;
+    int32_t echo_delay_median_ms = -1;
+    int32_t echo_delay_std_ms = -1;
+    int32_t echo_return_loss = -100;
+    int32_t echo_return_loss_enhancement = -100;
+    bool typing_noise_detected = false;
+  };
+
+  struct Config {
+    Config() = delete;
+    explicit Config(Transport* send_transport)
+        : send_transport(send_transport) {}
+
+    std::string ToString() const;
+
+    // Send-stream specific RTP settings.
+    struct Rtp {
+      std::string ToString() const;
+
+      // Sender SSRC.
+      uint32_t ssrc = 0;
+
+      // RTP header extensions used for the sent stream.
+      std::vector<RtpExtension> extensions;
+
+      // See NackConfig for description.
+      NackConfig nack;
+
+      // RTCP CNAME, see RFC 3550.
+      std::string c_name;
+    } rtp;
+
+    // Transport for outgoing packets. The transport is expected to exist for
+    // the entire life of the AudioSendStream and is owned by the API client.
+    Transport* send_transport = nullptr;
+
+    // Underlying VoiceEngine handle, used to map AudioSendStream to lower-level
+    // components.
+    // TODO(solenberg): Remove when VoiceEngine channels are created outside
+    // of Call.
+    int voe_channel_id = -1;
+
+    // Ownership of the encoder object is transferred to Call when the config is
+    // passed to Call::CreateAudioSendStream().
+    // TODO(solenberg): Implement, once we configure codecs through the new API.
+    // std::unique_ptr<AudioEncoder> encoder;
+    int cng_payload_type = -1;  // pt, or -1 to disable Comfort Noise Generator.
+
+    // Bitrate limits used for variable audio bitrate streams. Set both to -1 to
+    // disable audio bitrate adaptation.
+    // Note: This is still an experimental feature and not ready for real usage.
+    int min_bitrate_kbps = -1;
+    int max_bitrate_kbps = -1;
+  };
+
+  // Starts stream activity.
+  // When a stream is active, it can receive, process and deliver packets.
+  virtual void Start() = 0;
+  // Stops stream activity.
+  // When a stream is stopped, it can't receive, process or deliver packets.
+  virtual void Stop() = 0;
+
+  // TODO(solenberg): Make payload_type a config property instead.
+  virtual bool SendTelephoneEvent(int payload_type, int event,
+                                  int duration_ms) = 0;
+
+  virtual void SetMuted(bool muted) = 0;
+
+  virtual Stats GetStats() const = 0;
+
+ protected:
+  virtual ~AudioSendStream() {}
+};
+}  // namespace webrtc
+
+#endif  // WEBRTC_API_CALL_AUDIO_SEND_STREAM_H_
diff --git a/webrtc/api/call/audio_sink.h b/webrtc/api/call/audio_sink.h
new file mode 100644
index 0000000..e865ead
--- /dev/null
+++ b/webrtc/api/call/audio_sink.h
@@ -0,0 +1,53 @@
+/*
+ *  Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_API_CALL_AUDIO_SINK_H_
+#define WEBRTC_API_CALL_AUDIO_SINK_H_
+
+#if defined(WEBRTC_POSIX) && !defined(__STDC_FORMAT_MACROS)
+// Avoid conflict with format_macros.h.
+#define __STDC_FORMAT_MACROS
+#endif
+
+#include <inttypes.h>
+#include <stddef.h>
+
+namespace webrtc {
+
+// Represents a simple push audio sink.
+class AudioSinkInterface {
+ public:
+  virtual ~AudioSinkInterface() {}
+
+  struct Data {
+    Data(int16_t* data,
+         size_t samples_per_channel,
+         int sample_rate,
+         size_t channels,
+         uint32_t timestamp)
+        : data(data),
+          samples_per_channel(samples_per_channel),
+          sample_rate(sample_rate),
+          channels(channels),
+          timestamp(timestamp) {}
+
+    int16_t* data;               // The actual 16bit audio data.
+    size_t samples_per_channel;  // Number of frames in the buffer.
+    int sample_rate;             // Sample rate in Hz.
+    size_t channels;             // Number of channels in the audio data.
+    uint32_t timestamp;          // The RTP timestamp of the first sample.
+  };
+
+  virtual void OnData(const Data& audio) = 0;
+};
+
+}  // namespace webrtc
+
+#endif  // WEBRTC_API_CALL_AUDIO_SINK_H_
diff --git a/webrtc/api/call/audio_state.h b/webrtc/api/call/audio_state.h
new file mode 100644
index 0000000..ac91277
--- /dev/null
+++ b/webrtc/api/call/audio_state.h
@@ -0,0 +1,48 @@
+/*
+ *  Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
+ *
+ *  Use of this source code is governed by a BSD-style license
+ *  that can be found in the LICENSE file in the root of the source
+ *  tree. An additional intellectual property rights grant can be found
+ *  in the file PATENTS.  All contributing project authors may
+ *  be found in the AUTHORS file in the root of the source tree.
+ */
+#ifndef WEBRTC_API_CALL_AUDIO_STATE_H_
+#define WEBRTC_API_CALL_AUDIO_STATE_H_
+
+#include "webrtc/base/refcount.h"
+#include "webrtc/base/scoped_ref_ptr.h"
+
+namespace webrtc {
+
+class AudioDeviceModule;
+class VoiceEngine;
+
+// WORK IN PROGRESS
+// This class is under development and is not yet intended for for use outside
+// of WebRtc/Libjingle. Please use the VoiceEngine API instead.
+// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4690
+
+// AudioState holds the state which must be shared between multiple instances of
+// webrtc::Call for audio processing purposes.
+class AudioState : public rtc::RefCountInterface {
+ public:
+  struct Config {
+    // VoiceEngine used for audio streams and audio/video synchronization.
+    // AudioState will tickle the VoE refcount to keep it alive for as long as
+    // the AudioState itself.
+    VoiceEngine* voice_engine = nullptr;
+
+    // The AudioDeviceModule associated with the Calls.
+    AudioDeviceModule* audio_device_module = nullptr;
+  };
+
+  // TODO(solenberg): Replace scoped_refptr with shared_ptr once we can use it.
+  static rtc::scoped_refptr<AudioState> Create(
+      const AudioState::Config& config);
+
+  virtual ~AudioState() {}
+};
+}  // namespace webrtc
+
+#endif  // WEBRTC_API_CALL_AUDIO_STATE_H_
diff --git a/webrtc/api/remoteaudiosource.h b/webrtc/api/remoteaudiosource.h
index 4cc68f8..a67b895 100644
--- a/webrtc/api/remoteaudiosource.h
+++ b/webrtc/api/remoteaudiosource.h
@@ -14,8 +14,8 @@
 #include <list>
 #include <string>
 
+#include "webrtc/api/call/audio_sink.h"
 #include "webrtc/api/notifier.h"
-#include "webrtc/audio_sink.h"
 #include "webrtc/base/criticalsection.h"
 #include "webrtc/pc/channel.h"
 
diff --git a/webrtc/api/webrtcsession.cc b/webrtc/api/webrtcsession.cc
index f8a8f67..df4a48a 100644
--- a/webrtc/api/webrtcsession.cc
+++ b/webrtc/api/webrtcsession.cc
@@ -17,12 +17,12 @@
 #include <utility>
 #include <vector>
 
+#include "webrtc/api/call/audio_sink.h"
 #include "webrtc/api/jsepicecandidate.h"
 #include "webrtc/api/jsepsessiondescription.h"
 #include "webrtc/api/peerconnectioninterface.h"
 #include "webrtc/api/sctputils.h"
 #include "webrtc/api/webrtcsessiondescriptionfactory.h"
-#include "webrtc/audio_sink.h"
 #include "webrtc/base/basictypes.h"
 #include "webrtc/base/bind.h"
 #include "webrtc/base/checks.h"