1 
2 /*!
3  ***********************************************************************
4  *  \file: h264_dpb_ctl.c
5  *
6  ***********************************************************************
7  */
8 
9 //#include <limits.h>
10 
11 #include "h264parse.h"
12 
13 
14 // ---------------------------------------------------------------------------
15 // IMPORTANT: note that in this implementation int c is an int not a char
16 // ---------------------------------------------------------------------------
h264_memset(void * buf,uint32_t c,uint32_t num)17 void* h264_memset( void* buf, uint32_t c, uint32_t num )
18 {
19 	uint32_t* buf32 = buf;
20 	uint32_t  size32 = ( num >> 2 );
21 	uint32_t  i;
22 
23 	for ( i = 0; i < size32; i++ )
24 	{
25 		*buf32++ = c;
26 	}
27 
28 	return buf;
29 }
30 
31 
h264_memcpy(void * dest,void * src,uint32_t num)32 void* h264_memcpy( void* dest, void* src, uint32_t num )
33 {
34 	int32_t*	dest32 = dest;
35 	int32_t*    src32 = src;
36 	uint32_t	size32 = ( num >> 2 );
37 	uint32_t	i;
38 
39 	for ( i = 0; i < size32; i++ )
40 	{
41 		*dest32++ = *src32++;
42 	}
43 
44 	return dest;
45 }
46 
47 
48 #ifndef USER_MODE
49 
50 //h264_Parse_Copy_Sps_To_DDR () copy local sps to ddr mem
h264_Parse_Copy_Pps_To_DDR(h264_Info * pInfo,pic_param_set_ptr PPS,uint32_t nPPSId)51 void h264_Parse_Copy_Pps_To_DDR(h264_Info* pInfo, pic_param_set_ptr PPS, uint32_t nPPSId)
52 {
53    uint32_t  copy_size = sizeof(pic_param_set);
54    uint32_t  pps_entry_ptr = pInfo->PPS_PADDR_GL+nPPSId*copy_size;
55 
56    if(nPPSId < MAX_NUM_PPS)
57    {
58 	   cp_using_dma(pps_entry_ptr, (uint32_t)PPS, copy_size, 1, 0);
59    }
60 
61   return;
62 
63 }
64 //end of h264_Parse_Copy_Pps_To_DDR
65 
66 
67 // h264_Parse_Copy_Pps_From_DDR copy a pps with nPPSId from ddr mem to local PPS
h264_Parse_Copy_Pps_From_DDR(h264_Info * pInfo,pic_param_set_ptr PPS,uint32_t nPPSId)68 void h264_Parse_Copy_Pps_From_DDR(h264_Info* pInfo, pic_param_set_ptr PPS, uint32_t nPPSId)
69 {
70 
71   uint32_t copy_size= sizeof(pic_param_set);
72   uint32_t pps_entry_ptr = pInfo->PPS_PADDR_GL+nPPSId*copy_size;
73 
74   if( nPPSId < MAX_NUM_PPS)
75   {
76       cp_using_dma(pps_entry_ptr, (uint32_t)PPS, copy_size, 0, 0);
77   }
78 
79   return;
80 }
81 //end of h264_Parse_Copy_Pps_From_DDR
82 
83 
84 //h264_Parse_Copy_Sps_To_DDR () copy local sps to ddr mem with nSPSId
h264_Parse_Copy_Sps_To_DDR(h264_Info * pInfo,seq_param_set_used_ptr SPS,uint32_t nSPSId)85 void h264_Parse_Copy_Sps_To_DDR(h264_Info* pInfo, seq_param_set_used_ptr SPS, uint32_t nSPSId)
86 {
87    uint32_t  copy_size = sizeof(seq_param_set_used);
88    uint32_t  sps_entry_ptr = pInfo->SPS_PADDR_GL+nSPSId*sizeof(seq_param_set_all);
89 
90    if(nSPSId < MAX_NUM_SPS)
91    {
92 		cp_using_dma(sps_entry_ptr, (uint32_t)SPS, copy_size, 1, 0);
93    }
94 
95    //OS_INFO("SPS->seq_parameter_set_id = %d\n", SPS->seq_parameter_set_id);
96 
97 
98    return;
99 }
100 
101 //end of h264_Parse_Copy_Sps_To_DDR
102 
103 
104 // h264_Parse_Copy_Sps_From_DDR copy a sps with nSPSId from ddr mem to local SPS
h264_Parse_Copy_Sps_From_DDR(h264_Info * pInfo,seq_param_set_used_ptr SPS,uint32_t nSPSId)105 void h264_Parse_Copy_Sps_From_DDR(h264_Info* pInfo, seq_param_set_used_ptr SPS, uint32_t nSPSId)
106 {
107 	uint32_t copy_size= sizeof(seq_param_set_used);
108 	uint32_t sps_entry_ptr = pInfo->SPS_PADDR_GL+nSPSId*sizeof(seq_param_set_all);
109 
110    if(nSPSId < MAX_NUM_SPS)
111    {
112       cp_using_dma(sps_entry_ptr, (uint32_t)SPS, copy_size, 0, 0);
113    }
114 
115    return;
116 
117 }
118 //end of h264_Parse_Copy_Sps_From_DDR
119 
120 //h264_Parse_Copy_Offset_Ref_Frames_To_DDR () copy local offset_ref_frames to ddr mem with nSPSId
h264_Parse_Copy_Offset_Ref_Frames_To_DDR(h264_Info * pInfo,int32_t * pOffset_ref_frames,uint32_t nSPSId)121 void h264_Parse_Copy_Offset_Ref_Frames_To_DDR(h264_Info* pInfo, int32_t* pOffset_ref_frames, uint32_t nSPSId)
122 {
123    uint32_t  copy_size = sizeof(int32_t)*MAX_NUM_REF_FRAMES_IN_PIC_ORDER_CNT_CYCLE;
124    uint32_t  offset_ref_frames_entry_ptr = pInfo->OFFSET_REF_FRAME_PADDR_GL+nSPSId*copy_size;
125 
126    if(nSPSId < MAX_NUM_SPS)
127    {
128 		//cp_using_dma(offset_ref_frames_entry_ptr, (uint32_t)pOffset_ref_frames, copy_size, 1, 0);
129 		h264_memcpy((int32_t *)offset_ref_frames_entry_ptr,pOffset_ref_frames, copy_size);
130    }
131 
132    return;
133 }
134 
135 //end of h264_Parse_Copy_Offset_Ref_Frames_To_DDR
136 
137 
138 // h264_Parse_Copy_Offset_Ref_Frames_From_DDR copy a offset_ref_frames with nSPSId from ddr mem to local offset_ref_frames
h264_Parse_Copy_Offset_Ref_Frames_From_DDR(h264_Info * pInfo,int32_t * pOffset_ref_frames,uint32_t nSPSId)139 void h264_Parse_Copy_Offset_Ref_Frames_From_DDR(h264_Info* pInfo, int32_t* pOffset_ref_frames, uint32_t nSPSId)
140 {
141 	uint32_t copy_size= sizeof(int32_t)*MAX_NUM_REF_FRAMES_IN_PIC_ORDER_CNT_CYCLE;
142 	uint32_t offset_ref_frames_entry_ptr = pInfo->OFFSET_REF_FRAME_PADDR_GL+nSPSId*copy_size;
143 
144    if(nSPSId < MAX_NUM_SPS)
145    {
146       //cp_using_dma(offset_ref_frames_entry_ptr, (uint32_t)pOffset_ref_frames, copy_size, 0, 0);
147 		h264_memcpy(pOffset_ref_frames, (int32_t *)offset_ref_frames_entry_ptr, copy_size);
148    }
149 
150    return;
151 
152 }
153 //end of h264_Parse_Copy_Offset_Ref_Frames_From_DDR
154 
155 
156 //h264_Parse_Check_Sps_Updated_Flag () copy local sps to ddr mem with nSPSId
h264_Parse_Check_Sps_Updated_Flag(h264_Info * pInfo,uint32_t nSPSId)157 uint32_t h264_Parse_Check_Sps_Updated_Flag(h264_Info* pInfo, uint32_t nSPSId)
158 {
159    uint32_t  is_updated=0;
160    uint32_t  copy_size = sizeof(uint32_t);
161    uint32_t  sps_entry_ptr = pInfo->SPS_PADDR_GL+nSPSId*copy_size;
162 
163 
164    if(nSPSId < MAX_NUM_SPS)
165    {
166 		cp_using_dma(sps_entry_ptr, (uint32_t)(&is_updated), copy_size, 1, 0);
167    }
168 
169    //OS_INFO("SPS->seq_parameter_set_id = %d\n", SPS->seq_parameter_set_id);
170 
171 
172    return is_updated;
173 }
174 
175 //end of h264_Parse_Check_Sps_Updated_Flag
176 
177 
178 // h264_Parse_Clear_Sps_Updated_Flag copy a sps with nSPSId from ddr mem to local SPS
h264_Parse_Clear_Sps_Updated_Flag(h264_Info * pInfo,uint32_t nSPSId)179 void h264_Parse_Clear_Sps_Updated_Flag(h264_Info* pInfo, uint32_t nSPSId)
180 {
181     uint32_t  is_updated=0;
182 	uint32_t copy_size= sizeof(uint32_t);
183 	uint32_t sps_entry_ptr = pInfo->SPS_PADDR_GL+nSPSId*copy_size;
184 
185    if(nSPSId < MAX_NUM_SPS)
186    {
187       cp_using_dma(sps_entry_ptr, (uint32_t)(&is_updated), copy_size, 0, 0);
188    }
189 
190    return;
191 
192 }
193 //end of h264_Parse_Clear_Sps_Updated_Flag
194 
195 
196 #endif
197 
198 
199