-
Notifications
You must be signed in to change notification settings - Fork 5
/
vsg_init.c
73 lines (65 loc) · 1.87 KB
/
vsg_init.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
62
63
64
65
66
67
68
69
70
71
72
/** @file vsg_init.c - Implementation
** @brief Video stream grabber initialization
** @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 <stdlib.h>
#include <string.h>
#include <time.h>
#include <pthread.h>
#include "vsg_init.h"
#include "vsg_ring.h"
#include "vsg_recorder.h"
/* 线程属性初始化 */
void init_thread_attribute(video_pic_capture_context *context)
{
pthread_attr_init(&context->pattr);
pthread_attr_setdetachstate(&context->pattr, PTHREAD_CREATE_DETACHED);
}
void init_ring_queue(video_pic_capture_context *context)
{
context->yuv_frame = av_frame_alloc();
if(context->yuv_frame == NULL) {
printf("yuv frame malloc fail!!!\n");
return ;
}
context->save_frame = av_frame_alloc();
if(context->save_frame == NULL) {
printf("yuv frame malloc fail!!!\n");
return ;
}
/* 申请所需的空间 */
if( video_malloc_img_convert_buffer(&context->video,&context->picture_convert) == -1) {
printf("malloc img convert buffer error!!!\n");
return ;
}
/*循环队列资源申请*/
context->ring_zone = (ring_zone_t *)calloc(1, sizeof(ring_zone_t)) ;
if(context->ring_zone == NULL) {
printf("ring zone calloc fail\n");
return ;
}
context->ring_zone->in=0;
context->ring_zone->count=0;
context->ring_zone->out=0;
int i;
for(i=0; i<RING_BUF_NUM; i++) {
context->ring_zone->picture[i].packet = (AVPacket *)av_malloc(sizeof(AVPacket));
if(context->ring_zone->picture[i].packet == NULL) {
printf("packet malloc fail!!!\n");
return ;
}
av_init_packet(context->ring_zone->picture[i].packet);
}
pthread_mutex_init(&context->ring_zone->mutex,NULL);
printf("\n*********init_ring_queue is ok************\n");
return;
}