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 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 };