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 Libav.
5  *
6  * Libav 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  * Libav 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 Libav; 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 
38  return 0;
39 }
40 
41 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
42  AVPacket *avpkt)
43 {
44  int y=0;
45  int width= avctx->width;
46  AVFrame *pic= avctx->coded_frame;
47  const uint32_t *src= (const uint32_t *)avpkt->data;
48  uint16_t *ydst, *udst, *vdst, *yend;
49 
50  if(pic->data[0])
51  avctx->release_buffer(avctx, pic);
52 
53  if(avpkt->size < avctx->width * avctx->height * 8 / 3){
54  av_log(avctx, AV_LOG_ERROR, "Packet too small\n");
55  return -1;
56  }
57 
58  if(avpkt->size > avctx->width * avctx->height * 8 / 3){
59  av_log_ask_for_sample(avctx, "Probably padded data\n");
60  }
61 
62  pic->reference= 0;
63  if(ff_get_buffer(avctx, pic) < 0)
64  return -1;
65 
66  ydst= (uint16_t *)pic->data[0];
67  udst= (uint16_t *)pic->data[1];
68  vdst= (uint16_t *)pic->data[2];
69  yend= ydst + width;
71  pic->key_frame= 1;
72 
73  for(;;){
74  uint32_t v= av_be2ne32(*src++);
75  *udst++= (v>>16) & 0xFFC0;
76  *ydst++= (v>>6 ) & 0xFFC0;
77  *vdst++= (v<<4 ) & 0xFFC0;
78 
79  v= av_be2ne32(*src++);
80  *ydst++= (v>>16) & 0xFFC0;
81 
82  if(ydst >= yend){
83  ydst+= pic->linesize[0]/2 - width;
84  udst+= pic->linesize[1]/2 - width/2;
85  vdst+= pic->linesize[2]/2 - width/2;
86  yend= ydst + width;
87  if(++y >= avctx->height)
88  break;
89  }
90 
91  *udst++= (v>>6 ) & 0xFFC0;
92  *ydst++= (v<<4 ) & 0xFFC0;
93 
94  v= av_be2ne32(*src++);
95  *vdst++= (v>>16) & 0xFFC0;
96  *ydst++= (v>>6 ) & 0xFFC0;
97 
98  if(ydst >= yend){
99  ydst+= pic->linesize[0]/2 - width;
100  udst+= pic->linesize[1]/2 - width/2;
101  vdst+= pic->linesize[2]/2 - width/2;
102  yend= ydst + width;
103  if(++y >= avctx->height)
104  break;
105  }
106 
107  *udst++= (v<<4 ) & 0xFFC0;
108 
109  v= av_be2ne32(*src++);
110  *ydst++= (v>>16) & 0xFFC0;
111  *vdst++= (v>>6 ) & 0xFFC0;
112  *ydst++= (v<<4 ) & 0xFFC0;
113  if(ydst >= yend){
114  ydst+= pic->linesize[0]/2 - width;
115  udst+= pic->linesize[1]/2 - width/2;
116  vdst+= pic->linesize[2]/2 - width/2;
117  yend= ydst + width;
118  if(++y >= avctx->height)
119  break;
120  }
121  }
122 
123  *got_frame = 1;
124  *(AVFrame*)data= *avctx->coded_frame;
125 
126  return avpkt->size;
127 }
128 
130 {
131  AVFrame *pic = avctx->coded_frame;
132  if (pic->data[0])
133  avctx->release_buffer(avctx, pic);
134  av_freep(&avctx->coded_frame);
135 
136  return 0;
137 }
138 
140  .name = "v210x",
141  .type = AVMEDIA_TYPE_VIDEO,
142  .id = AV_CODEC_ID_V210X,
143  .init = decode_init,
144  .close = decode_close,
145  .decode = decode_frame,
146  .capabilities = CODEC_CAP_DR1,
147  .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
148 };
This structure describes decoded (raw) audio or video data.
Definition: avcodec.h:989
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
Definition: avcodec.h:2259
memory handling functions
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2725
int size
Definition: avcodec.h:916
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1533
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:2711
#define av_be2ne32(x)
Definition: bswap.h:93
AVCodec.
Definition: avcodec.h:2960
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:151
const char data[16]
Definition: mxf.c:66
uint8_t * data
Definition: avcodec.h:915
void av_log_ask_for_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message asking for a sample.
int reference
is this picture used as reference The values for this are the same as the MpegEncContext.picture_structure variable, that is 1->top field, 2->bottom field, 3->frame/both fields.
Definition: avcodec.h:1132
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:88
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:146
const char * name
Name of the codec implementation.
Definition: avcodec.h:2967
common internal API header
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
Definition: utils.c:616
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
Definition: avcodec.h:1065
int width
picture width / height.
Definition: avcodec.h:1508
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame)
Get a buffer for a frame.
Definition: utils.c:464
static av_cold int decode_init(AVCodecContext *avctx)
Definition: v210x.c:27
static int width
Definition: utils.c:156
external API header
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
Definition: avcodec.h:1008
main external API structure.
Definition: avcodec.h:1339
byte swapping routines
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: v210x.c:41
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: avcodec.h:997
AVCodec ff_v210x_decoder
Definition: v210x.c:139
common internal api header.
int key_frame
1 -> keyframe, 0-> not
Definition: avcodec.h:1058
static av_cold int decode_close(AVCodecContext *avctx)
Definition: v210x.c:129
This structure stores compressed data.
Definition: avcodec.h:898