annotate ffmpeg/libavcodec/avuidec.c @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 6840f77b83aa
children
rev   line source
yading@10 1 /*
yading@10 2 * AVID Meridien decoder
yading@10 3 *
yading@10 4 * Copyright (c) 2012 Carl Eugen Hoyos
yading@10 5 *
yading@10 6 * This file is part of FFmpeg.
yading@10 7 *
yading@10 8 * FFmpeg is free software; you can redistribute it and/or
yading@10 9 * modify it under the terms of the GNU Lesser General Public
yading@10 10 * License as published by the Free Software Foundation; either
yading@10 11 * version 2.1 of the License, or (at your option) any later version.
yading@10 12 *
yading@10 13 * FFmpeg is distributed in the hope that it will be useful,
yading@10 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
yading@10 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
yading@10 16 * Lesser General Public License for more details.
yading@10 17 *
yading@10 18 * You should have received a copy of the GNU Lesser General Public
yading@10 19 * License along with FFmpeg; if not, write to the Free Software
yading@10 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
yading@10 21 */
yading@10 22
yading@10 23 #include "avcodec.h"
yading@10 24 #include "internal.h"
yading@10 25 #include "libavutil/intreadwrite.h"
yading@10 26
yading@10 27 static av_cold int avui_decode_init(AVCodecContext *avctx)
yading@10 28 {
yading@10 29 avctx->pix_fmt = AV_PIX_FMT_YUVA422P;
yading@10 30 return 0;
yading@10 31 }
yading@10 32
yading@10 33 static int avui_decode_frame(AVCodecContext *avctx, void *data,
yading@10 34 int *got_frame, AVPacket *avpkt)
yading@10 35 {
yading@10 36 int ret;
yading@10 37 AVFrame *pic = data;
yading@10 38 const uint8_t *src = avpkt->data, *extradata = avctx->extradata;
yading@10 39 const uint8_t *srca;
yading@10 40 uint8_t *y, *u, *v, *a;
yading@10 41 int transparent, interlaced = 1, skip, opaque_length, i, j, k;
yading@10 42 uint32_t extradata_size = avctx->extradata_size;
yading@10 43
yading@10 44 while (extradata_size >= 24) {
yading@10 45 uint32_t atom_size = AV_RB32(extradata);
yading@10 46 if (!memcmp(&extradata[4], "APRGAPRG0001", 12)) {
yading@10 47 interlaced = extradata[19] != 1;
yading@10 48 break;
yading@10 49 }
yading@10 50 if (atom_size && atom_size <= extradata_size) {
yading@10 51 extradata += atom_size;
yading@10 52 extradata_size -= atom_size;
yading@10 53 } else {
yading@10 54 break;
yading@10 55 }
yading@10 56 }
yading@10 57 if (avctx->height == 486) {
yading@10 58 skip = 10;
yading@10 59 } else {
yading@10 60 skip = 16;
yading@10 61 }
yading@10 62 opaque_length = 2 * avctx->width * (avctx->height + skip) + 4 * interlaced;
yading@10 63 if (avpkt->size < opaque_length) {
yading@10 64 av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n");
yading@10 65 return AVERROR(EINVAL);
yading@10 66 }
yading@10 67 transparent = avctx->bits_per_coded_sample == 32 &&
yading@10 68 avpkt->size >= opaque_length * 2 + 4;
yading@10 69 srca = src + opaque_length + 5;
yading@10 70
yading@10 71 if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
yading@10 72 return ret;
yading@10 73
yading@10 74 pic->key_frame = 1;
yading@10 75 pic->pict_type = AV_PICTURE_TYPE_I;
yading@10 76
yading@10 77 if (!interlaced) {
yading@10 78 src += avctx->width * skip;
yading@10 79 srca += avctx->width * skip;
yading@10 80 }
yading@10 81
yading@10 82 for (i = 0; i < interlaced + 1; i++) {
yading@10 83 src += avctx->width * skip;
yading@10 84 srca += avctx->width * skip;
yading@10 85 if (interlaced && avctx->height == 486) {
yading@10 86 y = pic->data[0] + (1 - i) * pic->linesize[0];
yading@10 87 u = pic->data[1] + (1 - i) * pic->linesize[1];
yading@10 88 v = pic->data[2] + (1 - i) * pic->linesize[2];
yading@10 89 a = pic->data[3] + (1 - i) * pic->linesize[3];
yading@10 90 } else {
yading@10 91 y = pic->data[0] + i * pic->linesize[0];
yading@10 92 u = pic->data[1] + i * pic->linesize[1];
yading@10 93 v = pic->data[2] + i * pic->linesize[2];
yading@10 94 a = pic->data[3] + i * pic->linesize[3];
yading@10 95 }
yading@10 96
yading@10 97 for (j = 0; j < avctx->height >> interlaced; j++) {
yading@10 98 for (k = 0; k < avctx->width >> 1; k++) {
yading@10 99 u[ k ] = *src++;
yading@10 100 y[2 * k ] = *src++;
yading@10 101 a[2 * k ] = 0xFF - (transparent ? *srca++ : 0);
yading@10 102 srca++;
yading@10 103 v[ k ] = *src++;
yading@10 104 y[2 * k + 1] = *src++;
yading@10 105 a[2 * k + 1] = 0xFF - (transparent ? *srca++ : 0);
yading@10 106 srca++;
yading@10 107 }
yading@10 108
yading@10 109 y += (interlaced + 1) * pic->linesize[0];
yading@10 110 u += (interlaced + 1) * pic->linesize[1];
yading@10 111 v += (interlaced + 1) * pic->linesize[2];
yading@10 112 a += (interlaced + 1) * pic->linesize[3];
yading@10 113 }
yading@10 114 src += 4;
yading@10 115 srca += 4;
yading@10 116 }
yading@10 117 *got_frame = 1;
yading@10 118
yading@10 119 return avpkt->size;
yading@10 120 }
yading@10 121
yading@10 122 AVCodec ff_avui_decoder = {
yading@10 123 .name = "avui",
yading@10 124 .type = AVMEDIA_TYPE_VIDEO,
yading@10 125 .id = AV_CODEC_ID_AVUI,
yading@10 126 .init = avui_decode_init,
yading@10 127 .decode = avui_decode_frame,
yading@10 128 .capabilities = CODEC_CAP_DR1,
yading@10 129 .long_name = NULL_IF_CONFIG_SMALL("Avid Meridien Uncompressed"),
yading@10 130 };