Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: webrtc/examples/unityplugin/simple_peer_connection.h

Issue 2823783002: An example of Unity native plugin of webrtc for Windows OS (Closed)
Patch Set: Add readme and owners files Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2017 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_EXAMPLES_UNITYPLUGIN_SIMPLE_PEER_CONNECTION_H_
12 #define WEBRTC_EXAMPLES_UNITYPLUGIN_SIMPLE_PEER_CONNECTION_H_
13
14 #include <map>
15 #include <memory>
16 #include <string>
17 #include <vector>
18
19 #include "webrtc/api/datachannelinterface.h"
20 #include "webrtc/api/mediastreaminterface.h"
21 #include "webrtc/api/peerconnectioninterface.h"
22 #include "webrtc/examples/unityplugin/unity_plugin_apis.h"
23
24 class Conductor : public webrtc::PeerConnectionObserver,
25 public webrtc::CreateSessionDescriptionObserver,
26 public webrtc::DataChannelObserver,
27 public webrtc::AudioTrackSinkInterface {
28 public:
29 Conductor() {}
30 ~Conductor() {}
31
32 bool InitializePeerConnection(bool is_receiver);
33 void DeletePeerConnection();
34 void AddStreams(bool audio_only);
35 bool CreateDataChannel();
36 bool CreateOffer();
37 bool CreateAnswer();
38 bool SendDataViaDataChannel(const std::string& data);
39 void SetAudioControl(bool is_mute, bool is_record);
40
41 // Register callback functions.
42 void RegisterOnVideoFramReady(VIDEOFRAMEREADY_CALLBACK callback);
43 void RegisterOnLocalDataChannelReady(LOCALDATACHANNELREADY_CALLBACK callback);
44 void RegisterOnDataFromDataChannelReady(
45 DATAFROMEDATECHANNELREADY_CALLBACK callback);
46 void RegisterOnFailure(FAILURE_CALLBACK callback);
47 void RegisterOnAudioBusReady(AUDIOBUSREADY_CALLBACK callback);
48 void RegisterOnLocalSdpReadytoSend(LOCALSDPREADYTOSEND_CALLBACK callback);
49 void RegisterOnIceCandiateReadytoSend(
50 ICECANDIDATEREADYTOSEND_CALLBACK callback);
51 bool ReceivedSdp(const char* sdp);
52 bool ReceivedIceCandidate(const char* ice_candidate);
53
54 bool SetHeadPosition(float x, float y, float z);
55 bool SetHeadRotation(float rx, float ry, float rz, float rw);
56 bool SetRemoteAudioPosition(float x, float y, float z);
57 bool SetRemoteAudioRotation(float rx, float ry, float rz, float rw);
58
59 protected:
60 bool CreatePeerConnection(bool receiver);
61 void CloseDataChannel();
62 std::unique_ptr<cricket::VideoCapturer> OpenVideoCaptureDevice();
63 void SetAudioControl();
64
65 // PeerConnectionObserver implementation.
66 void OnSignalingChange(
67 webrtc::PeerConnectionInterface::SignalingState new_state) override{};
68 void OnAddStream(
69 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override;
70 void OnRemoveStream(
71 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream) override{};
72 void OnDataChannel(
73 rtc::scoped_refptr<webrtc::DataChannelInterface> channel) override;
74 void OnRenegotiationNeeded() override {}
75 void OnIceConnectionChange(
76 webrtc::PeerConnectionInterface::IceConnectionState new_state) override{};
77 void OnIceGatheringChange(
78 webrtc::PeerConnectionInterface::IceGatheringState new_state) override{};
79 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override;
80 void OnIceConnectionReceivingChange(bool receiving) override{};
81
82 // CreateSessionDescriptionObserver implementation.
83 void OnSuccess(webrtc::SessionDescriptionInterface* desc) override;
84 void OnFailure(const std::string& error) override;
85
86 // DataChannelObserver implementation.
87 void OnStateChange() override;
88 void OnMessage(const webrtc::DataBuffer& buffer) override;
89
90 // AudioTrackSinkInterface implementation.
91 void OnData(const void* audio_data,
92 int bits_per_sample,
93 int sample_rate,
94 size_t number_of_channels,
95 size_t number_of_frames) override;
96
97 // Get remote audio tracks ssrcs.
98 std::vector<uint32_t> GetRemoteAudioTrackSsrcs();
99
100 private:
101 static int peer_count_;
tommi 2017/04/21 09:47:51 should these static vars perhaps be in an anonymou
GeorgeZ 2017/04/21 22:00:04 I moved those static variables to the cc file. Cl
102 static std::unique_ptr<rtc::Thread> worker_thread_;
103 static std::unique_ptr<rtc::Thread> signaling_thread_;
104 static rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
105 peer_connection_factory_;
106
107 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_ =
tommi 2017/04/21 09:47:51 initializing scoped_refptr like this, isn't necess
GeorgeZ 2017/04/21 22:00:04 Done.
108 nullptr;
109 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel_ = nullptr;
110 std::map<std::string, rtc::scoped_refptr<webrtc::MediaStreamInterface> >
111 active_streams_;
112
113 webrtc::MediaStreamInterface* remote_stream_ = nullptr;
114
115 VIDEOFRAMEREADY_CALLBACK OnVideoFrameReady = nullptr;
116 LOCALDATACHANNELREADY_CALLBACK OnLocalDataChannelReady = nullptr;
117 DATAFROMEDATECHANNELREADY_CALLBACK OnDataFromDataChannelReady = nullptr;
118 FAILURE_CALLBACK OnFailureMessage = nullptr;
119 AUDIOBUSREADY_CALLBACK OnAudioReady = nullptr;
120
121 LOCALSDPREADYTOSEND_CALLBACK OnLocalSdpReady = nullptr;
122 ICECANDIDATEREADYTOSEND_CALLBACK OnIceCandiateReady = nullptr;
123
124 bool is_mute_audio_ = false;
125 bool is_record_audio_ = false;
126
127 // disallow copy-and-assign
128 Conductor(const Conductor&) = delete;
129 Conductor& operator=(const Conductor&) = delete;
130 };
131
132 #endif // WEBRTC_EXAMPLES_UNITYPLUGIN_SIMPLE_PEER_CONNECTION_H_
OLDNEW
« no previous file with comments | « webrtc/examples/unityplugin/README ('k') | webrtc/examples/unityplugin/simple_peer_connection.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698