-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvpu_wrapper.c
executable file
·8356 lines (7696 loc) · 262 KB
/
vpu_wrapper.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
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
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2010-2016, Freescale Semiconductor Inc.,
* Copyright 2020 NXP
*
* The following programs are the sole property of NXP,
* and contain its proprietary and confidential information.
*
*/
/*
* Vpu_wrapper.c
* vpu wrapper file contain all related vpu api exposed to application
*
* History :
* Date (y.m.d) Author Version Description
* 2010-09-07 eagle zhou 0.1 Created
* 2011-12-22 eagle zhou 1.0 refine
*/
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "utils.h"
#include "vpu_lib.h"
#include "vpu_io.h"
#include "vpu_wrapper.h"
#define DIVX_WARNING_LOG //always prompt warning info when find divx format !!!!
#ifdef DIVX_WARNING_LOG
#ifdef ANDROID_BUILD
#include "Log.h"
#define LOG_DIVX_WARNING LogOutput
#else
#define LOG_DIVX_WARNING printf
#endif
#else
#define LOG_DIVX_WARNING(...)
#endif
#ifdef USE_VPU_WRAPPER_TIMER
#include "vpu_wrapper_timer.h"
#define TIMER_INIT timer_init()
#define TIMER_MARK(id) timer_mark(id)
#define TIMER_START(id) timer_start(id)
#define TIMER_STOP(id) timer_stop(id)
#define TIMER_MARK_REPORT(id) timer_mark_report(id)
#define TIMER_REPORT(id) timer_report(id)
#else
#define TIMER_INIT
#define TIMER_MARK(id)
#define TIMER_START(id)
#define TIMER_STOP(id)
#define TIMER_MARK_REPORT(id)
#define TIMER_REPORT(id)
#endif
#define TIMER_MARK_GETOUTPUT_ID (0)
#define TIMER_CLEARDISP_ID (0)
//#define VPU_DEC_PIPELINE
#define VPU_DEC_CHECK_INIT_LENGTH //VPU limitation of minimum size 512 before seq init ?
#define VPU_SUPPORT_UNCLOSED_GOP // for unclosed gop case:(1) drop B frames whose reference are missing (2) drop non-I frame after flushing
#define VPU_PROTECT_MULTI_INSTANCE // for stream mode, we need to add protection for (startoneframe()--check busy/wait interrupt--getoutput()) to avoid hangup
//#define VPU_DEBUG_BS
//#define VPU_DEC_FILE_MODE // default, using file mode for all codecs
#define VPU_IFRAME_SEARCH // for file mode, we need to enable iframesearch to clear buffer: to implement seek(flush) feature: (3) skipping decoding until key frame
//In fact, (2)=(1)+(3)
#define VPU_FILEMODE_QUICK_EXIT // for vc1 complexity, vpu_DecSetEscSeqInit() will cost some time, so we return error directly for file mode, but not check the loop count
//for example: wmv9_CP_240x180_26fps_263kbps_vc1.cmplx.wmv
#define VPU_AVOID_DEAD_LOOP // avoid dead loop, cover: seqinit step; decode step
//for example: mp4v_mp3_mp3audio_4567_50_100_10_20.mp4
#define VPU_FILEMODE_WORKAROUND //add some work around for file mode: H.264/H.263/Mpeg2/Mpeg4/DivX456/XVID
#define VPU_SUPPORT_NO_ENOUGH_FRAME //avoid hang when no enough frame buffer
#define VPU_VC1_AP_SKIP_WORKAROUND //work around for skip frame(VC1), vpu may output one frame which has not been released, now, we simply drop this frame; clip: Test_1440x576_WVC1_6Mbps.wmv
#define VPU_INIT_FREE_SIZE_LIMITATION //after the first init step, rd may exceed wr (can no occur at decode state), for example, WR+8, but RD+512, As result, free size is not enough when try the second init. But in fact, we can ignore the info
//for example: Divx5_640x480_23.976_1013_a_mp3_48_158_2_1st-key-frame-is-the-2nd-frame_11.Search-for-the-Full-Moon-02.avi
#define VPU_FILEMODE_INTERLACE_WORKAROUND //for interlaced clips: If user feed two fields seperately, and vpu action is: return valid for the first field, and return invalid for the second field. So we need to drop the second field and notify user get one timestamp
#define VPU_FILEMODE_CORRUPT_WORKAROUND //for some corrupt clips(h264_P_B1.3_25.0fps_730k_320x240_aac_48KHz_128Kbps_c2_3min3s_Tomsk_iPod.mp4)
//vpu return dexindex=-2, dispindex=-3 even data length !=0
#define VPU_SUPPORT_NO_INBUF //no enough input buffer: to avoid null run
#define VPU_FAKE_FLUSH //for debug flush mode
#define VPU_FILEMODE_PBCHUNK_FLUSH_WORKAROUND //if flush is called between PB chunk(need to feed to vpu twice), the pb state is not cleared by vpu.
//as result, the following key frame will be regarded as B frame and the output is wrong until next key frame.
//video may be freeze after seek when VPU_SUPPORT_UNCLOSED_GOP is enabled:Xvid_SP1_640x480_23.98_655_aaclc_44_2_test.mkv(the first interval of key frame is about 6s)
#define VPU_FLUSH_BEFORE_DEC_WORKAROUND //for vpu, below case need to be avoided, eg. should not update 0 after register frame immediately
//register frame -> update 0 -> get EOS -> update non-0 -> always return EOS even data is valid
//#define VPU_SEEK_ANYPOINT_WORKAROUND //unrecoverable mosaic may be introduced by random seek point(mainly for H.264??), so we need to call some related flush operation.
//#define VPU_FILEMODE_SUPPORT_INTERLACED_SKIPMODE //for interlaced clips: we should make sure the skipmode for two field are the same, to avoid mosaic and hangup issues
//it is mainly for skip B strategy (performance issue): so we only consider skipframeMode
//#define VPU_FILEMODE_MERGE_INTERLACE_DEBUG //in file mode, it is unstable that feeding two fields seperately. So we make some effort to merge two fields into one frame
#define VPU_FILEMODE_INTERLACE_TIMESTAMP_ENHANCE //for field decoding: move "pop of timestampe" from decode order to display order
//for some interlaced clips with deep dpb, original design may introduce much bigger timestamp(about 0.5 seconds): technicolor/332_dec.ts
#define VPU_NOT_RETURN_ALLBUF_AFTER_FLUSH //we don't want to return all frame buffers after flush operation
#define VPU_IMX6_VC1AP_RANGEMAP_BUF_WORKAROUND //some buffers ared used for rangmap, and the buffer numbers will be accumulated for every flush operation. so we need to clear them explicitly after every flush operation
#define VPU_IMX6_MULTIINSTANCE_FRAMESTART_WORKAROUND //for multi-instance, frame start may point to memory space in another instance.
#define VPU_ENC_OUTFRAME_ALIGN //vpu limitation: 4(or 8?) bytes alignment for output frame address
#define VPU_ENC_GUESS_OUTLENGTH //no size in SetOutputBuffer(), so we guess one value
//#define VPU_ENC_ALIGN_LIMITATION //vpu encoder has 16 pixels alignment limitation: vpu will cut down to 16-aligned pixels automatically
#define VPU_ENC_SEQ_DATA_SEPERATE //output sequence header and data seperately, otherwise, only our vpu decoder can play it
#define VPU_FILEMODE_MERGE_FLAG 1
//#define VPU_USE_UNSPECIFIED_RATIO //added for special case
//#define VPU_BACKDOOR //use some special backdoor
#ifdef VPU_BACKDOOR
#define IMX6Q //only for compiler vpu_reg.h
#include "vpu_util.h"
#endif
static int nVpuLogLevel=0; //bit 0: api log; bit 1: raw dump; bit 2: yuv dump
#ifdef ANDROID_BUILD
#include "Log.h"
#define LOG_PRINTF LogOutput
#define VPU_LOG_LEVELFILE "/data/vpu_log_level"
#define VPU_DUMP_RAWFILE "/data/temp_wrapper.bit"
#define VPU_DUMP_YUVFILE "/data/temp_wrapper.yuv"
#else
#define LOG_PRINTF printf
#define VPU_LOG_LEVELFILE "/etc/vpu_log_level"
#define VPU_DUMP_RAWFILE "temp_wrapper.bit"
#define VPU_DUMP_YUVFILE "temp_wrapper.yuv"
#endif
typedef unsigned int UINT32;
#define MAX_YUV_FRAME (1000)
#define DUMP_ALL_DATA 1
static int g_seek_dump=DUMP_ALL_DATA; /*0: only dump data after seeking; otherwise: dump all data*/
//#define VPU_WRAPPER_DEBUG
#define VPU_LOG(...)
#define VPU_TRACE
#define VPU_API(...) if(nVpuLogLevel&0x1) {LOG_PRINTF(__VA_ARGS__);}
#define VPU_ERROR(...) if(nVpuLogLevel&0x1) {LOG_PRINTF(__VA_ARGS__);}
#define VPU_ENC_API(...) if(nVpuLogLevel&0x1) {LOG_PRINTF(__VA_ARGS__);}
#define VPU_ENC_LOG(...)
#define VPU_ENC_ERROR(...) if(nVpuLogLevel&0x1) {LOG_PRINTF(__VA_ARGS__);}
#define ASSERT(exp) if((!(exp))&&(nVpuLogLevel&0x1)) {LOG_PRINTF("%s: %d : assert condition !!!\r\n",__FUNCTION__,__LINE__);}
#define VPU_DUMP_RAW (nVpuLogLevel&0x2)
#define VPU_DUMP_YUV (nVpuLogLevel&0x4)
//#define VPU_RESET_TEST //avoid reset board for every changing to FW
#ifdef VPU_SUPPORT_UNCLOSED_GOP
#define MIN_REF_CNT 1 // ref number before B frame: it is display order, but not decode order !!!
#define MAX_DROPB_CNT 5 // maxium continuous dropping B frames number: avoid freeze for closed gop (I B B B B B B B B... B EOS)
#define MIN_KEY_CNT 1 // key number before the first non-I frame: display order
#define DIS_DROP_FRAME // to avoid seek timeout , decoder need to output one valid buffer, but not drop frame automaticaly
#endif
#define vpu_memset memset
#define vpu_memcpy memcpy
#define vpu_malloc malloc
#define vpu_free free
#ifdef NULL
#undef NULL
#define NULL 0
#endif
#define USE_NEW_VPU_API //api change for vp8
#if 1 //for iMX6
//#define IMX6_MULTI_FORMATS_WORKAROUND //need to reset to decoder different formats: such VC1 followed by Mpeg2
//#define IMX6_SKIPMODE_WORKAROUND_FILL_DUMMY
#define IMX6_RANGEMAP_WORKAROUND_IGNORE
//#define IMX6_LD_BUG_WORKAROUND //1 for iMX6 compiler : ld (2.20.1-system.20100303) bug ??
//#define IMX6_PIC_ORDER_WORKAROUND //fixed for 6_Gee_HD.avi
#define IMX6_BUFNOTENOUGH_WORKAROUND //when buffer is not enough, vpu may return dispIndex=-1(EOS) directly, but not decIndex=-1
//#define IMX6_INTER_DEBUG_RD_WR //internal debug: rd wr register
//#define IMX6_INTER_DEBUG //internal debug
//#define IMX6_BITBUFSPACE_WORKAROUND //the free sapce may be not correct for FW version 2.1.3 or later
#define IMX6_WRONG_EOS_WORKAROUND //for mpeg4, vpu may report disIndx=-1(EOS) in the middle of clip after seeking
#define IMX6_VP8_SHOWFRAME_WORKAROUND //for special frame(show_frame=0) in vpu8, buffer may be decoded repeatedly, as a result, timestamp will be accumulated
#define IMX6_AVC_NOFRAME_WORKAROUND //for h.264 clips, vpu may report no frame buffer before decoding the first frame(frames are just registered to vpu)
#define IMX6_DETECT_RESOLUTION_CHANGE_BEFORE_DECODE //detect resolution change before decoding
#endif
/****************************** cpu version ***************************************/
#define CPU_IS_MX5X cpu_is_mx5x
#if (VPU_LIB_VERSION_CODE >=VPU_LIB_VERSION(5,4,0))
#define CPU_IS_MX6X cpu_is_mx6x
#else
#define CPU_IS_MX6X cpu_is_mx6q
#endif
/****************************** binary version info *********************************/
#define SEPARATOR " "
#define BASELINE_SHORT_NAME "VPUWRAPPER_ARM"
#define OS_NAME "_LINUX"
#define VPUWRAPPER_BINARY_VERSION_STR \
(BASELINE_SHORT_NAME OS_NAME \
SEPARATOR "Build on" \
SEPARATOR __DATE__ SEPARATOR __TIME__)
/****************************** decoder part **************************************/
#define VPU_MEM_ALIGN 0x8
#define VPU_TILE_ALIGN (4096) //tile format: Y(or CbCr) address alignment limitation: bytes
#if 1 //for iMX6 stream mode
#define VPU_BITS_BUF_SIZE (3*1024*1024) //bitstream buffer size : big enough contain two big frames
#else
#define VPU_BITS_BUF_SIZE (1024*1024)
#endif
#define VPU_SLICE_SAVE_SIZE 0x17E800 //worst slice buffer size: 1920*1088*1.5/2= 1.5MB
#define VPU_PS_SAVE_SIZE 0x80000
#define VPU_VP8_MBPARA_SIZE 0x87780 //68 * (1920 * 1088 / 256)=0x87780;
#define VPU_MIN_INIT_SIZE (512) //min required data size for seq init
#define VPU_MIN_DEC_SIZE (64*1024) //min required data size for decode
#ifdef VPU_AVOID_DEAD_LOOP
#define VPU_MAX_INIT_SIZE (VPU_BITS_BUF_SIZE-256*1024) //avoid dead loop for unsupported clips
#define VPU_MAX_INIT_LOOP (500) //avoid dead loop for crashed files, including null file
#define VPU_MAX_DEC_SIZE (200*1024*1024)//(8*1024*1024) //avoid dead loop in decode state for corrupted clips
#define VPU_MAX_DEC_LOOP (4000) //avoid dead loop in decode state for corrupted clips
#endif
#define VPU_TIME_OUT (200) //used for flush operation: wait time
#define VPU_MAX_TIME_OUT_CNT (10) //used for flush operation: max counts
#define VPU_MAX_EOS_DEAD_LOOP_CNT (20) //used for flush operation
#define VPU_MAX_FRAME_INDEX 30
#define VPU_MIN_UINT_SIZE (512) //min required data size for vpu_DecStartOneFrame()
#define VIRT_INDEX 0
#define PHY_INDEX 1
#define VPU_POLLING_TIME_OUT (10) //used for normal decode
#define VPU_POLLING_MIN_TIME_OUT (1) //used for normal decode: use it when vpu is not busy
#define VPU_MAX_POLLING_BUSY_CNT (200) //used for normal decode: max counts
#define VPU_POLLING_PRESCAN_TIME_OUT (500) //used for prescan mode
#define VPU_MAX_POLLING_PRESCAN_BUSY_CNT (4) //used for prescan mode: max counts
#define VPU_OUT_DEC_INDEX_NOMEANING -4 //unmeaning value: it is not defined by vpu
#define VPU_OUT_DEC_INDEX_UNDEFINE -3
#define VPU_OUT_DEC_INDEX_UNDEC -2
#define VPU_OUT_DEC_INDEX_EOS -1
#define VPU_OUT_DIS_INDEX_NODIS -3
#define VPU_OUT_DIS_INDEX_NODIS_SKIP -2
#define VPU_OUT_DIS_INDEX_EOS -1
#define VPU_FRAME_STATE_FREE 0 //clear them by memset() at init step
#define VPU_FRAME_STATE_DEC 1 //decoded by vpu, but not send out
#define VPU_FRAME_STATE_DISP 2 //send out by vpu for display
#define MemAlign(mem,align) ((((unsigned int)mem)%(align))==0)
#define MemNotAlign(mem,align) ((((unsigned int)mem)%(align))!=0)
#define NotEnoughInitData(free) (((VPU_BITS_BUF_SIZE)-(free))<(VPU_MIN_INIT_SIZE))
#define NotEnoughDecData(free,min_validsize) (((VPU_BITS_BUF_SIZE)-(free))<(min_validsize))
#define VC1_MAX_SEQ_HEADER_SIZE 256 //for clip: WVC1_stress_a0_stress06.wmv, its header length = 176 (>128)
#define VC1_MAX_FRM_HEADER_SIZE 32
#define VP8_SEQ_HEADER_SIZE 32
#define VP8_FRM_HEADER_SIZE 12
#define DIV3_SEQ_HEADER_SIZE 32
#define DIV3_FRM_HEADER_SIZE 12
#define RCV_HEADER_LEN 24
#define RCV_CODEC_VERSION (0x5 << 24) //FOURCC_WMV3_WMV
#define RCV_NUM_FRAMES 0xFFFFFF
#define RCV_SET_HDR_EXT 0x80000000
#define VC1_IS_NOT_NAL(id) (( id & 0x00FFFFFF) != 0x00010000)
#define AVC_IS_IDR(type) (0==((type)&0x1)) //bit[0]==0
#define AVC_IS_ISLICE(type) ((1==((type)&0x1))&&(0==((type)&0x6))) //bit[0]==1 && bit[2:1]==0
#define AVC_IS_PSLICE(type) ((1==((type)&0x1))&&(2==((type)&0x6))) //bit[0]==1 && bit[2:1]==1
#define AVC_IS_BSLICE(type) ((1==((type)&0x1))&&((4==((type)&0x6))||(6==((type)&0x6)))) //bit[0]==1 && bit[2:1]==2 or 3
#define FRAME_IS_REF(type) ((type==VPU_IDR_PIC)||(type==VPU_I_PIC)||(type==VPU_P_PIC)||(type==VPU_UNKNOWN_PIC))
#define FRAME_IS_B(type) ((type==VPU_B_PIC))
#define FRAME_IS_KEY(type) ((type==VPU_IDR_PIC)||(type==VPU_I_PIC))
#define FRAME_ISNOT_KEY(type) ((type!=VPU_IDR_PIC)&&(type!=VPU_I_PIC))
#if 1
#define FRAME_START_OFFSET 0 //start regiter point to : frame start
#define FRAME_END_OFFSET 1 //end register point to : frame end + 1
#else
#define FRAME_START_OFFSET 1 //start regiter point to : frame start -1
#define FRAME_END_OFFSET 0 //end register point to : frame end
#endif
/*
for stream: WVC1_stress_NoAudio_intensitycomp.wmv, the first frame(two fields) is defined as I/P
here, we loose the rule and regard the frame as I frame for those P/I and I/P.
VC1-AP frame type:(it is not totally defined by specifiction, refer to table 105)
Bot 0 1 2 3 4 5 6 7
Top I P BI B SKIP * * *
0 I I I * * * * * *
1 P I P * * * * * *
2 BI * * BI B * * * *
3 B * * B B * * * *
4 SKIP* * * * SKIP* * *
5 * * * * * * * * *
6 * * * * * * * * *
7 * * * * * * * * *
*/
static VpuPicType g_VC1APPicType[8][8]={
{VPU_I_PIC,VPU_I_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC},
{VPU_I_PIC,VPU_P_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC},
{VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_BI_PIC,VPU_B_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC},
{VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_B_PIC,VPU_BI_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC},
{VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_SKIP_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC},
{VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC},
{VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC},
{VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC,VPU_UNKNOWN_PIC}
};
typedef enum
{
VPU_DEC_STATE_OPEN=0,
VPU_DEC_STATE_INITOK,
VPU_DEC_STATE_REGFRMOK,
VPU_DEC_STATE_DEC,
VPU_DEC_STATE_STARTFRAMEOK, /*it is used for non-block mode*/
VPU_DEC_STATE_OUTOK,
VPU_DEC_STATE_EOS,
VPU_DEC_STATE_RESOLUTION_CHANGE,
VPU_DEC_STATE_CORRUPT,
}VpuDecState;
typedef struct
{
int picType;
int idrFlag; /*for iMX6X*/
int topFieldFirst;
int repeatFirstField;
int pFrameInPBPacket; /*P frame in [P,B] chunk*/
int consumedBytes; /*record frame length*/
VpuFieldType eFieldType;
int viewID; /*MVC: view id*/
int width;
int height;
VpuRect frameCrop;
unsigned int Q16ShiftWidthDivHeightRatio;
}VpuFrameBufInfo;
typedef struct
{
/* open parameters */
VpuCodStd CodecFormat;
//int blockmode;
/* decode parameters */
int streamBufDelaySize; /*unit: bytes. used in stream mode: valid data size should reach the threshold before decoding*/
int iframeSearchEnable;
int skipFrameMode;
int skipFrameNum;
int inputType; /*normal, kick, drain(EOS)*/
/* init info */
VpuDecInitInfo initInfo;
/* out frame info */
VpuDecOutFrameInfo frameInfo;
/* frame buffer management */
int frameNum;
VpuFrameBuffer frameBuf[VPU_MAX_FRAME_INDEX]; /*buffer node*/
VpuFrameBufInfo frameBufInfo[VPU_MAX_FRAME_INDEX]; /*info required by user*/
int frameBufState[VPU_MAX_FRAME_INDEX]; /*record frame state for clearing display frame(if user forgot to clear them)*/
/* bitstream buffer pointer info */
unsigned char* pBsBufVirtStart;
unsigned char* pBsBufPhyStart;
unsigned char* pBsBufPhyEnd;
//unsigned char* pBsBufPhyWritePtr;
/* avc slice/ps buffer*/
unsigned char* pAvcSlicePhyBuf;
unsigned char* pAvcSPSPhyBuf; /*vpu may write sps/pps info into this buffer */
/* */
/* state */
VpuDecState state;
/* historical info */
VpuFrameBuffer * pPreDisplayFrameBuf;
//VpuFrameBuffer * pPreDecodedFrameBuf;
int nPrivateSeqHeaderInserted;
/*resolution for some special formats, such as package VC1 header,...*/
int picWidth;
int picHeight;
#ifdef VPU_SUPPORT_UNCLOSED_GOP
//(1) drop B frame
int refCnt; //IDR/I/P
int dropBCnt;
//(2) drop non-I frame
int keyCnt; //IDR/I
#endif
//#ifdef VPU_IFRAME_SEARCH
int keyDecCnt; //IDR/I: it is in decode order, not like keyCnt
int iframesearch_allowed; //iMX6: enable, iMX5: disable
//#endif
int fake_flush; //iMX6: enable, iMX5: disable
#ifdef VPU_SEEK_ANYPOINT_WORKAROUND
int seekKeyLoc; /*I/IDR location: it is decode order, similar with keyDecCnt*/
int recommendFlush; /*recommend user call flush to clear some related internal state in vpu*/
#endif
#ifdef VPU_SUPPORT_NO_ENOUGH_FRAME
int dataUsedInFileMode; //in file mode, avoid copy data repeatedly
int lastDatLenInFileMode; //record the last data length
int lastConfigMode; //protection for PB: use same skipmode for PB chunk
#endif
int filemode; /*now, for DivX3, VC1, RV*/
int firstData; /*for file mode: we need to send the first data to seqinit and startoneframe seperately */
int firstDataSize; /*data length for the first data*/
#ifdef VPU_PROTECT_MULTI_INSTANCE
int filledEOS; /* have vpu_DecUpdateBitstreamBuffer(handle,0) */
#endif
int pbPacket;/*divx PB chunk*/
int pbClips; /*for PB clips, skipmode will introduce problem*/
#ifdef VPU_FLUSH_BEFORE_DEC_WORKAROUND
int realWork; /*will be set 1 if only vpu_DecGetOutputInfo() is called*/
#endif
#ifdef VPU_FILEMODE_SUPPORT_INTERLACED_SKIPMODE
int firstFrameMode; /*record the skip frame mode for first field*/
int fieldCnt; /*first field decoded: 1; second field decoded: 0;*/
#endif
#ifdef VPU_FILEMODE_MERGE_INTERLACE_DEBUG
int needMergeFields; /*1: need merge; 0: needn't merge*/
int lastFieldOffset; /*record the length of first field*/
#endif
#ifdef VPU_FILEMODE_INTERLACE_TIMESTAMP_ENHANCE
int fieldDecoding; /*two fields are feed to vpu seperately*/
int oweFieldTS; /*the number of fields whose timestamp still not be popped*/
#endif
int mjpg_frmidx; /*for mjpg output frame*/
FrameBuffer vpu_regframebuf[VPU_MAX_FRAME_INDEX]; /*we need to record it for mjpg's frame management*/
int mjpg_linebuffmode; /*for iMX6: 1: line buffer mode; 0: non-line buffer mode*/
/*tile setting*/
int nMapType;
int nTiled2LinearEnable;
/*used to store extended frame info*/
VpuFrameExtInfo frmExtInfo;
/*management of consumed bytes: used to sync with frame boundary*/
int nDecFrameRptEnabled; /*1:support frame reported; 0: not support*/
int nAccumulatedConsumedStufferBytes;/*stuffer size between frames: if it <0, indicate that some frames are contained in config data*/
int nAccumulatedConsumedFrmBytes; /*frame size: >=0*/
int nAccumulatedConsumedBytes; /*it should match with the input data size == nAccumulatedConsumedStufferBytes+nAccumulatedConsumedFrmBytes*/
VpuFrameBuffer* pLastDecodedFrm; /*the nearest decoded frame*/
int nAdditionalSeqBytes; /*seq header inserted by wrapper itself , or config data */
int nAdditionalFrmHeaderBytes; /*frame header inserted by wrapper itself */
unsigned int nLastFrameEndPosPhy; /*point to the previous frame tail: used to compute the stuff data length between frames*/
/*profile/level info*/
int nProfile;
int nLevel;
/*resolution change*/
int nDecResolutionChangeEnabled; /*1: support resolution change notification; 0: not support*/
int nOriWidth; /*set in seqinit stage*/
int nOriHeight; /*set in seqinit stage*/
int nResolutionChanged; /*resolution change happen: checked in decoded stage*/
unsigned char* pSeqBak; /*backup the sequence data*/
int nSeqBakLen;
DecOpenParam sDecOpenParam; /*backup the open parameters*/
int initDataCountThd;
VpuDecErrInfo nLastErrorInfo; /*it record the last error info*/
int nIsAvcc; /*only for H.264 format*/
int nNalSizeLen;
int nNalNum; /*added for nal_size_length = 1 or 2*/
}VpuDecObj;
typedef struct
{
DecHandle handle;
VpuDecObj obj;
}VpuDecHandleInternal;
#ifdef VPU_BACKDOOR
int VpuLogClearFlag(DecHandle nInHandle)
{
int val,reg;
CodecInst *pCodecInst;
pCodecInst = nInHandle;
reg=VpuReadReg(BIT_FRM_DIS_FLG);
val=pCodecInst->ctxRegs[CTX_BIT_FRM_DIS_FLG];
printf("vpu frame buffer clear flag: 0x%X, clear reg: 0x%X \r\n",val,reg);
return 1;
}
int VpuVerifyClearFlag(DecHandle nInHandle,VpuDecObj* pObj)
{
CodecInst *pCodecInst;
int val;
int i,state;
pCodecInst = nInHandle;
val=pCodecInst->ctxRegs[CTX_BIT_FRM_DIS_FLG];
VPU_LOG("vpu frame buffer clear flag: 0x%X \r\n",val);
for(i=0;i<pObj->frameNum;i++)
{
/*
0: is cleared
1: is decoded(may already output to user or not)
*/
state=(1 << i) &val;
state=(state==0)?VPU_FRAME_STATE_FREE:(VPU_FRAME_STATE_DEC|VPU_FRAME_STATE_DISP);
if((VPU_FRAME_STATE_FREE==pObj->frameBufState[i])&&(state!=VPU_FRAME_STATE_FREE))
{
//user has clear it, but vpu hasn't clear it
VPU_ERROR("the state for buffer %d is not correct!!!, should be cleared \r\n",i);
}
else if((VPU_FRAME_STATE_FREE!=pObj->frameBufState[i])&&(state==VPU_FRAME_STATE_FREE))
{
//user hasn't clear it, but vpu has cleared it.
VPU_ERROR("the state for buffer %d is not correct!!!, shouldn't be cleared \r\n",i);
}
}
return 1;
}
int VpuSetClearFlag(DecHandle nInHandle,VpuDecObj* pObj,int nIndex)
{
CodecInst *pCodecInst;
int val;
pCodecInst = nInHandle;
printf("reset flag: bufer index: %d \r\n",nIndex);
val=pCodecInst->ctxRegs[CTX_BIT_FRM_DIS_FLG];
pCodecInst->ctxRegs[CTX_BIT_FRM_DIS_FLG]=(1<<nIndex)|val;
return 1;
}
#endif
#ifdef VPU_WRAPPER_DEBUG
void printf_memory(unsigned char* addr, int width, int height, int stride)
{
int i,j;
unsigned char* ptr;
ptr=addr;
VPU_LOG("addr: 0x%X \r\n",(unsigned int)addr);
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
VPU_LOG("%2X ",ptr[j]);
}
VPU_LOG("\r\n");
ptr+=stride;
}
VPU_LOG("\r\n");
return;
}
#endif
void WrapperFileDumpBitstrem(FILE** ppFp, unsigned char* pBits, unsigned int nSize)
{
int nWriteSize=0;
if(nSize==0)
{
return;
}
if (0==g_seek_dump) return;
if(*ppFp==NULL)
{
*ppFp=fopen(VPU_DUMP_RAWFILE,"wb");
if(*ppFp==NULL)
{
VPU_LOG("open %s failure \r\n",VPU_DUMP_RAWFILE);
return;
}
VPU_LOG("open %s OK \r\n",VPU_DUMP_RAWFILE);
}
nWriteSize=fwrite(pBits,1,nSize,*ppFp);
fflush(*ppFp);
return;
}
void WrapperFileDumpYUV(FILE** ppFp, unsigned char* pY,unsigned char* pU,unsigned char* pV, unsigned int nYSize,unsigned int nCSize,int nColorfmt)
{
static int cnt=0;
int nCScale=1;
int nWriteSize=0;
switch(nColorfmt)
{
case 0: //4:2:0
nCScale=1;
break;
case 1: //4:2:2 hor
case 2: //4:2:2 ver
nCScale=2;
break;
case 3: //4:4:4
nCScale=4;
break;
case 4: //4:0:0
nCScale=0;
break;
default: //4:2:0
break;
}
if (0==g_seek_dump) return;
if(*ppFp==NULL)
{
*ppFp=fopen(VPU_DUMP_YUVFILE,"wb");
if(*ppFp==NULL)
{
VPU_LOG("open %s failure \r\n",VPU_DUMP_YUVFILE);
return;
}
VPU_LOG("open %s OK \r\n",VPU_DUMP_YUVFILE);
}
if(cnt<MAX_YUV_FRAME)
{
nWriteSize=fwrite(pY,1,nYSize,*ppFp);
nWriteSize=fwrite(pU,1,nCSize*nCScale,*ppFp);
nWriteSize=fwrite(pV,1,nCSize*nCScale,*ppFp);
fflush(*ppFp);
cnt++;
}
return;
}
int VpuLogLevelParse(int * pLogLevel)
{
int level=0;
FILE* fpVpuLog;
fpVpuLog=fopen(VPU_LOG_LEVELFILE,"r");
if (NULL==fpVpuLog){
//LOG_PRINTF("no vpu log level file: %s \r\n",VPU_LOG_LEVELFILE);
}
else {
char symbol;
int readLen = 0;
readLen = fread(&symbol,1,1,fpVpuLog);
if(feof(fpVpuLog) != 0){
//LOG_PRINTF("\n End of file reached.");
}
else {
level=atoi(&symbol);
//LOG_PRINTF("vpu log level: %d \r\n",level);
if((level<0) || (level>255)){
level=0;
}
}
fclose(fpVpuLog);
}
nVpuLogLevel=level;
//*pLogLevel=level;
return 1;
}
int VpuTiledAddressMapping(int nInMapType,unsigned int nInYTop,unsigned int nInYBot,unsigned int nInCbTop,unsigned int nInCbBot,
unsigned int* pOutY, unsigned int* pOutCb,unsigned int* pOutCr)
{
unsigned int lum_top_20bits,chr_top_20bits;
unsigned int lum_bot_20bits,chr_bot_20bits;
/*
* In tiled map format the construction of the buffer pointers is as follows:
* addrY [31:12]: lum_top_20bits
* addrY [11: 0], addrCb[31:24]: chr_top_20bits
* addrCb[23: 4]: lum_bot_20bits
* addrCb[ 3: 0], addrCr[31:16]: chr_bot_20bits
*/
lum_top_20bits=nInYTop>>12;
chr_top_20bits=nInCbTop>>12;
if(1==nInMapType)
{
//frame tile
ASSERT(nInYBot==0);
lum_bot_20bits=0;
chr_bot_20bits=0;
}
else
{
//field tile
ASSERT(nInYBot!=0);
ASSERT(0==(nInYBot&0xFFF)); //aligned with 4K(VPU_DEC_TILE_ALIGN)
lum_bot_20bits=nInYBot>>12;
chr_bot_20bits=nInCbBot>>12;
}
*pOutY=(lum_top_20bits<< 12) + (chr_top_20bits >> 8);
*pOutCb=(chr_top_20bits << 24) + (lum_bot_20bits << 4) + (chr_bot_20bits >> 16);
*pOutCr=chr_bot_20bits << 16;
return 1;
}
int VP8CreateSeqHeader(unsigned char* pHeader, int* pHeaderLen,
unsigned int nTimeBaseDen,unsigned int nTimeBaseNum,unsigned int nFrameCnt,int nWidth,int nHeight)
{
int i=0;
pHeader[i++] = 'D';
pHeader[i++] = 'K';
pHeader[i++] = 'I';
pHeader[i++] = 'F';
/*version*/
pHeader[i++]=0;
pHeader[i++]=0;
/*headersize*/
pHeader[i++]=VP8_SEQ_HEADER_SIZE;
pHeader[i++]=0;
/*fourcc*/
pHeader[i++]='V';
pHeader[i++]='P';
pHeader[i++]='8';
pHeader[i++]='0';
/*width*/
pHeader[i++]=(unsigned char)nWidth;
pHeader[i++]=(unsigned char)(((nWidth >> 8) & 0xff));
/*height*/
pHeader[i++]=(unsigned char)nHeight;
pHeader[i++]=(unsigned char)(((nHeight >> 8) & 0xff));
/*rate*/
pHeader[i++] = (unsigned char)nTimeBaseDen;
pHeader[i++] = (unsigned char)(((nTimeBaseDen >> 8) & 0xff));
pHeader[i++] = (unsigned char)(((nTimeBaseDen >> 16) & 0xff));
pHeader[i++] = (unsigned char)(((nTimeBaseDen >> 24) & 0xff));
/*scale*/
pHeader[i++] = (unsigned char)nTimeBaseNum;
pHeader[i++] = (unsigned char)(((nTimeBaseNum >> 8) & 0xff));
pHeader[i++] = (unsigned char)(((nTimeBaseNum >> 16) & 0xff));
pHeader[i++] = (unsigned char)(((nTimeBaseNum >> 24) & 0xff));
/*frame cnt*/
pHeader[i++] = (unsigned char)nFrameCnt;
pHeader[i++] = (unsigned char)(((nFrameCnt >> 8) & 0xff));
pHeader[i++] = (unsigned char)(((nFrameCnt >> 16) & 0xff));
pHeader[i++] = (unsigned char)(((nFrameCnt >> 24) & 0xff));
/*unused*/
pHeader[i++]=0;
pHeader[i++]=0;
pHeader[i++]=0;
pHeader[i++]=0;
ASSERT(i==VP8_SEQ_HEADER_SIZE);
*pHeaderLen=VP8_SEQ_HEADER_SIZE;
return 1;
}
int VP8CreateFrameHeader(unsigned char* pHeader, int* pHeaderLen,unsigned int nInSize,unsigned nPTSLow32,unsigned int nPTSHig32)
{
int i=0;
/*frame size*/
pHeader[i++] = (unsigned char)nInSize;
pHeader[i++] = (unsigned char)(nInSize >> 8);
pHeader[i++] = (unsigned char)(nInSize >> 16);
pHeader[i++] = (unsigned char)(nInSize >> 24);
/*PTS[31:0]*/
pHeader[i++] = (unsigned char)nPTSLow32;
pHeader[i++] = (unsigned char)(nPTSLow32 >> 8);
pHeader[i++] = (unsigned char)(nPTSLow32 >> 16);
pHeader[i++] = (unsigned char)(nPTSLow32 >> 24);
/*PTS[63:32]*/
pHeader[i++] = (unsigned char)nPTSHig32;
pHeader[i++] = (unsigned char)(nPTSHig32 >> 8);
pHeader[i++] = (unsigned char)(nPTSHig32 >> 16);
pHeader[i++] = (unsigned char)(nPTSHig32 >> 24);
ASSERT(i==VP8_FRM_HEADER_SIZE);
*pHeaderLen=VP8_FRM_HEADER_SIZE;
return 1;
}
int DIV3CreateSeqHeader(unsigned char* pHeader, int* pHeaderLen,
unsigned int nTimeBaseDen,unsigned int nTimeBaseNum,unsigned int nFrameCnt,int nWidth,int nHeight)
{
int i=0;
pHeader[i++] = 'C';
pHeader[i++] = 'N';
pHeader[i++] = 'M';
pHeader[i++] = 'V';
/*version*/
pHeader[i++]=0;
pHeader[i++]=0;
/*headersize*/
pHeader[i++]=DIV3_SEQ_HEADER_SIZE;
pHeader[i++]=0;
/*fourcc*/
pHeader[i++]='D';
pHeader[i++]='I';
pHeader[i++]='V';
pHeader[i++]='3';
/*width*/
pHeader[i++]=(unsigned char)(nWidth&0xFF);
pHeader[i++]=(unsigned char)(((nWidth >> 8) & 0xFF));
/*height*/
pHeader[i++]=(unsigned char)(nHeight&0xFF);
pHeader[i++]=(unsigned char)(((nHeight >> 8) & 0xFF));
/*rate*/
pHeader[i++] = (unsigned char)nTimeBaseDen;
pHeader[i++] = (unsigned char)(((nTimeBaseDen >> 8) & 0xFF));
pHeader[i++] = (unsigned char)(((nTimeBaseDen >> 16) & 0xFF));
pHeader[i++] = (unsigned char)(((nTimeBaseDen >> 24) & 0xFF));
/*scale*/
pHeader[i++] = (unsigned char)(nTimeBaseNum&0xFF);
pHeader[i++] = (unsigned char)(((nTimeBaseNum >> 8) & 0xFF));
pHeader[i++] = (unsigned char)(((nTimeBaseNum >> 16) & 0xFF));
pHeader[i++] = (unsigned char)(((nTimeBaseNum >> 24) & 0xFF));
/*frame cnt*/
pHeader[i++] = (unsigned char)(nFrameCnt&0xFF);
pHeader[i++] = (unsigned char)(((nFrameCnt >> 8) & 0xFF));
pHeader[i++] = (unsigned char)(((nFrameCnt >> 16) & 0xFF));
pHeader[i++] = (unsigned char)(((nFrameCnt >> 24) & 0xFF));
/*unused*/
pHeader[i++]=0;
pHeader[i++]=0;
pHeader[i++]=0;
pHeader[i++]=0;
ASSERT(i==DIV3_SEQ_HEADER_SIZE);
*pHeaderLen=DIV3_SEQ_HEADER_SIZE;
return 1;
}
int DIV3CreateFrameHeader(unsigned char* pHeader, int* pHeaderLen,unsigned int nInSize,unsigned nPTSLow32,unsigned int nPTSHig32)
{
int i=0;
/*frame size*/
pHeader[i++] = (unsigned char)nInSize;
pHeader[i++] = (unsigned char)(nInSize >> 8);
pHeader[i++] = (unsigned char)(nInSize >> 16);
pHeader[i++] = (unsigned char)(nInSize >> 24);
/*PTS[31:0]*/
pHeader[i++] = (unsigned char)nPTSLow32;
pHeader[i++] = (unsigned char)(nPTSLow32 >> 8);
pHeader[i++] = (unsigned char)(nPTSLow32 >> 16);
pHeader[i++] = (unsigned char)(nPTSLow32 >> 24);
/*PTS[63:32]*/
pHeader[i++] = (unsigned char)nPTSHig32;
pHeader[i++] = (unsigned char)(nPTSHig32 >> 8);
pHeader[i++] = (unsigned char)(nPTSHig32 >> 16);
pHeader[i++] = (unsigned char)(nPTSHig32 >> 24);
ASSERT(i==DIV3_FRM_HEADER_SIZE);
*pHeaderLen=DIV3_FRM_HEADER_SIZE;
return 1;
}
unsigned int VpuConvertAspectRatio(VpuCodStd eInFormat,unsigned int InRatio,int InWidth,int InHeight, int profile, int level)
{
#define FIXED_POINTED_1 (0x10000) //(Q16_SHIFT)
unsigned int tmp;
//set default value: no scale
unsigned int OutWidth=FIXED_POINTED_1;
unsigned int OutHeight=FIXED_POINTED_1;
unsigned int Q16Ratio=FIXED_POINTED_1;
VPU_LOG("aspect ratio: format: %d, ratio: 0x%X, InWidth: %d, InHeight: %d \r\n",eInFormat,InRatio,InWidth,InHeight);
switch(eInFormat)
{
case VPU_V_MPEG2:
//FIXME: we have no other better info to identify mpeg1 or mpeg2 except profile/level
if((profile==0)&&(level==0))
{
//Mpeg1
/*
CODE HEIGHT/WIDTH COMMENT
0000 undefined Forbidden
0001 1.0 square pels
0010 0.6735
0011 0.7031 16:9 625-line
0100 0.7615
0101 0.8055
0110 0.8437 16:9 525-line
0111 0.8935
1000 0.9157 702x575 at 4:3 = 0.9157
1001 0.9815
1010 1.0255
1011 1.0695
1100 1.0950 711x487 at 4:3 = 1.0950
1101 1.1575
1110 1.2015
1111 undefined reserved
*/ switch(InRatio)
{
case 0x1: // 1.0 (SAR)
//no scale(use default value)
break;
case 0x2: // 1:0.6735 (SAR)
OutWidth=(double)FIXED_POINTED_1*10000;
OutHeight=FIXED_POINTED_1*6735;
break;
case 0x3: // 1:0.7031 (SAR)
OutWidth=(double)FIXED_POINTED_1*10000;
OutHeight=FIXED_POINTED_1*7031;
break;
case 0x4: // 1:0.7615 (SAR)
OutWidth=(double)FIXED_POINTED_1*10000;
OutHeight=FIXED_POINTED_1*7615;
break;
case 0x5: // 1:0.8055 (SAR)
OutWidth=(double)FIXED_POINTED_1*10000;
OutHeight=FIXED_POINTED_1*8055;
break;
case 0x6: // 1:0.8437 (SAR)
OutWidth=(double)FIXED_POINTED_1*10000;
OutHeight=FIXED_POINTED_1*8437;
break;
case 0x7: // 1:0.8935 (SAR)
OutWidth=(double)FIXED_POINTED_1*10000;
OutHeight=FIXED_POINTED_1*8935;
break;
case 0x8: // 1:0.9157 (SAR)
OutWidth=(double)FIXED_POINTED_1*10000;
OutHeight=FIXED_POINTED_1*9157;
break;
case 0x9: // 1:0.9815 (SAR)
OutWidth=(double)FIXED_POINTED_1*10000;
OutHeight=FIXED_POINTED_1*9815;
break;
case 0xA: // 1:1.0255 (SAR)
OutWidth=(double)FIXED_POINTED_1*10000;
OutHeight=FIXED_POINTED_1*10255;
break;
case 0xB: // 1:1.0695 (SAR)
OutWidth=(double)FIXED_POINTED_1*10000;
OutHeight=FIXED_POINTED_1*10695;
break;
case 0xC: // 1:1.0950 (SAR)
OutWidth=(double)FIXED_POINTED_1*10000;
OutHeight=FIXED_POINTED_1*10950;
break;
case 0xD: // 1:1.1575 (SAR)
OutWidth=(double)FIXED_POINTED_1*10000;
OutHeight=FIXED_POINTED_1*11575;
break;
case 0xE: // 1:1.2015 (SAR)
OutWidth=(double)FIXED_POINTED_1*10000;
OutHeight=FIXED_POINTED_1*12015;
break;
default:
VPU_ERROR("unsupported ration: 0x%X \r\n",InRatio);
break;
}
}
else
{
//Mpeg2
/*
aspect_ratio_information Sample Aspect Ratio DAR
0000 Forbidden Forbidden
0001 1.0 (Square Sample) –
0010 – 3 ÷ 4
0011 – 9 ÷ 16
0100 – 1 ÷ 2.21
0101 – Reserved
… …
1111 – Reserved
*/
switch(InRatio)
{
case 0x1: // 1.0 (SAR)
//no scale(use default value)
break;
case 0x2: // 4:3 (DAR)
OutWidth=(double)FIXED_POINTED_1*InHeight*4/(3*InWidth);
OutHeight=FIXED_POINTED_1;
break;
case 0x3: // 16:9 (DAR)
OutWidth=(double)FIXED_POINTED_1*InHeight*16/(9*InWidth);
OutHeight=FIXED_POINTED_1;
break;
case 0x4: // 2.21 : 1 (DAR)
OutWidth=(double)FIXED_POINTED_1*InHeight*221/(100*InWidth);
OutHeight=FIXED_POINTED_1;
break;
default:
VPU_ERROR("unsupported ration: 0x%X \r\n",InRatio);
break;
}
}
break;
case VPU_V_AVC: