FFmpeg
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, 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 || avctx->height <= 0) {
49  av_log(avctx, AV_LOG_ERROR, "Dimensions %dx%d not supported.\n", width, avctx->height);
50  return AVERROR_INVALIDDATA;
51  }
52 
53  if ( avctx->codec_tag == MKTAG('0', '1', '2', 'v')
54  && avpkt->size % avctx->height == 0
55  && avpkt->size / avctx->height * 3 >= width * 8)
56  stride = avpkt->size / avctx->height;
57 
58  if (avpkt->size < avctx->height * stride) {
59  av_log(avctx, AV_LOG_ERROR, "Packet too small: %d instead of %d\n",
60  avpkt->size, avctx->height * stride);
61  return AVERROR_INVALIDDATA;
62  }
63 
64  if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
65  return ret;
66 
68  pic->key_frame = 1;
69 
70  line_end = avpkt->data + stride;
71  for (line = 0; line < avctx->height; line++) {
72  uint16_t y_temp[6] = {0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000};
73  uint16_t u_temp[3] = {0x8000, 0x8000, 0x8000};
74  uint16_t v_temp[3] = {0x8000, 0x8000, 0x8000};
75  int x;
76  y = (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
77  u = (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
78  v = (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
79 
80  for (x = 0; x < width; x += 6) {
81  uint32_t t;
82 
83  if (width - x < 6 || line_end - src < 16) {
84  y = y_temp;
85  u = u_temp;
86  v = v_temp;
87  }
88 
89  if (line_end - src < 4)
90  break;
91 
92  t = AV_RL32(src);
93  src += 4;
94  *u++ = t << 6 & 0xFFC0;
95  *y++ = t >> 4 & 0xFFC0;
96  *v++ = t >> 14 & 0xFFC0;
97 
98  if (line_end - src < 4)
99  break;
100 
101  t = AV_RL32(src);
102  src += 4;
103  *y++ = t << 6 & 0xFFC0;
104  *u++ = t >> 4 & 0xFFC0;
105  *y++ = t >> 14 & 0xFFC0;
106 
107  if (line_end - src < 4)
108  break;
109 
110  t = AV_RL32(src);
111  src += 4;
112  *v++ = t << 6 & 0xFFC0;
113  *y++ = t >> 4 & 0xFFC0;
114  *u++ = t >> 14 & 0xFFC0;
115 
116  if (line_end - src < 4)
117  break;
118 
119  t = AV_RL32(src);
120  src += 4;
121  *y++ = t << 6 & 0xFFC0;
122  *v++ = t >> 4 & 0xFFC0;
123  *y++ = t >> 14 & 0xFFC0;
124 
125  if (width - x < 6)
126  break;
127  }
128 
129  if (x < width) {
130  y = x + (uint16_t *)(pic->data[0] + line * pic->linesize[0]);
131  u = x/2 + (uint16_t *)(pic->data[1] + line * pic->linesize[1]);
132  v = x/2 + (uint16_t *)(pic->data[2] + line * pic->linesize[2]);
133  memcpy(y, y_temp, sizeof(*y) * (width - x));
134  memcpy(u, u_temp, sizeof(*u) * (width - x + 1) / 2);
135  memcpy(v, v_temp, sizeof(*v) * (width - x + 1) / 2);
136  }
137 
138  line_end += stride;
139  src = line_end - stride;
140  }
141 
142  *got_frame = 1;
143 
144  return avpkt->size;
145 }
146 
148  .name = "012v",
149  .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
150  .type = AVMEDIA_TYPE_VIDEO,
151  .id = AV_CODEC_ID_012V,
152  .init = zero12v_decode_init,
153  .decode = zero12v_decode_frame,
154  .capabilities = AV_CODEC_CAP_DR1,
155 };
AVCodec
AVCodec.
Definition: codec.h:197
stride
int stride
Definition: mace.c:144
zero12v_decode_init
static av_cold int zero12v_decode_init(AVCodecContext *avctx)
Definition: 012v.c:27
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:264
MKTAG
#define MKTAG(a, b, c, d)
Definition: common.h:478
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:369
data
const char data[16]
Definition: mxf.c:142
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
AVFrame::key_frame
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:396
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
av_cold
#define av_cold
Definition: attributes.h:90
AV_PIX_FMT_YUV422P16
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:411
width
#define width
intreadwrite.h
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1747
ff_zero12v_decoder
AVCodec ff_zero12v_decoder
Definition: 012v.c:147
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
src
#define src
Definition: vp8dsp.c:255
AVFrame::pict_type
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:401
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1900
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:370
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
height
#define height
line
Definition: graph2dot.c:48
uint8_t
uint8_t
Definition: audio_convert.c:194
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:204
AVCodecContext::height
int height
Definition: avcodec.h:709
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:746
zero12v_decode_frame
static int zero12v_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: 012v.c:38
avcodec.h
ret
ret
Definition: filter_design.txt:187
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
AVCodecContext
main external API structure.
Definition: avcodec.h:536
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:39
AVCodecContext::codec_tag
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:561
AVPacket
This structure stores compressed data.
Definition: packet.h:346
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:709
AV_CODEC_ID_012V
@ AV_CODEC_ID_012V
Definition: codec_id.h:252
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:349
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
line
The official guide to swscale for confused that consecutive non overlapping rectangles of slice_bottom special converter These generally are unscaled converters of common like for each output line the vertical scaler pulls lines from a ring buffer When the ring buffer does not contain the wanted line
Definition: swscale.txt:40