Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
tsdebug: avoid I/O when file descriptors are not set
  • Loading branch information
perexg committed Dec 12, 2014
1 parent f98f580 commit d18fc1a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/input/mpegts.h
Expand Up @@ -823,9 +823,9 @@ static inline void
tsdebug_write(mpegts_mux_t *mm, uint8_t *buf, size_t len)
{
#if ENABLE_TSDEBUG
ssize_t r = write(mm->mm_tsdebug_fd2, buf, len);
if (r != len && mm->mm_tsdebug_fd2 >= 0)
tvherror("tsdebug", "unable to write input data (%i)", errno);
if (mm->mm_tsdebug_fd2 >= 0)
if (write(mm->mm_tsdebug_fd2, buf, len) != len)
tvherror("tsdebug", "unable to write input data (%i)", errno);
#endif
}

Expand Down
17 changes: 10 additions & 7 deletions src/input/mpegts/mpegts_input.c
Expand Up @@ -566,13 +566,16 @@ mpegts_input_stopped_mux

#if ENABLE_TSDEBUG
tsdebug_packet_t *tp;
close(mmi->mmi_mux->mm_tsdebug_fd);
close(mmi->mmi_mux->mm_tsdebug_fd2);
mmi->mmi_mux->mm_tsdebug_fd = -1;
mmi->mmi_mux->mm_tsdebug_fd2 = -1;
mmi->mmi_mux->mm_tsdebug_pos = 0;
while ((tp = TAILQ_FIRST(&mmi->mmi_mux->mm_tsdebug_packets)) != NULL) {
TAILQ_REMOVE(&mmi->mmi_mux->mm_tsdebug_packets, tp, link);
mpegts_mux_t *mm = mmi->mmi_mux;
if (mm->mm_tsdebug_fd >= 0)
close(mm->mm_tsdebug_fd);
if (mm->mm_tsdebug_fd2 >= 0)
close(mm->mm_tsdebug_fd2);
mm->mm_tsdebug_fd = -1;
mm->mm_tsdebug_fd2 = -1;
mm->mm_tsdebug_pos = 0;
while ((tp = TAILQ_FIRST(&mm->mm_tsdebug_packets)) != NULL) {
TAILQ_REMOVE(&mm->mm_tsdebug_packets, tp, link);
free(tp);
}
#endif
Expand Down

0 comments on commit d18fc1a

Please sign in to comment.