Ticket #915: udp_close.patch

File udp_close.patch, 1.6 KB (added by lbrulet, 5 years ago)
  • libavformat/udp.c

    diff --git a/libavformat/udp.c b/libavformat/udp.c
    index cdcd136..a49b94d 100644
    a b typedef struct { 
    7171    pthread_t circular_buffer_thread; 
    7272    pthread_mutex_t mutex; 
    7373    pthread_cond_t cond; 
     74    int exit_thread; 
    7475#endif 
    7576    uint8_t tmp[UDP_MAX_PKT_SIZE+4]; 
    7677    int remaining_in_dg; 
    static void *circular_buffer_task( void *_URLContext) 
    327328    fd_set rfds; 
    328329    struct timeval tv; 
    329330 
    330     for(;;) { 
     331    while(!s->exit_thread) { 
    331332        int left; 
    332333        int ret; 
    333334        int len; 
    static int udp_open(URLContext *h, const char *uri, int flags) 
    529530        s->fifo = av_fifo_alloc(s->circular_buffer_size); 
    530531        pthread_mutex_init(&s->mutex, NULL); 
    531532        pthread_cond_init(&s->cond, NULL); 
     533        s->exit_thread = 0; 
    532534        if (pthread_create(&s->circular_buffer_thread, NULL, circular_buffer_task, h)) { 
    533535            av_log(h, AV_LOG_ERROR, "pthread_create failed\n"); 
    534536            goto fail; 
    static int udp_write(URLContext *h, const uint8_t *buf, int size) 
    617619static int udp_close(URLContext *h) 
    618620{ 
    619621    UDPContext *s = h->priv_data; 
     622    int ret; 
    620623 
    621624    if (s->is_multicast && (h->flags & AVIO_FLAG_READ)) 
    622625        udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr); 
    623626    closesocket(s->udp_fd); 
    624627    av_fifo_free(s->fifo); 
    625628#if HAVE_PTHREADS 
     629    s->exit_thread = 1; 
     630    ret = pthread_join(s->circular_buffer_thread, NULL); 
     631    if (ret != 0) 
     632    { 
     633        av_log(h, AV_LOG_ERROR, "pthread_join(): %s\n", strerror(ret)); 
     634    } 
    626635    pthread_mutex_destroy(&s->mutex); 
    627636    pthread_cond_destroy(&s->cond); 
    628637#endif