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

libavcodec/v308dec.c

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