00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #include "avcodec.h"
00027
00028 typedef struct AuraDecodeContext {
00029 AVCodecContext *avctx;
00030 AVFrame frame;
00031 } AuraDecodeContext;
00032
00033 static av_cold int aura_decode_init(AVCodecContext *avctx)
00034 {
00035 AuraDecodeContext *s = avctx->priv_data;
00036
00037 s->avctx = avctx;
00038
00039 if (avctx->width & 0x3)
00040 return -1;
00041 avctx->pix_fmt = PIX_FMT_YUV422P;
00042 avcodec_get_frame_defaults(&s->frame);
00043
00044 return 0;
00045 }
00046
00047 static int aura_decode_frame(AVCodecContext *avctx,
00048 void *data, int *data_size,
00049 AVPacket *pkt)
00050 {
00051 AuraDecodeContext *s=avctx->priv_data;
00052
00053 uint8_t *Y, *U, *V;
00054 uint8_t val;
00055 int x, y;
00056 const uint8_t *buf = pkt->data;
00057
00058
00059 const int8_t *delta_table = (const int8_t*)buf + 16;
00060
00061 if (pkt->size != 48 + avctx->height * avctx->width) {
00062 av_log(avctx, AV_LOG_ERROR, "got a buffer with %d bytes when %d were expected\n",
00063 pkt->size, 48 + avctx->height * avctx->width);
00064 return -1;
00065 }
00066
00067
00068 buf += 48;
00069
00070 if(s->frame.data[0])
00071 avctx->release_buffer(avctx, &s->frame);
00072
00073 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID;
00074 s->frame.reference = 0;
00075 if(avctx->get_buffer(avctx, &s->frame) < 0) {
00076 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
00077 return -1;
00078 }
00079
00080 Y = s->frame.data[0];
00081 U = s->frame.data[1];
00082 V = s->frame.data[2];
00083
00084
00085 for (y = 0; y < avctx->height; y++) {
00086
00087 val = *buf++;
00088 U[0] = val & 0xF0;
00089 Y[0] = val << 4;
00090 val = *buf++;
00091 V[0] = val & 0xF0;
00092 Y[1] = Y[0] + delta_table[val & 0xF];
00093 Y += 2; U++; V++;
00094
00095
00096 for (x = 1; x < (avctx->width >> 1); x++) {
00097 val = *buf++;
00098 U[0] = U[-1] + delta_table[val >> 4];
00099 Y[0] = Y[-1] + delta_table[val & 0xF];
00100 val = *buf++;
00101 V[0] = V[-1] + delta_table[val >> 4];
00102 Y[1] = Y[ 0] + delta_table[val & 0xF];
00103 Y += 2; U++; V++;
00104 }
00105 Y += s->frame.linesize[0] - avctx->width;
00106 U += s->frame.linesize[1] - (avctx->width >> 1);
00107 V += s->frame.linesize[2] - (avctx->width >> 1);
00108 }
00109
00110 *data_size=sizeof(AVFrame);
00111 *(AVFrame*)data= s->frame;
00112
00113 return pkt->size;
00114 }
00115
00116 static av_cold int aura_decode_end(AVCodecContext *avctx)
00117 {
00118 AuraDecodeContext *s = avctx->priv_data;
00119
00120 if (s->frame.data[0])
00121 avctx->release_buffer(avctx, &s->frame);
00122
00123 return 0;
00124 }
00125
00126 AVCodec ff_aura2_decoder = {
00127 .name = "aura2",
00128 .type = AVMEDIA_TYPE_VIDEO,
00129 .id = CODEC_ID_AURA2,
00130 .priv_data_size = sizeof(AuraDecodeContext),
00131 .init = aura_decode_init,
00132 .close = aura_decode_end,
00133 .decode = aura_decode_frame,
00134 .capabilities = CODEC_CAP_DR1,
00135 .long_name = NULL_IF_CONFIG_SMALL("Auravision Aura 2"),
00136 };