FFmpeg
m101.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Michael Niedermayer
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg 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  * FFmpeg 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 FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavutil/intreadwrite.h"
22 
23 #include "avcodec.h"
24 #include "internal.h"
25 
26 
28 {
29  if (avctx->extradata_size < 6*4) {
30  avpriv_request_sample(avctx, "Missing or too small extradata (size %d)", avctx->extradata_size);
31  return AVERROR_INVALIDDATA;
32  }
33 
34  if (avctx->extradata[2*4] == 10)
36  else if (avctx->extradata[2*4] == 8) {
37  avctx->pix_fmt = AV_PIX_FMT_YUYV422;
38  } else {
39  avpriv_request_sample(avctx, "BPS %d", avctx->extradata[2*4]);
40  return AVERROR_INVALIDDATA;
41  }
42 
43  return 0;
44 }
45 
46 static int m101_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
47  AVPacket *avpkt)
48 {
49  const uint8_t *buf = avpkt->data;
50  int stride, ret;
51  int x, y;
52  int min_stride = 2 * avctx->width;
53  int bits = avctx->extradata[2*4];
54  AVFrame *frame = data;
55 
56  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
57  return ret;
59  frame->key_frame = 1;
60 
61  stride = AV_RL32(avctx->extradata + 5*4);
62 
63  if (avctx->pix_fmt == AV_PIX_FMT_YUV422P10)
64  min_stride = (avctx->width + 15) / 16 * 40;
65 
66  if (stride < min_stride || avpkt->size < stride * (uint64_t)avctx->height) {
67  av_log(avctx, AV_LOG_ERROR, "stride (%d) is invalid for packet sized %d\n",
68  stride, avpkt->size);
69  return AVERROR_INVALIDDATA;
70  }
71 
72  frame->interlaced_frame = ((avctx->extradata[3*4] & 3) != 3);
73  if (frame->interlaced_frame)
74  frame->top_field_first = avctx->extradata[3*4] & 1;
75 
76  for (y = 0; y < avctx->height; y++) {
77  int src_y = y;
78  if (frame->interlaced_frame)
79  src_y = ((y&1)^frame->top_field_first) ? y/2 : (y/2 + avctx->height/2);
80  if (bits == 8) {
81  uint8_t *line = frame->data[0] + y*frame->linesize[0];
82  memcpy(line, buf + src_y*stride, 2*avctx->width);
83  } else {
84  int block;
85  uint16_t *luma = (uint16_t*)&frame->data[0][y*frame->linesize[0]];
86  uint16_t *cb = (uint16_t*)&frame->data[1][y*frame->linesize[1]];
87  uint16_t *cr = (uint16_t*)&frame->data[2][y*frame->linesize[2]];
88  for (block = 0; 16*block < avctx->width; block ++) {
89  const uint8_t *buf_src = buf + src_y*stride + 40*block;
90  for (x = 0; x < 16 && x + 16*block < avctx->width; x++) {
91  int xd = x + 16*block;
92  if (x&1) {
93  luma [xd] = (4*buf_src[2*x + 0]) + ((buf_src[32 + (x>>1)]>>4)&3);
94  } else {
95  luma [xd] = (4*buf_src[2*x + 0]) + (buf_src[32 + (x>>1)] &3);
96  cb[xd>>1] = (4*buf_src[2*x + 1]) + ((buf_src[32 + (x>>1)]>>2)&3);
97  cr[xd>>1] = (4*buf_src[2*x + 3]) + (buf_src[32 + (x>>1)]>>6);
98  }
99  }
100  }
101  }
102  }
103 
104  *got_frame = 1;
105  return avpkt->size;
106 }
107 
109  .name = "m101",
110  .long_name = NULL_IF_CONFIG_SMALL("Matrox Uncompressed SD"),
111  .type = AVMEDIA_TYPE_VIDEO,
112  .id = AV_CODEC_ID_M101,
113  .init = m101_decode_init,
114  .decode = m101_decode_frame,
115  .capabilities = AV_CODEC_CAP_DR1,
116 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
static int m101_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: m101.c:46
This structure describes decoded (raw) audio or video data.
Definition: frame.h:295
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:100
#define avpriv_request_sample(...)
int size
Definition: avcodec.h:1478
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1775
AVCodec.
Definition: avcodec.h:3481
static av_cold int m101_decode_init(AVCodecContext *avctx)
Definition: m101.c:27
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:112
The exact code depends on how similar the blocks are and how related they are to the block
uint8_t
#define av_cold
Definition: attributes.h:82
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1666
uint8_t * data
Definition: avcodec.h:1477
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:442
ptrdiff_t size
Definition: opengl_enc.c:100
#define av_log(a,...)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:186
Definition: graph2dot.c:48
const char * name
Name of the codec implementation.
Definition: avcodec.h:3488
uint8_t bits
Definition: vp3data.h:202
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:378
int width
picture width / height.
Definition: avcodec.h:1738
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:326
AVCodec ff_m101_decoder
Definition: m101.c:108
main external API structure.
Definition: avcodec.h:1565
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:67
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1963
void * buf
Definition: avisynth_c.h:766
int extradata_size
Definition: avcodec.h:1667
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:388
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:309
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:104
common internal api header.
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:447
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:373
#define stride
static double cr(void *priv, double x, double y)
Definition: vf_geq.c:113
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:87
This structure stores compressed data.
Definition: avcodec.h:1454
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:981
for(j=16;j >0;--j)