012v.c
Go to the documentation of this file.
1 /*
2  * 012v decoder
3  *
4  * Copyright (C) 2012 Carl Eugen Hoyos
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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/intreadwrite.h"
26 
28 {
30  avctx->bits_per_raw_sample = 10;
31 
32  if (avctx->codec_tag == MKTAG('a', '1', '2', 'v'))
33  avpriv_request_sample(avctx, "transparency");
34 
35  return 0;
36 }
37 
38 static int zero12v_decode_frame(AVCodecContext *avctx, void *data,
39  int *got_frame, AVPacket *avpkt)
40 {
41  int line = 0, ret;
42  const int width = avctx->width;
43  AVFrame *pic = data;
44  uint16_t *y, *u, *v;
45  const uint8_t *line_end, *src = avpkt->data;
46  int stride = avctx->width * 8 / 3;
47 
48  if (width == 1) {
49  av_log(avctx, AV_LOG_ERROR, "Width 1 not supported.\n");
50  return AVERROR_INVALIDDATA;
51  }
52  if (avpkt->size < avctx->height * stride) {
53  av_log(avctx, AV_LOG_ERROR, "Packet too small: %d instead of %d\n",
54  avpkt->size, avctx->height * stride);
55  return AVERROR_INVALIDDATA;
56  }
57 
58  if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
59  return ret;
60 
62  pic->key_frame = 1;
63 
64  y = (uint16_t *)pic->data[0];
65  u = (uint16_t *)pic->data[1];
66  v = (uint16_t *)pic->data[2];
67  line_end = avpkt->data + stride;
68 
69  while (line++ < avctx->height) {
70  while (1) {
71  uint32_t t = AV_RL32(src);
72  src += 4;
73  *u++ = t << 6 & 0xFFC0;
74  *y++ = t >> 4 & 0xFFC0;
75  *v++ = t >> 14 & 0xFFC0;
76 
77  if (src >= line_end - 1) {
78  *y = 0x80;
79  src++;
80  line_end += stride;
81  y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
82  u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
83  v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
84  break;
85  }
86 
87  t = AV_RL32(src);
88  src += 4;
89  *y++ = t << 6 & 0xFFC0;
90  *u++ = t >> 4 & 0xFFC0;
91  *y++ = t >> 14 & 0xFFC0;
92  if (src >= line_end - 2) {
93  if (!(width & 1)) {
94  *y = 0x80;
95  src += 2;
96  }
97  line_end += stride;
98  y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
99  u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
100  v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
101  break;
102  }
103 
104  t = AV_RL32(src);
105  src += 4;
106  *v++ = t << 6 & 0xFFC0;
107  *y++ = t >> 4 & 0xFFC0;
108  *u++ = t >> 14 & 0xFFC0;
109 
110  if (src >= line_end - 1) {
111  *y = 0x80;
112  src++;
113  line_end += stride;
114  y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
115  u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
116  v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
117  break;
118  }
119 
120  t = AV_RL32(src);
121  src += 4;
122  *y++ = t << 6 & 0xFFC0;
123  *v++ = t >> 4 & 0xFFC0;
124  *y++ = t >> 14 & 0xFFC0;
125 
126  if (src >= line_end - 2) {
127  if (width & 1) {
128  *y = 0x80;
129  src += 2;
130  }
131  line_end += stride;
132  y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
133  u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
134  v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
135  break;
136  }
137  }
138  }
139 
140  *got_frame = 1;
141 
142  return avpkt->size;
143 }
144 
146  .name = "012v",
147  .type = AVMEDIA_TYPE_VIDEO,
148  .id = AV_CODEC_ID_012V,
149  .init = zero12v_decode_init,
150  .decode = zero12v_decode_frame,
151  .capabilities = CODEC_CAP_DR1,
152  .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
153 };
float v
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
int stride
Definition: mace.c:144
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
uint8_t
#define av_cold
Definition: attributes.h:78
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
static av_cold int zero12v_decode_init(AVCodecContext *avctx)
Definition: 012v.c:27
uint8_t * data
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Spectrum Plot time data
Definition: graph2dot.c:48
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
const char * name
Name of the codec implementation.
external API header
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:144
ret
Definition: avfilter.c:821
int width
picture width / height.
t
Definition: genspecsines3.m:6
#define AV_RL32
float u
static int width
Definition: tests/utils.c:158
AVS_Value src
Definition: avisynth_c.h:523
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:101
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> (&#39;D&#39;<<24) + (&#39;C&#39;<<16) + (&#39;B&#39;<<8) + &#39;A&#39;).
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:87
Synth Windw Norm while(pin< pend)%Until the end...%---Analysis x_w
AVCodec ff_zero12v_decoder
Definition: 012v.c:145
common internal api header.
function y
Definition: D.m:1
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:139
#define MKTAG(a, b, c, d)
Definition: common.h:282
This structure stores compressed data.
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:289
static int zero12v_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: 012v.c:38