@@ -119,8 +119,12 @@ video_rxtx::video_rxtx(const char *protocol_name,
119119
120120video_rxtx::~video_rxtx () noexcept
121121{
122+ if (!pthread_equal (m_receiver_thread_id, PTHREAD_NULL)) {
123+ pthread_join (m_receiver_thread_id, nullptr );
124+ }
125+
122126 join ();
123- if (!m_poisoned && m_compression) {
127+ if (!m_sender_poisoned && m_compression != nullptr ) {
124128 send (NULL );
125129 compress_pop (m_compression);
126130 }
@@ -135,15 +139,20 @@ video_rxtx::~video_rxtx() noexcept
135139void
136140video_rxtx::join () noexcept
137141{
138- if (m_joined) {
142+ if (!pthread_equal (m_receiver_thread_id, PTHREAD_NULL)) {
143+ pthread_join (m_receiver_thread_id, nullptr );
144+ m_receiver_thread_id = PTHREAD_NULL;
145+ }
146+
147+ if (m_sender_joined) {
139148 return ;
140149 }
141150 send (NULL ); // pass poisoned pill
142- pthread_join (m_thread_id , NULL );
151+ pthread_join (m_sender_thread_id , NULL );
143152 if (m_impl_funcs != nullptr && m_impl_funcs->join_sender != nullptr ) {
144153 m_impl_funcs->join_sender (m_impl_state);
145154 }
146- m_joined = true ;
155+ m_sender_joined = true ;
147156}
148157
149158const char *
@@ -162,11 +171,11 @@ video_rxtx::get_long_name(string const &short_name) noexcept
162171void
163172video_rxtx::send (shared_ptr<video_frame> frame) noexcept
164173{
165- if (!frame && m_poisoned ) {
174+ if (!frame && m_sender_poisoned ) {
166175 return ;
167176 }
168177 if (!frame) {
169- m_poisoned = true ;
178+ m_sender_poisoned = true ;
170179 } else {
171180 m_input_codec = frame->color_spec ;
172181 }
@@ -257,10 +266,23 @@ video_rxtx::create(string const &proto, const struct vrxtx_params *params,
257266 return nullptr ;
258267 }
259268
260- int rc = pthread_create (&ret->m_thread_id , nullptr , video_rxtx::sender_thread,
269+ if ((params->rxtx_mode & MODE_RECEIVER) != 0U ) {
270+ if (ret->m_impl_funcs ->receiver_routine == nullptr ) {
271+ MSG (ERROR,
272+ " Selected RX/TX mode doesn't support receiving.\n " );
273+ delete ret;
274+ return nullptr ;
275+ }
276+ int rc = pthread_create (&ret->m_receiver_thread_id , nullptr ,
277+ ret->m_impl_funcs ->receiver_routine ,
278+ ret->m_impl_state );
279+ assert (rc == 0 );
280+ }
281+
282+ int rc = pthread_create (&ret->m_sender_thread_id , nullptr , video_rxtx::sender_thread,
261283 (void *) ret);
262284 assert (rc == 0 );
263- ret->m_joined = false ;
285+ ret->m_sender_joined = false ;
264286
265287 return ret;
266288}
0 commit comments