r210dec.c
Go to the documentation of this file.
1 /*
2  * R210 decoder
3  *
4  * Copyright (c) 2009 Reimar Doeffinger <Reimar.Doeffinger@gmx.de>
5  *
6  * This file is part of Libav.
7  *
8  * Libav is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * Libav is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with Libav; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "avcodec.h"
24 #include "internal.h"
25 #include "libavutil/bswap.h"
26 #include "libavutil/common.h"
27 
29 {
30  avctx->pix_fmt = AV_PIX_FMT_RGB48;
31  avctx->bits_per_raw_sample = 10;
32 
34 
35  return 0;
36 }
37 
38 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
39  AVPacket *avpkt)
40 {
41  int h, w;
42  AVFrame *pic = avctx->coded_frame;
43  const uint32_t *src = (const uint32_t *)avpkt->data;
44  int aligned_width = FFALIGN(avctx->width, 64);
45  uint8_t *dst_line;
46 
47  if (pic->data[0])
48  avctx->release_buffer(avctx, pic);
49 
50  if (avpkt->size < 4 * aligned_width * avctx->height) {
51  av_log(avctx, AV_LOG_ERROR, "packet too small\n");
52  return -1;
53  }
54 
55  pic->reference = 0;
56  if (ff_get_buffer(avctx, pic) < 0)
57  return -1;
58 
60  pic->key_frame = 1;
61  dst_line = pic->data[0];
62 
63  for (h = 0; h < avctx->height; h++) {
64  uint16_t *dst = (uint16_t *)dst_line;
65  for (w = 0; w < avctx->width; w++) {
66  uint32_t pixel = av_be2ne32(*src++);
67  uint16_t r, g, b;
68  if (avctx->codec_id==AV_CODEC_ID_R210) {
69  b = pixel << 6;
70  g = (pixel >> 4) & 0xffc0;
71  r = (pixel >> 14) & 0xffc0;
72  } else {
73  b = pixel << 4;
74  g = (pixel >> 6) & 0xffc0;
75  r = (pixel >> 16) & 0xffc0;
76  }
77  *dst++ = r | (r >> 10);
78  *dst++ = g | (g >> 10);
79  *dst++ = b | (b >> 10);
80  }
81  src += aligned_width - avctx->width;
82  dst_line += pic->linesize[0];
83  }
84 
85  *got_frame = 1;
86  *(AVFrame*)data = *avctx->coded_frame;
87 
88  return avpkt->size;
89 }
90 
92 {
93  AVFrame *pic = avctx->coded_frame;
94  if (pic->data[0])
95  avctx->release_buffer(avctx, pic);
96  av_freep(&avctx->coded_frame);
97 
98  return 0;
99 }
100 
101 #if CONFIG_R210_DECODER
102 AVCodec ff_r210_decoder = {
103  .name = "r210",
104  .type = AVMEDIA_TYPE_VIDEO,
105  .id = AV_CODEC_ID_R210,
106  .init = decode_init,
107  .close = decode_close,
108  .decode = decode_frame,
109  .capabilities = CODEC_CAP_DR1,
110  .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"),
111 };
112 #endif
113 #if CONFIG_R10K_DECODER
114 AVCodec ff_r10k_decoder = {
115  .name = "r10k",
116  .type = AVMEDIA_TYPE_VIDEO,
117  .id = AV_CODEC_ID_R10K,
118  .init = decode_init,
119  .close = decode_close,
120  .decode = decode_frame,
121  .capabilities = CODEC_CAP_DR1,
122  .long_name = NULL_IF_CONFIG_SMALL("AJA Kona 10-bit RGB Codec"),
123 };
124 #endif
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
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
uint8_t
static av_cold int decode_close(AVCodecContext *avctx)
Definition: r210dec.c:91
#define b
Definition: input.c:52
const char data[16]
Definition: mxf.c:66
uint8_t * data
Definition: avcodec.h:915
#define r
Definition: input.c:51
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
g
Definition: yuv2rgb.c:540
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
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: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
#define pixel
external API header
enum AVCodecID codec_id
Definition: avcodec.h:1350
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: r210dec.c:38
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: avcodec.h:997
common internal api header.
common internal and external API header
static av_cold int decode_init(AVCodecContext *avctx)
Definition: r210dec.c:28
int key_frame
1 -> keyframe, 0-> not
Definition: avcodec.h:1058
This structure stores compressed data.
Definition: avcodec.h:898