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:
Peter Johnson
2016-12-28 00:47:26 -08:00
parent b91ab0b44f
commit 23135d7a5a
4 changed files with 21 additions and 10 deletions

View File

@@ -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.

View File

@@ -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();
}
}
}

View File

@@ -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);
}

View File

@@ -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);