• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

libavcodec/v210dec.c

Go to the documentation of this file.
00001 /*
00002  * V210 decoder
00003  *
00004  * Copyright (C) 2009 Michael Niedermayer <michaelni@gmx.at>
00005  * Copyright (c) 2009 Baptiste Coudurier <baptiste dot coudurier at gmail dot com>
00006  *
00007  * This file is part of FFmpeg.
00008  *
00009  * FFmpeg is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  * FFmpeg is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with FFmpeg; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
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_YUV422P16;
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 = FF_I_TYPE;
00067     pic->key_frame = 1;
00068 
00069 #define READ_PIXELS(a, b, c)         \
00070     do {                             \
00071         val  = le2me_32(*src++);     \
00072         *a++ =  val <<  6;           \
00073         *b++ = (val >>  4) & 0xFFC0; \
00074         *c++ = (val >> 14) & 0xFFC0; \
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  = le2me_32(*src++);
00090             *y++ =  val <<  6;
00091         }
00092         if (w < avctx->width - 3) {
00093             *u++ = (val >>  4) & 0xFFC0;
00094             *y++ = (val >> 14) & 0xFFC0;
00095 
00096             val  = le2me_32(*src++);
00097             *v++ =  val <<  6;
00098             *y++ = (val >>  4) & 0xFFC0;
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 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 };

Generated on Fri Sep 16 2011 17:17:44 for FFmpeg by  doxygen 1.7.1