FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
client-sdk-cpp/src/local_data_track.cpp at main · livekit/client-sdk-cpp · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
livekit
/
client-sdk-cpp
Public
Notifications
You must be signed in to change notification settings
Fork
38
Star
67
Code
Issues
2
Pull requests
5
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
client-sdk-cpp
/
src
/
local_data_track.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
102 lines (86 loc) · 3.69 KB
Breadcrumbs
client-sdk-cpp
/
src
/
local_data_track.cpp
Copy path
File metadata and controls
102 lines (86 loc) · 3.69 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* Copyright 2026 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#
include
"
livekit/local_data_track.h
"
#
include
"
data_track.pb.h
"
#
include
"
data_track_proto_converter.h
"
#
include
"
ffi.pb.h
"
#
include
"
ffi_client.h
"
#
include
"
livekit/data_track_error.h
"
#
include
"
lk_log.h
"
namespace
livekit
{
LocalDataTrack::LocalDataTrack
(
const
proto::OwnedLocalDataTrack& owned)
: handle_(
static_cast
<
uintptr_t
>(owned.handle().id())), info_(fromProto(owned.info())) {}
Result<
void
, LocalDataTrackTryPushError>
LocalDataTrack::tryPush
(
const
DataTrackFrame& frame) {
return
tryPush
(frame.
payload
.
data
(), frame.
payload
.
size
(), frame.
user_timestamp
);
}
Result<
void
, LocalDataTrackTryPushError>
LocalDataTrack::tryPush
(std::vector<std::
uint8_t
>&& payload,
std::optional<std::
uint64_t
> user_timestamp) {
const
DataTrackFrame
frame
(
std::move
(payload), user_timestamp);
return
tryPush
(frame);
}
Result<
void
, LocalDataTrackTryPushError>
LocalDataTrack::tryPush
(
const
std::
uint8_t
* data, std::
size_t
size,
std::optional<std::
uint64_t
> user_timestamp) {
if
(!handle_.
valid
()) {
return
Result<
void
, LocalDataTrackTryPushError>::
failure
(LocalDataTrackTryPushError{
LocalDataTrackTryPushErrorCode::
INVALID_HANDLE
,
"
LocalDataTrack::tryPush: invalid FFI handle
"
});
}
if
(size ==
0
) {
return
Result<
void
, LocalDataTrackTryPushError>::
success
();
}
if
(data ==
nullptr
) {
return
Result<
void
, LocalDataTrackTryPushError>::
failure
(LocalDataTrackTryPushError{
LocalDataTrackTryPushErrorCode::
INTERNAL
,
"
LocalDataTrack::tryPush: payload pointer is null
"
});
}
try
{
proto::FfiRequest req;
auto
* msg = req.
mutable_local_data_track_try_push
();
msg->
set_track_handle
(
static_cast
<
uint64_t
>(handle_.
get
()));
auto
* pf = msg->
mutable_frame
();
pf->
set_payload
(data, size);
if
(user_timestamp.
has_value
()) {
pf->
set_user_timestamp
(user_timestamp.
value
());
}
const
proto::FfiResponse resp =
FfiClient::instance
().
sendRequest
(req);
const
auto
& r = resp.
local_data_track_try_push
();
if
(r.
has_error
()) {
return
Result<
void
, LocalDataTrackTryPushError>::
failure
(
LocalDataTrackTryPushError::fromProto
(r.
error
()));
}
return
Result<
void
, LocalDataTrackTryPushError>::
success
();
}
catch
(
const
std::exception& e) {
return
Result<
void
, LocalDataTrackTryPushError>::
failure
(
LocalDataTrackTryPushError{LocalDataTrackTryPushErrorCode::
INTERNAL
, e.
what
()});
}
}
bool
LocalDataTrack::isPublished
()
const
{
if
(!handle_.
valid
()) {
return
false
;
}
proto::FfiRequest req;
auto
* msg = req.
mutable_local_data_track_is_published
();
msg->
set_track_handle
(
static_cast
<
uint64_t
>(handle_.
get
()));
const
proto::FfiResponse resp =
FfiClient::instance
().
sendRequest
(req);
return
resp.
local_data_track_is_published
().
is_published
();
}
void
LocalDataTrack::unpublishDataTrack
() {
if
(!handle_.
valid
()) {
return
;
}
proto::FfiRequest req;
auto
* msg = req.
mutable_local_data_track_unpublish
();
msg->
set_track_handle
(
static_cast
<
uint64_t
>(handle_.
get
()));
(
void
)
FfiClient::instance
().
sendRequest
(req);
}
}
//
namespace livekit
Back
|
FazBrowse Home
|
New Git URL