Replace 5 with AOT_SBR when referring to the MPEG-4 audio object type.
[FFMpeg-mirror/lagarith.git] / libavcodec / v210x.c
blob754b70a1f0f4dc70325e375bb0edf6c288ebe10b
1 /*
2 * Copyright (C) 2009 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "avcodec.h"
22 #include "libavutil/bswap.h"
24 static av_cold int decode_init(AVCodecContext *avctx)
26 if(avctx->width & 1){
27 av_log(avctx, AV_LOG_ERROR, "v210x needs even width\n");
28 return -1;
30 if(avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0)
31 return -1;
32 avctx->pix_fmt = PIX_FMT_YUV422P16;
33 avctx->bits_per_raw_sample= 10;
35 avctx->coded_frame= avcodec_alloc_frame();
37 return 0;
40 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
42 int y=0;
43 int width= avctx->width;
44 AVFrame *pic= avctx->coded_frame;
45 const uint32_t *src= (const uint32_t *)avpkt->data;
46 uint16_t *ydst, *udst, *vdst, *yend;
48 if(pic->data[0])
49 avctx->release_buffer(avctx, pic);
51 if(avpkt->size < avctx->width * avctx->height * 8 / 3){
52 av_log(avctx, AV_LOG_ERROR, "Packet too small\n");
53 return -1;
56 if(avpkt->size > avctx->width * avctx->height * 8 / 3){
57 av_log(avctx, AV_LOG_ERROR, "Probably padded data, need sample!\n");
60 pic->reference= 0;
61 if(avctx->get_buffer(avctx, pic) < 0)
62 return -1;
64 ydst= (uint16_t *)pic->data[0];
65 udst= (uint16_t *)pic->data[1];
66 vdst= (uint16_t *)pic->data[2];
67 yend= ydst + width;
68 pic->pict_type= FF_I_TYPE;
69 pic->key_frame= 1;
71 for(;;){
72 uint32_t v= be2me_32(*src++);
73 *udst++= (v>>16) & 0xFFC0;
74 *ydst++= (v>>6 ) & 0xFFC0;
75 *vdst++= (v<<4 ) & 0xFFC0;
77 v= be2me_32(*src++);
78 *ydst++= (v>>16) & 0xFFC0;
80 if(ydst >= yend){
81 ydst+= pic->linesize[0]/2 - width;
82 udst+= pic->linesize[1]/2 - width/2;
83 vdst+= pic->linesize[2]/2 - width/2;
84 yend= ydst + width;
85 if(++y >= avctx->height)
86 break;
89 *udst++= (v>>6 ) & 0xFFC0;
90 *ydst++= (v<<4 ) & 0xFFC0;
92 v= be2me_32(*src++);
93 *vdst++= (v>>16) & 0xFFC0;
94 *ydst++= (v>>6 ) & 0xFFC0;
96 if(ydst >= yend){
97 ydst+= pic->linesize[0]/2 - width;
98 udst+= pic->linesize[1]/2 - width/2;
99 vdst+= pic->linesize[2]/2 - width/2;
100 yend= ydst + width;
101 if(++y >= avctx->height)
102 break;
105 *udst++= (v<<4 ) & 0xFFC0;
107 v= be2me_32(*src++);
108 *ydst++= (v>>16) & 0xFFC0;
109 *vdst++= (v>>6 ) & 0xFFC0;
110 *ydst++= (v<<4 ) & 0xFFC0;
111 if(ydst >= yend){
112 ydst+= pic->linesize[0]/2 - width;
113 udst+= pic->linesize[1]/2 - width/2;
114 vdst+= pic->linesize[2]/2 - width/2;
115 yend= ydst + width;
116 if(++y >= avctx->height)
117 break;
121 *data_size=sizeof(AVFrame);
122 *(AVFrame*)data= *avctx->coded_frame;
124 return avpkt->size;
127 AVCodec v210x_decoder = {
128 "v210x",
129 CODEC_TYPE_VIDEO,
130 CODEC_ID_V210X,
132 decode_init,
133 NULL,
134 NULL,
135 decode_frame,
136 CODEC_CAP_DR1,