00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "avcodec.h"
00024
00025 static av_cold int avui_decode_init(AVCodecContext *avctx)
00026 {
00027 avctx->pix_fmt = PIX_FMT_YUVA422P;
00028
00029 avctx->coded_frame = avcodec_alloc_frame();
00030
00031 if (!avctx->coded_frame) {
00032 av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
00033 return AVERROR(ENOMEM);
00034 }
00035
00036 return 0;
00037 }
00038
00039 static int avui_decode_frame(AVCodecContext *avctx, void *data,
00040 int *data_size, AVPacket *avpkt)
00041 {
00042 AVFrame *pic = avctx->coded_frame;
00043 const uint8_t *src = avpkt->data;
00044 const uint8_t *srca;
00045 uint8_t *y, *u, *v, *a;
00046 int transparent, interlaced = 1, skip, opaque_length, i, j, k;
00047
00048 if (pic->data[0])
00049 avctx->release_buffer(avctx, pic);
00050
00051 if (avctx->extradata_size >= 24 &&
00052 !memcmp(&avctx->extradata[4], "APRGAPRG0001", 12))
00053 interlaced = avctx->extradata[19] != 1;
00054 if (avctx->height == 486) {
00055 skip = 10;
00056 } else {
00057 skip = 16;
00058 }
00059 opaque_length = 2 * avctx->width * (avctx->height + skip) + 4 * interlaced;
00060 if (avpkt->size < opaque_length) {
00061 av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n");
00062 return AVERROR(EINVAL);
00063 }
00064 transparent = avctx->bits_per_coded_sample == 32 &&
00065 avpkt->size >= opaque_length * 2 + 4;
00066 srca = src + opaque_length + 5;
00067
00068 pic->reference = 0;
00069
00070 if (avctx->get_buffer(avctx, pic) < 0) {
00071 av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n");
00072 return AVERROR(ENOMEM);
00073 }
00074
00075 pic->key_frame = 1;
00076 pic->pict_type = AV_PICTURE_TYPE_I;
00077
00078 if (!interlaced) {
00079 src += avctx->width * skip;
00080 srca += avctx->width * skip;
00081 }
00082
00083 for (i = 0; i < interlaced + 1; i++) {
00084 src += avctx->width * skip;
00085 srca += avctx->width * skip;
00086 if (interlaced && avctx->height == 486) {
00087 y = pic->data[0] + (1 - i) * pic->linesize[0];
00088 u = pic->data[1] + (1 - i) * pic->linesize[1];
00089 v = pic->data[2] + (1 - i) * pic->linesize[2];
00090 a = pic->data[3] + (1 - i) * pic->linesize[3];
00091 } else {
00092 y = pic->data[0] + i * pic->linesize[0];
00093 u = pic->data[1] + i * pic->linesize[1];
00094 v = pic->data[2] + i * pic->linesize[2];
00095 a = pic->data[3] + i * pic->linesize[3];
00096 }
00097
00098 for (j = 0; j < avctx->height >> interlaced; j++) {
00099 for (k = 0; k < avctx->width >> 1; k++) {
00100 u[ k ] = *src++;
00101 y[2 * k ] = *src++;
00102 a[2 * k ] = 0xFF - (transparent ? *srca++ : 0);
00103 srca++;
00104 v[ k ] = *src++;
00105 y[2 * k + 1] = *src++;
00106 a[2 * k + 1] = 0xFF - (transparent ? *srca++ : 0);
00107 srca++;
00108 }
00109
00110 y += (interlaced + 1) * pic->linesize[0];
00111 u += (interlaced + 1) * pic->linesize[1];
00112 v += (interlaced + 1) * pic->linesize[2];
00113 a += (interlaced + 1) * pic->linesize[3];
00114 }
00115 src += 4;
00116 srca += 4;
00117 }
00118 *data_size = sizeof(AVFrame);
00119 *(AVFrame *)data = *pic;
00120
00121 return avpkt->size;
00122 }
00123
00124 static av_cold int avui_decode_close(AVCodecContext *avctx)
00125 {
00126 if (avctx->coded_frame->data[0])
00127 avctx->release_buffer(avctx, avctx->coded_frame);
00128
00129 av_freep(&avctx->coded_frame);
00130
00131 return 0;
00132 }
00133
00134 AVCodec ff_avui_decoder = {
00135 .name = "avui",
00136 .type = AVMEDIA_TYPE_VIDEO,
00137 .id = CODEC_ID_AVUI,
00138 .init = avui_decode_init,
00139 .decode = avui_decode_frame,
00140 .close = avui_decode_close,
00141 .capabilities = CODEC_CAP_DR1,
00142 .long_name = NULL_IF_CONFIG_SMALL("AVID Meridien"),
00143 };