00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "libavutil/intreadwrite.h"
00024 #include "avcodec.h"
00025
00026 static av_cold int v308_encode_init(AVCodecContext *avctx)
00027 {
00028 if (avctx->width & 1) {
00029 av_log(avctx, AV_LOG_ERROR, "v308 requires width to be even.\n");
00030 return AVERROR_INVALIDDATA;
00031 }
00032
00033 avctx->coded_frame = avcodec_alloc_frame();
00034
00035 if (!avctx->coded_frame) {
00036 av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
00037 return AVERROR(ENOMEM);
00038 }
00039
00040 return 0;
00041 }
00042
00043 static int v308_encode_frame(AVCodecContext *avctx, uint8_t *buf,
00044 int buf_size, void *data)
00045 {
00046 AVFrame *pic = data;
00047 uint8_t *dst = buf;
00048 uint8_t *y, *u, *v;
00049 int i, j;
00050 int output_size = 0;
00051
00052 if (buf_size < avctx->width * avctx->height * 3) {
00053 av_log(avctx, AV_LOG_ERROR, "Out buffer is too small.\n");
00054 return AVERROR(ENOMEM);
00055 }
00056
00057 avctx->coded_frame->reference = 0;
00058 avctx->coded_frame->key_frame = 1;
00059 avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
00060
00061 y = pic->data[0];
00062 u = pic->data[1];
00063 v = pic->data[2];
00064
00065 for (i = 0; i < avctx->height; i++) {
00066 for (j = 0; j < avctx->width; j++) {
00067 *dst++ = v[j];
00068 *dst++ = y[j];
00069 *dst++ = u[j];
00070 output_size += 3;
00071 }
00072 y += pic->linesize[0];
00073 u += pic->linesize[1];
00074 v += pic->linesize[2];
00075 }
00076
00077 return output_size;
00078 }
00079
00080 static av_cold int v308_encode_close(AVCodecContext *avctx)
00081 {
00082 av_freep(&avctx->coded_frame);
00083
00084 return 0;
00085 }
00086
00087 AVCodec ff_v308_encoder = {
00088 .name = "v308",
00089 .type = AVMEDIA_TYPE_VIDEO,
00090 .id = CODEC_ID_V308,
00091 .init = v308_encode_init,
00092 .encode = v308_encode_frame,
00093 .close = v308_encode_close,
00094 .pix_fmts = (const enum PixelFormat[]){ PIX_FMT_YUV444P, PIX_FMT_NONE },
00095 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed 4:4:4"),
00096 };