• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • 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 FFmpeg.
00007  *
00008  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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_WARNING, "v410 requires width to be even.\n");
00033     }
00034 
00035     avctx->coded_frame = avcodec_alloc_frame();
00036 
00037     if (!avctx->coded_frame) {
00038         av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
00039         return AVERROR(ENOMEM);
00040     }
00041 
00042     return 0;
00043 }
00044 
00045 static int v410_decode_frame(AVCodecContext *avctx, void *data,
00046                              int *data_size, AVPacket *avpkt)
00047 {
00048     AVFrame *pic = avctx->coded_frame;
00049     uint8_t *src = avpkt->data;
00050     uint16_t *y, *u, *v;
00051     uint32_t val;
00052     int i, j;
00053 
00054     if (pic->data[0])
00055         avctx->release_buffer(avctx, pic);
00056 
00057     if (avpkt->size < 4 * avctx->height * avctx->width) {
00058         av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n");
00059         return AVERROR(EINVAL);
00060     }
00061 
00062     pic->reference = 0;
00063 
00064     if (avctx->get_buffer(avctx, pic) < 0) {
00065         av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n");
00066         return AVERROR(ENOMEM);
00067     }
00068 
00069     pic->key_frame = 1;
00070     pic->pict_type = AV_PICTURE_TYPE_I;
00071 
00072     y = (uint16_t *)pic->data[0];
00073     u = (uint16_t *)pic->data[1];
00074     v = (uint16_t *)pic->data[2];
00075 
00076     for (i = 0; i < avctx->height; i++) {
00077         for (j = 0; j < avctx->width; j++) {
00078             val = AV_RL32(src);
00079 
00080             u[j] = (val >>  2) & 0x3FF;
00081             y[j] = (val >> 12) & 0x3FF;
00082             v[j] = (val >> 22);
00083 
00084             src += 4;
00085         }
00086 
00087         y += pic->linesize[0] >> 1;
00088         u += pic->linesize[1] >> 1;
00089         v += pic->linesize[2] >> 1;
00090     }
00091 
00092     *data_size = sizeof(AVFrame);
00093     *(AVFrame *)data = *pic;
00094 
00095     return avpkt->size;
00096 }
00097 
00098 static av_cold int v410_decode_close(AVCodecContext *avctx)
00099 {
00100     if (avctx->coded_frame->data[0])
00101         avctx->release_buffer(avctx, avctx->coded_frame);
00102 
00103     av_freep(&avctx->coded_frame);
00104 
00105     return 0;
00106 }
00107 
00108 AVCodec ff_v410_decoder = {
00109     .name         = "v410",
00110     .type         = AVMEDIA_TYPE_VIDEO,
00111     .id           = CODEC_ID_V410,
00112     .init         = v410_decode_init,
00113     .decode       = v410_decode_frame,
00114     .close        = v410_decode_close,
00115     .capabilities = CODEC_CAP_DR1,
00116     .long_name    = NULL_IF_CONFIG_SMALL("Uncompressed 4:4:4 10-bit"),
00117 };
Generated on Fri Feb 1 2013 14:34:45 for FFmpeg by doxygen 1.7.1