Recognizes if input is ogg or not.
[xiph.git] / theora-fpga / testbenchs / reconrefframes / reconframes.vhd
blob684d26e6147703ece38e6331d20bc574c86bd1b4
1 library std;
2 library ieee;
3 library work;
5 use ieee.std_logic_1164.all;
6 use ieee.numeric_std.all;
7 use work.all;
9 entity ReconFrames is
10 port (
11 Clk,
12 Reset_n : in std_logic;
13 Enable : in std_logic;
15 in_request : out std_logic;
16 in_valid : in std_logic;
17 in_data : in signed(31 downto 0);
19 in_sem_request : out std_logic;
20 in_sem_valid : in std_logic;
21 in_sem_addr : out unsigned(19 downto 0);
22 in_sem_data : in signed(31 downto 0);
24 out_sem_requested : in std_logic;
25 out_sem_valid : out std_logic;
26 out_sem_addr : out unsigned(19 downto 0);
27 out_sem_data : out signed(31 downto 0);
29 out_done : out std_logic;
30 out_eb_done : out std_logic);
31 end ReconFrames;
33 architecture a_ReconFrames of ReconFrames is
34 component ExpandBlock
35 port (
36 Clk,
37 Reset_n : in std_logic;
38 Enable : in std_logic;
40 in_request : out std_logic;
41 in_valid : in std_logic;
42 in_data : in signed(31 downto 0);
44 in_sem_request : out std_logic;
45 in_sem_valid : in std_logic;
46 in_sem_addr : out unsigned(19 downto 0);
47 in_sem_data : in signed(31 downto 0);
49 out_sem_requested : in std_logic;
50 out_sem_valid : out std_logic;
51 out_sem_addr : out unsigned(19 downto 0);
52 out_sem_data : out signed(31 downto 0);
54 in_newframe : in std_logic;
55 out_done : out std_logic);
56 end component;
58 constant LG_MAX_SIZE : natural := 10;
59 constant MEM_ADDR_WIDTH : natural := 20;
60 -------------------------------------------------------------------------------
61 -- ExpandBlock's signals
62 -------------------------------------------------------------------------------
63 signal out_eb_request : std_logic;
64 signal out_eb_valid : std_logic := '0';
65 signal out_eb_data : signed(31 downto 0);
67 signal in_eb_DtBuf_request : std_logic;
68 signal in_eb_DtBuf_valid : std_logic;
69 signal in_eb_DtBuf_addr : unsigned(MEM_ADDR_WIDTH-1 downto 0);
70 signal in_eb_DtBuf_data : signed(31 downto 0);
72 signal out_eb_DtBuf_request : std_logic;
73 signal out_eb_DtBuf_valid : std_logic;
74 signal out_eb_DtBuf_addr : unsigned(19 downto 0);
75 signal out_eb_DtBuf_data : signed(31 downto 0);
77 signal eb_done : std_logic;
78 signal eb_enable : std_logic;
80 -------------------------------------------------------------------------------
81 -- Internal signals
82 -------------------------------------------------------------------------------
83 signal QuantDispFrags : unsigned(LG_MAX_SIZE*2-1 downto 0);
85 signal count : integer;
86 signal countExpand : unsigned(LG_MAX_SIZE*2-1 downto 0);
87 signal s_in_request : std_logic;
89 signal s_out_done : std_logic;
90 -------------------------------------------------------------------------------
91 -- States and sub-states
92 -------------------------------------------------------------------------------
93 type state_t is (stt_Read, stt_Proc);
94 signal state : state_t;
96 type read_state_t is (stt_read_HFragments,
97 stt_read_YPlaneFragments,
98 stt_read_YStride,
99 stt_read_UVPlaneFragments,
100 stt_read_UVStride,
101 stt_read_VFragments,
102 stt_read_ReconYDataOffset,
103 stt_read_ReconUDataOffset,
104 stt_read_ReconVDataOffset,
105 stt_read_QuantDispFrags,
106 stt_read_Others);
107 signal read_state : read_state_t;
109 begin -- a_ReconFrames
111 expandblock0: expandblock
112 port map(
113 Clk => clk,
114 Reset_n => reset_n,
115 Enable => eb_enable,
117 in_request => out_eb_request,
118 in_valid => out_eb_valid,
119 in_data => out_eb_data,
121 in_sem_request => out_eb_DtBuf_request,
122 in_sem_valid => out_eb_DtBuf_valid,
123 in_sem_addr => out_eb_DtBuf_addr,
124 in_sem_data => out_eb_DtBuf_data,
126 out_sem_requested => in_eb_DtBuf_request,
127 out_sem_valid => in_eb_DtBuf_valid,
128 out_sem_addr => in_eb_DtBuf_addr,
129 out_sem_data => in_eb_DtBuf_data,
131 in_newframe => s_out_done, -- Avoid latch
132 out_done => eb_done
135 in_sem_request <= out_eb_DtBuf_request;
136 out_eb_DtBuf_valid <= in_sem_valid;
137 in_sem_addr <= out_eb_DtBuf_addr;
138 out_eb_DtBuf_data <= in_sem_data;
140 in_eb_DtBuf_request <= out_sem_requested;
141 out_sem_valid <= in_eb_DtBuf_valid;
142 out_sem_addr <= in_eb_DtBuf_addr;
143 out_sem_data <= in_eb_DtBuf_data;
144 out_eb_data <= in_data;
145 in_request <= s_in_request;
148 -----------------------------------------------------------------------------
149 -- Put the s_out_done signal on the output port
150 -----------------------------------------------------------------------------
151 out_done <= s_out_done;
153 -----------------------------------------------------------------------------
154 -- Switch the in_request
155 -----------------------------------------------------------------------------
156 process(read_state, out_eb_request, in_valid, Enable)
157 begin
158 s_in_request <= out_eb_request;
159 out_eb_valid <= in_valid;
160 if (read_state = stt_read_QuantDispFrags) then
161 s_in_request <= '1';
162 out_eb_valid <= '0';
163 end if;
164 if (Enable = '0') then
165 s_in_request <= '0';
166 out_eb_valid <= '0';
167 end if;
168 end process;
171 process(clk)
172 variable QuantDispFragsIsZero : std_logic;
173 begin
175 if (clk'event and clk = '1') then
176 if (Reset_n = '0') then
177 s_out_done <= '0';
178 count <= 0;
179 countExpand <= to_unsigned(0, LG_MAX_SIZE*2);
180 eb_enable <= '1';
181 QuantDispFrags <= to_unsigned(0, LG_MAX_SIZE*2);
182 read_state <= stt_read_HFragments;
183 else
184 s_out_done <= '0';
185 out_eb_done <= '0';
186 if (Enable = '1') then
187 case state is
189 when stt_Read =>
191 -- assert false report "read_state = "&read_state_t'image(read_state) severity note;
193 if (s_in_request = '1' and in_valid = '1') then
194 -- assert false report "rf.in_data = "&integer'image(to_integer(in_data)) severity note;
195 count <= count + 1;
196 case read_state is
197 when stt_read_HFragments =>
198 -- Count = 0
199 read_state <= stt_read_YPlaneFragments;
201 when stt_read_YPlaneFragments =>
202 -- Count = 1
203 read_state <= stt_read_YStride;
205 when stt_read_YStride =>
206 -- Count = 2
207 read_state <= stt_read_UVPlaneFragments;
209 when stt_read_UVPlaneFragments =>
210 -- Count = 3
211 read_state <= stt_read_UVStride;
213 when stt_read_UVStride =>
214 -- Count = 4
215 read_state <= stt_read_VFragments;
217 when stt_read_VFragments =>
218 -- Count = 5
219 read_state <= stt_read_ReconYDataOffset;
221 when stt_read_ReconYDataOffset =>
222 -- Count = 6
223 read_state <= stt_read_ReconUDataOffset;
225 when stt_read_ReconUDataOffset =>
226 -- Count = 7
227 read_state <= stt_read_ReconVDataOffset;
229 when stt_read_ReconVDataOffset =>
230 -- Count = 8
231 read_state <= stt_read_QuantDispFrags;
233 when stt_read_QuantDispFrags =>
234 -- Count = 9
235 -- One per Frame
236 -- QuantDispFrags is equal to pbi->CodedBlockIndex of the software
237 read_state <= stt_read_Others;
238 QuantDispFrags <= unsigned(in_data(LG_MAX_SIZE*2-1 downto 0));
239 if (in_data(LG_MAX_SIZE*2-1 downto 0) = 0) then
240 state <= stt_Proc;
241 end if;
242 when others =>
243 -----------------------------------------------------------
244 -- Forward to ExpandBlock the parameters below that are
245 -- received only one time pre frame
246 -----------------------------------------------------------
247 -- For Count = 10 to Count = 73 receive the
248 -- pbi->dequant_Y_coeffs matrix
249 -----------------------------------------------------------
250 -- For Count = 74 to Count = 137 receive the
251 -- pbi->dequant_U_coeffs matrix
252 -----------------------------------------------------------
253 -- For Count = 138 to Count = 201 receive the
254 -- pbi->dequant_V_coeffs matrix
255 -----------------------------------------------------------
256 -- For Count = 202 to Count = 265 receive the
257 -- dequant_InterY_coeffs matrix
258 -----------------------------------------------------------
259 -- For Count = 266 to Count = 329 receive the
260 -- dequant_InterU_coeffs matrix
261 -----------------------------------------------------------
262 -- For Count = 330 to Count = 393 receive the
263 -- dequant_InterV_coeffs matrix
264 -----------------------------------------------------------
265 -- If Count = 394 receive the pbi->FrameType value
266 -----------------------------------------------------------
267 -- If Count = 395 receive the
268 -- Offset of the GoldenFrame Buffer
269 -----------------------------------------------------------
270 -- If Count = 396 receive the
271 -- Offset of the LastFrame Buffer
272 -----------------------------------------------------------
273 -- If Count = 397 receive the
274 -- Offset of the ThisFrame Buffer
275 -----------------------------------------------------------
277 -----------------------------------------------------------
278 -- Forward to ExpandBlock the parameters below that are
279 -- received for all fragments
280 -----------------------------------------------------------
281 -- For Count = 398 to Count = 461 receive the
282 -- pbi->QFragData(number of the fragment to be expanded)
283 -- matrix
284 ------------------------------------------------------------
285 -- If Count = 462 receive the
286 -- pbi->FragCodingMethod(number of the fragment to be expanded)
287 -- value
288 -----------------------------------------------------------
289 -- If Count = 463 receive the
290 -- pbi->FragCoefEOB(number of the fragment to be expanded)
291 -- value
292 -----------------------------------------------------------
293 -- If Count = 464 receive the
294 -- (pbi->FragMVect(number of the fragment to be expanded)).x
295 -- value
296 -----------------------------------------------------------
297 -- If Count = 465 receive the
298 -- (pbi->FragMVect(number of the fragment to be expanded)).y
299 -- value
300 -----------------------------------------------------------
301 -- If Count = 466 receive the
302 -- (number of fragment to be expanded)
303 -----------------------------------------------------------
304 if (count = 466) then
305 state <= stt_Proc;
306 count <= 398;
307 end if;
308 end case;
309 end if;
311 when stt_Proc =>
312 if (QuantDispFrags = 0) then
313 QuantDispFragsIsZero := '1';
314 else
315 QuantDispFragsIsZero := '0';
316 end if;
318 if (eb_done = '1' or QuantDispFragsIsZero = '1') then
319 out_eb_done <= '1';
320 countExpand <= countExpand + 1;
321 state <= stt_Read;
322 if (countExpand = TO_INTEGER(QuantDispFrags-1) or QuantDispFragsIsZero = '1') then
323 count <= 9;
324 read_state <= stt_read_QuantDispFrags;
325 countExpand <= to_unsigned(0, LG_MAX_SIZE*2);
326 s_out_done <= '1';
327 end if;
328 end if;
330 end case;
331 end if;
332 end if;
333 end if;
334 end process;
335 end a_ReconFrames;