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

libavcodec/v410dec.c

Go to the documentation of this file.
00001 /*
00002  * v410 decoder
00003  *
00004  * Copyright (c) 2011 Derek Buitenhuis
00005  *
00006  * This file is part of Libav.
00007  *
00008  * Libav is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * Libav is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with Libav; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 #include "libavutil/intreadwrite.h"
00024 #include "avcodec.h"
00025 
00026 static av_cold int v410_decode_init(AVCodecContext *avctx)
00027 {
00028     avctx->pix_fmt             = PIX_FMT_YUV444P10;
00029     avctx->bits_per_raw_sample = 10;
00030 
00031     if (avctx->width & 1) {
00032         av_log(avctx, AV_LOG_ERROR, "v410 requires even width.\n");
00033         return AVERROR_INVALIDDATA;
00034     }
00035 
00036     avctx->coded_frame = avcodec_alloc_frame();
00037 
00038     if (!avctx->coded_frame) {
00039         av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
00040         return AVERROR(ENOMEM);
00041     }
00042 
00043     return 0;
00044 }
00045 
00046 static int v410_decode_frame(AVCodecContext *avctx, void *data,
00047                              int *data_size, AVPacket *avpkt)
00048 {
00049     AVFrame *pic = avctx->coded_frame;
00050     uint8_t *src = avpkt->data;
00051     uint16_t *y, *u, *v;
00052     uint32_t val;
00053     int i, j;
00054 
00055     if (pic->data[0])
00056         avctx->release_buffer(avctx, pic);
00057 
00058     if (avpkt->size < 4 * avctx->height * avctx->width) {
00059         av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n");
00060         return AVERROR(EINVAL);
00061     }
00062 
00063     pic->reference = 0;
00064 
00065     if (avctx->get_buffer(avctx, pic) < 0) {
00066         av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n");
00067         return AVERROR(ENOMEM);
00068     }
00069 
00070     pic->key_frame = 1;
00071     pic->pict_type = AV_PICTURE_TYPE_I;
00072 
00073     y = (uint16_t *)pic->data[0];
00074     u = (uint16_t *)pic->data[1];
00075     v = (uint16_t *)pic->data[2];
00076 
00077     for (i = 0; i < avctx->height; i++) {
00078         for (j = 0; j < avctx->width; j++) {
00079             val = AV_RL32(src);
00080 
00081             u[j] = (val >>  2) & 0x3FF;
00082             y[j] = (val >> 12) & 0x3FF;
00083             v[j] = (val >> 22);
00084 
00085             src += 4;
00086         }
00087 
00088         y += pic->linesize[0] >> 1;
00089         u += pic->linesize[1] >> 1;
00090         v += pic->linesize[2] >> 1;
00091     }
00092 
00093     *data_size = sizeof(AVFrame);
00094     *(AVFrame *)data = *pic;
00095 
00096     return avpkt->size;
00097 }
00098 
00099 static av_cold int v410_decode_close(AVCodecContext *avctx)
00100 {
00101     if (avctx->coded_frame->data[0])
00102         avctx->release_buffer(avctx, avctx->coded_frame);
00103 
00104     av_freep(&avctx->coded_frame);
00105 
00106     return 0;
00107 }
00108 
00109 AVCodec ff_v410_decoder = {
00110     .name         = "v410",
00111     .type         = AVMEDIA_TYPE_VIDEO,
00112     .id           = CODEC_ID_V410,
00113     .init         = v410_decode_init,
00114     .decode       = v410_decode_frame,
00115     .close        = v410_decode_close,
00116     .capabilities = CODEC_CAP_DR1,
00117     .long_name    = NULL_IF_CONFIG_SMALL("Uncompressed 4:4:4 10-bit"),
00118 };
Generated on Sat Mar 17 2012 12:57:50 for Libav by doxygen 1.7.1