-
Notifications
You must be signed in to change notification settings - Fork 5
/
vsg_ring.c
63 lines (52 loc) · 1.21 KB
/
vsg_ring.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/** @file vsg_ring.c - Implementation
** @brief AVPacket ring operation
** @author Zhiwei Zeng
** @date 2018.04.11
**/
/*
Copyright (C) 2018 Zhiwei Zeng.
Copyright (C) 2018 Chengdu ZLT Technology Co., Ltd.
All rights reserved.
This file is part of the railway monitor toolkit and is made available under
the terms of the BSD license (see the COPYING file).
*/
#include <stdio.h>
#include <string.h>
#ifdef _WIN32
#include <windows.h>
#endif
#include "vsg_ring.h"
int ring_put_picture_packet(ring_zone_t *ring)
{
if( ring->in==(RING_BUF_NUM-1)) {
ring->in = (ring->in + 1) % RING_BUF_NUM;
pthread_mutex_lock(&ring->mutex);
ring->count++;
pthread_mutex_unlock(&ring->mutex);
while((ring->count)>0) {
// printf("***ring->count >RING_BUF_CACHE_MIN_QUEUE****\n");
#ifdef _WIN32
Sleep(10);
#else
usleep(10000);
#endif
}
return 0;
}
ring->in = (ring->in + 1) % RING_BUF_NUM;
pthread_mutex_lock(&ring->mutex);
ring->count++;
pthread_mutex_unlock(&ring->mutex);
return 0;
}
int ring_get_picture_packet(ring_zone_t *ring)
{
if((ring->count) <=0) {
return -1;
}
ring->out = (ring->out + 1) % RING_BUF_NUM;
pthread_mutex_lock(&ring->mutex);
ring->count--;
pthread_mutex_unlock(&ring->mutex);
return 0;
}