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 "codec_internal.h"
25 #include "decode.h"
26 
27 
29 {
30  if (avctx->extradata_size < 6*4) {
31  avpriv_request_sample(avctx, "Missing or too small extradata (size %d)", avctx->extradata_size);
32  return AVERROR_INVALIDDATA;
33  }
34 
35  if (avctx->extradata[2*4] == 10)
37  else if (avctx->extradata[2*4] == 8) {
38  avctx->pix_fmt = AV_PIX_FMT_YUYV422;
39  } else {
40  avpriv_request_sample(avctx, "BPS %d", avctx->extradata[2*4]);
41  return AVERROR_INVALIDDATA;
42  }
43 
44  return 0;
45 }
46 
48  int *got_frame, AVPacket *avpkt)
49 {
50  const uint8_t *buf = avpkt->data;
51  int stride, ret;
52  int x, y;
53  int min_stride = 2 * avctx->width;
54  int bits = avctx->extradata[2*4];
55 
56  stride = AV_RL32(avctx->extradata + 5*4);
57 
58  if (avctx->pix_fmt == AV_PIX_FMT_YUV422P10)
59  min_stride = (avctx->width + 15) / 16 * 40;
60 
61  if (stride < min_stride || avpkt->size < stride * (uint64_t)avctx->height) {
62  av_log(avctx, AV_LOG_ERROR, "stride (%d) is invalid for packet sized %d\n",
63  stride, avpkt->size);
64  return AVERROR_INVALIDDATA;
65  }
66 
67  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
68  return ret;
71  if ((avctx->extradata[3*4] & 3) != 3) {
73  if (avctx->extradata[3*4] & 1)
75  }
76 
77  for (y = 0; y < avctx->height; y++) {
78  int src_y = y;
80  src_y = ((y&1) ^ !!(frame->flags & AV_FRAME_FLAG_TOP_FIELD_FIRST)) ? y/2 : (y/2 + avctx->height/2);
81  if (bits == 8) {
82  uint8_t *line = frame->data[0] + y*frame->linesize[0];
83  memcpy(line, buf + src_y*stride, 2*avctx->width);
84  } else {
85  int block;
86  uint16_t *luma = (uint16_t*)&frame->data[0][y*frame->linesize[0]];
87  uint16_t *cb = (uint16_t*)&frame->data[1][y*frame->linesize[1]];
88  uint16_t *cr = (uint16_t*)&frame->data[2][y*frame->linesize[2]];
89  for (block = 0; 16*block < avctx->width; block ++) {
90  const uint8_t *buf_src = buf + src_y*stride + 40*block;
91  for (x = 0; x < 16 && x + 16*block < avctx->width; x++) {
92  int xd = x + 16*block;
93  if (x&1) {
94  luma [xd] = (4*buf_src[2*x + 0]) + ((buf_src[32 + (x>>1)]>>4)&3);
95  } else {
96  luma [xd] = (4*buf_src[2*x + 0]) + (buf_src[32 + (x>>1)] &3);
97  cb[xd>>1] = (4*buf_src[2*x + 1]) + ((buf_src[32 + (x>>1)]>>2)&3);
98  cr[xd>>1] = (4*buf_src[2*x + 3]) + (buf_src[32 + (x>>1)]>>6);
99  }
100  }
101  }
102  }
103  }
104 
105  *got_frame = 1;
106  return avpkt->size;
107 }
108 
110  .p.name = "m101",
111  CODEC_LONG_NAME("Matrox Uncompressed SD"),
112  .p.type = AVMEDIA_TYPE_VIDEO,
113  .p.id = AV_CODEC_ID_M101,
114  .init = m101_decode_init,
116  .p.capabilities = AV_CODEC_CAP_DR1,
117 };
m101_decode_init
static av_cold int m101_decode_init(AVCodecContext *avctx)
Definition: m101.c:28
cb
static double cb(void *priv, double x, double y)
Definition: vf_geq.c:241
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
AVPacket::data
uint8_t * data
Definition: packet.h:522
FFCodec
Definition: codec_internal.h:127
AVFrame::flags
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:616
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:365
AV_FRAME_FLAG_TOP_FIELD_FIRST
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
Definition: frame.h:608
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:595
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:524
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:287
intreadwrite.h
bits
uint8_t bits
Definition: vp3data.h:128
decode.h
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
frame
static AVFrame * frame
Definition: demux_decode.c:54
AV_PIX_FMT_YUYV422
@ AV_PIX_FMT_YUYV422
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:74
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:279
AV_PIX_FMT_YUV422P10
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:479
AVFrame::pict_type
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:446
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1569
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:523
codec_internal.h
ff_m101_decoder
const FFCodec ff_m101_decoder
Definition: m101.c:109
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
size
int size
Definition: twinvq_data.h:10344
line
Definition: graph2dot.c:48
m101_decode_frame
static int m101_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
Definition: m101.c:47
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:523
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
AVCodecContext::height
int height
Definition: avcodec.h:618
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:657
AV_FRAME_FLAG_INTERLACED
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition: frame.h:603
avcodec.h
stride
#define stride
Definition: h264pred_template.c:537
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:445
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
AVPacket
This structure stores compressed data.
Definition: packet.h:499
cr
static double cr(void *priv, double x, double y)
Definition: vf_geq.c:242
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:618
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:389
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
AV_CODEC_ID_M101
@ AV_CODEC_ID_M101
Definition: codec_id.h:269