Mercurial > libavcodec.hg
annotate mdec.c @ 11032:01bd040f8607 libavcodec
Unroll main loop so the edge==0 case is seperate.
This allows many things to be simplified away.
h264 decoder is overall 1% faster with a mbaff sample and
0.1% slower with the cathedral sample, probably because the slow loop
filter code must be loaded into the code cache for each first MB of each
row but isnt used for the following MBs.
author | michael |
---|---|
date | Thu, 28 Jan 2010 01:24:25 +0000 |
parents | 8754b8361dc9 |
children | 98970e51365a |
rev | line source |
---|---|
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
1 /* |
7629 | 2 * Sony PlayStation MDEC (Motion DECoder) |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
3 * Copyright (c) 2003 Michael Niedermayer |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
4 * |
5214 | 5 * based upon code from Sebastian Jedruszkiewicz <elf@frogger.rules.pl> |
6 * | |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3089
diff
changeset
|
7 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3089
diff
changeset
|
8 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3089
diff
changeset
|
9 * FFmpeg is free software; you can redistribute it and/or |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
10 * modify it under the terms of the GNU Lesser General Public |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
11 * License as published by the Free Software Foundation; either |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3089
diff
changeset
|
12 * version 2.1 of the License, or (at your option) any later version. |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
13 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3089
diff
changeset
|
14 * FFmpeg is distributed in the hope that it will be useful, |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
17 * Lesser General Public License for more details. |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
18 * |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
19 * You should have received a copy of the GNU Lesser General Public |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3089
diff
changeset
|
20 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2967
diff
changeset
|
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
22 */ |
2967 | 23 |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
24 /** |
8718
e9d9d946f213
Use full internal pathname in doxygen @file directives.
diego
parents:
7630
diff
changeset
|
25 * @file libavcodec/mdec.c |
7629 | 26 * Sony PlayStation MDEC (Motion DECoder) |
27 * This is very similar to intra-only MPEG-1. | |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
28 */ |
2967 | 29 |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
30 #include "avcodec.h" |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
31 #include "dsputil.h" |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
32 #include "mpegvideo.h" |
7623
0bd920dcb7a5
Untangle mpeg12.c and mdec.c so that mdec.c can be compiled separately.
diego
parents:
7153
diff
changeset
|
33 #include "mpeg12.h" |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
34 |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
35 typedef struct MDECContext{ |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
36 AVCodecContext *avctx; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
37 DSPContext dsp; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
38 AVFrame picture; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
39 GetBitContext gb; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
40 ScanTable scantable; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
41 int version; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
42 int qscale; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
43 int last_dc[3]; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
44 int mb_width; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
45 int mb_height; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
46 int mb_x, mb_y; |
10961
34a65026fa06
Move array specifiers outside DECLARE_ALIGNED() invocations
mru
parents:
10086
diff
changeset
|
47 DECLARE_ALIGNED_16(DCTELEM, block)[6][64]; |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
48 uint8_t *bitstream_buffer; |
3066
04b924f8f5a5
warning fixes by Luca Abeni, lucabe72 ##@## email ##.## it
diego
parents:
3036
diff
changeset
|
49 unsigned int bitstream_buffer_size; |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
50 int block_last_index[6]; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
51 } MDECContext; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
52 |
7629 | 53 //very similar to MPEG-1 |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
54 static inline int mdec_decode_block_intra(MDECContext *a, DCTELEM *block, int n) |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
55 { |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
56 int level, diff, i, j, run; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
57 int component; |
5210 | 58 RLTable *rl = &ff_rl_mpeg1; |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
59 uint8_t * const scantable= a->scantable.permutated; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
60 const uint16_t *quant_matrix= ff_mpeg1_default_intra_matrix; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
61 const int qscale= a->qscale; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
62 |
7629 | 63 /* DC coefficient */ |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
64 if(a->version==2){ |
1437 | 65 block[0]= 2*get_sbits(&a->gb, 10) + 1024; |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
66 }else{ |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
67 component = (n <= 3 ? 0 : n - 4 + 1); |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
68 diff = decode_dc(&a->gb, component); |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
69 if (diff >= 0xffff) |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
70 return -1; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
71 a->last_dc[component]+= diff; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
72 block[0] = a->last_dc[component]<<3; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
73 } |
2967 | 74 |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
75 i = 0; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
76 { |
2967 | 77 OPEN_READER(re, &a->gb); |
7629 | 78 /* now quantify & encode AC coefficients */ |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
79 for(;;) { |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
80 UPDATE_CACHE(re, &a->gb); |
2615
0d88e3f89379
avoid UPDATE_CACHE() in GET_RL_VLC() if not needed
michael
parents:
2453
diff
changeset
|
81 GET_RL_VLC(level, run, re, &a->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); |
2967 | 82 |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
83 if(level == 127){ |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
84 break; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
85 } else if(level != 0) { |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
86 i += run; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
87 j = scantable[i]; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
88 level= (level*qscale*quant_matrix[j])>>3; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
89 level = (level ^ SHOW_SBITS(re, &a->gb, 1)) - SHOW_SBITS(re, &a->gb, 1); |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
90 LAST_SKIP_BITS(re, &a->gb, 1); |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
91 } else { |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
92 /* escape */ |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
93 run = SHOW_UBITS(re, &a->gb, 6)+1; LAST_SKIP_BITS(re, &a->gb, 6); |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
94 UPDATE_CACHE(re, &a->gb); |
1436 | 95 level = SHOW_SBITS(re, &a->gb, 10); SKIP_BITS(re, &a->gb, 10); |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
96 i += run; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
97 j = scantable[i]; |
1437 | 98 if(level<0){ |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
99 level= -level; |
1437 | 100 level= (level*qscale*quant_matrix[j])>>3; |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
101 level= (level-1)|1; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
102 level= -level; |
1437 | 103 }else{ |
104 level= (level*qscale*quant_matrix[j])>>3; | |
105 level= (level-1)|1; | |
106 } | |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
107 } |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
108 if (i > 63){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1532
diff
changeset
|
109 av_log(a->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", a->mb_x, a->mb_y); |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
110 return -1; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
111 } |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
112 |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
113 block[j] = level; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
114 } |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
115 CLOSE_READER(re, &a->gb); |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
116 } |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
117 a->block_last_index[n] = i; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
118 return 0; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
119 } |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
120 |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
121 static inline int decode_mb(MDECContext *a, DCTELEM block[6][64]){ |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
122 int i; |
1438 | 123 const int block_index[6]= {5,4,0,1,2,3}; |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
124 |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
125 a->dsp.clear_blocks(block[0]); |
2967 | 126 |
1437 | 127 for(i=0; i<6; i++){ |
2967 | 128 if( mdec_decode_block_intra(a, block[ block_index[i] ], block_index[i]) < 0) |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
129 return -1; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
130 } |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
131 return 0; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
132 } |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
133 |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
134 static inline void idct_put(MDECContext *a, int mb_x, int mb_y){ |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
135 DCTELEM (*block)[64]= a->block; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
136 int linesize= a->picture.linesize[0]; |
2967 | 137 |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
138 uint8_t *dest_y = a->picture.data[0] + (mb_y * 16* linesize ) + mb_x * 16; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
139 uint8_t *dest_cb = a->picture.data[1] + (mb_y * 8 * a->picture.linesize[1]) + mb_x * 8; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
140 uint8_t *dest_cr = a->picture.data[2] + (mb_y * 8 * a->picture.linesize[2]) + mb_x * 8; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
141 |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
142 a->dsp.idct_put(dest_y , linesize, block[0]); |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
143 a->dsp.idct_put(dest_y + 8, linesize, block[1]); |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
144 a->dsp.idct_put(dest_y + 8*linesize , linesize, block[2]); |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
145 a->dsp.idct_put(dest_y + 8*linesize + 8, linesize, block[3]); |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
146 |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
147 if(!(a->avctx->flags&CODEC_FLAG_GRAY)){ |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
148 a->dsp.idct_put(dest_cb, a->picture.linesize[1], block[4]); |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
149 a->dsp.idct_put(dest_cr, a->picture.linesize[2], block[5]); |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
150 } |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
151 } |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
152 |
2967 | 153 static int decode_frame(AVCodecContext *avctx, |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
154 void *data, int *data_size, |
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
155 AVPacket *avpkt) |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
156 { |
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
157 const uint8_t *buf = avpkt->data; |
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8718
diff
changeset
|
158 int buf_size = avpkt->size; |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
159 MDECContext * const a = avctx->priv_data; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
160 AVFrame *picture = data; |
7153 | 161 AVFrame * const p= &a->picture; |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
162 int i; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
163 |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
164 if(p->data[0]) |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
165 avctx->release_buffer(avctx, p); |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
166 |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
167 p->reference= 0; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
168 if(avctx->get_buffer(avctx, p) < 0){ |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1532
diff
changeset
|
169 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
170 return -1; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
171 } |
6481 | 172 p->pict_type= FF_I_TYPE; |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
173 p->key_frame= 1; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
174 |
9415
141badec76fc
Add a av_fast_malloc function and replace several uses of av_fast_realloc,
reimar
parents:
9355
diff
changeset
|
175 av_fast_malloc(&a->bitstream_buffer, &a->bitstream_buffer_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); |
141badec76fc
Add a av_fast_malloc function and replace several uses of av_fast_realloc,
reimar
parents:
9355
diff
changeset
|
176 if (!a->bitstream_buffer) |
141badec76fc
Add a av_fast_malloc function and replace several uses of av_fast_realloc,
reimar
parents:
9355
diff
changeset
|
177 return AVERROR(ENOMEM); |
1431 | 178 for(i=0; i<buf_size; i+=2){ |
179 a->bitstream_buffer[i] = buf[i+1]; | |
180 a->bitstream_buffer[i+1]= buf[i ]; | |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
181 } |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
182 init_get_bits(&a->gb, a->bitstream_buffer, buf_size*8); |
2967 | 183 |
1435 | 184 /* skip over 4 preamble bytes in stream (typically 0xXX 0xXX 0x00 0x38) */ |
185 skip_bits(&a->gb, 32); | |
186 | |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
187 a->qscale= get_bits(&a->gb, 16); |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
188 a->version= get_bits(&a->gb, 16); |
2967 | 189 |
5986 | 190 a->last_dc[0]= |
191 a->last_dc[1]= | |
192 a->last_dc[2]= 128; | |
193 | |
1436 | 194 for(a->mb_x=0; a->mb_x<a->mb_width; a->mb_x++){ |
195 for(a->mb_y=0; a->mb_y<a->mb_height; a->mb_y++){ | |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
196 if( decode_mb(a, a->block) <0) |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
197 return -1; |
2967 | 198 |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
199 idct_put(a, a->mb_x, a->mb_y); |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
200 } |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
201 } |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
202 |
7150 | 203 p->quality= a->qscale * FF_QP2LAMBDA; |
10977
a7a2892e24de
Use qstride = 0 and allocate only a single line for qscale_table since
reimar
parents:
10961
diff
changeset
|
204 memset(p->qscale_table, a->qscale, a->mb_width); |
2967 | 205 |
7153 | 206 *picture = a->picture; |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
207 *data_size = sizeof(AVPicture); |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
208 |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
209 return (get_bits_count(&a->gb)+31)/32*4; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
210 } |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
211 |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6481
diff
changeset
|
212 static av_cold void mdec_common_init(AVCodecContext *avctx){ |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
213 MDECContext * const a = avctx->priv_data; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
214 |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
215 dsputil_init(&a->dsp, avctx); |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
216 |
2270 | 217 a->mb_width = (avctx->coded_width + 15) / 16; |
218 a->mb_height = (avctx->coded_height + 15) / 16; | |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
219 |
7153 | 220 avctx->coded_frame= &a->picture; |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
221 a->avctx= avctx; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
222 } |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
223 |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6481
diff
changeset
|
224 static av_cold int decode_init(AVCodecContext *avctx){ |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
225 MDECContext * const a = avctx->priv_data; |
7153 | 226 AVFrame *p= &a->picture; |
2967 | 227 |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
228 mdec_common_init(avctx); |
7630
d6390123201d
Rename ff_init_vlcs function to the more descriptive name ff_mpeg12_init_vlcs.
diego
parents:
7629
diff
changeset
|
229 ff_mpeg12_init_vlcs(); |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
230 ff_init_scantable(a->dsp.idct_permutation, &a->scantable, ff_zigzag_direct); |
7151 | 231 |
10977
a7a2892e24de
Use qstride = 0 and allocate only a single line for qscale_table since
reimar
parents:
10961
diff
changeset
|
232 p->qstride= 0; |
a7a2892e24de
Use qstride = 0 and allocate only a single line for qscale_table since
reimar
parents:
10961
diff
changeset
|
233 p->qscale_table= av_mallocz(a->mb_width); |
2832 | 234 avctx->pix_fmt= PIX_FMT_YUV420P; |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
235 |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
236 return 0; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
237 } |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
238 |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6481
diff
changeset
|
239 static av_cold int decode_end(AVCodecContext *avctx){ |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
240 MDECContext * const a = avctx->priv_data; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
241 |
10978 | 242 if(a->picture.data[0]) |
243 avctx->release_buffer(avctx, &a->picture); | |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
244 av_freep(&a->bitstream_buffer); |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
245 av_freep(&a->picture.qscale_table); |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
246 a->bitstream_buffer_size=0; |
2967 | 247 |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
248 return 0; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
249 } |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
250 |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
251 AVCodec mdec_decoder = { |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
252 "mdec", |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
253 CODEC_TYPE_VIDEO, |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
254 CODEC_ID_MDEC, |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
255 sizeof(MDECContext), |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
256 decode_init, |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
257 NULL, |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
258 decode_end, |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
259 decode_frame, |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
260 CODEC_CAP_DR1, |
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6798
diff
changeset
|
261 .long_name= NULL_IF_CONFIG_SMALL("Sony PlayStation MDEC (Motion DECoder)"), |
1410
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
262 }; |
524c904a66b8
PSX MDEC decoder, based upon some code from Sebastian Jedruszkiewicz <elf at frogger dot rules dot pl>
michaelni
parents:
diff
changeset
|
263 |