Mercurial > libavcodec.hg
comparison v210x.c @ 9535:4a4929da4ddc libavcodec
Support reading packed YUV422 10bit samples from Sveriges Television AB (SVT)
which have AFAIK been created for the jvt:
ftp://vqeg.its.bldrdoc.gov/HDTV/SVT_exports/SVT_YUV10_Exports_/NewMobCal_YUV10_720p5994_/
I have called the format v210x due to its similarity to v210, note though I have
not confirmed that v210x is different from actual v210 samples it just is
different from the description of v210 I am aware of.
author | michael |
---|---|
date | Wed, 22 Apr 2009 01:50:15 +0000 |
parents | |
children | 2f804e0a17fc |
comparison
equal
deleted
inserted
replaced
9534:717f799077ad | 9535:4a4929da4ddc |
---|---|
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 "libavutil/bswap.h" | |
23 | |
24 static av_cold int decode_init(AVCodecContext *avctx) | |
25 { | |
26 if(avctx->width & 1){ | |
27 av_log(avctx, AV_LOG_ERROR, "v210x needs even width\n"); | |
28 return -1; | |
29 } | |
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; | |
34 | |
35 avctx->coded_frame= avcodec_alloc_frame(); | |
36 | |
37 return 0; | |
38 } | |
39 | |
40 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) | |
41 { | |
42 int y=0; | |
43 int width= avctx->width; | |
44 AVFrame *pic= avctx->coded_frame; | |
45 const uint32_t *src= avpkt->data; | |
46 uint16_t *ydst, *udst, *vdst, *yend; | |
47 | |
48 if(pic->data[0]) | |
49 avctx->release_buffer(avctx, pic); | |
50 | |
51 if(avpkt->size < avctx->width * avctx->height * 8 / 3){ | |
52 av_log(avctx, AV_LOG_ERROR, "Packet too small\n"); | |
53 return -1; | |
54 } | |
55 | |
56 if(avpkt->size > avctx->width * avctx->height * 8 / 3){ | |
57 av_log(avctx, AV_LOG_ERROR, "Probably padded data, need sample!\n"); | |
58 } | |
59 | |
60 pic->reference= 0; | |
61 if(avctx->get_buffer(avctx, pic) < 0) | |
62 return -1; | |
63 | |
64 ydst= pic->data[0]; | |
65 udst= pic->data[1]; | |
66 vdst= pic->data[2]; | |
67 yend= ydst + width; | |
68 pic->pict_type= FF_I_TYPE; | |
69 pic->key_frame= 1; | |
70 | |
71 for(;;){ | |
72 uint32_t v= be2me_32(*src++); | |
73 *udst++= (v>>16) & 0xFFC0; | |
74 *ydst++= (v>>6 ) & 0xFFC0; | |
75 *vdst++= (v<<4 ) & 0xFFC0; | |
76 | |
77 v= be2me_32(*src++); | |
78 *ydst++= (v>>16) & 0xFFC0; | |
79 | |
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; | |
87 } | |
88 | |
89 *udst++= (v>>6 ) & 0xFFC0; | |
90 *ydst++= (v<<4 ) & 0xFFC0; | |
91 | |
92 v= be2me_32(*src++); | |
93 *vdst++= (v>>16) & 0xFFC0; | |
94 *ydst++= (v>>6 ) & 0xFFC0; | |
95 | |
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; | |
103 } | |
104 | |
105 *udst++= (v<<4 ) & 0xFFC0; | |
106 | |
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; | |
118 } | |
119 } | |
120 | |
121 *data_size=sizeof(AVFrame); | |
122 *(AVFrame*)data= *avctx->coded_frame; | |
123 | |
124 return avpkt->size; | |
125 } | |
126 | |
127 AVCodec v210x_decoder = { | |
128 "v210x", | |
129 CODEC_TYPE_VIDEO, | |
130 CODEC_ID_V210X, | |
131 0, | |
132 decode_init, | |
133 NULL, | |
134 NULL, | |
135 decode_frame, | |
136 CODEC_CAP_DR1, | |
137 }; |