2013-07-10 00:45:36 +00:00
|
|
|
/*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Copyright 2012 The WebRTC project authors. All Rights Reserved.
|
2013-07-10 00:45:36 +00:00
|
|
|
*
|
2016-02-10 07:54:43 -08:00
|
|
|
* 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.
|
2013-07-10 00:45:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// This file contains interfaces for DataChannels
|
|
|
|
|
// http://dev.w3.org/2011/webrtc/editor/webrtc.html#rtcdatachannel
|
|
|
|
|
|
2016-02-10 10:53:12 +01:00
|
|
|
#ifndef WEBRTC_API_DATACHANNELINTERFACE_H_
|
|
|
|
|
#define WEBRTC_API_DATACHANNELINTERFACE_H_
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
#include "webrtc/base/basictypes.h"
|
Revert of Use CopyOnWriteBuffer instead of Buffer to avoid unnecessary copies. (patchset #4 id:60001 of https://codereview.webrtc.org/1785713005/ )
Reason for revert:
I'm really sorry for having to revert this but it seems this hit an unexpected compile error downstream:
webrtc/media/sctp/sctpdataengine.cc: In function 'void cricket::VerboseLogPacket(const void*, size_t, int)':
webrtc/media/sctp/sctpdataengine.cc:172:37: error: invalid conversion from 'const void*' to 'void*' [-fpermissive]
data, length, direction)) != NULL) {
^
In file included from webrtc/media/sctp/sctpdataengine.cc:20:0:
third_party/usrsctp/usrsctplib/usrsctp.h:964:1: error: initializing argument 1 of 'char* usrsctp_dumppacket(void*, size_t, int)' [-fpermissive]
usrsctp_dumppacket(void *, size_t, int);
^
I'm sure you can fix this easily and just re-land this CL, while I'm going to look into how to add this warning at the public bots (on Monday).
Original issue's description:
> Use CopyOnWriteBuffer instead of Buffer to avoid unnecessary copies.
>
> This CL removes copy and assign support from Buffer and changes various
> parameters from Buffer to CopyOnWriteBuffer so they can be passed along
> and copied without actually copying the underlying data.
>
> With this changed some parameters to be "const" and fixed an issue when
> creating a CopyOnWriteBuffer with empty data.
>
> BUG=webrtc:5155
>
> Committed: https://crrev.com/944c39006f1c52aee20919676002dac7a42b1c05
> Cr-Commit-Position: refs/heads/master@{#12058}
TBR=kwiberg@webrtc.org,tkchin@webrtc.org,tommi@webrtc.org,pthatcher@webrtc.org,jbauch@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:5155
Review URL: https://codereview.webrtc.org/1817753003
Cr-Commit-Position: refs/heads/master@{#12060}
2016-03-19 12:12:52 -07:00
|
|
|
#include "webrtc/base/buffer.h"
|
2015-01-15 22:55:07 +00:00
|
|
|
#include "webrtc/base/checks.h"
|
2014-07-29 17:36:52 +00:00
|
|
|
#include "webrtc/base/refcount.h"
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
struct DataChannelInit {
|
|
|
|
|
DataChannelInit()
|
|
|
|
|
: reliable(false),
|
|
|
|
|
ordered(true),
|
|
|
|
|
maxRetransmitTime(-1),
|
|
|
|
|
maxRetransmits(-1),
|
|
|
|
|
negotiated(false),
|
|
|
|
|
id(-1) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool reliable; // Deprecated.
|
|
|
|
|
bool ordered; // True if ordered delivery is required.
|
|
|
|
|
int maxRetransmitTime; // The max period of time in milliseconds in which
|
|
|
|
|
// retransmissions will be sent. After this time, no
|
|
|
|
|
// more retransmissions will be sent. -1 if unset.
|
|
|
|
|
int maxRetransmits; // The max number of retransmissions. -1 if unset.
|
|
|
|
|
std::string protocol; // This is set by the application and opaque to the
|
|
|
|
|
// WebRTC implementation.
|
|
|
|
|
bool negotiated; // True if the channel has been externally negotiated
|
|
|
|
|
// and we do not send an in-band signalling in the
|
|
|
|
|
// form of an "open" message.
|
|
|
|
|
int id; // The stream id, or SID, for SCTP data channels. -1
|
|
|
|
|
// if unset.
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct DataBuffer {
|
Revert of Use CopyOnWriteBuffer instead of Buffer to avoid unnecessary copies. (patchset #4 id:60001 of https://codereview.webrtc.org/1785713005/ )
Reason for revert:
I'm really sorry for having to revert this but it seems this hit an unexpected compile error downstream:
webrtc/media/sctp/sctpdataengine.cc: In function 'void cricket::VerboseLogPacket(const void*, size_t, int)':
webrtc/media/sctp/sctpdataengine.cc:172:37: error: invalid conversion from 'const void*' to 'void*' [-fpermissive]
data, length, direction)) != NULL) {
^
In file included from webrtc/media/sctp/sctpdataengine.cc:20:0:
third_party/usrsctp/usrsctplib/usrsctp.h:964:1: error: initializing argument 1 of 'char* usrsctp_dumppacket(void*, size_t, int)' [-fpermissive]
usrsctp_dumppacket(void *, size_t, int);
^
I'm sure you can fix this easily and just re-land this CL, while I'm going to look into how to add this warning at the public bots (on Monday).
Original issue's description:
> Use CopyOnWriteBuffer instead of Buffer to avoid unnecessary copies.
>
> This CL removes copy and assign support from Buffer and changes various
> parameters from Buffer to CopyOnWriteBuffer so they can be passed along
> and copied without actually copying the underlying data.
>
> With this changed some parameters to be "const" and fixed an issue when
> creating a CopyOnWriteBuffer with empty data.
>
> BUG=webrtc:5155
>
> Committed: https://crrev.com/944c39006f1c52aee20919676002dac7a42b1c05
> Cr-Commit-Position: refs/heads/master@{#12058}
TBR=kwiberg@webrtc.org,tkchin@webrtc.org,tommi@webrtc.org,pthatcher@webrtc.org,jbauch@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:5155
Review URL: https://codereview.webrtc.org/1817753003
Cr-Commit-Position: refs/heads/master@{#12060}
2016-03-19 12:12:52 -07:00
|
|
|
DataBuffer(const rtc::Buffer& data, bool binary)
|
2013-07-10 00:45:36 +00:00
|
|
|
: data(data),
|
|
|
|
|
binary(binary) {
|
|
|
|
|
}
|
|
|
|
|
// For convenience for unit tests.
|
|
|
|
|
explicit DataBuffer(const std::string& text)
|
|
|
|
|
: data(text.data(), text.length()),
|
|
|
|
|
binary(false) {
|
|
|
|
|
}
|
2015-03-24 09:19:06 +00:00
|
|
|
size_t size() const { return data.size(); }
|
2013-08-01 00:00:07 +00:00
|
|
|
|
Revert of Use CopyOnWriteBuffer instead of Buffer to avoid unnecessary copies. (patchset #4 id:60001 of https://codereview.webrtc.org/1785713005/ )
Reason for revert:
I'm really sorry for having to revert this but it seems this hit an unexpected compile error downstream:
webrtc/media/sctp/sctpdataengine.cc: In function 'void cricket::VerboseLogPacket(const void*, size_t, int)':
webrtc/media/sctp/sctpdataengine.cc:172:37: error: invalid conversion from 'const void*' to 'void*' [-fpermissive]
data, length, direction)) != NULL) {
^
In file included from webrtc/media/sctp/sctpdataengine.cc:20:0:
third_party/usrsctp/usrsctplib/usrsctp.h:964:1: error: initializing argument 1 of 'char* usrsctp_dumppacket(void*, size_t, int)' [-fpermissive]
usrsctp_dumppacket(void *, size_t, int);
^
I'm sure you can fix this easily and just re-land this CL, while I'm going to look into how to add this warning at the public bots (on Monday).
Original issue's description:
> Use CopyOnWriteBuffer instead of Buffer to avoid unnecessary copies.
>
> This CL removes copy and assign support from Buffer and changes various
> parameters from Buffer to CopyOnWriteBuffer so they can be passed along
> and copied without actually copying the underlying data.
>
> With this changed some parameters to be "const" and fixed an issue when
> creating a CopyOnWriteBuffer with empty data.
>
> BUG=webrtc:5155
>
> Committed: https://crrev.com/944c39006f1c52aee20919676002dac7a42b1c05
> Cr-Commit-Position: refs/heads/master@{#12058}
TBR=kwiberg@webrtc.org,tkchin@webrtc.org,tommi@webrtc.org,pthatcher@webrtc.org,jbauch@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:5155
Review URL: https://codereview.webrtc.org/1817753003
Cr-Commit-Position: refs/heads/master@{#12060}
2016-03-19 12:12:52 -07:00
|
|
|
rtc::Buffer data;
|
2013-07-10 00:45:36 +00:00
|
|
|
// Indicates if the received data contains UTF-8 or binary data.
|
|
|
|
|
// Note that the upper layers are left to verify the UTF-8 encoding.
|
|
|
|
|
// TODO(jiayl): prefer to use an enum instead of a bool.
|
|
|
|
|
bool binary;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class DataChannelObserver {
|
|
|
|
|
public:
|
|
|
|
|
// The data channel state have changed.
|
|
|
|
|
virtual void OnStateChange() = 0;
|
|
|
|
|
// A data buffer was successfully received.
|
|
|
|
|
virtual void OnMessage(const DataBuffer& buffer) = 0;
|
2015-07-01 13:34:33 -07:00
|
|
|
// The data channel's buffered_amount has changed.
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
virtual void OnBufferedAmountChange(uint64_t previous_amount){};
|
2013-07-10 00:45:36 +00:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual ~DataChannelObserver() {}
|
|
|
|
|
};
|
|
|
|
|
|
2014-07-29 17:36:52 +00:00
|
|
|
class DataChannelInterface : public rtc::RefCountInterface {
|
2013-07-10 00:45:36 +00:00
|
|
|
public:
|
2014-04-30 18:32:33 +00:00
|
|
|
// Keep in sync with DataChannel.java:State and
|
|
|
|
|
// RTCDataChannel.h:RTCDataChannelState.
|
|
|
|
|
enum DataState {
|
2013-07-10 00:45:36 +00:00
|
|
|
kConnecting,
|
|
|
|
|
kOpen, // The DataChannel is ready to send data.
|
|
|
|
|
kClosing,
|
|
|
|
|
kClosed
|
|
|
|
|
};
|
|
|
|
|
|
2015-01-15 22:55:07 +00:00
|
|
|
static const char* DataStateString(DataState state) {
|
|
|
|
|
switch (state) {
|
|
|
|
|
case kConnecting:
|
|
|
|
|
return "connecting";
|
|
|
|
|
case kOpen:
|
|
|
|
|
return "open";
|
|
|
|
|
case kClosing:
|
|
|
|
|
return "closing";
|
|
|
|
|
case kClosed:
|
|
|
|
|
return "closed";
|
|
|
|
|
}
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_CHECK(false) << "Unknown DataChannel state: " << state;
|
2015-01-15 22:55:07 +00:00
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
virtual void RegisterObserver(DataChannelObserver* observer) = 0;
|
|
|
|
|
virtual void UnregisterObserver() = 0;
|
|
|
|
|
// The label attribute represents a label that can be used to distinguish this
|
|
|
|
|
// DataChannel object from other DataChannel objects.
|
|
|
|
|
virtual std::string label() const = 0;
|
|
|
|
|
virtual bool reliable() const = 0;
|
2013-08-15 23:38:54 +00:00
|
|
|
|
|
|
|
|
// TODO(tommyw): Remove these dummy implementations when all classes have
|
|
|
|
|
// implemented these APIs. They should all just return the values the
|
|
|
|
|
// DataChannel was created with.
|
|
|
|
|
virtual bool ordered() const { return false; }
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
virtual uint16_t maxRetransmitTime() const { return 0; }
|
|
|
|
|
virtual uint16_t maxRetransmits() const { return 0; }
|
2013-08-15 23:38:54 +00:00
|
|
|
virtual std::string protocol() const { return std::string(); }
|
|
|
|
|
virtual bool negotiated() const { return false; }
|
|
|
|
|
|
2013-07-10 00:45:36 +00:00
|
|
|
virtual int id() const = 0;
|
|
|
|
|
virtual DataState state() const = 0;
|
|
|
|
|
// The buffered_amount returns the number of bytes of application data
|
|
|
|
|
// (UTF-8 text and binary data) that have been queued using SendBuffer but
|
|
|
|
|
// have not yet been transmitted to the network.
|
Use suffixed {uint,int}{8,16,32,64}_t types.
Removes the use of uint8, etc. in favor of uint8_t.
BUG=webrtc:5024
R=henrik.lundin@webrtc.org, henrikg@webrtc.org, perkj@webrtc.org, solenberg@webrtc.org, stefan@webrtc.org, tina.legrand@webrtc.org
Review URL: https://codereview.webrtc.org/1362503003 .
Cr-Commit-Position: refs/heads/master@{#10196}
2015-10-07 12:23:21 +02:00
|
|
|
virtual uint64_t buffered_amount() const = 0;
|
2013-07-10 00:45:36 +00:00
|
|
|
virtual void Close() = 0;
|
|
|
|
|
// Sends |data| to the remote peer.
|
|
|
|
|
virtual bool Send(const DataBuffer& buffer) = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
virtual ~DataChannelInterface() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2016-02-10 10:53:12 +01:00
|
|
|
#endif // WEBRTC_API_DATACHANNELINTERFACE_H_
|