Mercurial > libavcodec.hg
annotate aasc.c @ 9380:54e650136c87 libavcodec
Add a ff_h264_free_context function and call it from the H.264 parser.
This ensures that the parser will no longer leak memory for all SPS/PPS it encounters.
author | reimar |
---|---|
date | Fri, 10 Apr 2009 07:01:55 +0000 |
parents | 54bc8a2727b0 |
children | 4cab394c16ea |
rev | line source |
---|---|
2588
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
1 /* |
6683 | 2 * Autodesk RLE Decoder |
2588
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
3 * Copyright (C) 2005 the ffmpeg project |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
4 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
5 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
6 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
2588
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
2588
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
11 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
2588
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
16 * |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2588
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
2588
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
20 */ |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
21 |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
22 /** |
8718
e9d9d946f213
Use full internal pathname in doxygen @file directives.
diego
parents:
8264
diff
changeset
|
23 * @file libavcodec/aasc.c |
6683 | 24 * Autodesk RLE Video Decoder by Konstantin Shishkov |
2588
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
25 */ |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
26 |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
27 #include <stdio.h> |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
28 #include <stdlib.h> |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
29 #include <string.h> |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
30 |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
31 #include "avcodec.h" |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
32 #include "dsputil.h" |
7885
f874e1d5cf07
Factorize out code used for MS RLE format decoding in different decoders.
kostya
parents:
7040
diff
changeset
|
33 #include "msrledec.h" |
2588
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
34 |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
35 typedef struct AascContext { |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
36 AVCodecContext *avctx; |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
37 AVFrame frame; |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
38 } AascContext; |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
39 |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
40 #define FETCH_NEXT_STREAM_BYTE() \ |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
41 if (stream_ptr >= buf_size) \ |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
42 { \ |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
43 av_log(s->avctx, AV_LOG_ERROR, " AASC: stream ptr just went out of bounds (fetch)\n"); \ |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
44 break; \ |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
45 } \ |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
46 stream_byte = buf[stream_ptr++]; |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
47 |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6221
diff
changeset
|
48 static av_cold int aasc_decode_init(AVCodecContext *avctx) |
2588
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
49 { |
4827 | 50 AascContext *s = avctx->priv_data; |
2588
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
51 |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
52 s->avctx = avctx; |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
53 |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
54 avctx->pix_fmt = PIX_FMT_BGR24; |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
55 s->frame.data[0] = NULL; |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
56 |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
57 return 0; |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
58 } |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
59 |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
60 static int aasc_decode_frame(AVCodecContext *avctx, |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
61 void *data, int *data_size, |
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8720
diff
changeset
|
62 AVPacket *avpkt) |
2588
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
63 { |
9355
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8720
diff
changeset
|
64 const uint8_t *buf = avpkt->data; |
54bc8a2727b0
Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents:
8720
diff
changeset
|
65 int buf_size = avpkt->size; |
4827 | 66 AascContext *s = avctx->priv_data; |
8264 | 67 int compr, i, stride; |
2588
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
68 |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
69 s->frame.reference = 1; |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
70 s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
71 if (avctx->reget_buffer(avctx, &s->frame)) { |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
72 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
73 return -1; |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
74 } |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
75 |
8264 | 76 compr = AV_RL32(buf); |
77 buf += 4; | |
78 buf_size -= 4; | |
79 switch(compr){ | |
80 case 0: | |
81 stride = (avctx->width * 3 + 3) & ~3; | |
82 for(i = avctx->height - 1; i >= 0; i--){ | |
83 memcpy(s->frame.data[0] + i*s->frame.linesize[0], buf, avctx->width*3); | |
84 buf += stride; | |
85 } | |
86 break; | |
87 case 1: | |
8720
052c676c433b
Silence useless compiler warning when passing AVFrame* instead of AVPicture*
kostya
parents:
8718
diff
changeset
|
88 ff_msrle_decode(avctx, (AVPicture*)&s->frame, 8, buf - 4, buf_size + 4); |
8264 | 89 break; |
90 default: | |
91 av_log(avctx, AV_LOG_ERROR, "Unknown compression type %d\n", compr); | |
92 return -1; | |
93 } | |
2588
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
94 |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
95 *data_size = sizeof(AVFrame); |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
96 *(AVFrame*)data = s->frame; |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
97 |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
98 /* report that the buffer was completely consumed */ |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
99 return buf_size; |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
100 } |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
101 |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
6221
diff
changeset
|
102 static av_cold int aasc_decode_end(AVCodecContext *avctx) |
2588
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
103 { |
4827 | 104 AascContext *s = avctx->priv_data; |
2588
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
105 |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
106 /* release the last frame */ |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
107 if (s->frame.data[0]) |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
108 avctx->release_buffer(avctx, &s->frame); |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
109 |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
110 return 0; |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
111 } |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
112 |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
113 AVCodec aasc_decoder = { |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
114 "aasc", |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
115 CODEC_TYPE_VIDEO, |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
116 CODEC_ID_AASC, |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
117 sizeof(AascContext), |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
118 aasc_decode_init, |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
119 NULL, |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
120 aasc_decode_end, |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
121 aasc_decode_frame, |
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
122 CODEC_CAP_DR1, |
7040
e943e1409077
Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents:
6710
diff
changeset
|
123 .long_name = NULL_IF_CONFIG_SMALL("Autodesk RLE"), |
2588
b6b618986f80
Autodesk Animator Studio Codec (AASC) video decoder, courtesy of
melanson
parents:
diff
changeset
|
124 }; |