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 "libavutil/bswap.h"
23 
25 {
26  if(avctx->width & 1){
27  av_log(avctx, AV_LOG_ERROR, "v210x needs even width\n");
28  return -1;
29  }
30  avctx->pix_fmt = PIX_FMT_YUV422P16;
31  avctx->bits_per_raw_sample= 10;
32 
34 
35  return 0;
36 }
37 
38 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
39 {
40  int y=0;
41  int width= avctx->width;
42  AVFrame *pic= avctx->coded_frame;
43  const uint32_t *src= (const uint32_t *)avpkt->data;
44  uint16_t *ydst, *udst, *vdst, *yend;
45 
46  if(pic->data[0])
47  avctx->release_buffer(avctx, pic);
48 
49  if(avpkt->size < avctx->width * avctx->height * 8 / 3){
50  av_log(avctx, AV_LOG_ERROR, "Packet too small\n");
51  return -1;
52  }
53 
54  if(avpkt->size > avctx->width * avctx->height * 8 / 3){
55  av_log_ask_for_sample(avctx, "Probably padded data\n");
56  }
57 
58  pic->reference= 0;
59  if(avctx->get_buffer(avctx, pic) < 0)
60  return -1;
61 
62  ydst= (uint16_t *)pic->data[0];
63  udst= (uint16_t *)pic->data[1];
64  vdst= (uint16_t *)pic->data[2];
65  yend= ydst + width;
67  pic->key_frame= 1;
68 
69  for(;;){
70  uint32_t v= av_be2ne32(*src++);
71  *udst++= (v>>16) & 0xFFC0;
72  *ydst++= (v>>6 ) & 0xFFC0;
73  *vdst++= (v<<4 ) & 0xFFC0;
74 
75  v= av_be2ne32(*src++);
76  *ydst++= (v>>16) & 0xFFC0;
77 
78  if(ydst >= yend){
79  ydst+= pic->linesize[0]/2 - width;
80  udst+= pic->linesize[1]/2 - width/2;
81  vdst+= pic->linesize[2]/2 - width/2;
82  yend= ydst + width;
83  if(++y >= avctx->height)
84  break;
85  }
86 
87  *udst++= (v>>6 ) & 0xFFC0;
88  *ydst++= (v<<4 ) & 0xFFC0;
89 
90  v= av_be2ne32(*src++);
91  *vdst++= (v>>16) & 0xFFC0;
92  *ydst++= (v>>6 ) & 0xFFC0;
93 
94  if(ydst >= yend){
95  ydst+= pic->linesize[0]/2 - width;
96  udst+= pic->linesize[1]/2 - width/2;
97  vdst+= pic->linesize[2]/2 - width/2;
98  yend= ydst + width;
99  if(++y >= avctx->height)
100  break;
101  }
102 
103  *udst++= (v<<4 ) & 0xFFC0;
104 
105  v= av_be2ne32(*src++);
106  *ydst++= (v>>16) & 0xFFC0;
107  *vdst++= (v>>6 ) & 0xFFC0;
108  *ydst++= (v<<4 ) & 0xFFC0;
109  if(ydst >= yend){
110  ydst+= pic->linesize[0]/2 - width;
111  udst+= pic->linesize[1]/2 - width/2;
112  vdst+= pic->linesize[2]/2 - width/2;
113  yend= ydst + width;
114  if(++y >= avctx->height)
115  break;
116  }
117  }
118 
119  *data_size=sizeof(AVFrame);
120  *(AVFrame*)data= *avctx->coded_frame;
121 
122  return avpkt->size;
123 }
124 
126 {
127  AVFrame *pic = avctx->coded_frame;
128  if (pic->data[0])
129  avctx->release_buffer(avctx, pic);
130  av_freep(&avctx->coded_frame);
131 
132  return 0;
133 }
134 
136  .name = "v210x",
137  .type = AVMEDIA_TYPE_VIDEO,
138  .id = CODEC_ID_V210X,
139  .init = decode_init,
140  .close = decode_close,
141  .decode = decode_frame,
142  .capabilities = CODEC_CAP_DR1,
143  .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
144 };
int(* get_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called at the beginning of each frame to get a buffer for it.
Definition: avcodec.h:1726
enum PixelFormat pix_fmt
Pixel format, see PIX_FMT_xxx.
Definition: avcodec.h:1426
Audio Video Frame.
Definition: avcodec.h:985
void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
Definition: avcodec.h:1737
AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:2000
int size
Definition: avcodec.h:909
int width
Definition: rotozoom.c:164
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:2863
#define av_be2ne32(x)
Definition: bswap.h:93
AVCodec.
Definition: avcodec.h:3189
#define v(n)
Definition: regs.h:34
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:147
#define PIX_FMT_YUV422P16
Definition: pixfmt.h:191
#define av_cold
Definition: attributes.h:71
const char data[16]
Definition: mxf.c:60
uint8_t * data
Definition: avcodec.h:908
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:719
static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
Definition: v210x.c:38
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:1074
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:191
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:140
const char * name
Name of the codec implementation.
Definition: avcodec.h:3196
AVFrame * avcodec_alloc_frame(void)
Allocate an AVFrame and set its fields to default values.
Definition: utils.c:618
enum AVPictureType pict_type
Picture type of the frame, see ?_TYPE below.
Definition: avcodec.h:1029
int width
picture width / height.
Definition: avcodec.h:1408
struct AVFrame AVFrame
Audio Video Frame.
static av_cold int decode_init(AVCodecContext *avctx)
Definition: v210x.c:24
external API header
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
Definition: avcodec.h:1008
void av_log_ask_for_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message asking for a sample.
main external API structure.
Definition: avcodec.h:1329
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:111
byte swapping routines
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: avcodec.h:997
AVCodec ff_v210x_decoder
Definition: v210x.c:135
int key_frame
1 -> keyframe, 0-> not
Definition: avcodec.h:1022
static av_cold int decode_close(AVCodecContext *avctx)
Definition: v210x.c:125