Fixes Ticket1075
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
(cherry picked from commit 6f9803e5e02c557e1003cface9f3084a7e1e43e4)
Conflicts:
libavcodec/sonic.c
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
... | ... |
@@ -44,6 +44,7 @@ |
44 | 44 |
#define RIGHT_SIDE 2 |
45 | 45 |
|
46 | 46 |
typedef struct SonicContext { |
47 |
+ AVFrame frame; |
|
47 | 48 |
int lossless, decorrelation; |
48 | 49 |
|
49 | 50 |
int num_taps, downsampling; |
... | ... |
@@ -757,6 +758,9 @@ static av_cold int sonic_decode_init(AVCodecContext *avctx) |
757 | 757 |
s->channels = avctx->channels; |
758 | 758 |
s->samplerate = avctx->sample_rate; |
759 | 759 |
|
760 |
+ avcodec_get_frame_defaults(&s->frame); |
|
761 |
+ avctx->coded_frame = &s->frame; |
|
762 |
+ |
|
760 | 763 |
if (!avctx->extradata) |
761 | 764 |
{ |
762 | 765 |
av_log(avctx, AV_LOG_ERROR, "No mandatory headers present\n"); |
... | ... |
@@ -848,18 +852,25 @@ static av_cold int sonic_decode_close(AVCodecContext *avctx) |
848 | 848 |
} |
849 | 849 |
|
850 | 850 |
static int sonic_decode_frame(AVCodecContext *avctx, |
851 |
- void *data, int *data_size, |
|
851 |
+ void *data, int *got_frame_ptr, |
|
852 | 852 |
AVPacket *avpkt) |
853 | 853 |
{ |
854 | 854 |
const uint8_t *buf = avpkt->data; |
855 | 855 |
int buf_size = avpkt->size; |
856 | 856 |
SonicContext *s = avctx->priv_data; |
857 | 857 |
GetBitContext gb; |
858 |
- int i, quant, ch, j; |
|
859 |
- short *samples = data; |
|
858 |
+ int i, quant, ch, j, ret; |
|
859 |
+ short *samples; |
|
860 | 860 |
|
861 | 861 |
if (buf_size == 0) return 0; |
862 | 862 |
|
863 |
+ s->frame.nb_samples = s->frame_size; |
|
864 |
+ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { |
|
865 |
+ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); |
|
866 |
+ return ret; |
|
867 |
+ } |
|
868 |
+ samples = s->frame.data[0]; |
|
869 |
+ |
|
863 | 870 |
// av_log(NULL, AV_LOG_INFO, "buf_size: %d\n", buf_size); |
864 | 871 |
|
865 | 872 |
init_get_bits(&gb, buf, buf_size*8); |
... | ... |
@@ -930,20 +941,21 @@ static int sonic_decode_frame(AVCodecContext *avctx, |
930 | 930 |
|
931 | 931 |
align_get_bits(&gb); |
932 | 932 |
|
933 |
- *data_size = s->frame_size * 2; |
|
933 |
+ *got_frame_ptr = 1; |
|
934 |
+ *(AVFrame*)data = s->frame; |
|
934 | 935 |
|
935 | 936 |
return (get_bits_count(&gb)+7)/8; |
936 | 937 |
} |
937 | 938 |
|
938 | 939 |
AVCodec ff_sonic_decoder = { |
939 |
- "sonic", |
|
940 |
- AVMEDIA_TYPE_AUDIO, |
|
941 |
- CODEC_ID_SONIC, |
|
942 |
- sizeof(SonicContext), |
|
943 |
- sonic_decode_init, |
|
944 |
- NULL, |
|
945 |
- sonic_decode_close, |
|
946 |
- sonic_decode_frame, |
|
940 |
+ .name = "sonic", |
|
941 |
+ .type = AVMEDIA_TYPE_AUDIO, |
|
942 |
+ .id = CODEC_ID_SONIC, |
|
943 |
+ .priv_data_size = sizeof(SonicContext), |
|
944 |
+ .init = sonic_decode_init, |
|
945 |
+ .close = sonic_decode_close, |
|
946 |
+ .decode = sonic_decode_frame, |
|
947 |
+ .capabilities = CODEC_CAP_DR1, |
|
947 | 948 |
.long_name = NULL_IF_CONFIG_SMALL("Sonic"), |
948 | 949 |
}; |
949 | 950 |
#endif /* CONFIG_SONIC_DECODER */ |