00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00025 #include "avcodec.h"
00026 #include "mpegvideo.h"
00027
00028
00029
00030
00031 typedef struct VCR1Context{
00032 AVCodecContext *avctx;
00033 AVFrame picture;
00034 int delta[16];
00035 int offset[4];
00036 } VCR1Context;
00037
00038 static int decode_frame(AVCodecContext *avctx,
00039 void *data, int *data_size,
00040 uint8_t *buf, int buf_size)
00041 {
00042 VCR1Context * const a = avctx->priv_data;
00043 AVFrame *picture = data;
00044 AVFrame * const p= (AVFrame*)&a->picture;
00045 uint8_t *bytestream= buf;
00046 int i, x, y;
00047
00048 if(p->data[0])
00049 avctx->release_buffer(avctx, p);
00050
00051 p->reference= 0;
00052 if(avctx->get_buffer(avctx, p) < 0){
00053 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
00054 return -1;
00055 }
00056 p->pict_type= I_TYPE;
00057 p->key_frame= 1;
00058
00059 for(i=0; i<16; i++){
00060 a->delta[i]= *(bytestream++);
00061 bytestream++;
00062 }
00063
00064 for(y=0; y<avctx->height; y++){
00065 int offset;
00066 uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ];
00067
00068 if((y&3) == 0){
00069 uint8_t *cb= &a->picture.data[1][ (y>>2)*a->picture.linesize[1] ];
00070 uint8_t *cr= &a->picture.data[2][ (y>>2)*a->picture.linesize[2] ];
00071
00072 for(i=0; i<4; i++)
00073 a->offset[i]= *(bytestream++);
00074
00075 offset= a->offset[0] - a->delta[ bytestream[2]&0xF ];
00076 for(x=0; x<avctx->width; x+=4){
00077 luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
00078 luma[1]=( offset += a->delta[ bytestream[2]>>4 ]);
00079 luma[2]=( offset += a->delta[ bytestream[0]&0xF ]);
00080 luma[3]=( offset += a->delta[ bytestream[0]>>4 ]);
00081 luma += 4;
00082
00083 *(cb++) = bytestream[3];
00084 *(cr++) = bytestream[1];
00085
00086 bytestream+= 4;
00087 }
00088 }else{
00089 offset= a->offset[y&3] - a->delta[ bytestream[2]&0xF ];
00090
00091 for(x=0; x<avctx->width; x+=8){
00092 luma[0]=( offset += a->delta[ bytestream[2]&0xF ]);
00093 luma[1]=( offset += a->delta[ bytestream[2]>>4 ]);
00094 luma[2]=( offset += a->delta[ bytestream[3]&0xF ]);
00095 luma[3]=( offset += a->delta[ bytestream[3]>>4 ]);
00096 luma[4]=( offset += a->delta[ bytestream[0]&0xF ]);
00097 luma[5]=( offset += a->delta[ bytestream[0]>>4 ]);
00098 luma[6]=( offset += a->delta[ bytestream[1]&0xF ]);
00099 luma[7]=( offset += a->delta[ bytestream[1]>>4 ]);
00100 luma += 8;
00101 bytestream+= 4;
00102 }
00103 }
00104 }
00105
00106 *picture= *(AVFrame*)&a->picture;
00107 *data_size = sizeof(AVPicture);
00108
00109 emms_c();
00110
00111 return buf_size;
00112 }
00113
00114 #if 0
00115 static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){
00116 VCR1Context * const a = avctx->priv_data;
00117 AVFrame *pict = data;
00118 AVFrame * const p= (AVFrame*)&a->picture;
00119 int size;
00120 int mb_x, mb_y;
00121
00122 *p = *pict;
00123 p->pict_type= I_TYPE;
00124 p->key_frame= 1;
00125
00126 emms_c();
00127
00128 align_put_bits(&a->pb);
00129 while(get_bit_count(&a->pb)&31)
00130 put_bits(&a->pb, 8, 0);
00131
00132 size= get_bit_count(&a->pb)/32;
00133
00134 return size*4;
00135 }
00136 #endif
00137
00138 static void common_init(AVCodecContext *avctx){
00139 VCR1Context * const a = avctx->priv_data;
00140
00141 avctx->coded_frame= (AVFrame*)&a->picture;
00142 a->avctx= avctx;
00143 }
00144
00145 static int decode_init(AVCodecContext *avctx){
00146
00147 common_init(avctx);
00148
00149 avctx->pix_fmt= PIX_FMT_YUV410P;
00150
00151 return 0;
00152 }
00153
00154 #if 0
00155 static int encode_init(AVCodecContext *avctx){
00156
00157 common_init(avctx);
00158
00159 return 0;
00160 }
00161 #endif
00162
00163 AVCodec vcr1_decoder = {
00164 "vcr1",
00165 CODEC_TYPE_VIDEO,
00166 CODEC_ID_VCR1,
00167 sizeof(VCR1Context),
00168 decode_init,
00169 NULL,
00170 NULL,
00171 decode_frame,
00172 CODEC_CAP_DR1,
00173 };
00174 #if 0
00175 #ifdef CONFIG_ENCODERS
00176
00177 AVCodec vcr1_encoder = {
00178 "vcr1",
00179 CODEC_TYPE_VIDEO,
00180 CODEC_ID_VCR1,
00181 sizeof(VCR1Context),
00182 encode_init,
00183 encode_frame,
00184
00185 };
00186
00187 #endif //CONFIG_ENCODERS
00188 #endif