FFmpeg
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
v210x.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009 Michael Niedermayer <michaelni@gmx.at>
3  *
4  * This file is part of FFmpeg.
5  *
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.
10  *
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.
15  *
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
19  */
20 
21 #include "avcodec.h"
22 #include "internal.h"
23 #include "libavutil/bswap.h"
24 #include "libavutil/internal.h"
25 #include "libavutil/mem.h"
26 
28 {
29  if(avctx->width & 1){
30  av_log(avctx, AV_LOG_ERROR, "v210x needs even width\n");
31  return -1;
32  }
34  avctx->bits_per_raw_sample= 10;
35 
37  if (!avctx->coded_frame)
38  return AVERROR(ENOMEM);
39 
40  return 0;
41 }
42 
43 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
44  AVPacket *avpkt)
45 {
46  int y=0;
47  int width= avctx->width;
48  AVFrame *pic= avctx->coded_frame;
49  const uint32_t *src= (const uint32_t *)avpkt->data;
50  uint16_t *ydst, *udst, *vdst, *yend;
51 
52  if(pic->data[0])
53  avctx->release_buffer(avctx, pic);
54 
55  if(avpkt->size < avctx->width * avctx->height * 8 / 3){
56  av_log(avctx, AV_LOG_ERROR, "Packet too small\n");
57  return -1;
58  }
59 
60  if(avpkt->size > avctx->width * avctx->height * 8 / 3){
61  av_log_ask_for_sample(avctx, "Probably padded data\n");
62  }
63 
64  pic->reference= 0;
65  if(ff_get_buffer(avctx, pic) < 0)
66  return -1;
67 
68  ydst= (uint16_t *)pic->data[0];
69  udst= (uint16_t *)pic->data[1];
70  vdst= (uint16_t *)pic->data[2];
71  yend= ydst + width;
73  pic->key_frame= 1;
74 
75  for(;;){
76  uint32_t v= av_be2ne32(*src++);
77  *udst++= (v>>16) & 0xFFC0;
78  *ydst++= (v>>6 ) & 0xFFC0;
79  *vdst++= (v<<4 ) & 0xFFC0;
80 
81  v= av_be2ne32(*src++);
82  *ydst++= (v>>16) & 0xFFC0;
83 
84  if(ydst >= yend){
85  ydst+= pic->linesize[0]/2 - width;
86  udst+= pic->linesize[1]/2 - width/2;
87  vdst+= pic->linesize[2]/2 - width/2;
88  yend= ydst + width;
89  if(++y >= avctx->height)
90  break;
91  }
92 
93  *udst++= (v>>6 ) & 0xFFC0;
94  *ydst++= (v<<4 ) & 0xFFC0;
95 
96  v= av_be2ne32(*src++);
97  *vdst++= (v>>16) & 0xFFC0;
98  *ydst++= (v>>6 ) & 0xFFC0;
99 
100  if(ydst >= yend){
101  ydst+= pic->linesize[0]/2 - width;
102  udst+= pic->linesize[1]/2 - width/2;
103  vdst+= pic->linesize[2]/2 - width/2;
104  yend= ydst + width;
105  if(++y >= avctx->height)
106  break;
107  }
108 
109  *udst++= (v<<4 ) & 0xFFC0;
110 
111  v= av_be2ne32(*src++);
112  *ydst++= (v>>16) & 0xFFC0;
113  *vdst++= (v>>6 ) & 0xFFC0;
114  *ydst++= (v<<4 ) & 0xFFC0;
115  if(ydst >= yend){
116  ydst+= pic->linesize[0]/2 - width;
117  udst+= pic->linesize[1]/2 - width/2;
118  vdst+= pic->linesize[2]/2 - width/2;
119  yend= ydst + width;
120  if(++y >= avctx->height)
121  break;
122  }
123  }
124 
125  *got_frame = 1;
126  *(AVFrame*)data= *avctx->coded_frame;
127 
128  return avpkt->size;
129 }
130 
132 {
133  AVFrame *pic = avctx->coded_frame;
134  if (pic->data[0])
135  avctx->release_buffer(avctx, pic);
136  av_freep(&avctx->coded_frame);
137 
138  return 0;
139 }
140 
142  .name = "v210x",
143  .type = AVMEDIA_TYPE_VIDEO,
144  .id = AV_CODEC_ID_V210X,
145  .init = decode_init,
146  .close = decode_close,
147  .decode = decode_frame,
148  .capabilities = CODEC_CAP_DR1,
149  .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
150 };