mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-04 03:11:43 +00:00
Allow Sink.SetSource() to be given an empty source.
In Java, allow source to be null (pointers are not used in C++, so this isn't necessary).
This commit is contained in:
@@ -84,7 +84,11 @@ public class VideoSink {
|
||||
/// provide frames to multiple clients.
|
||||
/// @param source Source
|
||||
public void setSource(VideoSource source) {
|
||||
CameraServerJNI.setSinkSource(m_handle, source.m_handle);
|
||||
if (source == null) {
|
||||
CameraServerJNI.setSinkSource(m_handle, 0);
|
||||
} else {
|
||||
CameraServerJNI.setSinkSource(m_handle, source.m_handle);
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the connected source.
|
||||
|
||||
@@ -671,9 +671,9 @@ void MjpegServerImpl::SetSourceImpl(std::shared_ptr<SourceImpl> source) {
|
||||
if (auto thr = connThread.GetThread()) {
|
||||
if (thr->m_source != source) {
|
||||
bool streaming = thr->m_streaming;
|
||||
if (streaming) thr->m_source->DisableSink();
|
||||
if (thr->m_source && streaming) thr->m_source->DisableSink();
|
||||
thr->m_source = source;
|
||||
if (streaming) thr->m_source->EnableSink();
|
||||
if (source && streaming) thr->m_source->EnableSink();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,13 +67,16 @@ void SinkImpl::SetEnabled(bool enabled) {
|
||||
void SinkImpl::SetSource(std::shared_ptr<SourceImpl> source) {
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
if (m_source == source) return;
|
||||
if (m_source) {
|
||||
if (m_enabledCount > 0) m_source->DisableSink();
|
||||
m_source->RemoveSink();
|
||||
}
|
||||
m_source = source;
|
||||
m_source->AddSink();
|
||||
if (m_enabledCount > 0) m_source->EnableSink();
|
||||
if (m_source) {
|
||||
m_source->AddSink();
|
||||
if (m_enabledCount > 0) m_source->EnableSink();
|
||||
}
|
||||
}
|
||||
SetSourceImpl(source);
|
||||
}
|
||||
|
||||
@@ -407,12 +407,16 @@ void SetSinkSource(CS_Sink sink, CS_Source source, CS_Status* status) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
auto sourceData = Sources::GetInstance().Get(source);
|
||||
if (!sourceData) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
if (source == 0) {
|
||||
data->sink->SetSource(nullptr);
|
||||
} else {
|
||||
auto sourceData = Sources::GetInstance().Get(source);
|
||||
if (!sourceData) {
|
||||
*status = CS_INVALID_HANDLE;
|
||||
return;
|
||||
}
|
||||
data->sink->SetSource(sourceData->source);
|
||||
}
|
||||
data->sink->SetSource(sourceData->source);
|
||||
data->sourceHandle.store(source);
|
||||
Notifier::GetInstance().NotifySinkSourceChanged(data->sink->GetName(), sink,
|
||||
source);
|
||||
|
||||
Reference in New Issue
Block a user