00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "avcodec.h"
00023
00024 static av_cold int v408_decode_init(AVCodecContext *avctx)
00025 {
00026 avctx->pix_fmt = PIX_FMT_YUVA444P;
00027
00028 avctx->coded_frame = avcodec_alloc_frame();
00029
00030 if (!avctx->coded_frame) {
00031 av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
00032 return AVERROR(ENOMEM);
00033 }
00034
00035 return 0;
00036 }
00037
00038 static int v408_decode_frame(AVCodecContext *avctx, void *data,
00039 int *data_size, AVPacket *avpkt)
00040 {
00041 AVFrame *pic = avctx->coded_frame;
00042 const uint8_t *src = avpkt->data;
00043 uint8_t *y, *u, *v, *a;
00044 int i, j;
00045
00046 if (pic->data[0])
00047 avctx->release_buffer(avctx, pic);
00048
00049 if (avpkt->size < 4 * avctx->height * avctx->width) {
00050 av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n");
00051 return AVERROR(EINVAL);
00052 }
00053
00054 pic->reference = 0;
00055
00056 if (avctx->get_buffer(avctx, pic) < 0) {
00057 av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n");
00058 return AVERROR(ENOMEM);
00059 }
00060
00061 pic->key_frame = 1;
00062 pic->pict_type = AV_PICTURE_TYPE_I;
00063
00064 y = pic->data[0];
00065 u = pic->data[1];
00066 v = pic->data[2];
00067 a = pic->data[3];
00068
00069 for (i = 0; i < avctx->height; i++) {
00070 for (j = 0; j < avctx->width; j++) {
00071 if (avctx->codec_id==CODEC_ID_AYUV) {
00072 v[j] = *src++;
00073 u[j] = *src++;
00074 y[j] = *src++;
00075 a[j] = *src++;
00076 } else {
00077 u[j] = *src++;
00078 y[j] = *src++;
00079 v[j] = *src++;
00080 a[j] = *src++;
00081 }
00082 }
00083
00084 y += pic->linesize[0];
00085 u += pic->linesize[1];
00086 v += pic->linesize[2];
00087 a += pic->linesize[3];
00088 }
00089
00090 *data_size = sizeof(AVFrame);
00091 *(AVFrame *)data = *pic;
00092
00093 return avpkt->size;
00094 }
00095
00096 static av_cold int v408_decode_close(AVCodecContext *avctx)
00097 {
00098 if (avctx->coded_frame->data[0])
00099 avctx->release_buffer(avctx, avctx->coded_frame);
00100
00101 av_freep(&avctx->coded_frame);
00102
00103 return 0;
00104 }
00105
00106 #if CONFIG_AYUV_DECODER
00107 AVCodec ff_ayuv_decoder = {
00108 .name = "ayuv",
00109 .type = AVMEDIA_TYPE_VIDEO,
00110 .id = CODEC_ID_AYUV,
00111 .init = v408_decode_init,
00112 .decode = v408_decode_frame,
00113 .close = v408_decode_close,
00114 .capabilities = CODEC_CAP_DR1,
00115 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed MS 4:4:4:4"),
00116 };
00117 #endif
00118 #if CONFIG_V408_DECODER
00119 AVCodec ff_v408_decoder = {
00120 .name = "v408",
00121 .type = AVMEDIA_TYPE_VIDEO,
00122 .id = CODEC_ID_V408,
00123 .init = v408_decode_init,
00124 .decode = v408_decode_frame,
00125 .close = v408_decode_close,
00126 .capabilities = CODEC_CAP_DR1,
00127 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed QT 4:4:4:4"),
00128 };
00129 #endif