-
Notifications
You must be signed in to change notification settings - Fork 0
/
h264_decoder.c
117 lines (89 loc) · 2.21 KB
/
h264_decoder.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* h264_decoder.c
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "h264_decoder.h"
#include "openh264_decoder.h"
#include "ffm_decoder.h"
#define MAX_DECODER_COUNT 8
static H264_DECODER_FACTORY *gp_decoder_factorys[MAX_DECODER_COUNT] = {0};
int32_t h264_decoder_register(H264_DECODER_FACTORY *pdec_fact)
{
int32_t i = 0;
for (i = 0; i < MAX_DECODER_COUNT; i++)
{
if (gp_decoder_factorys[i] == NULL)
{
gp_decoder_factorys[i] = pdec_fact;
return 0;
}
}
return -1;
}
static H264_DECODER_FACTORY *h264_decoder_find_by_codec_id(H264_DECODER_ID id)
{
int32_t i = 0;
for (i = 0; i < MAX_DECODER_COUNT; i++)
{
if ((gp_decoder_factorys[i] != NULL) && (gp_decoder_factorys[i]->id == id))
{
return gp_decoder_factorys[i];
}
}
return NULL;
}
void h264_decoder_init()
{
int32_t i = 0;
for (i = 0; i < MAX_DECODER_COUNT; i++)
{
gp_decoder_factorys[i] = NULL;
}
ffm_decoder_init();
openh264_decoder_init();
}
H264_DECODER_TH *alloc_decoder_by_id(H264_DECODER_ID id)
{
H264_DECODER_FACTORY * pfact = h264_decoder_find_by_codec_id(id);
if (NULL == pfact)
{
elog("Can not get decoder factory by decoder id[%d].", id);
return NULL;
}
H264_DECODER_TH * pdecth = (H264_DECODER_TH *)malloc(sizeof(struct __H264_DECODER_TH));
if (NULL == pdecth)
{
elog("Alloc memery fail!");
return NULL;
}
memset(pdecth, 0, sizeof(struct __H264_DECODER_TH));
pdecth->_id = id;
if (0 != pfact->init(pdecth))
{
elog("H264_DECODER_TH initial by factory is fail!");
free(pdecth);
return NULL;
}
return pdecth;
}
void free_decoder(H264_DECODER_TH *pdecth)
{
H264_DECODER_FACTORY * pfact = NULL;
if (NULL == pdecth)
{
elog("free_decoder:input is error!");
return ;
}
pfact = h264_decoder_find_by_codec_id(pdecth->_id);
if (NULL == pfact)
{
elog("Can not get decoder factory by decoder id[%d]. Is posible memery leak!", pdecth->_id);
free(pdecth);
return ;
}
pfact->release(pdecth);
free(pdecth);
}