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