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/common.h"
00024 #include "libavutil/intreadwrite.h"
00025 #include "avcodec.h"
00026 #include "internal.h"
00027
00028 static av_cold int v410_encode_init(AVCodecContext *avctx)
00029 {
00030 if (avctx->width & 1) {
00031 av_log(avctx, AV_LOG_ERROR, "v410 requires width to be even.\n");
00032 return AVERROR_INVALIDDATA;
00033 }
00034
00035 avctx->coded_frame = avcodec_alloc_frame();
00036
00037 if (!avctx->coded_frame) {
00038 av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n");
00039 return AVERROR(ENOMEM);
00040 }
00041
00042 return 0;
00043 }
00044
00045 static int v410_encode_frame(AVCodecContext *avctx, AVPacket *pkt,
00046 const AVFrame *pic, int *got_packet)
00047 {
00048 uint8_t *dst;
00049 uint16_t *y, *u, *v;
00050 uint32_t val;
00051 int i, j, ret;
00052
00053 if ((ret = ff_alloc_packet2(avctx, pkt, avctx->width * avctx->height * 4)) < 0)
00054 return ret;
00055 dst = pkt->data;
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 = (uint16_t *)pic->data[0];
00062 u = (uint16_t *)pic->data[1];
00063 v = (uint16_t *)pic->data[2];
00064
00065 for (i = 0; i < avctx->height; i++) {
00066 for (j = 0; j < avctx->width; j++) {
00067 val = u[j] << 2;
00068 val |= y[j] << 12;
00069 val |= (uint32_t) v[j] << 22;
00070 AV_WL32(dst, val);
00071 dst += 4;
00072 }
00073 y += pic->linesize[0] >> 1;
00074 u += pic->linesize[1] >> 1;
00075 v += pic->linesize[2] >> 1;
00076 }
00077
00078 pkt->flags |= AV_PKT_FLAG_KEY;
00079 *got_packet = 1;
00080 return 0;
00081 }
00082
00083 static av_cold int v410_encode_close(AVCodecContext *avctx)
00084 {
00085 av_freep(&avctx->coded_frame);
00086
00087 return 0;
00088 }
00089
00090 AVCodec ff_v410_encoder = {
00091 .name = "v410",
00092 .type = AVMEDIA_TYPE_VIDEO,
00093 .id = AV_CODEC_ID_V410,
00094 .init = v410_encode_init,
00095 .encode2 = v410_encode_frame,
00096 .close = v410_encode_close,
00097 .pix_fmts = (const enum PixelFormat[]){ PIX_FMT_YUV444P10, PIX_FMT_NONE },
00098 .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:4:4 10-bit"),
00099 };