forked from AndDiSa/platform_manifest-Grouper-AOSP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
external_libavc.patch
788 lines (742 loc) · 31.9 KB
/
external_libavc.patch
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
diff --git a/decoder/ih264d_api.c b/decoder/ih264d_api.c
index 2cde456..70e19aa 100644
--- a/decoder/ih264d_api.c
+++ b/decoder/ih264d_api.c
@@ -1623,6 +1623,109 @@ UWORD32 ih264d_map_error(UWORD32 i4_err_status)
}
+UWORD32 ih264d_get_outbuf_size(WORD32 pic_wd,
+ UWORD32 pic_ht,
+ UWORD8 u1_chroma_format,
+ UWORD32 *p_buf_size)
+{
+ UWORD32 u4_min_num_out_bufs = 0;
+
+ if(u1_chroma_format == IV_YUV_420P)
+ u4_min_num_out_bufs = MIN_OUT_BUFS_420;
+ else if(u1_chroma_format == IV_YUV_422ILE)
+ u4_min_num_out_bufs = MIN_OUT_BUFS_422ILE;
+ else if(u1_chroma_format == IV_RGB_565)
+ u4_min_num_out_bufs = MIN_OUT_BUFS_RGB565;
+ else if((u1_chroma_format == IV_YUV_420SP_UV)
+ || (u1_chroma_format == IV_YUV_420SP_VU))
+ u4_min_num_out_bufs = MIN_OUT_BUFS_420SP;
+
+ if(u1_chroma_format == IV_YUV_420P)
+ {
+ p_buf_size[0] = (pic_wd * pic_ht);
+ p_buf_size[1] = (pic_wd * pic_ht) >> 2;
+ p_buf_size[2] = (pic_wd * pic_ht) >> 2;
+ }
+ else if(u1_chroma_format == IV_YUV_422ILE)
+ {
+ p_buf_size[0] = (pic_wd * pic_ht) * 2;
+ p_buf_size[1] = p_buf_size[2] = 0;
+ }
+ else if(u1_chroma_format == IV_RGB_565)
+ {
+ p_buf_size[0] = (pic_wd * pic_ht) * 2;
+ p_buf_size[1] = p_buf_size[2] = 0;
+ }
+ else if((u1_chroma_format == IV_YUV_420SP_UV)
+ || (u1_chroma_format == IV_YUV_420SP_VU))
+ {
+ p_buf_size[0] = (pic_wd * pic_ht);
+ p_buf_size[1] = (pic_wd * pic_ht) >> 1;
+ p_buf_size[2] = 0;
+ }
+
+ return u4_min_num_out_bufs;
+}
+
+WORD32 check_app_out_buf_size(dec_struct_t *ps_dec)
+{
+ UWORD32 au4_min_out_buf_size[IVD_VIDDEC_MAX_IO_BUFFERS];
+ UWORD32 u4_min_num_out_bufs, i;
+ UWORD32 pic_wd, pic_ht;
+
+ if(0 == ps_dec->u4_share_disp_buf)
+ {
+ pic_wd = ps_dec->u2_disp_width;
+ pic_ht = ps_dec->u2_disp_height;
+
+ }
+ else
+ {
+ pic_wd = ps_dec->u2_frm_wd_y;
+ pic_ht = ps_dec->u2_frm_ht_y;
+ }
+
+ if(ps_dec->u4_app_disp_width > pic_wd)
+ pic_wd = ps_dec->u4_app_disp_width;
+
+ u4_min_num_out_bufs = ih264d_get_outbuf_size(pic_wd, pic_ht,
+ ps_dec->u1_chroma_format,
+ &au4_min_out_buf_size[0]);
+
+
+ if(0 == ps_dec->u4_share_disp_buf)
+ {
+ if(ps_dec->ps_out_buffer->u4_num_bufs < u4_min_num_out_bufs)
+ return IV_FAIL;
+
+ for(i = 0; i < u4_min_num_out_bufs; i++)
+ {
+ if(ps_dec->ps_out_buffer->u4_min_out_buf_size[i]
+ < au4_min_out_buf_size[i])
+ return (IV_FAIL);
+ }
+ }
+ else
+ {
+ if(ps_dec->disp_bufs[0].u4_num_bufs < u4_min_num_out_bufs)
+ return IV_FAIL;
+
+ for(i = 0; i < u4_min_num_out_bufs; i++)
+ {
+ /* We need to check only with the disp_buffer[0], because we have
+ * already ensured that all the buffers are of the same size in
+ * ih264d_set_display_frame.
+ */
+ if(ps_dec->disp_bufs[0].u4_bufsize[i] < au4_min_out_buf_size[i])
+ return (IV_FAIL);
+ }
+
+ }
+
+ return (IV_SUCCESS);
+}
+
+
/*****************************************************************************/
/* */
/* Function Name : ih264d_video_decode */
@@ -1721,7 +1824,8 @@ WORD32 ih264d_video_decode(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
&& ps_dec->i4_decode_header == 0)
{
UWORD32 i;
- if(ps_dec->ps_out_buffer->u4_num_bufs == 0)
+ if((ps_dec->ps_out_buffer->u4_num_bufs == 0) ||
+ (ps_dec->ps_out_buffer->u4_num_bufs > IVD_VIDDEC_MAX_IO_BUFFERS))
{
ps_dec_op->u4_error_code |= 1 << IVD_UNSUPPORTEDPARAM;
ps_dec_op->u4_error_code |= IVD_DISP_FRM_ZERO_OP_BUFS;
@@ -1865,6 +1969,13 @@ WORD32 ih264d_video_decode(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
&(ps_dec->s_disp_op));
if(0 == ps_dec->s_disp_op.u4_error_code)
{
+ /* check output buffer size given by the application */
+ if(check_app_out_buf_size(ps_dec) != IV_SUCCESS)
+ {
+ ps_dec_op->u4_error_code= IVD_DISP_FRM_ZERO_OP_BUF_SIZE;
+ return (IV_FAIL);
+ }
+
ps_dec->u4_fmt_conv_cur_row = 0;
ps_dec->u4_fmt_conv_num_rows = ps_dec->s_disp_frame_info.u4_y_ht;
ih264d_format_convert(ps_dec, &(ps_dec->s_disp_op),
@@ -2094,7 +2205,8 @@ WORD32 ih264d_video_decode(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
|| (ret == IVD_MEM_ALLOC_FAILED)
|| (ret == ERROR_UNAVAIL_PICBUF_T)
|| (ret == ERROR_UNAVAIL_MVBUF_T)
- || (ret == ERROR_INV_SPS_PPS_T))
+ || (ret == ERROR_INV_SPS_PPS_T)
+ || (ret == IVD_DISP_FRM_ZERO_OP_BUF_SIZE))
{
ps_dec->u4_slice_start_code_found = 0;
break;
@@ -2148,7 +2260,7 @@ WORD32 ih264d_video_decode(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
}
while(( header_data_left == 1)||(frame_data_left == 1));
- if((ps_dec->u4_slice_start_code_found == 1)
+ if((ps_dec->u4_pic_buf_got == 1)
&& (ret != IVD_MEM_ALLOC_FAILED)
&& ps_dec->u2_total_mbs_coded < ps_dec->u2_frm_ht_in_mbs * ps_dec->u2_frm_wd_in_mbs)
{
@@ -2290,7 +2402,7 @@ WORD32 ih264d_video_decode(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
}
- if((ps_dec->u4_slice_start_code_found == 1)
+ if((ps_dec->u4_pic_buf_got == 1)
&& (ERROR_DANGLING_FIELD_IN_PIC != i4_err_status))
{
/*
@@ -2316,8 +2428,7 @@ WORD32 ih264d_video_decode(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
/* if new frame in not found (if we are still getting slices from previous frame)
* ih264d_deblock_display is not called. Such frames will not be added to reference /display
*/
- if (((ps_dec->ps_dec_err_status->u1_err_flag & REJECT_CUR_PIC) == 0)
- && (ps_dec->u4_pic_buf_got == 1))
+ if ((ps_dec->ps_dec_err_status->u1_err_flag & REJECT_CUR_PIC) == 0)
{
/* Calling Function to deblock Picture and Display */
ret = ih264d_deblock_display(ps_dec);
@@ -2549,6 +2660,7 @@ WORD32 ih264d_set_display_frame(iv_obj_t *dec_hdl,
void *pv_api_op)
{
+ UWORD32 u4_disp_buf_size[3], u4_num_disp_bufs;
ivd_set_display_frame_ip_t *dec_disp_ip;
ivd_set_display_frame_op_t *dec_disp_op;
@@ -2568,8 +2680,36 @@ WORD32 ih264d_set_display_frame(iv_obj_t *dec_hdl,
u4_num_bufs = MIN(u4_num_bufs, MAX_DISP_BUFS_NEW);
ps_dec->u4_num_disp_bufs = u4_num_bufs;
+
+ /* Get the number and sizes of the first buffer. Compare this with the
+ * rest to make sure all the buffers are of the same size.
+ */
+ u4_num_disp_bufs = dec_disp_ip->s_disp_buffer[0].u4_num_bufs;
+
+ u4_disp_buf_size[0] =
+ dec_disp_ip->s_disp_buffer[0].u4_min_out_buf_size[0];
+ u4_disp_buf_size[1] =
+ dec_disp_ip->s_disp_buffer[0].u4_min_out_buf_size[1];
+ u4_disp_buf_size[2] =
+ dec_disp_ip->s_disp_buffer[0].u4_min_out_buf_size[2];
+
for(i = 0; i < u4_num_bufs; i++)
{
+ if(dec_disp_ip->s_disp_buffer[i].u4_num_bufs != u4_num_disp_bufs)
+ {
+ return IV_FAIL;
+ }
+
+ if((dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[0]
+ != u4_disp_buf_size[0])
+ || (dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[1]
+ != u4_disp_buf_size[1])
+ || (dec_disp_ip->s_disp_buffer[i].u4_min_out_buf_size[2]
+ != u4_disp_buf_size[2]))
+ {
+ return IV_FAIL;
+ }
+
ps_dec->disp_bufs[i].u4_num_bufs =
dec_disp_ip->s_disp_buffer[i].u4_num_bufs;
@@ -2843,27 +2983,15 @@ WORD32 ih264d_get_buf_info(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
UWORD16 pic_wd, pic_ht;
ivd_ctl_getbufinfo_op_t *ps_ctl_op =
(ivd_ctl_getbufinfo_op_t*)pv_api_op;
+ UWORD32 au4_min_out_buf_size[IVD_VIDDEC_MAX_IO_BUFFERS];
UNUSED(pv_api_ip);
+
ps_ctl_op->u4_error_code = 0;
ps_dec = (dec_struct_t *)(dec_hdl->pv_codec_handle);
ps_ctl_op->u4_min_num_in_bufs = MIN_IN_BUFS;
- if(ps_dec->u1_chroma_format == IV_YUV_420P)
- ps_ctl_op->u4_min_num_out_bufs = MIN_OUT_BUFS_420;
- else if(ps_dec->u1_chroma_format == IV_YUV_422ILE)
- ps_ctl_op->u4_min_num_out_bufs = MIN_OUT_BUFS_422ILE;
- else if(ps_dec->u1_chroma_format == IV_RGB_565)
- ps_ctl_op->u4_min_num_out_bufs = MIN_OUT_BUFS_RGB565;
- else if((ps_dec->u1_chroma_format == IV_YUV_420SP_UV)
- || (ps_dec->u1_chroma_format == IV_YUV_420SP_VU))
- ps_ctl_op->u4_min_num_out_bufs = MIN_OUT_BUFS_420SP;
- else
- {
- //Invalid chroma format; Error code may be updated, verify in testing if needed
- return IV_FAIL;
- }
ps_ctl_op->u4_num_disp_bufs = 1;
@@ -2930,37 +3058,15 @@ WORD32 ih264d_get_buf_info(iv_obj_t *dec_hdl, void *pv_api_ip, void *pv_api_op)
ps_ctl_op->u4_num_disp_bufs, 32);
}
- /*!*/
- if(ps_dec->u1_chroma_format == IV_YUV_420P)
- {
- ps_ctl_op->u4_min_out_buf_size[0] = (pic_wd * pic_ht);
- ps_ctl_op->u4_min_out_buf_size[1] = (pic_wd * pic_ht)
- >> 2;
- ps_ctl_op->u4_min_out_buf_size[2] = (pic_wd * pic_ht)
- >> 2;
- }
- else if(ps_dec->u1_chroma_format == IV_YUV_422ILE)
- {
- ps_ctl_op->u4_min_out_buf_size[0] = (pic_wd * pic_ht)
- * 2;
- ps_ctl_op->u4_min_out_buf_size[1] =
- ps_ctl_op->u4_min_out_buf_size[2] = 0;
- }
- else if(ps_dec->u1_chroma_format == IV_RGB_565)
- {
- ps_ctl_op->u4_min_out_buf_size[0] = (pic_wd * pic_ht)
- * 2;
- ps_ctl_op->u4_min_out_buf_size[1] =
- ps_ctl_op->u4_min_out_buf_size[2] = 0;
- }
- else if((ps_dec->u1_chroma_format == IV_YUV_420SP_UV)
- || (ps_dec->u1_chroma_format == IV_YUV_420SP_VU))
+ ps_ctl_op->u4_min_num_out_bufs = ih264d_get_outbuf_size(
+ pic_wd, pic_ht, ps_dec->u1_chroma_format,
+ &au4_min_out_buf_size[0]);
+
+ for(i = 0; i < ps_ctl_op->u4_min_num_out_bufs; i++)
{
- ps_ctl_op->u4_min_out_buf_size[0] = (pic_wd * pic_ht);
- ps_ctl_op->u4_min_out_buf_size[1] = (pic_wd * pic_ht)
- >> 1;
- ps_ctl_op->u4_min_out_buf_size[2] = 0;
+ ps_ctl_op->u4_min_out_buf_size[i] = au4_min_out_buf_size[i];
}
+
ps_dec->u4_num_disp_bufs_requested = ps_ctl_op->u4_num_disp_bufs;
return IV_SUCCESS;
diff --git a/decoder/ih264d_dpb_mgr.c b/decoder/ih264d_dpb_mgr.c
index 0a61ffd..7e0db74 100644
--- a/decoder/ih264d_dpb_mgr.c
+++ b/decoder/ih264d_dpb_mgr.c
@@ -721,7 +721,7 @@ WORD32 ih264d_ref_idx_reordering(dec_struct_t *ps_dec, UWORD8 uc_lx)
UWORD16 ui_max_frame_num =
ps_dec->ps_cur_sps->u2_u4_max_pic_num_minus1 + 1;
- WORD32 i;
+ WORD32 i, count = 0;
UWORD32 ui_remapIdc, ui_nextUev;
WORD16 u2_pred_frame_num = u4_cur_pic_num;
WORD32 i_temp;
@@ -742,7 +742,8 @@ WORD32 ih264d_ref_idx_reordering(dec_struct_t *ps_dec, UWORD8 uc_lx)
ui_remapIdc = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
- while(ui_remapIdc != 3)
+ while((ui_remapIdc != 3)
+ && (count < ps_cur_slice->u1_num_ref_idx_lx_active[uc_lx]))
{
ui_nextUev = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
if(ui_remapIdc != 2)
@@ -811,6 +812,7 @@ WORD32 ih264d_ref_idx_reordering(dec_struct_t *ps_dec, UWORD8 uc_lx)
ui_remapIdc = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
/* Get the remapping_idc - 0/1/2/3 */
+ count++;
}
//Handle the ref indices that were not remapped
diff --git a/decoder/ih264d_parse_bslice.c b/decoder/ih264d_parse_bslice.c
index 772964a..f087f8d 100644
--- a/decoder/ih264d_parse_bslice.c
+++ b/decoder/ih264d_parse_bslice.c
@@ -1197,7 +1197,8 @@ void ih264d_get_implicit_weights(dec_struct_t *ps_dec)
struct pic_buffer_t *ps_pic_buff0, *ps_pic_buff1;
WORD16 i2_dist_scale_factor;
WORD16 i16_tb, i16_td, i16_tx;
- UWORD32 u4_poc0, u4_poc1;
+ WORD32 i4_tb, i4_td;
+ WORD32 i4_poc0, i4_poc1;
UWORD32 ui_temp0, ui_temp1;
UWORD8 uc_num_ref_idx_l0_active, uc_num_ref_idx_l1_active;
@@ -1210,18 +1211,18 @@ void ih264d_get_implicit_weights(dec_struct_t *ps_dec)
for(i = 0; i < uc_num_ref_idx_l0_active; i++)
{
ps_pic_buff0 = ps_dec->ps_ref_pic_buf_lx[0][i];
- u4_poc0 = ps_pic_buff0->i4_avg_poc;
+ i4_poc0 = ps_pic_buff0->i4_avg_poc;
for(j = 0; j < uc_num_ref_idx_l1_active; j++)
{
ps_pic_buff1 = ps_dec->ps_ref_pic_buf_lx[1][j];
- u4_poc1 = ps_pic_buff1->i4_avg_poc;
+ i4_poc1 = ps_pic_buff1->i4_avg_poc;
- if(u4_poc1 != u4_poc0)
+ if(i4_poc1 != i4_poc0)
{
- i16_tb = ps_dec->ps_cur_pic->i4_poc - u4_poc0;
- i16_tb = CLIP3(-128, 127, i16_tb);
- i16_td = u4_poc1 - u4_poc0;
- i16_td = CLIP3(-128, 127, i16_td);
+ i4_tb = ps_dec->ps_cur_pic->i4_poc - i4_poc0;
+ i16_tb = CLIP3(-128, 127, i4_tb);
+ i4_td = i4_poc1 - i4_poc0;
+ i16_td = CLIP3(-128, 127, i4_td);
i16_tx = (16384 + ABS(SIGN_POW2_DIV(i16_td, 1))) / i16_td;
i2_dist_scale_factor = CLIP3(-1024, 1023,
(((i16_tb * i16_tx) + 32) >> 6));
@@ -1272,7 +1273,7 @@ void ih264d_get_implicit_weights(dec_struct_t *ps_dec)
u2_l0_idx += MAX_REF_BUFS;
}
ps_pic_buff0 = ps_dec->ps_ref_pic_buf_lx[0][u2_l0_idx];
- u4_poc0 = ps_pic_buff0->i4_poc;
+ i4_poc0 = ps_pic_buff0->i4_poc;
for(j = 0; j < (uc_num_ref_idx_l1_active << 1); j++)
{
UWORD16 u2_l1_idx;
@@ -1285,13 +1286,13 @@ void ih264d_get_implicit_weights(dec_struct_t *ps_dec)
u2_l1_idx += MAX_REF_BUFS;
}
ps_pic_buff1 = ps_dec->ps_ref_pic_buf_lx[1][u2_l1_idx];
- u4_poc1 = ps_pic_buff1->i4_poc;
- if(u4_poc1 != u4_poc0)
+ i4_poc1 = ps_pic_buff1->i4_poc;
+ if(i4_poc1 != i4_poc0)
{
- i16_tb = i4_cur_poc - u4_poc0;
- i16_tb = CLIP3(-128, 127, i16_tb);
- i16_td = u4_poc1 - u4_poc0;
- i16_td = CLIP3(-128, 127, i16_td);
+ i4_tb = i4_cur_poc - i4_poc0;
+ i16_tb = CLIP3(-128, 127, i4_tb);
+ i4_td = i4_poc1 - i4_poc0;
+ i16_td = CLIP3(-128, 127, i4_td);
i16_tx = (16384 + ABS(SIGN_POW2_DIV(i16_td, 1)))
/ i16_td;
i2_dist_scale_factor = CLIP3(
@@ -1398,7 +1399,8 @@ WORD32 ih264d_parse_bslice(dec_struct_t * ps_dec, UWORD16 u2_first_mb_in_slice)
{
u1_max_ref_idx = MAX_FRAMES << 1;
}
- if((u4_temp > u1_max_ref_idx) || (ui_temp1 > u1_max_ref_idx))
+ if((u4_temp > u1_max_ref_idx) || (ui_temp1 > u1_max_ref_idx)
+ || (u4_temp < 1) || (ui_temp1 < 1))
{
return ERROR_NUM_REF;
}
@@ -1531,10 +1533,7 @@ WORD32 ih264d_parse_bslice(dec_struct_t * ps_dec, UWORD16 u2_first_mb_in_slice)
}
num_entries = ((2 * num_entries) + 1);
- if(BASE_PROFILE_IDC != ps_dec->ps_cur_sps->u1_profile_idc)
- {
- num_entries *= 2;
- }
+ num_entries *= 2;
size = num_entries * sizeof(void *);
size += PAD_MAP_IDX_POC * sizeof(void *);
diff --git a/decoder/ih264d_parse_headers.c b/decoder/ih264d_parse_headers.c
index d8c37a6..47db800 100644
--- a/decoder/ih264d_parse_headers.c
+++ b/decoder/ih264d_parse_headers.c
@@ -904,12 +904,25 @@ WORD32 ih264d_parse_sps(dec_struct_t *ps_dec, dec_bit_stream_t *ps_bitstrm)
ps_dec->u1_res_changed = 1;
return IVD_RES_CHANGED;
}
+
+ if((ps_dec->i4_header_decoded & 1) && (ps_dec->u2_disp_width != i4_cropped_wd))
+ {
+ ps_dec->u1_res_changed = 1;
+ return IVD_RES_CHANGED;
+ }
+
if((ps_dec->i4_header_decoded & 1) && (ps_dec->u2_pic_ht != u2_pic_ht))
{
ps_dec->u1_res_changed = 1;
return IVD_RES_CHANGED;
}
+ if((ps_dec->i4_header_decoded & 1) && (ps_dec->u2_disp_height != i4_cropped_ht))
+ {
+ ps_dec->u1_res_changed = 1;
+ return IVD_RES_CHANGED;
+ }
+
/* Check for unsupported resolutions */
if((u2_pic_wd > H264_MAX_FRAME_WIDTH) || (u2_pic_ht > H264_MAX_FRAME_HEIGHT))
{
diff --git a/decoder/ih264d_parse_pslice.c b/decoder/ih264d_parse_pslice.c
index bcfbe05..9b9256b 100644
--- a/decoder/ih264d_parse_pslice.c
+++ b/decoder/ih264d_parse_pslice.c
@@ -1696,10 +1696,8 @@ WORD32 ih264d_mark_err_slice_skip(dec_struct_t * ps_dec,
num_entries = 1;
}
num_entries = ((2 * num_entries) + 1);
- if(BASE_PROFILE_IDC != ps_dec->ps_cur_sps->u1_profile_idc)
- {
- num_entries *= 2;
- }
+ num_entries *= 2;
+
size = num_entries * sizeof(void *);
size += PAD_MAP_IDX_POC * sizeof(void *);
@@ -1963,7 +1961,7 @@ WORD32 ih264d_parse_pslice(dec_struct_t *ps_dec, UWORD16 u2_first_mb_in_slice)
UWORD8 u1_max_ref_idx = MAX_FRAMES << u1_field_pic_flag;
- if(u4_temp > u1_max_ref_idx)
+ if(u4_temp > u1_max_ref_idx || u4_temp < 1)
{
return ERROR_NUM_REF;
}
@@ -2063,10 +2061,7 @@ WORD32 ih264d_parse_pslice(dec_struct_t *ps_dec, UWORD16 u2_first_mb_in_slice)
num_entries = 1;
}
num_entries = ((2 * num_entries) + 1);
- if(BASE_PROFILE_IDC != ps_dec->ps_cur_sps->u1_profile_idc)
- {
- num_entries *= 2;
- }
+ num_entries *= 2;
size = num_entries * sizeof(void *);
size += PAD_MAP_IDX_POC * sizeof(void *);
diff --git a/decoder/ih264d_parse_slice.c b/decoder/ih264d_parse_slice.c
index fad2dff..063594b 100644
--- a/decoder/ih264d_parse_slice.c
+++ b/decoder/ih264d_parse_slice.c
@@ -72,6 +72,7 @@
#include "ih264d_parse_islice.h"
#define RET_LAST_SKIP 0x80000000
+WORD32 check_app_out_buf_size(dec_struct_t *ps_dec);
/*!
**************************************************************************
* \if Function name : ih264d_form_pred_weight_matrix \endif
@@ -181,6 +182,10 @@ WORD32 ih264d_start_of_pic(dec_struct_t *ps_dec,
H264_MUTEX_LOCK(&ps_dec->process_disp_mutex);
+ /* check output buffer size given by the application */
+ if(check_app_out_buf_size(ps_dec) != IV_SUCCESS)
+ return IVD_DISP_FRM_ZERO_OP_BUF_SIZE;
+
ps_prev_poc->i4_pic_order_cnt_lsb = ps_cur_poc->i4_pic_order_cnt_lsb;
ps_prev_poc->i4_pic_order_cnt_msb = ps_cur_poc->i4_pic_order_cnt_msb;
ps_prev_poc->i4_delta_pic_order_cnt_bottom =
@@ -436,11 +441,23 @@ WORD32 ih264d_start_of_pic(dec_struct_t *ps_dec,
ps_dec->au1_pic_buf_ref_flag[cur_pic_buf_id] = 0;
{
- /*make first entry of list0 point to cur pic,so that if first Islice is in error, ref pic struct will have valid entries*/
+ /*make first entry of list0 and list1 point to cur pic,
+ *so that if first slice is in error, ref pic struct will have valid entries*/
ps_dec->ps_ref_pic_buf_lx[0] = ps_dec->ps_dpb_mgr->ps_init_dpb[0];
+ ps_dec->ps_ref_pic_buf_lx[1] = ps_dec->ps_dpb_mgr->ps_init_dpb[1];
*(ps_dec->ps_dpb_mgr->ps_init_dpb[0][0]) = *ps_cur_pic;
/* Initialize for field reference as well */
*(ps_dec->ps_dpb_mgr->ps_init_dpb[0][MAX_REF_BUFS]) = *ps_cur_pic;
+
+ *(ps_dec->ps_dpb_mgr->ps_mod_dpb[0][0]) = *ps_cur_pic;
+ /* Initialize for field reference as well */
+ *(ps_dec->ps_dpb_mgr->ps_mod_dpb[0][MAX_REF_BUFS]) = *ps_cur_pic;
+ *(ps_dec->ps_dpb_mgr->ps_init_dpb[1][0]) = *ps_cur_pic;
+ /* Initialize for field reference as well */
+ *(ps_dec->ps_dpb_mgr->ps_init_dpb[1][MAX_REF_BUFS]) = *ps_cur_pic;
+ *(ps_dec->ps_dpb_mgr->ps_mod_dpb[1][0]) = *ps_cur_pic;
+ /* Initialize for field reference as well */
+ *(ps_dec->ps_dpb_mgr->ps_mod_dpb[1][MAX_REF_BUFS]) = *ps_cur_pic;
}
if(!ps_dec->ps_cur_pic)
@@ -962,6 +979,69 @@ WORD32 ih264d_end_of_pic(dec_struct_t *ps_dec)
return OK;
}
+
+/*!
+ **************************************************************************
+ * \if Function name : ih264d_fix_error_in_dpb \endif
+ *
+ * \brief
+ * fix error in DPB
+ *
+ * \return
+ * Number of node(s) deleted
+ **************************************************************************
+ */
+
+WORD32 ih264d_fix_error_in_dpb(dec_struct_t *ps_dec)
+{
+ /*--------------------------------------------------------------------*/
+ /* If there is common node in lt_list and st_list then delete it from */
+ /* st_list */
+ /*--------------------------------------------------------------------*/
+ UWORD8 no_of_nodes_deleted = 0;
+ UWORD8 lt_ref_num = ps_dec->ps_dpb_mgr->u1_num_lt_ref_bufs;
+ struct dpb_info_t *ps_lt_curr_dpb = ps_dec->ps_dpb_mgr->ps_dpb_ht_head;
+ while(lt_ref_num && ps_lt_curr_dpb)
+ {
+ if(ps_dec->ps_dpb_mgr->ps_dpb_st_head
+ && ((ps_lt_curr_dpb->s_bot_field.u1_reference_info
+ | ps_lt_curr_dpb->s_top_field.u1_reference_info)
+ == (IS_SHORT_TERM | IS_LONG_TERM)))
+ {
+ struct dpb_info_t *ps_st_next_dpb = ps_dec->ps_dpb_mgr->ps_dpb_st_head;
+ struct dpb_info_t *ps_st_curr_dpb = ps_dec->ps_dpb_mgr->ps_dpb_st_head;
+ UWORD8 st_ref_num = ps_dec->ps_dpb_mgr->u1_num_st_ref_bufs;
+ while(st_ref_num && ps_st_curr_dpb)
+ {
+ if(ps_st_curr_dpb == ps_lt_curr_dpb)
+ {
+ if(st_ref_num == ps_dec->ps_dpb_mgr->u1_num_st_ref_bufs)
+ {
+ ps_dec->ps_dpb_mgr->ps_dpb_st_head =
+ ps_dec->ps_dpb_mgr->ps_dpb_st_head->ps_prev_short;
+ ps_st_curr_dpb = ps_dec->ps_dpb_mgr->ps_dpb_st_head;
+ }
+ else
+ {
+ ps_st_next_dpb->ps_prev_short = ps_st_curr_dpb->ps_prev_short;
+ }
+ ps_dec->ps_dpb_mgr->u1_num_st_ref_bufs--;
+ ps_dec->ps_dpb_mgr->u1_num_lt_ref_bufs++;
+ no_of_nodes_deleted++;
+ break;
+ }
+ ps_st_next_dpb = ps_st_curr_dpb;
+ ps_st_curr_dpb = ps_st_curr_dpb->ps_prev_short;
+ st_ref_num--;
+ }
+ }
+ ps_lt_curr_dpb = ps_lt_curr_dpb->ps_prev_long;
+ lt_ref_num--;
+ }
+ return no_of_nodes_deleted;
+}
+
+
/*!
**************************************************************************
* \if Function name : DecodeSlice \endif
@@ -1365,9 +1445,8 @@ WORD32 ih264d_parse_decode_slice(UWORD8 u1_is_idr_slice,
if(ps_dec->u1_dangling_field == 1)
{
ps_dec->u1_second_field = 1 - ps_dec->u1_second_field;
- ps_cur_slice->u1_bottom_field_flag = u1_bottom_field_flag;
- ps_dec->u2_prv_frame_num = u2_frame_num;
ps_dec->u1_first_slice_in_stream = 0;
+ ps_dec->u1_top_bottom_decoded = TOP_FIELD_ONLY | BOT_FIELD_ONLY;
return ERROR_DANGLING_FIELD_IN_PIC;
}
@@ -1785,10 +1864,8 @@ WORD32 ih264d_parse_decode_slice(UWORD8 u1_is_idr_slice,
num_entries = 1;
}
num_entries = ((2 * num_entries) + 1);
- if(BASE_PROFILE_IDC != ps_dec->ps_cur_sps->u1_profile_idc)
- {
- num_entries *= 2;
- }
+ num_entries *= 2;
+
size = num_entries * sizeof(void *);
size += PAD_MAP_IDX_POC * sizeof(void *);
@@ -1807,6 +1884,10 @@ WORD32 ih264d_parse_decode_slice(UWORD8 u1_is_idr_slice,
ps_dec->pv_proc_tu_coeff_data = ps_dec->pv_parse_tu_coeff_data;
}
+ ret = ih264d_fix_error_in_dpb(ps_dec);
+ if(ret < 0)
+ return ERROR_DBP_MANAGER_T;
+
if(u1_slice_type == I_SLICE)
{
ps_dec->ps_cur_pic->u4_pack_slc_typ |= I_SLC_BIT;
diff --git a/decoder/ih264d_parse_slice.h b/decoder/ih264d_parse_slice.h
index c012062..0f82ec9 100644
--- a/decoder/ih264d_parse_slice.h
+++ b/decoder/ih264d_parse_slice.h
@@ -37,6 +37,7 @@
#include "ih264_platform_macros.h"
#include "ih264d_structs.h"
#include "ih264d_error_handler.h"
+WORD32 ih264d_fix_error_in_dpb(dec_struct_t * ps_dec);
WORD32 ih264d_parse_decode_slice(UWORD8 u1_is_idr_slice,
UWORD8 u1_nal_ref_idc,
dec_struct_t * ps_dec );
diff --git a/decoder/ih264d_process_bslice.c b/decoder/ih264d_process_bslice.c
index 7784110..42fad03 100644
--- a/decoder/ih264d_process_bslice.c
+++ b/decoder/ih264d_process_bslice.c
@@ -1212,7 +1212,8 @@ void ih264d_init_ref_idx_lx_b(dec_struct_t *ps_dec)
struct dpb_info_t *ps_next_dpb;
WORD32 i_cur_poc, i_max_st_poc, i_min_st_poc, i_ref_poc, i_temp_poc;
WORD8 i;
- UWORD8 u1_max_lt_index, u1_min_lt_index, u1_lt_index;
+ UWORD8 u1_max_lt_index, u1_min_lt_index;
+ UWORD32 u4_lt_index;
UWORD8 u1_field_pic_flag;
dec_slice_params_t *ps_cur_slice;
UWORD8 u1_L0, u1_L1;
@@ -1264,9 +1265,9 @@ void ih264d_init_ref_idx_lx_b(dec_struct_t *ps_dec)
}
for(i = 0; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++)
{
- u1_lt_index = ps_next_dpb->u1_lt_idx;
- u1_max_lt_index = (UWORD8)(MAX(u1_max_lt_index, u1_lt_index));
- u1_min_lt_index = (UWORD8)(MIN(u1_min_lt_index, u1_lt_index));
+ u4_lt_index = ps_next_dpb->u1_lt_idx;
+ u1_max_lt_index = (UWORD8)(MAX(u1_max_lt_index, u4_lt_index));
+ u1_min_lt_index = (UWORD8)(MIN(u1_min_lt_index, u4_lt_index));
/* Chase the next link */
ps_next_dpb = ps_next_dpb->ps_prev_long;
@@ -1333,12 +1334,12 @@ void ih264d_init_ref_idx_lx_b(dec_struct_t *ps_dec)
/* Start from ST head */
u1_num_short_term_bufs = u1_L0;
- for(u1_lt_index = u1_min_lt_index; u1_lt_index <= u1_max_lt_index; u1_lt_index++)
+ for(u4_lt_index = u1_min_lt_index; u4_lt_index <= u1_max_lt_index; u4_lt_index++)
{
ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head;
for(i = 0; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++)
{
- if(ps_next_dpb->u1_lt_idx == u1_lt_index)
+ if(ps_next_dpb->u1_lt_idx == u4_lt_index)
{
ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
ps_next_dpb->ps_pic_buf);
@@ -1466,13 +1467,13 @@ void ih264d_init_ref_idx_lx_b(dec_struct_t *ps_dec)
/* Start from ST head */
u1_num_short_term_bufs = u1_L1;
- for(u1_lt_index = u1_min_lt_index; u1_lt_index <= u1_max_lt_index;
- u1_lt_index++)
+ for(u4_lt_index = u1_min_lt_index; u4_lt_index <= u1_max_lt_index;
+ u4_lt_index++)
{
ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head;
for(i = 0; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++)
{
- if(ps_next_dpb->u1_lt_idx == u1_lt_index)
+ if(ps_next_dpb->u1_lt_idx == u4_lt_index)
{
ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
ps_next_dpb->ps_pic_buf);
diff --git a/decoder/ih264d_process_pslice.c b/decoder/ih264d_process_pslice.c
index 95ac557..efda5cf 100644
--- a/decoder/ih264d_process_pslice.c
+++ b/decoder/ih264d_process_pslice.c
@@ -971,7 +971,8 @@ void ih264d_init_ref_idx_lx_p(dec_struct_t *ps_dec)
dpb_manager_t *ps_dpb_mgr;
struct dpb_info_t *ps_next_dpb;
WORD8 i;
- UWORD8 u1_max_lt_index, u1_min_lt_index, u1_lt_index;
+ UWORD8 u1_max_lt_index, u1_min_lt_index;
+ UWORD32 u4_lt_index;
UWORD8 u1_field_pic_flag;
dec_slice_params_t *ps_cur_slice;
UWORD8 u1_L0;
@@ -1018,9 +1019,9 @@ void ih264d_init_ref_idx_lx_p(dec_struct_t *ps_dec)
for(i = 0; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++)
{
- u1_lt_index = ps_next_dpb->u1_lt_idx;
- u1_max_lt_index = (UWORD8)(MAX(u1_max_lt_index, u1_lt_index));
- u1_min_lt_index = (UWORD8)(MIN(u1_min_lt_index, u1_lt_index));
+ u4_lt_index = ps_next_dpb->u1_lt_idx;
+ u1_max_lt_index = (UWORD8)(MAX(u1_max_lt_index, u4_lt_index));
+ u1_min_lt_index = (UWORD8)(MIN(u1_min_lt_index, u4_lt_index));
/* Chase the next link */
ps_next_dpb = ps_next_dpb->ps_prev_long;
@@ -1065,13 +1066,13 @@ void ih264d_init_ref_idx_lx_p(dec_struct_t *ps_dec)
/* Arrange all Long term buffers in ascending order, in LongtermIndex */
/* Start from LT head */
u1_num_short_term_bufs = u1_L0;
- for(u1_lt_index = u1_min_lt_index; u1_lt_index <= u1_max_lt_index;
- u1_lt_index++)
+ for(u4_lt_index = u1_min_lt_index; u4_lt_index <= u1_max_lt_index;
+ u4_lt_index++)
{
ps_next_dpb = ps_dpb_mgr->ps_dpb_ht_head;
for(i = 0; i < ps_dpb_mgr->u1_num_lt_ref_bufs; i++)
{
- if(ps_next_dpb->u1_lt_idx == u1_lt_index)
+ if(ps_next_dpb->u1_lt_idx == u4_lt_index)
{
ih264d_insert_pic_in_ref_pic_listx(ps_ref_pic_buf_lx,
ps_next_dpb->ps_pic_buf);
diff --git a/decoder/ih264d_utils.c b/decoder/ih264d_utils.c
index 4f6deca..b37acec 100644
--- a/decoder/ih264d_utils.c
+++ b/decoder/ih264d_utils.c
@@ -1042,12 +1042,15 @@ WORD32 ih264d_get_next_display_field(dec_struct_t * ps_dec,
buf = ps_dec->disp_bufs[i].buf[1];
buf += ps_dec->disp_bufs[i].u4_ofst[1];
pv_disp_op->s_disp_frm_buf.pv_u_buf = buf
- + pic_buf->u2_crop_offset_uv;
+ + (pic_buf->u2_crop_offset_uv
+ / YUV420SP_FACTOR);
buf = ps_dec->disp_bufs[i].buf[2];
buf += ps_dec->disp_bufs[i].u4_ofst[2];
pv_disp_op->s_disp_frm_buf.pv_v_buf = buf
- + pic_buf->u2_crop_offset_uv;
+ + (pic_buf->u2_crop_offset_uv
+ / YUV420SP_FACTOR);
+
}
}
}
@@ -1979,10 +1982,7 @@ WORD16 ih264d_allocate_dynamic_bufs(dec_struct_t * ps_dec)
num_entries = 1;
}
num_entries = ((2 * num_entries) + 1);
- if(BASE_PROFILE_IDC != ps_dec->ps_cur_sps->u1_profile_idc)
- {
- num_entries *= 2;
- }
+ num_entries *= 2;
size = num_entries * sizeof(void *);
size += PAD_MAP_IDX_POC * sizeof(void *);