Skip to content

Commit

Permalink
audioEnabled = false
Browse files Browse the repository at this point in the history
  • Loading branch information
radioman committed Nov 6, 2016
1 parent 99e2a27 commit 0027241
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 18 deletions.
35 changes: 25 additions & 10 deletions WebRtc.NET/src/conductor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace Native
{
const char kAudioLabel[] = "audio_label";
const char kVideoLabel[] = "video_label";
const char kStreamLabel[] = "stream_label";
const char kSoftware[] = "libjingle TurnServer";
Expand Down Expand Up @@ -62,8 +63,11 @@ namespace Native
onFailure = nullptr;
onIceCandidate = nullptr;
capturer = nullptr;

caputureFps = 5;
barcodeEnabled = false;
audioEnabled = false;

turnServer = nullptr;
data_channel = nullptr;
onDataMessage = nullptr;
Expand Down Expand Up @@ -98,7 +102,7 @@ namespace Native
{
if (peer_connection_)
{
local_renderer_.reset();
local_video.reset();

for (auto it = active_streams_.begin(); it != active_streams_.end(); ++it)
{
Expand Down Expand Up @@ -309,25 +313,26 @@ namespace Native
if (active_streams_.find(kStreamLabel) != active_streams_.end())
return; // Already added.

//webrtc::AudioTrackInterface * audio_track = peer_connection_factory_->CreateAudioTrack(
// kAudioLabel, peer_connection_factory_->CreateAudioSource(NULL));

if (!capturer)
{
capturer = new Native::YuvFramesCapturer2(*this);
}

auto v = pc_factory_->CreateVideoSource(capturer, NULL);

auto video_track = pc_factory_->CreateVideoTrack(kVideoLabel, v);
if (onRenderLocal)
{
local_renderer_.reset(new VideoRenderer(*this, false, video_track));
local_video.reset(new VideoRenderer(*this, false, video_track));
}

auto stream = pc_factory_->CreateLocalMediaStream(kStreamLabel);
{
//stream->AddTrack(audio_track);
if (audioEnabled)
{
auto a = pc_factory_->CreateAudioSource(NULL);
auto audio_track = pc_factory_->CreateAudioTrack(kAudioLabel, a);
stream->AddTrack(audio_track);
}
stream->AddTrack(video_track);

if (!peer_connection_->AddStream(stream))
Expand All @@ -347,19 +352,29 @@ namespace Native
if (onRenderRemote)
{
webrtc::VideoTrackVector tracks = stream->GetVideoTracks();
// Only render the first track.
if (!tracks.empty())
{
webrtc::VideoTrackInterface* track = tracks[0];
remote_renderer_.reset(new VideoRenderer(*this, true, track));
remote_video.reset(new Native::VideoRenderer(*this, true, track));
}
}

if (audioEnabled)
{
webrtc::AudioTrackVector atracks = stream->GetAudioTracks();
if (!atracks.empty())
{
webrtc::AudioTrackInterface* track = atracks[0];
remote_audio.reset(new Native::AudioRenderer(*this, true, track));
}
}
}

void Conductor::OnRemoveStream(rtc::scoped_refptr<webrtc::MediaStreamInterface> stream)
{
LOG(INFO) << __FUNCTION__ << " " << stream->label();
remote_renderer_.reset();
remote_video.reset();
remote_audio.reset();
}

void Conductor::OnIceCandidate(const webrtc::IceCandidateInterface* candidate)
Expand Down
6 changes: 4 additions & 2 deletions WebRtc.NET/src/conductor.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,17 @@ namespace Native

std::vector<webrtc::PeerConnectionInterface::IceServer> serverConfigs;

std::unique_ptr<VideoRenderer> local_renderer_;
std::unique_ptr<VideoRenderer> remote_renderer_;
std::unique_ptr<VideoRenderer> local_video;
std::unique_ptr<VideoRenderer> remote_video;
std::unique_ptr<AudioRenderer> remote_audio;

cricket::TurnServer * turnServer;
cricket::StunServer * stunServer;

public:
int caputureFps;
bool barcodeEnabled;
bool audioEnabled;
};
}
#endif // WEBRTC_NET_CONDUCTOR_H_
16 changes: 16 additions & 0 deletions WebRtc.NET/src/defaults.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,20 @@ namespace Native
con->onRenderLocal((uint8_t*)b->DataY(), b->width(), b->height());
}
}

// AudioTrackSinkInterface implementation
void AudioRenderer::OnData(const void* audio_data,
int bits_per_sample,
int sample_rate,
size_t number_of_channels,
size_t number_of_frames)
{
std::stringstream s;
s << "AudioRenderer::OnData, bps: " << bits_per_sample
<< ", rate: " << sample_rate
<< ", channels: " << number_of_channels
<< ", frames: " << number_of_frames;

::OutputDebugStringA(s.str().c_str());
}
}
29 changes: 27 additions & 2 deletions WebRtc.NET/src/defaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,33 @@ namespace Native

bool remote;
Conductor * con;
CRITICAL_SECTION buffer_lock_;
rtc::scoped_refptr<webrtc::VideoTrackInterface> rendered_track_;
rtc::scoped_refptr<webrtc::VideoTrackInterface> rendered_track_;
};

class AudioRenderer : public webrtc::AudioTrackSinkInterface
{
public:
AudioRenderer(Conductor & c, bool remote, webrtc::AudioTrackInterface * track_to_render) :
audio_track_(track_to_render), con(&c), remote(remote)
{
audio_track_->AddSink(this);
}
virtual ~AudioRenderer()
{
audio_track_->RemoveSink(this);
}

virtual void OnData(const void* audio_data,
int bits_per_sample,
int sample_rate,
size_t number_of_channels,
size_t number_of_frames) override;

protected:

bool remote;
Conductor * con;
rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track_;
};
}
#endif // WEBRTC_NET_DEFAULTS_H_
2 changes: 1 addition & 1 deletion web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<div style="color: white" id="statsdiv"></div>
</div>
</br>
<video id="vidLocal" autoplay controls style="display: none"></video>
<video id="vidLocal" autoplay controls muted style="display: none"></video>
</div>
</body >
</html >
7 changes: 4 additions & 3 deletions web/rtc_main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ var offerOptions = {
};

var vgaConstraints = {
video: true
video: true,
//audio: true
};

var dataChannelOptions = {
Expand Down Expand Up @@ -111,15 +112,15 @@ function startStream() {
var s = o[key];
return (
(s.type == "inboundrtp" && !s.isRemote) ||
(s.type == "ssrc" && s.id.indexOf("recv") >= 0)
(s.type == "ssrc" && s.mediaType == "video" && s.id.indexOf("recv") >= 0)
);
})];

var snd = o[Object.keys(o).find(function (key) {
var s = o[key];
return (
(s.type == "outboundrtp" && !s.isRemote) ||
(s.type == "ssrc" && s.id.indexOf("send") >= 0)
(s.type == "ssrc" && s.mediaType == "video" && s.id.indexOf("send") >= 0)
);
})];

Expand Down

0 comments on commit 0027241

Please sign in to comment.