00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "avcodec.h"
00025 #include "libavutil/bswap.h"
00026
00027 static av_cold int decode_init(AVCodecContext *avctx)
00028 {
00029 if (avctx->width & 1) {
00030 av_log(avctx, AV_LOG_ERROR, "v210 needs even width\n");
00031 return -1;
00032 }
00033 avctx->pix_fmt = PIX_FMT_YUV422P10;
00034 avctx->bits_per_raw_sample = 10;
00035
00036 avctx->coded_frame = avcodec_alloc_frame();
00037
00038 return 0;
00039 }
00040
00041 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size,
00042 AVPacket *avpkt)
00043 {
00044 int h, w;
00045 AVFrame *pic = avctx->coded_frame;
00046 const uint8_t *psrc = avpkt->data;
00047 uint16_t *y, *u, *v;
00048 int aligned_width = ((avctx->width + 47) / 48) * 48;
00049 int stride = aligned_width * 8 / 3;
00050
00051 if (pic->data[0])
00052 avctx->release_buffer(avctx, pic);
00053
00054 if (avpkt->size < stride * avctx->height) {
00055 av_log(avctx, AV_LOG_ERROR, "packet too small\n");
00056 return -1;
00057 }
00058
00059 pic->reference = 0;
00060 if (avctx->get_buffer(avctx, pic) < 0)
00061 return -1;
00062
00063 y = (uint16_t*)pic->data[0];
00064 u = (uint16_t*)pic->data[1];
00065 v = (uint16_t*)pic->data[2];
00066 pic->pict_type = AV_PICTURE_TYPE_I;
00067 pic->key_frame = 1;
00068
00069 #define READ_PIXELS(a, b, c) \
00070 do { \
00071 val = av_le2ne32(*src++); \
00072 *a++ = val & 0x3FF; \
00073 *b++ = (val >> 10) & 0x3FF; \
00074 *c++ = (val >> 20) & 0x3FF; \
00075 } while (0)
00076
00077 for (h = 0; h < avctx->height; h++) {
00078 const uint32_t *src = (const uint32_t*)psrc;
00079 uint32_t val;
00080 for (w = 0; w < avctx->width - 5; w += 6) {
00081 READ_PIXELS(u, y, v);
00082 READ_PIXELS(y, u, y);
00083 READ_PIXELS(v, y, u);
00084 READ_PIXELS(y, v, y);
00085 }
00086 if (w < avctx->width - 1) {
00087 READ_PIXELS(u, y, v);
00088
00089 val = av_le2ne32(*src++);
00090 *y++ = val & 0x3FF;
00091 }
00092 if (w < avctx->width - 3) {
00093 *u++ = (val >> 10) & 0x3FF;
00094 *y++ = (val >> 20) & 0x3FF;
00095
00096 val = av_le2ne32(*src++);
00097 *v++ = val & 0x3FF;
00098 *y++ = (val >> 10) & 0x3FF;
00099 }
00100
00101 psrc += stride;
00102 y += pic->linesize[0] / 2 - avctx->width;
00103 u += pic->linesize[1] / 2 - avctx->width / 2;
00104 v += pic->linesize[2] / 2 - avctx->width / 2;
00105 }
00106
00107 *data_size = sizeof(AVFrame);
00108 *(AVFrame*)data = *avctx->coded_frame;
00109
00110 return avpkt->size;
00111 }
00112
00113 static av_cold int decode_close(AVCodecContext *avctx)
00114 {
00115 AVFrame *pic = avctx->coded_frame;
00116 if (pic->data[0])
00117 avctx->release_buffer(avctx, pic);
00118 av_freep(&avctx->coded_frame);
00119
00120 return 0;
00121 }
00122
00123 AVCodec ff_v210_decoder = {
00124 "v210",
00125 AVMEDIA_TYPE_VIDEO,
00126 CODEC_ID_V210,
00127 0,
00128 decode_init,
00129 NULL,
00130 decode_close,
00131 decode_frame,
00132 CODEC_CAP_DR1,
00133 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"),
00134 };